Exercises
Practice head-axis shapes, two-head calculations, output projection, parameter and score counts, ablation claims, head permutation, and silent implementation errors.
These exercises move from head dimensions and numerical calculations to cost, ablation, and implementation audits. Each prompt states the convention it uses.
Trace Head Dimensions
Q1. Count the attention distributions
A multi-head layer receives a batch with sequences, uses heads, and has sequence length . How many separate attention rows are formed for one query position across the complete batch?
Compute it first, then check your number.
Hint
Solution
Q2. Derive a valid output projection
A layer uses , , and . The implementation does not require . What shape must have?
Select one choice, then check.
Hint
Solution
Calculate Two Heads
Q3. Calculate one head result
For the final query, a head has attention weights and value vectors , , and . What is the first coordinate of the head result?
Compute it first, then check your number.
Hint
Solution
Q4. Place the head axis correctly
Combined query projection produces a tensor with shape . The layer uses equal-width heads. Which shape should enter the batched query-key product?
Select one choice, then check.
Hint
Solution
Q5. Apply the shared output projection
Two heads produce and . They are concatenated in that order. Let
What is the second coordinate of ?
Compute it first, then check your number.
Hint
Solution
Count What the Layer Stores and Learns
Q6. Count projection parameters
A bias-free layer uses , , and . Count all entries in , , , and .
Compute it first, then check your number.
Hint
Solution
Q7. Count dense score entries
A dense attention layer has , , and . How many score entries does its full score tensor contain before masking?
Compute it first, then check your number.
Hint
Solution
Interpret Interventions Carefully
Q8. Interpret a head-zeroing result
Zeroing head 4 before concatenation reduces validation accuracy by 0.2 percentage points on one task. Which conclusion is supported?
Select one choice, then check.
Hint
Solution
Q9. Preserve a layer while permuting heads
All head-result blocks are permuted before concatenation. Which additional change preserves the same layer function?
Select one choice, then check.
Hint
Solution
Integrated Audit
Q10. Locate a silent head-order error
A combined implementation and a verified separate-head implementation agree on each . Both final outputs have shape , but their values differ. The combined implementation concatenates heads in the order while using the original . What is the smallest complete repair?
Select one choice, then check.