Text Generation
Safetensors
legospec
speculative-decoding
dflux

Qwen3-4B-DFlux

Qwen3-4B-DFlux is a DFlux speculative draft model for Qwen/Qwen3-4B, trained with LEGOSpec (LEGOSpec: A Composable and Efficient Framework for Speculative Draft Design and Training).

DFlux is a balanced general-purpose speculative draft architecture that combines:

  • SWA–GQA Hybrid Backbone with Block-Local Convolution: 5 Sliding-Window Attention layers followed by 1 dense GQA full-attention layer, each equipped with a block-local grouped convolution to preserve within-block dependencies across both short and long contexts while bounding historical KV cache growth.
  • Residual Corrector (R-Corrector): Computes parallel predecessor–successor residual corrections over the top-16 candidates while retaining full-vocabulary base logits, preserving the exact target distribution under rejection sampling.
  • Hierarchical Supervision: Jointly trains the backbone with forward KL for candidate coverage and the final output with D-PAL loss to directly optimize block-level acceptance length.

Training Data & Setup

  • Dataset (1.4M samples total):
  • Supervision: Prompts are retained and responses are regenerated by Qwen/Qwen3-4B at T = 1.
  • Optimization: Trained for 6 epochs on 16 NVIDIA H800 GPUs with global batch size 128, Adam (lr = 6e-4) and Muon (lr = 0.01).

Evaluation Results

Mean Acceptance Length (τ) at T = 1

Evaluated with block size 8 (except Qwen3-4B DFlash2 which retains its native block size 9), maximum generation length 1,024 tokens, and rejection sampling, averaged over 5 random seeds. Long-context benchmarks (LongBench-v2 MD-QA, L-ICL, SD-QA, and SWE-bench) use 32K–64K-token inputs.

Method Alpaca MT-Bench GSM8K MATH-500 MBPP LCB MD-QA L-ICL SD-QA SWE
DFlash 3.23 3.75 5.63 5.32 4.77 3.97 2.14 2.52 2.50 1.58
DFlash2 3.25 3.88 5.87 5.64 4.83 3.89 3.12 3.45 3.17 2.96
DSpark 3.57 3.89 6.04 5.61 5.12 4.30 2.42 2.75 2.67 2.24
DLite 3.56 3.88 6.12 5.98 5.14 4.04 2.74 3.11 2.98 3.03
DFlux (Ours) 4.03 4.39 6.47 6.35 5.74 4.95 3.60 3.81 3.63 4.08

Usage

This checkpoint is a speculative draft model and requires its matching target model (Qwen/Qwen3-4B) for shared embeddings, output head, and verification.

Install LEGOSpec and run speculative generation:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from legospec import LegoSpecConfig, LegoSpecModel

target_path = "Qwen/Qwen3-4B"
draft_path = "SJTU-DAI-Sys/Qwen3-4B-DFlux"

tokenizer = AutoTokenizer.from_pretrained(target_path)
target = AutoModelForCausalLM.from_pretrained(
    target_path, dtype=torch.bfloat16
).cuda().eval()

config = LegoSpecConfig.from_pretrained(draft_path)
draft = LegoSpecModel.from_pretrained(
    draft_path, config=config, dtype=torch.bfloat16
).cuda().eval()

text = tokenizer.apply_chat_template(
    [{"role": "user", "content": "Explain speculative decoding briefly."}],
    tokenize=False,
    add_generation_prompt=True,
    enable_thinking=False,
)
input_ids = tokenizer(text, return_tensors="pt", add_special_tokens=False).input_ids.cuda()
eos = target.generation_config.eos_token_id
stop_ids = [] if eos is None else eos if isinstance(eos, list) else [eos]

with torch.inference_mode():
    output_ids = draft.spec_generate(
        target,
        input_ids,
        max_new_tokens=128,
        stop_token_ids=stop_ids,
        temperature=0.0,
        top_p=1.0,
        seed=42,
    )

print(tokenizer.decode(output_ids[0, input_ids.shape[1]:], skip_special_tokens=True))

See the LEGOSpec repository for SGLang serving and evaluation scripts.

Citation

TBD
Downloads last month
-
Safetensors
Model size
0.6B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for SJTU-DAI-Sys/Qwen3-4B-DFlux

Finetuned
Qwen/Qwen3-4B
Finetuned
(1,324)
this model

Datasets used to train SJTU-DAI-Sys/Qwen3-4B-DFlux

Collection including SJTU-DAI-Sys/Qwen3-4B-DFlux

Paper for SJTU-DAI-Sys/Qwen3-4B-DFlux