~/satyajit

HydraHead: hybrid attention at the head, not the layer

mdjsonmcp

2026-07-01 · 8 min · llm · attention · long-context · interpretability · explainer

The attention that made transformers work is also what makes them expensive: every token attends to every other, so cost grows with the square of the context length. That quadratic term is fine at 4K tokens and ruinous at 512K — exactly the regime long-context models are pushing into. Linear attention (LA) fixes the scaling by keeping a fixed-size recurrent state instead of a full attention matrix, so cost grows linearly. But that fixed state is lossy: it can't do exact, long-range token retrieval — the "find the one sentence 400K tokens ago" trick that full attention nails.

attention cost vs context length · full (n²) vs linear (n) vs HydraHead
0K128K256K384K512Kcontext lengthrelative costfull · n²HydraHeadlinear · n
context length128K tokens
full attention 1.8× linear·HydraHead 1.7× linear

At 128K tokens, full attention costs 1.8× what linear does — the quadratic term runs away exactly when you need long context most. HydraHead stays close to the linear curve because only a few heads pay the FA price.

So the field mixes them — hybrid attention. Almost everyone does it per layer: interleave whole full-attention (FA) layers with whole linear-attention layers at some fixed ratio (3:1, 7:1), sometimes searched with NAS (as in GLM-5). HydraHead, from Alibaba, argues that the layer is the wrong unit — and backs it with an interpretability result.

The finding: layers are smooth, heads are not

HydraHead's authors probe a pretrained dense model (Qwen3-1.7B) and look at two things:

You can see the heterogeneity directly — heads in one layer specialize, and only some need to reach far back:

one layer · heads do different jobs
token sequence · attention of head 2needlequeryhead 2full attentionhead 5linear attentionhead 6full attentionhead 9linear attention
head 2 · retrieval — reaches back to the needle token
→ retrieval-critical: keep FULL attention

Same layer, same input — yet these heads specialize. Only the ones that reach far back for a specific token genuinely need full attention; the local and diffuse heads lose almost nothing under linear attention. That split is the whole basis for hybridizing per head instead of per layer.

That's the whole argument in one observation. If retrieval capability lives in a sparse, scattered set of heads, then the head — not the layer — is the natural granularity for deciding where to spend full attention.

attention hybridization · where full attention lives
layers →heads →full attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionfull attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionfull attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionfull attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionfull attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionfull attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionfull attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionlinear attentionfull attention
full attention (FA) linear attention (LA)FA units 8/64LA:FA ≈ 7.0:1

Head-wise: full attention is kept only for the handful of retrieval-critical heads, scattered wherever they occur. The same long-context quality falls out of far less FA — a leaner LA:FA ratio at equal capability.

Picking the retrieval-critical heads

HydraHead keeps FA for about 25% of heads by default and runs the rest as Gated DeltaNet (GDN, the linear-attention variant it builds on). The question is which 25%.

Side-by-side diagram: standard full attention (left) sends all heads through one softmax operation; HydraHead's head-wise hybrid attention (right) splits heads into a full-attention branch and a linear-attention (GDN) branch, recombining them through a Norm & Scale block before the shared output projection.
Standard full attention vs. HydraHead's head-wise hybrid: a subset of heads keeps the full-attention branch while the rest run linear attention (GDN), fused by per-head norm-and-scale before the output projection (paper, Figure 3).

The selection is a causal interpretability procedure, not a guess:

It's cheap — the ranking stabilizes from roughly six calibration samples — and it's faithful: knock out just the top ~1% of heads by this score and needle-retrieval accuracy collapses, while ablating random heads barely moves it. Crucially, the ablation confirms the selection beats fixed or random head assignment — the interpretability signal is doing real work.

Reconciling two kinds of output

You can't just concatenate FA and GDN heads and project them — their outputs live on different scales. Softmax attention is query-magnitude-modulated: it produces sharp, low-entropy distributions peaked on a few tokens. Linear attention cancels that magnitude out, giving smoother, higher-entropy, more uniform outputs. Splice the two naively and the model degrades badly.

HydraHead's scale-normalized fusion handles it with two moves: an independent per-head RMSNorm on every head's output, then a learnable per-head scalar γh\gamma_h that re-weights each head before the shared output projection. It's a small module, but it's load-bearing — remove the normalization and RULER's extended-context score drops from 87.5 to 71.4. A learnable scale also beats a learnable gate by ~20 points, so the model keeps every head's contribution and just rescales it, rather than gating heads off.

Building it cheaply

