Views
No views yet
Important: this is a draft/speculator model, not a standalone language model. It cannot be used with the standardtext-generationpipeline by itself. The Qwen3-8B target model is required for generation.
num_domains=5)dflash.pysafetensors weight shards| 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) |
pip install "transformers==4.57.1" "huggingface_hub>=0.36" accelerate safetensors typing_extensionstrust_remote_code=True:1import torch
2from transformers import AutoModel
3
4repo_id = "ryan-0608/MoS-DFlash-Qwen3-8B"
5
6draft = AutoModel.from_pretrained(
7 repo_id,
8 trust_remote_code=True,
9 torch_dtype=torch.bfloat16,
10)
11draft.eval()
12
13print(type(draft).__name__) # DFlashDraftModel
14print(draft.num_domains) # 5
15print(draft.block_size) # 16revision to a specific repository commit when loading remote code.1DOMAIN_TO_ID = {
2 "code": 0,
3 "math": 1,
4 "factual_qa": 2,
5 "creative_writing": 3,
6 "general": 4,
7}
8
9device = next(draft.parameters()).device
10domain_ids = torch.tensor([DOMAIN_TO_ID["code"]], device=device)
11draft.set_domain_ids(domain_ids)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.num_domains > 1 and no domain IDs are set, the model intentionally raises an error instead of silently selecting an expert.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.1import torch
2from transformers import AutoModel, AutoModelForCausalLM, AutoTokenizer
3
4target_id = "Qwen/Qwen3-8B"
5draft_id = "ryan-0608/MoS-DFlash-Qwen3-8B"
6device = "cuda:0"
7dtype = torch.bfloat16
8
9tokenizer = AutoTokenizer.from_pretrained(target_id)
10target = AutoModelForCausalLM.from_pretrained(
11 target_id,
12 torch_dtype=dtype,
13).to(device).eval()
14draft = AutoModel.from_pretrained(
15 draft_id,
16 trust_remote_code=True,
17 torch_dtype=dtype,
18).to(device).eval()
19
20# Manual request-level routing for this example: select the code path.
21draft.set_domain_ids(torch.tensor([0], device=device))
22
23prompt = "Write a Python function that returns the longest common prefix."
24input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
25
26with torch.inference_mode():
27 output_ids = draft.spec_generate(
28 target=target,
29 input_ids=input_ids,
30 max_new_tokens=128,
31 stop_token_ids=[tokenizer.eos_token_id],
32 temperature=0.0,
33 )
34
35print(tokenizer.decode(output_ids[0], skip_special_tokens=True))set_domain_ids() for manual or externally supplied routing.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.json