# 03 · DSpark: the drafter, verifier and scheduler

Primary authority: [Cheng et al., arXiv:2607.05147v1](https://arxiv.org/html/2607.05147v1), [DeepSpec at `005e03b81`](https://github.com/deepseek-ai/DeepSpec/tree/005e03b81cec38b7da6399833d609ee89a2587f2), and [Qwen3-4B research draft config at `3457dff`](https://huggingface.co/deepseek-ai/dspark_qwen3_4b_block7/blob/3457dff1417cb84927f6098a5fcb7cee85c934b7/config.json). Public config and training code are **not** the same artifacts as DeepSeek's serving engine. This note does not assert that a model was loaded or run.

## One round, including shapes

Let `B` be request batch size (the released single-request proposal helper asserts `B=1`), `L` available cached target prefix positions, `G` maximum proposal slots, `D` hidden width, `V` vocabulary, `r` transition rank, `m` tapped layers. Shape labels below are logical, not an assertion that large tensors are fully materialized on the GPU.

| Step | What enters → what leaves | Equation / reading |
|---|---|---|
| 1. Target context | `m` tapped `[B,L,D]` → concat `[B,L,mD]` → `[B,L,D]` | \(H_c=\mathrm{RMSNorm}(\mathrm{Concat}(H^{\ell_i})W_c^\top)\). `extract_context_feature` offsets nonnegative layer IDs by 1 in the hidden-state tuple so the embedding output is not mistaken for layer 0. |
| 2. Anchor and slots | Last available token plus `G−1` masks → IDs `[B,G]` → embeddings `[B,G,D]` | Anchor position also **predicts the first draft token**. Do not add a spare output slot or treat [MASK] as a categorical diffusion time variable. |
| 3. Parallel backbone | `[B,G,D]` query branch and context-plus-block KV → `[B,G,D]` → base logits `[B,G,V]` | The denominator in attention is \(\sqrt{d_{\rm head}}\); keys/values include projected context and the current block. In packed training, each block sees context strictly before its anchor plus its own block, not other draft blocks. |
| 4. Markov projection and sampling | Position logits `[B,V]`, previous ID `[B]` → lookup `[B,r]` → vocabulary bias `[B,V]` → corrected probabilities `[B,V]` → sampled ID `[B]` | \(b_k=W_1[x_{k-1}]W_2\), \(q_k=\mathrm{softmax}(U_k+b_k)\) at temperature one. Next step uses the **sampled** ID. In PyTorch, the second weight is stored `[V,r]`, transpose of the paper's row-vector convention. |
| 5. Confidence | \(h_k\) `[B,D]` and previous token vector `[B,r]` → `[B,D+r]` → scalar logit `[B]` | \(c_k=\mathrm{sigmoid}(u^\top[h_k;e_{k-1}]+b)\) for the released biased Linear, optionally using the Markov feature as configured. The paper writes the projection without a bias. \(c_k\) ranks/calibrates future acceptance; it is **not** the acceptance decision for the sampled token. |
| 6. Scheduler | `[B,G]` conditional confidence → per-request survival and a prefix length | \(a_{r,j}=\prod_{i\le j}c_{r,i}\). Only prefix extensions are eligible. This may prune low-confidence suffix slots before verification. |
| 7. Verify and commit | Anchor + retained proposal (logical `[B,1+\ell]` if equal lengths; ragged otherwise) → target distributions → committed prefix + one target token | Accept left to right at \(\min(1,p_k(x_k)/q_k(x_k))\). First reject ⇒ positive-residual correction; all pass ⇒ next target sample. Discard the remaining speculative suffix. Stop/length handling can truncate protocol output. |

Check source: [attention, embeddings and confidence](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/deepspec/modeling/dspark/qwen3/modeling.py#L43), [anchor mask](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/deepspec/modeling/dspark/common.py#L78), [Markov implementation](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/deepspec/modeling/dspark/markov_head.py#L8), [target verification](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/deepspec/eval/base_evaluator.py#L186).

### Research checkpoint vs production paper

**Qwen3-4B research draft (config):** `G=7`, `D=2560`, `V=151936`, `m=5`, `r=256`, 5 draft layers, 32 query heads and 8 KV heads with head dimension 128, FFN width 9728, target taps `[1,9,17,25,33]`. For `B=1,L=12` the concat is `[1,12,12800]`; draft output `[1,7,2560]`; base logits `[1,7,151936]`; Q `[1,32,7,128]`, K/V `[1,8,19,128]` before any cache/backend-specific rearrangement. GQA head counts are not `D/128`: Q uses its own projection width `32×128`. The rank-256 matrices contain `2×151936×256 = 77,791,232` elements combined (derived from shapes, **not** the total draft parameter count).

**Public verification handoff:** Draft IDs `[1,7]` contain one anchor and six masks. This predicts seven new tokens: the anchor query itself predicts the first proposal. With the full proposed prefix the target receives `[1,8]` IDs, the sampler has draft `q [1,7,151936]` from corrected logits and target `p [1,8,151936]` from the target forward. At `ℓ=0`, send the anchor alone and do not supply `q`. The anchor's target row scores proposal 1; the last target row supplies the bonus when all checked proposals pass. At a continuing round, keep the already cached history plus the anchor and accepted prefix; the correction/bonus is the next anchor (not cached yet). See [public proposal limit and packing](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/deepspec/eval/dspark/evaluator.py#L41-L42) and [cache update](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/deepspec/eval/base_evaluator.py#L411-L426).

**V4 production (§§5.1–5.4):** Three MoE draft layers with mHC, 128-token sliding-window attention, maximum `G=5`, Markov head. The [V4-Flash-DSpark `62af8ff` config](https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash-DSpark/blob/62af8fffb2f7030cac4de2f0169f5b8d1101b646/config.json) lists taps `[40,41,42]`, rank 256; the [V4-Pro-DSpark `7c09739` config](https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro-DSpark/blob/7c09739fd136abfb70a49ec334157f65f45b52cd/config.json) lists `[58,59,60]`, rank 512. The public Qwen packet shapes do not describe the V4 engine layout. Do not interpret root `num_hidden_layers` of a combined config as the number of draft layers, or NVIDIA repackager counts as independently verified DeepSeek observations.

## Why speculative sampling can preserve the target

For fixed history, draft \(x\sim q\). The chance of producing \(x\) on the accept branch is \(q(x)\min(1,p(x)/q(x))=\min(q(x),p(x))\) on the support of \(q\). Total reject probability is \(\sum_v[p(v)-q(v)]_+=\frac12\|p-q\|_1\). The correction distribution is its normalized positive part. Summing accepted and corrected mass gives \(p(x)\). Apply this at every valid prefix, using **actual** sampling distributions (including temperature or truncation) and a non-anticipating admission rule. If p=q there is no rejection; there is no reason to sample from an all-zero residual. A target logit check at all positions in parallel does not imply accepting disconnected positions after the first rejection.

**Worked example:** Vocabulary `[A,B]`, `p=[.7,.3]`, `q=[.5,.5]`. Conditional accept for A is `1`, for B `.6`. Accepted mass `[.5,.3]`, rejection mass `.2`, replacement distribution `[1,0]`, emitted mass `[.7,.3]`. In [Appendix A](https://arxiv.org/html/2607.05147v1#A1), the one-request profile `(1.0, .5, .45)` for 0/1/2 extra slots and first confidence `.8` gives estimated throughput `1.00` and `.90` at 0 and 1 slot. A draw of A makes `c₂=.9` and `Θ₂=1.134`; a draw of B makes `c₂=0` and `Θ₂=.81`. The causal first-stop procedure chooses 0 for either draw. The invalid retrospective search admits two only when x₁ is A, and otherwise samples fresh from p. This gives first-token mass `[.85,.15]`. The same `min` ratio cannot repair this selectively admitted draft.

## Train, calibrate, then schedule

**Training (§3.3, Eqs. 9–12):** Choose anchor spans of samples whose answers were regenerated by the target. Keep target frozen and copy/freeze its embedding/LM head in the release. Train the drafter, transition head and acceptance predictor. For anchor at `a`, the [code](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/deepspec/modeling/dspark/qwen3/modeling.py#L429-L476) pairs proposal `k` with label `a+k` and teacher logits at `a+k−1`. For each valid position:

- CE to the logged target-generated token, \(-\log q(x^*)\).
- Vocabulary L1 distillation, \(\|q-p\|_1\), **twice** total variation; don't accidentally halve the implementation's loss. It raises the expected per-position accept probability \(c^*=1-\tfrac12\|p-q\|_1\).
- BCE with soft label \(c^*\). The release detaches that target. The release's vanilla Markov path consumes teacher-forced previous IDs during training, then its own sampled IDs at inference.

**Material doc correction:** The paper writes exponential decay with suffix scale \(\gamma\); the [Qwen3-4B released training recipe](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/config/dspark/dspark_qwen3_4b.py) explicitly uses `block_size=7` and `loss_decay_gamma=4.0` as separate knobs. `loss.py` actually uses denominator 4 in that recipe and normalizes by valid weighted positions. Coefficients `.1/.9/1.0`, batch 512, 10 epochs, learning rate `6e-4`, warmup `.04`, optional compiled training, max input 4096 and 512 anchors in config; these are defaults, not values executed locally. Open-PerfectBlend provided prompts; responses regenerated by the target, non-thinking for the comparison (§4.1). No model weights or ~38 TB default target cache was downloaded.

**Confidence calibration (§3.2.1):** Temperature-scale each confidence **logit** on held-out data in position order, minimizing calibration error of its cumulative product while earlier temperatures stay fixed. Discrimination (AUROC) is not calibrated probability (ECE); good ranking alone cannot estimate absolute expected tokens. This temperature is not the sampling temperature of corrected draft logits.

**Scheduler (§3.2.2):** With `R` requests, total verification slots \(B_v=\sum_r(1+\ell_r)\); estimated committed tokens per round \(\tau=\sum_r[1+\sum_{j\le\ell_r}a_{r,j}]\); estimated throughput \(\Theta=\tau\,\mathrm{SPS}(B_v)\). At fixed extra capacity, sort survival estimates descending, preserving precursor order when tied, and select top K. Admission of `xₖ` must not depend on its value, including via `cₖ₊₁`. Algorithm 1 stops at the first non-improvement; it can miss a later peak on a jagged SPS curve. In reported production ([§5.2](https://arxiv.org/html/2607.05147v1#S5.SS2)), the capacity search removes the early stop: it evaluates feasible capacities against the profiled SPS curve using confidence scores from two decoding steps earlier. This selects K in time for CUDA graph replay without depending on current draws. Current prefix-survival ranks allocate that fixed K; they do not choose its size. Dropping the early stop on current scores instead would allow Appendix A's biased lookahead. Pruning cuts target verification slots after the full draft has run; it does not eliminate the draft pass. The lesson teaches the counterexample and a **fixed precommitted budget** allocation, not a clone or finite-precision validation of the production scheduler.

**Released evaluator vs paper:** [`draft_ops.py`](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/deepspec/eval/dspark/draft_ops.py#L82) is batch-one proposal selection with a threshold on the sigmoid of conditional confidence (threshold 0 keeps the full block). [`confidence_head.py`](https://github.com/deepseek-ai/DeepSpec/blob/005e03b81cec38b7da6399833d609ee89a2587f2/deepspec/eval/dspark/confidence_head.py#L345) measures cumulative confidence. Neither is a verified reimplementation of the hardware-aware asynchronous scheduler.

## What the benchmarks answer

- **Table 1:** Same data, retrained drafts, same targets, chain, sampling temperature 1, fixed budget with scheduler disabled, nine tasks. Accepted length per round includes one target-generated token under the paper's convention. Qwen3-4B macro means from the nine rounded entries are `3.6111`, `4.0644`, `4.7267` (Eagle3 / DFlash / DSpark). That's an author result plus a derived arithmetic check, **not** tokens per second. The paper reports 30.9% and 16.3% improvements on that target; ratios computed from the rounded cells may differ.
- **Figures 2–4:** Conditional acceptance given earlier acceptance is not prefix survival. Depth-controlled and proposal-length sweeps show why a lightweight dependency head can help and how length costs change. Results apply to the experiments' target and data, not all prompts.
- **Figures 5–6:** Raising a static threshold can improve acceptance fraction while rejecting useful throughput; the plot compares accepted and rejected tokens as well as the fraction. Reliability curves and histogram support calibration discussion only under that evaluation distribution.
- **Figures 7–8:** Live fitted frontiers compare DSpark-5 and the previous MTP-1 on V4 preview infrastructure. The paper reports +60–85% and +57–78% per-user speeds at matched throughput for Flash and Pro respectively. It also reports +51% and +52% aggregate at moderate service anchors; the large strict-anchor percentage gains are near the MTP-1 operating cliff. These are not comparable to dLLM low-batch TPS and were not reproduced. Serving speed depends on load, kernel, precision, context, cache and both model costs.

**Bottom line:** DSpark's one anchor-plus-mask draft pass is a descendant of DFlash, but its incremental Markov logits and confidence are not an iterative reverse diffusion chain. The deployed target AR decoder owns the text law. A diffusion LM may itself be used as a drafter (DiffuSpec/SpecDiff) or have a speculative accelerator for its own output; “diffusion” describes the mechanism, “draft” describes the role.