You don't train HydraHead from scratch — you convert a pretrained FA model in a three-stage transfer pipeline that reuses as much as possible:

  1. Parameter migration + alignment — the FA heads keep their pretrained weights; the new GDN heads reuse the base model's Q/K/V projections (repeated channel-wise to bridge the GQA→multi-head shape gap), so nothing starts from random. A per-layer MSE loss aligns the hybrid's hidden states to the original.
  2. Logit distillation — unfreeze the whole model and match its output distribution to the original FA teacher with a KL objective.
  3. Long-context fine-tuning — ordinary next-token prediction at 16K context.

The controlled conversion runs on ~2.3B tokens; the scaled-up model in the paper uses ~15B. Either way it's a rounding error next to pretraining — the capability is inherited, not learned fresh.

The payoff: long context that doesn't collapse

The headline result is retention. On RULER single-needle retrieval, most hybrid models — and the base model itself — fall to near zero by 256K. HydraHead holds:

RULER single-needle retrieval @ 256K context (%)
HydraHead (hybrid)
94.53%
HypeNet-2B (hybrid)
68.93%
Qwen3-1.7B + YaRN
40.2%
Jet-Nemotron-2B
1.07%
Qwen3-1.7B (base)
0%
050100

The harder multi-key retrieval shows the same shape — everything else craters, HydraHead degrades gracefully:

RULER multi-key retrieval @ 256K context (%)
HydraHead (hybrid)
52.7%
Qwen3-1.7B + YaRN
14.2%
Jet-Nemotron-2B
0%
Qwen3-1.7B (base)
0%
0204060

Across the full context sweep the retention gap only widens: HydraHead tracks the baselines up to 64K, then holds as they collapse — reaching +86.6 points on single-needle and +69.2 on multi-key at 512K, closing on Qwen3.5-2B-Base (which ships native 256K support):

Two grouped bar charts of RULER needle-in-a-haystack recall from 16K to 512K context. Left: Single NIAH. Right: Multi-Key NIAH. Qwen3-1.7B and its YaRN variant fall toward zero past 128K, while HydraHead stays high, with red annotations marking +54.3/+86.6 (single) and +58.4/+69.2 (multi-key) gains at 256K and 512K.
RULER needle-in-a-haystack recall from 16K to 512K: HydraHead retains accuracy where Qwen3-1.7B and its YaRN variant collapse, approaching Qwen3.5-2B-Base (paper, Figure 1). The 512K and Qwen3.5 numbers come only from this figure, not a table.

And it buys that without wrecking short-context ability — the usual tax on linear-attention conversions. On general reasoning it lands within ~3.4 points of the full-attention base model, and on MMLU it essentially matches it:

General reasoning — average of MMLU, BBH, MBPP, GSM8k (%)
Qwen3-1.7B (FA base)
54.02%
HydraHead
50.62%
Qwen3-1.7B + YaRN
50.37%
Gemma-3n-E2B
39.29%
0204060

The efficiency claim is the one to internalize: at a 7:1 GDN-to-FA head ratio — only one head in eight keeping full attention — HydraHead matches a 3:1 layer-wise hybrid's long-context average, while doing better on hard reasoning. Same quality, far less full attention, which means a smaller KV cache (HydraHead's is ~0.35× a full-attention model's). If you've read the inference write-up, that cache number is the whole game at long context — it's what decides how many requests fit on the GPU.

The take

What I like here is that the architecture change follows from an interpretability result instead of being reverse-justified by one. The claim "retrieval lives in a sparse, scattered set of heads" is measured with causal patching, the ablations show fixed/random selection is worse, and the fix — hybridize per head, keep FA where the retrieval heads are — falls straight out of the measurement. It's a clean example of interpretability paying rent.

Two honest caveats. The flashiest numbers — "69% improvement at 512K" and "approaching Qwen3.5" — come only from a figure, with no supporting table; the tabulated results stop at 256K, so treat the 512K story as directional. And this is all at the 1.7B scale on retrieval-style benchmarks; whether head-level hybridization holds its edge at 30B+ and on messier long-context reasoning is the open question. But the core idea — that the head is the right unit for spending your quadratic-attention budget — is the kind of insight that tends to generalize.


Built on HydraHead: From Head-Level Functional Heterogeneity to Specialized Attention Hybridization (Tan, Chen, Shen, Liu, Shen, Wu, Ye; Alibaba Group, 2026). Benchmark figures are quoted from the paper's tables; the 512K and Qwen3.5 comparisons are from its Figure 1.

Cite this article

For attribution, please use the following reference or BibTeX:

Satyajit Ghana, "HydraHead: hybrid attention at the head, not the layer", ai.thesatyajit.com, July 2026.

bibtex
@misc{ghana2026hydrahead,
  author = {Satyajit Ghana},
  title  = {HydraHead: hybrid attention at the head, not the layer},
  url    = {https://ai.thesatyajit.com/articles/hydrahead},
  year   = {2026}
}
share