Downloads · 30 days
23
32% of all-time downloads
ryan-0608/MoS-DFlash-Qwen3-8B
MoS-DFlash-Qwen3-8B is a feature extraction model from ryan-0608. Use it when you need embeddings to search or compare text. It is set up for transformers.
This repository contains a routed Mixture of Speculators (MoS) checkpoint built on DFlash for speculative decoding with Qwen3-8B as the target model. MoS shares the DFlash attention parameters across domains while ret…
Downloads · 30 days
23
32% of all-time downloads
All-time downloads
72
Public
Parameters
664M
8.1 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors8.1 GB · 100%
From the Hugging Face model README
This repository contains a routed Mixture of Speculators (MoS) checkpoint built on DFlash for speculative decoding with Qwen3-8B as the target model. MoS shares the DFlash attention parameters across domains while retaining a separate MLP path for each domain. A request is assigned to one path before drafting, and that path is used throughout the response.
Important: this is a draft/speculator model, not a standalone language model. It cannot be used with the standard
text-generationpipeline by itself. The Qwen3-8B target model is required for generation.
num_domains=5)dflash.pysafetensors weight shardsThe learned request router, the Qwen3-8B target weights, exported standalone experts, and the optimized serving harness are not included in this repository.
| Item | Value |
|---|---|
| Experiment | MoS Arm B, the best-performing recipe in the 800K-sample comparison |
| Source run | dflash_e2e_genwarm |
| Checkpoint | epoch_5_step_149820 |
| Target model | Qwen/Qwen3-8B |
| Training mixture | 800K samples: 400K code and 100K from each of four other domains |
| Initialization | dflash_gen800k/epoch_3_step_49940 |
| Training | Shared attention and all five domain-specific MLP paths jointly optimized |
| Reported code-task acceptance length | 3.7186 (3.719) |
Only this selected checkpoint is published here. Other epochs, optimizer states, baselines, 250K experiments, 4B experiments, serving logs, and evaluation caches are excluded.
The checkpoint was validated with:
Install PyTorch for your CUDA environment first, then install the remaining dependencies:
pip install "transformers==4.57.1" "huggingface_hub>=0.36" accelerate safetensors typing_extensions
Because this repository contains custom model code, loading requires trust_remote_code=True:
import torch
from transformers import AutoModel
repo_id = "ryan-0608/MoS-DFlash-Qwen3-8B"
draft = AutoModel.from_pretrained(
repo_id,
trust_remote_code=True,
torch_dtype=torch.bfloat16,
)
draft.eval()
print(type(draft).__name__) # DFlashDraftModel
print(draft.num_domains) # 5
print(draft.block_size) # 16
For reproducible deployments, pin revision to a specific repository commit when loading remote code.
This routed checkpoint requires one domain ID per batch element. Set the IDs before every forward or generation call:
DOMAIN_TO_ID = {
"code": 0,
"math": 1,
"factual_qa": 2,
"creative_writing": 3,
"general": 4,
}
device = next(draft.parameters()).device
domain_ids = torch.tensor([DOMAIN_TO_ID["code"]], device=device)
draft.set_domain_ids(domain_ids)
For a batch of size B, pass a tensor of shape [B] containing one ID for each sample. set_domain_ids() only sets transient routing state; the IDs are not stored in the checkpoint.
If num_domains > 1 and no domain IDs are set, the model intentionally raises an error instead of silently selecting an expert.
The following example uses the reference spec_generate() implementation included in dflash.py. It is intended to verify model behavior; it is not the optimized serving benchmark used for throughput measurements.
import torch
from transformers import AutoModel, AutoModelForCausalLM, AutoTokenizer
target_id = "Qwen/Qwen3-8B"
draft_id = "ryan-0608/MoS-DFlash-Qwen3-8B"
device = "cuda:0"
dtype = torch.bfloat16
tokenizer = AutoTokenizer.from_pretrained(target_id)
target = AutoModelForCausalLM.from_pretrained(
target_id,
torch_dtype=dtype,
).to(device).eval()
draft = AutoModel.from_pretrained(
draft_id,
trust_remote_code=True,
torch_dtype=dtype,
).to(device).eval()
# Manual request-level routing for this example: select the code path.
draft.set_domain_ids(torch.tensor([0], device=device))
prompt = "Write a Python function that returns the longest common prefix."
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
with torch.inference_mode():
output_ids = draft.spec_generate(
target=target,
input_ids=input_ids,
max_new_tokens=128,
stop_token_ids=[tokenizer.eos_token_id],
temperature=0.0,
)
print(tokenizer.decode(output_ids[0], skip_special_tokens=True))
Both models must fit in accelerator memory. The target and draft should use the same tokenizer and compatible Qwen3-8B configuration.
MoS performs routing once per request, before the token-level drafting loop:
The route remains fixed for the response. The direct checkpoint interface exposes this decision through set_domain_ids() for manual or externally supplied routing.
For optimized serving, the five paths can instead be exported as five standalone DFlash drafters, each combining the shared attention parameters with one domain-specific MLP path. A separate request router then dispatches each request to the corresponding target-plus-drafter service. The router checkpoint and export/serving utilities are part of the MoS experimental stack and are not packaged in this model repository.
config.json: DFlash configuration, including num_domains=5, block size 16, and the target hidden-state layersdflash.py: custom DFlashDraftModel implementation and reference speculative-generation loopmodel-00001-of-00002.safetensorsmodel-00002-of-00002.safetensorsmodel.safetensors.index.jsonThis checkpoint is released for research on multi-domain speculative decoding, request-level speculator routing, and MoS evaluation with Qwen3-8B. It is intended for researchers who already have a compatible Qwen3-8B target and DFlash inference environment.