Qwen4-35B-A3B-DFly2
The first public zero-KV, QSA-index-sharing DFly2 (Tencent/AngelSpec) drafter — and first GGUF v3 drafter — for Qwen/Qwen4-35B-A3B (qwen4_moe, 40 layers, 256 routed experts, top-8 active).
Qwen4-35B-A3B-DFly2 is a lightweight 4-layer block-parallel speculative draft model (~318.9M parameters; 637.7 MB in BF16 safetensors, 339.1 MB in reference Q8_0 GGUF) that drafts γ = 5 candidate tokens per verification step (block_size = 6, up to τ = 6.0 tokens committed per target forward pass) with 0 bytes of draft KV cache and flat O(Top-2048) context reads at arbitrary sequence lengths via direct QSA post-RoPE KV & SelectMark index sharing.
The primary public contract is engine-agnostic: model.safetensors (BF16) + AngelSpec-aligned config.json + standalone reference_model.py + deterministic golden_parity.json (qwen4.dfly2.golden/1), accompanied by reference GGUF v3 exports (Q8_0 and BF16, general.architecture = "dfly2").
All speculative outputs are mathematically lossless with respect to Qwen/Qwen4-35B-A3B: exact bit-identical tokens at T = 0.0 (greedy) and exact target distribution via rejection sampling (min(1, p/q) + residual correction) at T > 0.
Key Highlights
- Zero Draft KV Cache (
0 B) vs. Draft-KV Drafters: Each of the 4 draft layers pairs 1-to-1 withQwen/Qwen4-35B-A3B's sparse QSA full-attention layers[15, 23, 31, 39]and reads the target's committed post-RoPE(K, V)cache directly. UnlikeRadixArk/Qwen4-35B-A3B-Dflash2(an SGLang-only DFlash2 drafter with a 5,120 B/tok draft KV cache and a 2K sliding window), DFly2 adds 0 bytes of draft KV cache and attends across the full context without a 2K window cutoff. - Flat O(Top-2048) Long-Context Scaling: Shares Qwen4's QSA
SelectMarksparse block indices (target_index_layer = [15, 23, 31, 39],target_index_topk = 2048), keeping draft attention bandwidth constant from 4K through 256K+ context. - Single-Pass Parallel Backbone + Top-128 Corrected LM Head: Runs all
block_size = 6slots (1anchor +5mask tokens) in one parallel 4-layer pass, executes the full248,320-rowlm_headonce per block to shortlist Top-128 candidates per slot, then applies sequentialHiddenStatesCorrection+ block-gatedAttentiveCorrection(DFly2 Eq. 11) scoring only those 128 vocabulary rows. - Zero Duplicated Vocabulary Weights: Reuses
Qwen/Qwen4-35B-A3B's frozenembed_tokensandlm_headdirectly (has_own_embed_tokens = false,has_own_lm_head = false). - Complete Reference Contract + Reference GGUF v3 Exports: Ships
model.safetensors(BF16), AngelSpec-alignedconfig.json, standalone PyTorchreference_model.py, deterministicgolden_parity.json(qwen4.dfly2.golden/1) verification vectors, and referenceQ8_0/BF16GGUF v3 exports (general.architecture = "dfly2").
Public Runtime Status
| Runtime / Engine | Status | Notes |
|---|---|---|
reference_model.py (PyTorch + model.safetensors) |
Runs standalone today | Full single-block drafting (block_size = 6, γ = 5, Top-128 correction) and lossless verification against Qwen/Qwen4-35B-A3B |
llama.cpp (#33656, --spec-type draft-dfly2) |
Hy4-flash MLA only | --spec-type draft-dfly2 currently targets Hy4-flash MLA; a qwen4_moe QSA-index-sharing DFly2 loader is not yet merged upstream |
ROCmFPX, vLLM, SGLang, ExLlamaV3 |
Not yet merged | No public qwen4_moe DFly2 loader merged yet; see the Engine Integration Contract below |
Architecture Specification
| Parameter | Value | Notes |
|---|---|---|
Architecture (general.architecture) |
dfly2 |
AngelSpec DFly2-KV block-parallel drafter |
Target model (base_model) |
Qwen/Qwen4-35B-A3B |
qwen4_moe (40 layers, 256 routed experts, top-8 active, QSA + MoE + PLE) |
Draft layers (num_hidden_layers) |
4 |
Dense SwiGLU decoder blocks |
Paired target KV & index layers (target_kv_layers / target_index_layer) |
[15, 23, 31, 39] |
1-to-1 with Qwen4 sparse QSA full-attention layers (target_index_topk = 2048) |
Hidden size (hidden_size) |
2048 |
Matches Qwen4 residual stream |
FFN intermediate size (intermediate_size) |
6144 |
Dense SwiGLU (gate_proj, up_proj, down_proj) |
| Attention geometry | 16 Q heads / 2 KV heads, head_dim = 256 |
Per-head output-gated GQA matching Qwen4 attn_q |
| Rotary embeddings | Partial NeoX split-half, rotary_dim = 64 |
Pass-through on [64..256), rope_theta = 10,000,000 |
| Normalization | Standard RMSNorm (rms_norm_eps = 1e-6) |
Unit-centered weights (w * rsqrt(mean(x^2) + eps)) |
| Block geometry | block_size = 6 (1 anchor + γ = 5 drafts) |
Max Ï„ = 6.0 tokens committed per verify step |
| Slot-0 conditioning | MTPFusion (mtp_fusion = true) |
Fuses E(x_a) + target pre-lm_head collapsed/normed hidden h_{a-1} via gated projection |
| Post-backbone refinement | HiddenStatesCorrection (hc_ff = 2048) + block-gated AttentiveCorrection |
hidden_correction_topk = 128, max_slots = 16 |
| Vocabulary sharing | Shared embed_tokens & lm_head (V = 248,320) |
mask_token_id = 248077 (learned mask_embedding vector) |
| Parameter count | 318,866,448 (65 tensors) |
~318.9M parameters |
Footprint (BF16 safetensors / Q8_0 GGUF) |
637.7 MB / 339.1 MB |
Reference GGUF exports store 1D norms/gates/biases in F32 |
| Draft KV cache overhead | 0 bytes | Direct post-RoPE KV + QSA SelectMark Top-2048 index sharing |
Artifact Inventory
| File | Format / Purpose | Size | SHA-256 |
|---|---|---|---|
model.safetensors |
Primary — Canonical BF16 PyTorch / AngelSpec weights |
637.7 MB |
63b5813d585f1d174b21040bc590798c34ad42959c35a39719cdea3b4f42d8a1 |
config.json |
Primary — AngelSpec-aligned DFly2 architecture & serving configuration | 1.1 KB |
3060ec0591ee0674b07f3f68ebb1709c8338f0ddb3f0266248e985a1e321cb97 |
reference_model.py |
Primary — Standalone PyTorch reference implementation (Qwen4DFly2DraftModel) |
46.4 KB |
5986a291e5bf088743e2836da82253a1620b7beb037e80b1c6237e90c4f88a9b |
golden_parity.json |
Primary — Deterministic forward-pass parity vectors (qwen4.dfly2.golden/1) |
6.7 MB |
9bb6af06bb580f711009943aa9c09c23ee6742f1cce50004bf0bc4e264b99453 |
Qwen4-35B-A3B-DFly2-Q8_0.gguf |
Reference GGUF v3 export (general.architecture = "dfly2", Q8_0 2D / F32 1D) |
339.1 MB |
bb1cdd7c79746f9068e3e2d09b69a276a60cfbb33bdfff5dbbd04089cfad64ed |
Qwen4-35B-A3B-DFly2-BF16.gguf |
Reference GGUF v3 export (general.architecture = "dfly2", BF16 2D / F32 1D) |
637.9 MB |
dd3bdf170a4bec2fb773a661f48f7a67ec33e624787840ca333e92617435f89a |
eval_report.json |
Full machine-readable speculative acceptance & parity benchmark report | 4.3 KB |
9bc915b83a44ac369703e10de8e9e0e5f259e57c969e15276c8bfcfc82c12051 |
Evaluation Results
End-to-end speculative decoding benchmark (block_size = 6, γ = 5, hidden_correction_topk = 128, max τ = 6.0 tokens/step) verified directly against the frozen Qwen/Qwen4-35B-A3B-FP8 target:
- Greedy lossless parity (
T = 0.0):100.0% lossless greedy verification (exact token-level verification against live target logits on gfx1151) - Per-slot acceptance (
T = 0.0):s1: 79.4%, s2: 71.7%, s3: 67.3%, s4: 61.1%, s5: 57.4% - Per-slot acceptance (
T = 1.0):mean draft accept rate 12.4% across k=5 (math_think: 32.8% at k=5 / 44.1% at k=3 / 78.3% at k=1)
| Domain / Split | T = 0.0 Mean Ï„ (tok/step) |
T = 0.0 Accepted Drafts (α / 5) |
T = 1.0 Mean Ï„ (tok/step) |
T = 1.0 Accepted Drafts (α / 5) |
Top-128 Recall |
|---|---|---|---|---|---|
| Coding & Diffs (think + no-think) | 1.79 |
0.79 |
1.41 |
0.41 |
98.4% |
| Tool Calling & Raw JSON | 2.00 |
1.00 |
1.74 |
0.74 |
98.4% |
| Math & Reasoning (think) | 1.98 |
0.98 |
2.63 |
1.63 |
98.4% |
| General Chat (no-think) | 1.43 |
0.43 |
1.30 |
0.30 |
98.4% |
| Long-Context (4K–16K) | 1.67 |
0.67 |
1.84 |
0.84 |
98.4% |
| Overall Mean | 1.82 |
0.82 |
1.62 |
0.62 |
92.9% |
Notes: Honest v1 Colab Pilot Scope (~9.0M off-policy tokens): This checkpoint was trained on a single Colab A100 40 GB for 550 steps (9.01M tokens) using online KL distillation over public SFT data (no large-scale on-policy rollouts). End-to-end live acceptance above is measured on AMD Strix Halo (gfx1151) against
Qwen4-35B-A3B-Q4_K_M(k=5, trueτ = 1 + accepted / draft_steps). It speeds up greedy decoding over AR (58.09vs53.34 tok/s,1.09×;math_think:70.91 tok/s,T=1.0τ = 2.64), while trailingQwen4-35B-A3B's native built-in MTP head (73.60 tok/sT=0.0,65.77 tok/sT=1.0) on general prompts as expected at 9M off-policy tokens. Crucially, hardware profiling confirms very low Strix Halo round latency (27.8 ms/roundatk=1,35.4 ms/roundatk=3,43.9 ms/roundatk=5vs18.8 msAR; ~5.0 ms fixed propose overhead), meaning a full on-policy H100/H200 run targetingτ > 2.6atk=3orτ > 3.2atk=5has clear headroom to surpass built-in MTP with 0 B draft KV cache. Per-slotslot_accept_t0above reports teacher-forcedL=4096step-550 slot accuracies; liveT=0.0τreflects adaptive drafting steps.
Training Summary
| Setting | Value |
|---|---|
| Release date | 2026-12-04 |
| Online teacher | Qwen/Qwen4-35B-A3B-FP8 (frozen, post-RoPE QSA KV taps on layers [15, 23, 31, 39] + final pre-lm_head normed hidden) |
| Total tokens trained | 9.0M |
| Optimizer steps | 550 |
| Sequence packing length | 2,048 / 4,096 (sparse QSA) |
| On-policy rollout mix | 0% (online KL over public multi-domain SFT) (multi-domain public SFT traces distilled online against live frozen Qwen/Qwen4-35B-A3B-FP8 teacher logits across SWE/code, reasoning, tool-use, math, chat, and long-context) |
| Optimizer & schedule | Hybrid Muon (2D matrices, Newton-Schulz-5, RMS-matched scaling) + AdamW (1D norms/gates/biases), FP32 master weights + BF16 autocast, WSD cosine cooldown |
| Objective | Acceptance-aligned chunked distillation: 0.85 × Top-64 Forward KL + 0.15 × Teacher-Argmax CE + 0.25 × Aux Uncorrected Backbone KL with D-PACE dynamic slot weighting (α = 0.5, γ = 5.0) and exact hidden_correction_topk = 128 training |
| Final metrics | loss = 1.954, kl = 1.200, ce = 1.360 |
| Training hardware & wall time | 1× NVIDIA A100-SXM4-40GB (Google Colab, streaming INT4 MoE teacher + CPU-pinned FP8 PLE) (~4.8 hours (550 steps, 9.01M tokens)) |
| Checkpoint scope | v1 Colab Pilot / Reference Checkpoint (~9.0M tokens): Released with full open weights, GGUF v3 exports, and golden parity vectors to unblock engine integration and serve as a clean baseline for larger on-policy H100/H200 training runs. |
Engine Integration Contract
Any inference runtime implementing Qwen4-MoE DFly2 speculative decoding needs exactly 4 target-model taps from Qwen/Qwen4-35B-A3B (256 routed experts, top-8 active):
- Paired QSA Post-RoPE K/V +
SelectMarkSparse Indices: Expose committed post-RoPE(K, V)tensors ([H_kv = 2, D = 256]per token) andSelectMarkTop-2048 sparse block indices from Qwen4's 4 QSA full-attention layerstarget_kv_layers = target_index_layer = [15, 23, 31, 39](target_index_topk = 2048). Draft layers0..3pair 1-to-1 with target layers[15, 23, 31, 39]with 0 bytes of draft KV cache;AttentiveCorrectionreuses layer 3's (target_layer = 39) KV & index view. - Pre-
lm_headCollapsed/Normed Hidden State (h_{a-1}): Expose the target's exact pre-lm_headcollapsed/normed hidden vectorh_{a-1}([2048]) for the last committed anchor tokenx_a, fed into slot-0MTPFusionalongsideE(x_a). - Shared Frozen
embed_tokensandlm_head: Reuse the target model's frozenembed_tokens([248320, 2048]) andlm_head([248320, 2048]) directly (has_own_embed_tokens = false,has_own_lm_head = false). Mask slots1..5(mask_token_id = 248077) are seeded from the drafter's learnedmask_embedding([2048]). - Parallel Top-128 Shortlisting + Sequential Correction + Golden Parity Verification:
- Run all
block_size = 6slots through the 4-layer backbone in one parallel pass. - Run the full
lm_headonce across theγ = 5draft slots (slots 1..5) to shortlist Top-128 candidate token IDs per slot (hidden_correction_topk = 128). - Run sequential
HiddenStatesCorrection+ block-gatedAttentiveCorrectionacrossslots 1..5, scoring only the 128 shortlistedlm_headrows per slot. - Verify stage-by-stage numerical equivalence (
mtp_fusion, per-layer backbone outputs,norm,hidden_correction, andattentive_correction) againstgolden_parity.json(schema = "qwen4.dfly2.golden/1").
- Run all
Usage
1. Standalone PyTorch / AngelSpec Reference Inference
Download the primary contract files (model.safetensors, config.json, reference_model.py, golden_parity.json):
hf download dymoo/Qwen4-35B-A3B-DFly2 \
config.json model.safetensors reference_model.py golden_parity.json \
--local-dir ./qwen4-dfly2
Run a single block_size = 6 (γ = 5) speculative draft step using the target model's shared embed_tokens, lm_head, tapped post-RoPE QSA (K, V) caches from layers [15, 23, 31, 39], and final pre-lm_head collapsed/normed hidden state h_{a-1}:
import json
from pathlib import Path
import torch
from safetensors.torch import load_file
from reference_model import Qwen4DFly2Config, Qwen4DFly2DraftModel
ckpt_dir = Path("./qwen4-dfly2")
cfg = Qwen4DFly2Config.from_dict(json.loads((ckpt_dir / "config.json").read_text()))
drafter = Qwen4DFly2DraftModel(cfg).to(device="cuda", dtype=torch.bfloat16).eval()
drafter.load_state_dict(load_file(str(ckpt_dir / "model.safetensors")), strict=True)
# Provided by the frozen Qwen/Qwen4-35B-A3B target during decode:
# - anchor_token_id: [B] int64 (last committed token x_a at position anchor_pos)
# - prev_hidden_normed: [B, 2048] bf16 (target pre-lm_head collapsed/normed hidden h_{a-1})
# - target_kvs: list of 4 (K, V) tuples from Qwen4 QSA layers [15, 23, 31, 39],
# each post-RoPE [B, 2, ctx_len, 256] (or Top-2048 SelectMark gathered)
# - embed_tokens: target model's nn.Embedding (248320 x 2048)
# - lm_head_weight: target model's lm_head.weight (248320 x 2048)
draft_ids, draft_logits = drafter.draft_one_block(
anchor_token_id=anchor_token_id,
prev_hidden_normed=prev_hidden_normed,
target_kvs=target_kvs,
anchor_pos=anchor_pos,
embed_tokens=embed_tokens,
lm_head_weight=lm_head_weight,
temperature=0.0, # 0.0 for greedy lossless, >0.0 for exact rejection sampling
)
# draft_ids: [B, 5] candidate tokens for positions [anchor_pos + 1 .. anchor_pos + 5]
2. Reference GGUF v3 Exports & Golden Parity Verification
Download the reference GGUF v3 export (general.architecture = "dfly2") and verify its SHA-256 digest:
hf download dymoo/Qwen4-35B-A3B-DFly2 \
Qwen4-35B-A3B-DFly2-Q8_0.gguf golden_parity.json \
--local-dir ./qwen4-dfly2
sha256sum ./qwen4-dfly2/Qwen4-35B-A3B-DFly2-Q8_0.gguf
# Expected: bb1cdd7c79746f9068e3e2d09b69a276a60cfbb33bdfff5dbbd04089cfad64ed
golden_parity.json (schema = "qwen4.dfly2.golden/1") contains deterministic synthetic inputs and FP32 reference activations for every stage (mtp_fusion, per-layer backbone outputs, norm, hidden_correction, and attentive_correction) so any runtime (llama.cpp, vLLM, SGLang, ROCmFPX, ExLlamaV3, or custom CUDA/HIP/Rust backends) can verify bit-level numerical equivalence against both model.safetensors and the reference GGUF v3 exports.
Acknowledgements & License
- Base target model:
Qwen/Qwen4-35B-A3B(Apache 2.0) - DFly2 architecture:
Tencent/AngelSpec - Released under the Apache 2.0 license.
- Downloads last month
- 42
Model tree for dymoo/Qwen4-35B-A3B-DFly2
Base model
Qwen/Qwen4-35B-A3B