InterviewsVector
Arc 5
Concept labAdvanced95 min estimateOriginal publication

Multi-Head Attention Is Parallel Representation Routing

Multiple heads create parallel learned routing subspaces; their existence permits diversity but does not prove semantic specialization.

Authorship
InterviewsVector
Published / updated
2026-08-25 / 2026-08-25
Review status
Artifact tests passing · primary sources recorded

Original InterviewsVector material. Code examples are covered by repository tests and primary references are recorded. No named human reviewer is claimed.

The decision in one pass

Multi-head attention projects the same input representations through separate Q, K, and V matrices, performs attention independently in each lower-dimensional subspace, concatenates the per-head payloads, and applies an output projection. This architecture makes parallel routing functions possible; it does not guarantee that every head learns a unique, human-readable, or necessary role. Head count, projection contents, dimensions, mask, scale, concatenation order, and output projection form one contract. Claims of specialization need task-linked probes and controlled ablations across examples and seeds, not a compelling heatmap or the mere existence of different matrices.

Why this matters

Head-count folklore leads teams to misread visualizations, prune on weak evidence, or break checkpoint compatibility by changing projection layouts. A shape-first and evidence-bounded view separates architectural capacity from empirical contribution.

You will be able to

  • Derive multi-head attention as parallel projected routing followed by concatenation and output projection.
  • Trace model, head, and value dimensions through every projection and combination step.
  • Separate representational diversity, observed routing difference, importance, and semantic specialization.
  • Build a content-addressed audit binding every per-head matrix, output projection, input representation, and decision.
  • Design controlled head ablations and task metrics that can support a bounded specialization claim.

Your Vector Loop for this lab

  1. 01

    Model

    Name head identities, projection contents, dimensions, mask, concatenation order, and output semantics.

  2. 02

    Derive

    Derive independent head routing and show how concatenation plus WO returns to model width.

  3. 03

    Build

    Execute a bounded fixture through concrete per-head projections and material output digests.

  4. 04

    Stress

    Probe duplicate IDs, reordered heads, stale matrices, malformed shapes, redundant heads, pruning, and numeric extremes.

  5. 05

    Operate

    Join head-level traces to task metrics and controlled ablations across examples, layers, checkpoints, and seeds.

  6. 06

    Defend

    State whether evidence shows different outputs, causal task contribution, or semantic specialization—and do not collapse them.

Create parallel routing subspaces with learned projections

Each head receives the same sequence of model-width representations but owns distinct Q, K, and V projection parameters. The projections select and recombine input coordinates into a head-specific compatibility space and payload space. The head then performs the same scaled routing operation derived in the previous lesson.

headi = Attention(XWQi, XWKi, XWVi)

Separate matrices allow head i to implement a different routing function. ‘Allow’ is a capacity statement; training may learn diverse, redundant, unstable, or unused functions.

ProjectionTypical shapeRole
WQidmodel × dkmap model representation into query coordinates
WKidmodel × dkmap model representation into key coordinates
WVidmodel × dvmap model representation into payload coordinates
WOh·dv × dmodelmix concatenated head payloads back to model width

Derive the dimension and parameter budget

Concat(head1,…,headh)[n, h·dv] · WO[h·dv, dmodel] → Y[n, dmodel]

Concatenation order is observable because WO assigns different rows to different head coordinates. Reordering heads without the corresponding WO rows changes the function.

A common configuration chooses dk = dv = dmodel/h, keeping the concatenated width equal to dmodel. That is a design convention, not a mathematical requirement. Grouped-query and multi-query attention further change how query heads share K/V projections. Always derive the actual checkpoint shapes instead of inferring them from a generic Transformer diagram.

Keep independent routing and learned combination distinct

Heads normalize their own score rows, so one head cannot directly trade probability mass with another. Their payloads meet only after independent routing, through concatenation and WO. Consequently, a head's apparent pattern can be amplified, cancelled, or remixed by the output projection and residual stream.

  1. 01Project per headBind matrix contents and projection versions; matching shapes cannot detect stale or swapped parameters.
  2. 02Route independentlyApply the same bound mask, scale, and stable softmax to each head while retaining head identity.
  3. 03Concatenate in declared orderPreserve the mapping from head output coordinates to output-projection rows.
  4. 04Project and rejoin the residual pathInterpret head evidence in the context of WO and downstream computation, not in isolation.

Require evidence before naming a head's role

Use the narrowest claim licensed by the intervention and evaluation scope.
ObservationWhat it supportsWhat remains unproven
different projection matricesdifferent parameter contentsdifferent behavior on traffic
different attention mapsdifferent routing on sampled inputscausal task contribution
probe predicts a featurefeature is decodable from evidencehead alone computes or uses it
ablation changes metriccausal contribution under that interventionunique human-readable semantics
pattern repeats across seedsgreater stability of the observationuniversal role across models/tasks

A strong specialization study defines a task metric and reference population before inspecting heads, evaluates held-out examples, intervenes on one or matched sets of heads, includes random and magnitude-matched controls, measures confidence intervals, and repeats across checkpoints or seeds. Even then, name the bounded behavior rather than assigning an anthropomorphic job title.

Bind every projection and keep interpretation bounded

The reference artifact validates concrete frozen head records, unique head IDs, Q/K/V and output-projection shapes, model/layer revisions, mask and scale semantics, bounded input representations, operation count, provenance, and scope. It emits separate content identities for the contract, projection collection, input evidence, each head output, and material combined result. Its policy always reports that head existence does not establish specialization.

