Speculative decoding accelerates large language model generation by using a fast draft model to propose candidate tokens that a target model verifies in parallel. For coding agents that iteratively write and edit code, existing drafters struggle to keep pace with long, predictable syntax blocks broken by sparse branching points. A new preprint introduces Spancast, a draft architecture that replaces Transformer blocks with recurrent state channels and null-key attention to capture code structure more effectively.
Autoregressive models generate one token per forward pass, making latency scale linearly with sequence length. Speculative decoding breaks this linear scaling while preserving the target distribution. In natural language, many words remain plausible at almost every position, keeping accepted spans short. Executable code follows strict grammar and reuses local identifiers, forming long predictable stretches that offer far higher potential speedup. However, learned drafters rely on stateless Transformer blocks that drop sequential state and suffer from attention sinks on unseen tokens. Retrieval methods halt whenever generation shifts from verbatim repetition to new code.
Recurrent state and null-key attention
Spancast decouples the draft vocabulary from the target model and builds a native draft backbone. It replaces standard feed-forward networks with a Grouped State Channel that partitions channel state into parallel groups. The mechanism takes layer inputs, applies learnable-scale normalization, and produces per-group token evidence alongside scalar gate logits. For every step in parallel, it computes a retention gate that blends the previous recurrent state with fresh token evidence. The recurrent state norm is restricted to unity via parameter-free normalization, ensuring stable propagation over long prefixes. Meanwhile, the gated residual output remains free in scale and sign, keeping active channels sharp while inactive channels vanish. A cross-group bilinear residual then couples representations across groups before projecting back to the model width.
The architecture also introduces Null-Key Attention to handle the constant alternation between copying prefix spans and predicting novel tokens. Standard softmax attention forces queries on unseen tokens to place leftover probability mass on visible prefix positions, empirically concentrating on position zero and mixing sink values into the residual stream. Null-Key Attention relaxes this constraint by augmenting the valid key set with a query-dependent null key carrying a zero-value vector. From normalized projections, each head projects a query, key, value, scalar phase shift, and null logit. The null logit combines a linear query projection with a per-head bias. Over the augmented key set, the mechanism computes attention weights where prefix weights sum to less than one. On novel tokens, increasing the null logit concentrates probability mass on the null key and drives the output to zero. On copied spans, the null probability drops toward zero and attention sharpens onto matching prefix keys.
Illustrative image: Surprising_Media / Pixabay
To draft efficiently, Spancast uses Masked Parallel Tree Decoding. Optimal tree pruning ranks every candidate path by exact joint reach probability, but flat parallel predictors only estimate marginals while autoregressive drafters evaluate distributions at linear depth. Spancast executes three shared-decoder passes of varying depths, cycling parameter-shared decoder cells with per-layer depth embeddings and residual scales. This yields a constant total depth independent of the horizon length. All stages attend to one shared prefix representation formed from convex layer mixtures. The state bridge projects the final encoder state at the prefix boundary to seed all decoder layers. A causal pass scores an initial parallel span to rank likely branches, and masked parallel passes predict the continuation for each selected branch without sequential rollout.
Acceptance lengths and context limits
The evaluation spans 18 benchmarks and 17 target models across 15 families, ranging from 3B to 32B parameters. The target models include SmolLM3, Phi-4-mini, Falcon3, OLMo-2, EXAONE-3.5, Qwen3, Llama-3.1, OpenCoder, Granite, InternLM3, Yi-1.5, StarCoder2, Gemma-3, Muse-Glimmer, Qwen2.5, and GLM-4. Spancast operates over an independent draft vocabulary and communicates with the target model through plain text, removing shared tokenizer constraints and hidden-state coupling. The authors measure acceptance lengths and inter-token latency to quantify speedup. The architecture consistently outperforms learned drafters like EAGLE-2, EAGLE-3, DFlash, and Medusa, as well as retrieval methods including SuffixTree, SAM Decoding, Prompt Lookup, Lookahead, and REST.
Qualitative traces reveal why the architectural choices matter in practice. Spancast sustains multi-token spans across high-reuse Python refactoring, low-reuse algorithmic synthesis, statically typed Rust code, and mixed prose-to-code switching. In high-reuse refactoring, stage-two branch rescues bridge copied class definitions and newly edited method signatures inside single verification steps. Retrieval baselines match verbatim class headers before fragmenting into single-token stripes at every refactored signature. In low-reuse algorithmic synthesis, retrieval methods collapse into near-single-token decoding across the remaining body. Spancast's stage-two branch rescues cluster on high-entropy algorithmic decisions inside the recurrence body, including table initialization, index offsets, and control keywords. On statically typed Rust solutions, Spancast absorbs full docstring spans and transitions into novel iterator and pattern-matching bodies through branch rescues on loop binders and match arms.
The draft model does face a hard limit on context length. When the input context exceeds the 2,048-token training window by 2.7 times, both Spancast and a matched Transformer degrade toward single-token verification. The authors note that this breakdown originates in out-of-window rotary position extrapolation rather than a failure in recurrent state tracking, suggesting that extended-context training or rotary frequency scaling will be necessary to handle longer agentic workflows.
Sources
PNEUMETRON EDITORIAL
Pneumetron's pipeline pairs AI-assisted drafting with human editorial review before publishing — our goal is to make staying informed easier, not to replace real reporting.




