Draft Models and Sparse Attention in Practice
Long-context LLM decoding is often limited by per-token attention cost and memory bandwidth. This article explains how draft models and sparse attention work together to cut full target-model forwards, and covers applicability, training for acceptance rate, inference engineering, evaluation, and common failure modes—without tying the discussion to a specific repository or product.
In large-model inference, autoregressive decoding latency is often limited by per-token attention and memory bandwidth. Long context further inflates KV-cache size and attention cost. Pairing a draft model with sparse attention is a widely discussed acceleration path: a smaller, faster model proposes a candidate sequence, and the target model verifies it in parallel, reducing the number of full forwards. This article describes the approach from a general technical view—where it applies, how to train it, and how to run it in the cloud—without binding to any specific open-source repository or product model.
Background: Compute and Bandwidth Limits at Long Context
Standard multi-head attention grows roughly quadratically with sequence length. At contexts on the order of hundreds of thousands of tokens, even grouped-query attention or KV quantization still faces three pressures. First, memory traffic for the attention matrix is hard to hide fully behind compute. Second, the KV cache crowds out device memory and forces smaller batches. Third, decoding cannot reuse the high parallelism available during training. Sparse attention—block-sparse patterns, sliding windows, learned selection, and similar methods—keeps only the key/value positions that matter for the current query, pushing complexity closer to linear. Approaches in the DSA family emphasize dynamic, learnable sparsity so the model learns which positions are worth computing, rather than relying only on a fixed window.
A draft model does not replace sparse attention; the two are orthogonal. Sparsity lowers the cost of one attention pass, while drafting reduces how often the full target model must run. When they are combined, position encodings, masks, and KV layout must be consistent. Otherwise verification sees a distribution shift.
How a Draft Model Works
A typical loop has four steps. First, the draft model cheaply generates a candidate span of length k. Second, the target model runs one parallel forward over those k positions, optionally with a sparse mask. Third, tokens are accepted or rejected one by one for autoregressive consistency. Fourth, after the first rejection the target model samples a correction token and the next round begins. Acceptance rate sets the speedup. When it is high, effective throughput approaches multiple tokens per target forward. When it is low, draft overhead can cancel the gain.
A draft model is therefore not “smaller is better.” It must trade speed against closeness to the target distribution. A network that is too small struggles to match the target’s conditional distribution, especially on long-range dependencies and on low-entropy but strictly structured tasks such as code and math. A network that is too large makes the draft stage itself the bottleneck. A common practice is to share the vocabulary and part of the embeddings, or to reuse shallow representations from the target model, so token-level alignment improves.
Designing Drafting and Sparse Attention Together
If the target uses dynamic sparse attention, the draft path must follow the same visibility rules. Otherwise the draft writes context the target treats as invisible, and verification fails systematically. In practice:
- Shared masks: draft and target should use the same block selection, window, or routing result, and at least force alignment on the verification step.
- Compatible position encodings: relative, rotary, or segmented positions must be numerically compatible across the two networks.
- Unified KV layout: paged cache, block size, and head grouping should match so verification does not pay for extra copies and reordering.
- Matched training objectives: if the sparse pattern is learned, an auxiliary loss on the draft can encourage its next-token predictions to land in the target’s high-probability set.
At long context, sparse selection often uses a local window plus a few global slots. The draft model should keep local coherence first, while remaining sensitive to global slots such as document-level instructions and system prompts. A curriculum on context length helps: stabilize acceptance on short sequences, then lengthen gradually and watch whether sparse routing collapses as length grows.
Training for Acceptance Rate, Not Perplexity Alone
Standard language-modeling loss often yields a draft that is fluent but unlike the target. A more useful goal is to raise speculative-decoding acceptance. General methods include:
- Distillation: supervise the draft with the target’s soft labels or top-k distribution. Temperature and label smoothing should match the sampling policy used at inference.
- Online alignment: run a speculative-decoding step inside the training loop and up-weight rejected positions so hard contexts are reinforced.
- Mixed lengths and tasks: blend long documents, multi-turn dialogue, and code completion so the draft is not only strong on short sentences.
- Sparse-consistency regularization: for the same input, constrain the distance between draft and target representations on the selected attention blocks.
Weights can be initialized by truncating shallow layers of the target or by distillation, but copying target capacity wholesale makes the draft too slow. In training code, mask generation, KV paging, and acceptance statistics should be reproducible modules. Logs should record perplexity, acceptance rate, mean accepted length, and end-to-end tokens per second together. Do not invent interface names or unpublished hyperparameters; use ordinary distributed data parallelism, gradient checkpointing, and mixed precision.
The following training loop is structural only, not a product-specific API:
for batch in loader:draft_logits = draft_model(batch.tokens, attn_mask)with torch.no_grad():target_logits = target_model(batch.tokens, attn_mask)distill = kl_div(draft_logits, target_logits, T=tau)# Optional: up-weight rejected positionsloss = distill + lm_loss(draft_logits, batch.labels)loss.backward()opt.step()
At validation, fix the random seed and sampling parameters. Report acceptance separately for short, medium, and long contexts so an average does not hide tail degradation.
Inference and Systems Engineering
Whether drafting pays off in production depends on batch size, sequence length, and the hardware’s compute-to-memory ratio. A practical checklist:
- Batch scheduling: keep sequence lengths inside a micro-batch close together to limit fragmentation of sparse masks and KV pages.
- Cache management: paged KV, prefix reuse, and shared state across multi-turn sessions. Draft and target should share a cache view so memory is not doubled.
- Early stop and adaptive k: adjust draft length from recent acceptance. When acceptance is low, shorten k or turn drafting off.
- Numerical stability: in half precision, attention scaling and mask fill values must match training so long sequences do not overflow.
- Observability: log accepted length per step, rejection cause (distribution mismatch or an uncovered sparse block), and GPU utilization.
Training and inference can be split across a container platform, checkpoints stored in object storage, and metrics sent to logging and alerting. Elastic instances suit acceptance sweeps and sparse-pattern ablations. Stable online serving should pin images and operator versions so kernel or attention-implementation differences do not change mask behavior. General compute, storage, containers, and monitoring—such as those on Baidu AI Cloud—are enough to support this pipeline; unverified proprietary features are not required.
Evaluation and Common Failures
Open-domain perplexity is not enough. Report:
- Task quality: accuracy or human agreement versus a no-draft baseline under the same decoding settings, to confirm speedup did not hurt alignment.
- Speedup: wall-clock time versus target-only decoding, stating batch size, context length, and whether prefill is included.
- Long-context checks: needle retrieval, multi-hop citation, and very long code-repository question answering, to see whether sparse routing drops critical blocks.
- Stability: whether acceptance falls across successive turns of a conversation.
Common failures include mismatched vocabularies or special tokens; draft models that never saw the target’s system-prompt format; block size and page size that are not multiples, so boundary tokens are dropped silently; and a sampling temperature at verification that differs from training. Regress these items on a checklist rather than replacing them with a single synthetic benchmark.
Where It Fits and Where It Can Go
Drafting plus sparse attention fits workloads where prefill is acceptable, decoding is long, and output structure is relatively stable—document question answering, code completion, and multi-turn support. Gains can be limited for highly random sampling, strongly constrained per-token decoding, or tiny-batch real-time speech. Further work includes sharing layers between draft and target, differentiable sparse routing, and putting acceptance rate directly into the training objective. Any specific speedup depends on the model pair, hardware, and workload; this article does not state unverified numbers.
In short, a draft model trades distribution alignment for fewer decoding steps, and sparse attention trades selective compute for lower complexity. Treat masks, positions, KV layout, and training objectives as one contract, then freeze experiments in the cloud with object storage, containers, and monitoring. That is what makes latency and throughput gains hold up at long context. Iterate on acceptance rate and task quality together, rather than chasing a smaller draft network or a sparser attention pattern in isolation.