multi_head_routing_audit.py
1def format_example() -> str:
2 report = audit_multi_head_routing(ILLUSTRATIVE_CONTRACT, ILLUSTRATIVE_EVIDENCE)
3 return "\n".join(
4 (
5 "example=illustrative_only",
6 f"contract_id={report.contract_content_id}",
7 f"projection_id={report.projection_content_id}",
8 f"head_ids={','.join(head.head_id for head in report.heads)}",
9 f"token0_output={','.join(f'{value:.3f}' for value in report.combined_output[0])}",
10 f"specialization={report.specialization_conclusion}",
11 f"required_evidence={report.required_specialization_evidence}",
12 f"material_id={report.material_evidence_id}",
13 f"decision={report.decision}",
14 )
15 )

Expected output

example=illustrative_only
contract_id=multi-head-contract@sha256:a11697bdba26208873482329d54a60fd0866d4c0129aaedb2a27d8be91575534
projection_id=multi-head-projections@sha256:208a126e380bfd2a5c0546f6bfa6900bd8f77303d8a4bc20a5b7bc6fe7afacc5
head_ids=head-0,head-1
token0_output=0.731,0.500
specialization=NOT_ESTABLISHED_FROM_HEAD_EXISTENCE
required_evidence=TASK_METRICS_PLUS_CONTROLLED_HEAD_ABLATION
material_id=multi-head-material@sha256:9578fa762103f264813d58b008406ae7fafdfb954425f58d9880b22d76c1ad97
decision=PASS

Verify: python3 -m unittest discover courses/ai-engineering/reference-impl/multi_head_routing

Operate head changes with controlled equivalence evidence

Change or symptomImmediate gateRequired follow-up
head reorderprojection identity and WO row mappingreference output equivalence
head pruningtask and safety metricslatency/memory gain plus ablation controls
MHA to GQAK/V sharing map and cache shapequality, serving, and migration evaluation
collapsed mapsQ/K variance and scaletraining dynamics and gradient evidence
specialization claimpredeclared task-linked criterionheld-out ablation across seeds

Do not log every full attention map by default. Aggregate entropy, concentration, and inter-head similarity on sampled, access-controlled traces; join anomalies to task outcomes and model identities. A low-diversity alert is a prompt for investigation, not an automatic pruning command.

Operate at three altitudes

Production lens

  • Version per-head projections, concatenation order, output projection, mask, dimensions, and K/V sharing as one executable layout contract.
  • Use material head-output identities and bounded reference fixtures to detect silent checkpoint or compiler remapping.
  • Monitor sampled routing diversity only as a diagnostic signal and join it to task outcomes before acting.
  • Treat pruning or MHA/GQA conversion as model migrations with quality, capacity, cache, compatibility, and rollback gates.

Staff lens

  • Create an interpretation policy that distinguishes visualization, decodability, importance, ablation, and stable semantic specialization.
  • Require head studies to predeclare tasks, controls, held-out data, uncertainty, seed coverage, and the narrow claim they can support.
  • Standardize checkpoint layout identities across training frameworks, compilers, serving kernels, cache formats, and observability.

Interview defense

What does multi-head attention add, and does each head necessarily specialize?

It applies separate learned Q, K, and V projections, runs attention independently in several lower-dimensional subspaces, concatenates those payloads, and uses an output projection to mix them back to model width. This enables parallel routing functions but does not guarantee unique or interpretable roles. I would bind every matrix, dimension, head order, mask, and input; test shapes and a reference output; then require task-linked held-out probes and controlled ablations across seeds before claiming specialization. Different heatmaps or matrices alone only show difference, not necessity or semantics.

Expect the interviewer to press on

  • Why does changing head order require changing the output projection?
  • How would you test whether one head is important?
  • How do MHA, GQA, and MQA differ for K/V state?

Misconceptions to remove

Each attention head learns one distinct linguistic feature.

The architecture permits different routing functions, but heads can be redundant, distributed, unstable, or task-specific. Semantic roles require controlled evidence.

A different attention pattern proves a head matters to the output.

Observed routing difference is not causal contribution. Measure a task outcome under controlled intervention and account for WO, residual, and compensating paths.

More heads always create more model capacity.

At fixed model width, more heads can reduce each head dimension, and empirical work finds redundancy in some settings. Capacity and usefulness depend on the full architecture and training evidence.

Check your model

1. Why is concatenation order part of the contract?

The output projection maps fixed concatenated coordinates back to model width. Reordering head coordinates without the matching projection-row permutation changes the function.

2. What is the narrow conclusion from two heads producing different outputs?

Only that the bound projections routed this evidence differently. It does not show that either head has a stable semantic role or causal task importance.

3. What evidence strengthens a specialization claim?

A predefined task-linked criterion, held-out probes, controlled head interventions with random or matched controls, uncertainty estimates, and repetition across examples, checkpoints, and seeds.

Prove the mechanism

Add a third head and a non-identity output projection. Demonstrate with tests that reordering head outputs without the corresponding output-projection rows changes the material result.

Add a production constraint

Design a preregistered specialization study for one bounded behavior. Include task metric, probe, ablation controls, seed strategy, uncertainty, privacy limits, and a claim ladder from observation to causality.

Artifact: Multi-head routing audit

courses/ai-engineering/reference-impl/multi_head_routing/multi_head_routing_audit.py

Download reference implementation

Primary references and next links

References

  1. 1. Attention Is All You Need

    Vaswani et al.. Primary source defining the Transformer's multi-head attention construction.

  2. 2. Are Sixteen Heads Really Better than One?

    Michel, Levy, and Neubig. Primary empirical study of attention-head pruning and redundancy.

  3. 3. Analyzing Multi-Head Self-Attention: Specialized Heads Do the Heavy Lifting, the Rest Can Be Pruned

    Voita et al.. Primary empirical analysis relating head patterns, importance, and pruning.

Continue through the graph

Glossary: attention head · head dimension · projection matrix · concatenation · head ablation · specialization