IV-34 / Part VIII · Positional Information
Why Position Matters to Attention
Reorder three token rows, prove unmasked attention's permutation equivariance, and calculate a fixed-slot positional counterexample.
Review the ideas this chapter uses
“Dog bites person” and “Person bites dog” contain the same words but describe different events. An operation that receives only word features needs some way to distinguish their positions. Attention compares feature vectors; the array’s row number does not automatically become an input feature. We will separate moving a token’s output with that token from producing the same output at an unchanged row number.
Learning objective: Demonstrate that attention without positional signals is permutation equivariant.
Review IV-25 — Self-Attention: Complete Numerical Trace for the full attention calculation and IV-33 — A Complete Transformer Block for its place in a block. Book II’s II.10 — Matrix × matrix as composition and II.11 — Transpose and orthogonality explain composition and transpose; Book III’s III-41 — Composition and Learned Representations explains composed representations. Here parameters are hand-set and editable. No learning update occurs.
Move the rows and compare corresponding outputs
Why Position Matters to Attention
These controls recompute the actual example. Trace navigation shows saved calculation steps; editing starts a new trace from the displayed inputs.
Complete results from this trace’s starting inputs
Starting inputs for these results
- permutation
- 4
- signal
- 0
- x000
- 1
- x001
- 0
- x010
- 0
- x011
- 1
- x020
- 1
- x021
- 1
- wq00
- 1
- wq01
- 0
- wq10
- 0
- wq11
- 1
- wk00
- 1
- wk01
- 0
- wk10
- 0
- wk11
- 1
- wv00
- 1
- wv01
- 0
- wv10
- 0
- wv11
- 1
Original token rows X
WQ projection weights
WK projection weights
WV projection weights
maxAbsDifference 0. difference00 0. difference01 0. difference10 0. Validate inputs and choose the new-slot to old-row permutation. All 20 scalars are checked. Positions stay attached to slots. The comparison permutes the left outputs rather than comparing unchanged row labels.. B 1. T 3. D 2. permutation 4. signal 0
Validate inputs and choose the new-slot to old-row permutation
B=1; T=3; D=Dk=Dv=2; pi[new slot]=old row; both attention calls are unmasked
All 20 scalars are checked. Positions stay attached to slots. The comparison permutes the left outputs rather than comparing unchanged row labels.
Inputs
- permutation
- 4
- signal
- 0
- x000
- 1
- x001
- 0
- x010
- 0
- x011
- 1
- x020
- 1
- x021
- 1
- wq00
- 1
- wq01
- 0
- wq10
- 0
- wq11
- 1
- wk00
- 1
- wk01
- 0
- wk10
- 0
- wk11
- 1
- wv00
- 1
- wv01
- 0
- wv10
- 0
- wv11
- 1
Outputs
- B
- 1
- T
- 3
- D
- 2
- permutation
- 4
- signal
- 0
Compare corresponding rows after a real recomputation
Inspecting token 0, feature 0. These selectors change the view only. The live graded question uses a fixed coordinate and the current starting inputs.
The selected trace operation is setup; its matching saved table row is marked current. Calculation step above exposes its equation, explanation and all inputs and outputs.
All validated setup fields and declared dimensions
| Saved operation | Input permutation | Input signal | Input x000 | Input x001 | Input x010 | Input x011 | Input x020 | Input x021 | Input wq00 | Input wq01 | Input wq10 | Input wq11 | Input wk00 | Input wk01 | Input wk10 | Input wk11 | Input wv00 | Input wv01 | Input wv10 | Input wv11 | Result B | Result T | Result D | Result permutation | Result signal |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| setup | 4 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 3 | 2 | 4 | 0 |
A permutation is a rearrangement of rows. Here pi maps a new slot to its old row. Left computes F(X+P), Right computes F(pi X+P), and Expected gathers pi F(X+P). P stays attached to slots in both inputs. Both calls use the same editable projection weights, all keys allowed, and no causal mask.
Saved compare_0_0: right slot 0, feature 0 has 0.7517449217422769; expected left row 2 has 0.7517449217422769. The actual subtraction right−expected is . The largest absolute coordinate difference is 0.
RawX
B=1 × T=3 × D=2 · float64 · display precision 8. Original three editable token rows, before slot signals or reordering.
| Original token row (batch 0) | Feature 0 | Feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 2 | 1 | 1 |
SlotSignals
B=1 × T=3 × D=2 · float64 · display precision 8. Fixed slot vectors: all zero, or (0,0),(1,0),(0,1). They do not move with tokens.
| Fixed slot (batch 0) | Feature 0 | Feature 1 |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 2 | 0 | 0 |
Permutation
NewSlot=3 · int32 · display precision 8. pi[new slot] is the old token row, in lexicographic permutation order.
| New slot | Old row 0 |
|---|---|
| 0 | 2 |
| 1 | 0 |
| 2 | 1 |
All input assemblies, in saved execution order
For every coordinate, first gather the indicated token feature and then add the fixed slot coordinate. All six left assemblies precede all six right assemblies.
| Saved operation | Input t | Input d | Input sourceIndex | Input token | Input signal | Result value |
|---|---|---|---|---|---|---|
| left_input_0_0 | 0 | 0 | 0 | 1 | 0 | 1 |
| left_input_0_1 | 0 | 1 | 0 | 0 | 0 | 0 |
| left_input_1_0 | 1 | 0 | 1 | 0 | 0 | 0 |
| left_input_1_1 | 1 | 1 | 1 | 1 | 0 | 1 |
| left_input_2_0 | 2 | 0 | 2 | 1 | 0 | 1 |
| left_input_2_1 | 2 | 1 | 2 | 1 | 0 | 1 |
| Saved operation | Input t | Input d | Input sourceIndex | Input token | Input signal | Result value |
|---|---|---|---|---|---|---|
| right_input_0_0 | 0 | 0 | 2 | 1 | 0 | 1 |
| right_input_0_1 | 0 | 1 | 2 | 1 | 0 | 1 |
| right_input_1_0 | 1 | 0 | 0 | 1 | 0 | 1 |
| right_input_1_1 | 1 | 1 | 0 | 0 | 0 | 0 |
| right_input_2_0 | 2 | 0 | 1 | 0 | 0 | 0 |
| right_input_2_1 | 2 | 1 | 1 | 1 | 0 | 1 |
Left: the protected IV-25 computation, used unchanged
Each side retains all 37 saved child steps, including setup, and all 13 child tensors. The names identify the side; the arithmetic is the same projection → score → key-axis softmax → weighted-value sequence taught in IV-25.
Left child setup: all 33 input fields
| Saved operation | Input B | Input T | Input Dk | Input Dv | Input x000 | Input x001 | Input x010 | Input x011 | Input x020 | Input x021 | Input x100 | Input x101 | Input x110 | Input x111 | Input x120 | Input x121 | Input wq00 | Input wq01 | Input wq10 | Input wq11 | Input wk00 | Input wk01 | Input wk10 | Input wk11 | Input wv00 | Input wv01 | Input wv10 | Input wv11 | Input mode | Input valid0 | Input valid1 | Input valid2 | Input shift | Result B | Result T | Result D | Result Dk | Result Dv |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| left_setup | 1 | 3 | 2 | 2 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | -1 | 0 | 0 | 2 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 3 | 2 | 2 | 2 |
LeftX
B=1 × T=3 × D=2 · float64 · display precision 8. Active input token rows, selected without padding or broadcasting.
| Token / query (batch 0) | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 2 | 1 | 1 |
LeftWQ
D=2 × Dk=2 · float64 · display precision 8. Both input rows; leading Dk query columns of the editable WQ.
| Input feature | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
LeftWK
D=2 × Dk=2 · float64 · display precision 8. Both input rows; leading Dk key columns of the editable WK.
| Input feature | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
LeftWV
D=2 × Dv=2 · float64 · display precision 8. Both input rows; leading Dv value columns of the editable WV.
| Input feature | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
LeftQ
B=1 × T=3 × Dk=2 · float64 · display precision 8. Q=XWQ, with each coordinate traced as two products and one sum.
| Token / query (batch 0) | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 2 | 1 | 1 |
LeftK
B=1 × T=3 × Dk=2 · float64 · display precision 8. K=XWK, with each coordinate traced as two products and one sum.
| Token / query (batch 0) | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 2 | 1 | 1 |
LeftV
B=1 × T=3 × Dv=2 · float64 · display precision 8. V=XWV, available for later value mixing; not mixed in IV-22–24.
| Token / query (batch 0) | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 2 | 1 | 1 |
Every projection product and sum
A token row times each weight column gives two feature products and their sum. Q, K and V are separately recomputed on this side's assembled X.
| Saved operation | Input b | Input t | Input f | Input x0 | Input x1 | Input w0 | Input w1 | Result product0 | Result product1 | Result value |
|---|---|---|---|---|---|---|---|---|---|---|
| left_project_Q_0_0_0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
| left_project_Q_0_0_1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| left_project_Q_0_1_0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| left_project_Q_0_1_1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 |
| left_project_Q_0_2_0 | 0 | 2 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
| left_project_Q_0_2_1 | 0 | 2 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 |
| left_project_K_0_0_0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
| left_project_K_0_0_1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| left_project_K_0_1_0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| left_project_K_0_1_1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 |
| left_project_K_0_2_0 | 0 | 2 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
| left_project_K_0_2_1 | 0 | 2 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 |
| left_project_V_0_0_0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
| left_project_V_0_0_1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| left_project_V_0_1_0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| left_project_V_0_1_1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 |
| left_project_V_0_2_0 | 0 | 2 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
| left_project_V_0_2_1 | 0 | 2 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 |
Every query–key dot product and scaling
The saved product0 and product1 add to raw; score divides raw by sqrt(2). These signed scores are not probabilities.
| Saved operation | Input b | Input i | Input j | Input Dk | Input divisor | Input q0 | Input k0 | Input q1 | Input k1 | Result product0 | Result product1 | Result raw | Result score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| left_score_0_0_0 | 0 | 0 | 0 | 2 | 1.4142135623730951 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0.7071067811865475 |
| left_score_0_0_1 | 0 | 0 | 1 | 2 | 1.4142135623730951 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| left_score_0_0_2 | 0 | 0 | 2 | 2 | 1.4142135623730951 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 0.7071067811865475 |
| left_score_0_1_0 | 0 | 1 | 0 | 2 | 1.4142135623730951 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
| left_score_0_1_1 | 0 | 1 | 1 | 2 | 1.4142135623730951 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0.7071067811865475 |
| left_score_0_1_2 | 0 | 1 | 2 | 2 | 1.4142135623730951 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0.7071067811865475 |
| left_score_0_2_0 | 0 | 2 | 0 | 2 | 1.4142135623730951 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0.7071067811865475 |
| left_score_0_2_1 | 0 | 2 | 1 | 2 | 1.4142135623730951 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0.7071067811865475 |
| left_score_0_2_2 | 0 | 2 | 2 | 2 | 1.4142135623730951 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1.414213562373095 |
Leftraw
B=1 × Query=3 × Key=3 · float64 · display precision 8. QK transpose: explicit feature products followed by their sum, within each batch.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 2 | 1 | 1 | 2 |
Leftscores
B=1 × Query=3 × Key=3 · float64 · display precision 8. Raw query-key agreement divided by sqrt(Dk); not softmax probabilities.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | 0.7071067811865475 | 0 | 0.7071067811865475 |
| 1 | 0 | 0.7071067811865475 | 0.7071067811865475 |
| 2 | 0.7071067811865475 | 0.7071067811865475 | 1.414213562373095 |
Every unmasked softmax row
All allowed flags are true. Subtract the saved row maximum, exponentiate each shifted logit, add the terms in increasing key order, then divide each term by the denominator. No key is dropped, and shift is zero.
| Saved operation | Input b | Input i | Input mode | Input shift | Input score0 | Input score1 | Input score2 | Input allowed0 | Input allowed1 | Input allowed2 | Result max | Result denominator | Result shifted0 | Result shifted1 | Result shifted2 | Result term0 | Result term1 | Result term2 | Result p0 | Result p1 | Result p2 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| left_row_0_0 | 0 | 0 | 0 | 0 | 0.7071067811865475 | 0 | 0.7071067811865475 | 1 | 1 | 1 | 0.7071067811865475 | 2.49306869139524 | 0 | -0.7071067811865475 | 0 | 1 | 0.49306869139523984 | 1 | 0.4011120926797859 | 0.1977758146404282 | 0.4011120926797859 |
| left_row_0_1 | 0 | 1 | 0 | 0 | 0 | 0.7071067811865475 | 0.7071067811865475 | 1 | 1 | 1 | 0.7071067811865475 | 2.49306869139524 | -0.7071067811865475 | 0 | 0 | 0.49306869139523984 | 1 | 1 | 0.1977758146404282 | 0.4011120926797859 | 0.4011120926797859 |
| left_row_0_2 | 0 | 2 | 0 | 0 | 0.7071067811865475 | 0.7071067811865475 | 1.414213562373095 | 1 | 1 | 1 | 1.414213562373095 | 1.9861373827904796 | -0.7071067811865475 | -0.7071067811865475 | 0 | 0.49306869139523984 | 0.49306869139523984 | 1 | 0.2482550782577231 | 0.2482550782577231 | 0.5034898434845538 |
Leftallowed
B=1 × Query=3 × Key=3 · bool · display precision 8. True means this key may contribute to this query; key validity is shared across batches.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | true | true | true |
| 1 | true | true | true |
| 2 | true | true | true |
Leftlogits
B=1 × Query=3 × Key=3 · float64 · display precision 8. Finite score+common shift for every active key, including forbidden keys; no mask sentinel.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | 0.7071067811865475 | 0 | 0.7071067811865475 |
| 1 | 0 | 0.7071067811865475 | 0.7071067811865475 |
| 2 | 0.7071067811865475 | 0.7071067811865475 | 1.414213562373095 |
Leftprobabilities
B=1 × Query=3 × Key=3 · float64 · display precision 8. Allowed-key stable softmax along the key axis only. Forbidden keys have exactly zero; allowed exponential underflow is separately possible.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | 0.4011120926797859 | 0.1977758146404282 | 0.4011120926797859 |
| 1 | 0.1977758146404282 | 0.4011120926797859 | 0.4011120926797859 |
| 2 | 0.2482550782577231 | 0.2482550782577231 | 0.5034898434845538 |
Every probability × value product and running sum
For a fixed output feature, multiply each saved key probability by that key's V coordinate, and accumulate from zero in key order. The final running sum is the output feature.
| Saved operation | Input b | Input i | Input f | Input p0 | Input v0 | Input p1 | Input v1 | Input p2 | Input v2 | Result product0 | Result product1 | Result product2 | Result running0 | Result running1 | Result running2 | Result value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| left_mix_0_0_0 | 0 | 0 | 0 | 0.4011120926797859 | 1 | 0.1977758146404282 | 0 | 0.4011120926797859 | 1 | 0.4011120926797859 | 0 | 0.4011120926797859 | 0.4011120926797859 | 0.4011120926797859 | 0.8022241853595719 | 0.8022241853595719 |
| left_mix_0_0_1 | 0 | 0 | 1 | 0.4011120926797859 | 0 | 0.1977758146404282 | 1 | 0.4011120926797859 | 1 | 0 | 0.1977758146404282 | 0.4011120926797859 | 0 | 0.1977758146404282 | 0.5988879073202141 | 0.5988879073202141 |
| left_mix_0_1_0 | 0 | 1 | 0 | 0.1977758146404282 | 1 | 0.4011120926797859 | 0 | 0.4011120926797859 | 1 | 0.1977758146404282 | 0 | 0.4011120926797859 | 0.1977758146404282 | 0.1977758146404282 | 0.5988879073202141 | 0.5988879073202141 |
| left_mix_0_1_1 | 0 | 1 | 1 | 0.1977758146404282 | 0 | 0.4011120926797859 | 1 | 0.4011120926797859 | 1 | 0 | 0.4011120926797859 | 0.4011120926797859 | 0 | 0.4011120926797859 | 0.8022241853595719 | 0.8022241853595719 |
| left_mix_0_2_0 | 0 | 2 | 0 | 0.2482550782577231 | 1 | 0.2482550782577231 | 0 | 0.5034898434845538 | 1 | 0.2482550782577231 | 0 | 0.5034898434845538 | 0.2482550782577231 | 0.2482550782577231 | 0.7517449217422769 | 0.7517449217422769 |
| left_mix_0_2_1 | 0 | 2 | 1 | 0.2482550782577231 | 0 | 0.2482550782577231 | 1 | 0.5034898434845538 | 1 | 0 | 0.2482550782577231 | 0.5034898434845538 | 0 | 0.2482550782577231 | 0.7517449217422769 | 0.7517449217422769 |
LeftO
B=1 × Query=3 × Dv=2 · float64 · display precision 8. O=PV: one weighted sum over keys per query and value feature, with every product and sequential running sum recorded.
| Query / slot (batch 0) | Value feature 0 | Value feature 1 |
|---|---|---|
| 0 | 0.8022241853595719 | 0.5988879073202141 |
| 1 | 0.5988879073202141 | 0.8022241853595719 |
| 2 | 0.7517449217422769 | 0.7517449217422769 |
Right: the protected IV-25 computation, used unchanged
Each side retains all 37 saved child steps, including setup, and all 13 child tensors. The names identify the side; the arithmetic is the same projection → score → key-axis softmax → weighted-value sequence taught in IV-25.
Right child setup: all 33 input fields
| Saved operation | Input B | Input T | Input Dk | Input Dv | Input x000 | Input x001 | Input x010 | Input x011 | Input x020 | Input x021 | Input x100 | Input x101 | Input x110 | Input x111 | Input x120 | Input x121 | Input wq00 | Input wq01 | Input wq10 | Input wq11 | Input wk00 | Input wk01 | Input wk10 | Input wk11 | Input wv00 | Input wv01 | Input wv10 | Input wv11 | Input mode | Input valid0 | Input valid1 | Input valid2 | Input shift | Result B | Result T | Result D | Result Dk | Result Dv |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| right_setup | 1 | 3 | 2 | 2 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | -1 | 0 | 0 | 2 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 3 | 2 | 2 | 2 |
RightX
B=1 × T=3 × D=2 · float64 · display precision 8. Active input token rows, selected without padding or broadcasting.
| Token / query (batch 0) | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 1 | 0 |
| 2 | 0 | 1 |
RightWQ
D=2 × Dk=2 · float64 · display precision 8. Both input rows; leading Dk query columns of the editable WQ.
| Input feature | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
RightWK
D=2 × Dk=2 · float64 · display precision 8. Both input rows; leading Dk key columns of the editable WK.
| Input feature | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
RightWV
D=2 × Dv=2 · float64 · display precision 8. Both input rows; leading Dv value columns of the editable WV.
| Input feature | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 0 | 1 |
RightQ
B=1 × T=3 × Dk=2 · float64 · display precision 8. Q=XWQ, with each coordinate traced as two products and one sum.
| Token / query (batch 0) | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 1 | 0 |
| 2 | 0 | 1 |
RightK
B=1 × T=3 × Dk=2 · float64 · display precision 8. K=XWK, with each coordinate traced as two products and one sum.
| Token / query (batch 0) | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 1 | 0 |
| 2 | 0 | 1 |
RightV
B=1 × T=3 × Dv=2 · float64 · display precision 8. V=XWV, available for later value mixing; not mixed in IV-22–24.
| Token / query (batch 0) | Output feature 0 | Output feature 1 |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 1 | 0 |
| 2 | 0 | 1 |
Every projection product and sum
A token row times each weight column gives two feature products and their sum. Q, K and V are separately recomputed on this side's assembled X.
| Saved operation | Input b | Input t | Input f | Input x0 | Input x1 | Input w0 | Input w1 | Result product0 | Result product1 | Result value |
|---|---|---|---|---|---|---|---|---|---|---|
| right_project_Q_0_0_0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
| right_project_Q_0_0_1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 |
| right_project_Q_0_1_0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
| right_project_Q_0_1_1 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| right_project_Q_0_2_0 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| right_project_Q_0_2_1 | 0 | 2 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 |
| right_project_K_0_0_0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
| right_project_K_0_0_1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 |
| right_project_K_0_1_0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
| right_project_K_0_1_1 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| right_project_K_0_2_0 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| right_project_K_0_2_1 | 0 | 2 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 |
| right_project_V_0_0_0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
| right_project_V_0_0_1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 |
| right_project_V_0_1_0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
| right_project_V_0_1_1 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| right_project_V_0_2_0 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| right_project_V_0_2_1 | 0 | 2 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 |
Every query–key dot product and scaling
The saved product0 and product1 add to raw; score divides raw by sqrt(2). These signed scores are not probabilities.
| Saved operation | Input b | Input i | Input j | Input Dk | Input divisor | Input q0 | Input k0 | Input q1 | Input k1 | Result product0 | Result product1 | Result raw | Result score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| right_score_0_0_0 | 0 | 0 | 0 | 2 | 1.4142135623730951 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1.414213562373095 |
| right_score_0_0_1 | 0 | 0 | 1 | 2 | 1.4142135623730951 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0.7071067811865475 |
| right_score_0_0_2 | 0 | 0 | 2 | 2 | 1.4142135623730951 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0.7071067811865475 |
| right_score_0_1_0 | 0 | 1 | 0 | 2 | 1.4142135623730951 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 0.7071067811865475 |
| right_score_0_1_1 | 0 | 1 | 1 | 2 | 1.4142135623730951 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0.7071067811865475 |
| right_score_0_1_2 | 0 | 1 | 2 | 2 | 1.4142135623730951 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| right_score_0_2_0 | 0 | 2 | 0 | 2 | 1.4142135623730951 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0.7071067811865475 |
| right_score_0_2_1 | 0 | 2 | 1 | 2 | 1.4142135623730951 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
| right_score_0_2_2 | 0 | 2 | 2 | 2 | 1.4142135623730951 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0.7071067811865475 |
Rightraw
B=1 × Query=3 × Key=3 · float64 · display precision 8. QK transpose: explicit feature products followed by their sum, within each batch.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | 2 | 1 | 1 |
| 1 | 1 | 1 | 0 |
| 2 | 1 | 0 | 1 |
Rightscores
B=1 × Query=3 × Key=3 · float64 · display precision 8. Raw query-key agreement divided by sqrt(Dk); not softmax probabilities.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | 1.414213562373095 | 0.7071067811865475 | 0.7071067811865475 |
| 1 | 0.7071067811865475 | 0.7071067811865475 | 0 |
| 2 | 0.7071067811865475 | 0 | 0.7071067811865475 |
Every unmasked softmax row
All allowed flags are true. Subtract the saved row maximum, exponentiate each shifted logit, add the terms in increasing key order, then divide each term by the denominator. No key is dropped, and shift is zero.
| Saved operation | Input b | Input i | Input mode | Input shift | Input score0 | Input score1 | Input score2 | Input allowed0 | Input allowed1 | Input allowed2 | Result max | Result denominator | Result shifted0 | Result shifted1 | Result shifted2 | Result term0 | Result term1 | Result term2 | Result p0 | Result p1 | Result p2 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| right_row_0_0 | 0 | 0 | 0 | 0 | 1.414213562373095 | 0.7071067811865475 | 0.7071067811865475 | 1 | 1 | 1 | 1.414213562373095 | 1.9861373827904796 | 0 | -0.7071067811865475 | -0.7071067811865475 | 1 | 0.49306869139523984 | 0.49306869139523984 | 0.5034898434845538 | 0.2482550782577231 | 0.2482550782577231 |
| right_row_0_1 | 0 | 1 | 0 | 0 | 0.7071067811865475 | 0.7071067811865475 | 0 | 1 | 1 | 1 | 0.7071067811865475 | 2.49306869139524 | 0 | 0 | -0.7071067811865475 | 1 | 1 | 0.49306869139523984 | 0.4011120926797859 | 0.4011120926797859 | 0.1977758146404282 |
| right_row_0_2 | 0 | 2 | 0 | 0 | 0.7071067811865475 | 0 | 0.7071067811865475 | 1 | 1 | 1 | 0.7071067811865475 | 2.49306869139524 | 0 | -0.7071067811865475 | 0 | 1 | 0.49306869139523984 | 1 | 0.4011120926797859 | 0.1977758146404282 | 0.4011120926797859 |
Rightallowed
B=1 × Query=3 × Key=3 · bool · display precision 8. True means this key may contribute to this query; key validity is shared across batches.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | true | true | true |
| 1 | true | true | true |
| 2 | true | true | true |
Rightlogits
B=1 × Query=3 × Key=3 · float64 · display precision 8. Finite score+common shift for every active key, including forbidden keys; no mask sentinel.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | 1.414213562373095 | 0.7071067811865475 | 0.7071067811865475 |
| 1 | 0.7071067811865475 | 0.7071067811865475 | 0 |
| 2 | 0.7071067811865475 | 0 | 0.7071067811865475 |
Rightprobabilities
B=1 × Query=3 × Key=3 · float64 · display precision 8. Allowed-key stable softmax along the key axis only. Forbidden keys have exactly zero; allowed exponential underflow is separately possible.
| Query | Key 0 | Key 1 | Key 2 |
|---|---|---|---|
| 0 | 0.5034898434845538 | 0.2482550782577231 | 0.2482550782577231 |
| 1 | 0.4011120926797859 | 0.4011120926797859 | 0.1977758146404282 |
| 2 | 0.4011120926797859 | 0.1977758146404282 | 0.4011120926797859 |
Every probability × value product and running sum
For a fixed output feature, multiply each saved key probability by that key's V coordinate, and accumulate from zero in key order. The final running sum is the output feature.
| Saved operation | Input b | Input i | Input f | Input p0 | Input v0 | Input p1 | Input v1 | Input p2 | Input v2 | Result product0 | Result product1 | Result product2 | Result running0 | Result running1 | Result running2 | Result value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| right_mix_0_0_0 | 0 | 0 | 0 | 0.5034898434845538 | 1 | 0.2482550782577231 | 1 | 0.2482550782577231 | 0 | 0.5034898434845538 | 0.2482550782577231 | 0 | 0.5034898434845538 | 0.7517449217422769 | 0.7517449217422769 | 0.7517449217422769 |
| right_mix_0_0_1 | 0 | 0 | 1 | 0.5034898434845538 | 1 | 0.2482550782577231 | 0 | 0.2482550782577231 | 1 | 0.5034898434845538 | 0 | 0.2482550782577231 | 0.5034898434845538 | 0.5034898434845538 | 0.7517449217422769 | 0.7517449217422769 |
| right_mix_0_1_0 | 0 | 1 | 0 | 0.4011120926797859 | 1 | 0.4011120926797859 | 1 | 0.1977758146404282 | 0 | 0.4011120926797859 | 0.4011120926797859 | 0 | 0.4011120926797859 | 0.8022241853595719 | 0.8022241853595719 | 0.8022241853595719 |
| right_mix_0_1_1 | 0 | 1 | 1 | 0.4011120926797859 | 1 | 0.4011120926797859 | 0 | 0.1977758146404282 | 1 | 0.4011120926797859 | 0 | 0.1977758146404282 | 0.4011120926797859 | 0.4011120926797859 | 0.5988879073202141 | 0.5988879073202141 |
| right_mix_0_2_0 | 0 | 2 | 0 | 0.4011120926797859 | 1 | 0.1977758146404282 | 1 | 0.4011120926797859 | 0 | 0.4011120926797859 | 0.1977758146404282 | 0 | 0.4011120926797859 | 0.5988879073202141 | 0.5988879073202141 | 0.5988879073202141 |
| right_mix_0_2_1 | 0 | 2 | 1 | 0.4011120926797859 | 1 | 0.1977758146404282 | 0 | 0.4011120926797859 | 1 | 0.4011120926797859 | 0 | 0.4011120926797859 | 0.4011120926797859 | 0.4011120926797859 | 0.8022241853595719 | 0.8022241853595719 |
RightO
B=1 × Query=3 × Dv=2 · float64 · display precision 8. O=PV: one weighted sum over keys per query and value feature, with every product and sequential running sum recorded.
| Query / slot (batch 0) | Value feature 0 | Value feature 1 |
|---|---|---|
| 0 | 0.7517449217422769 | 0.7517449217422769 |
| 1 | 0.8022241853595719 | 0.5988879073202141 |
| 2 | 0.5988879073202141 | 0.8022241853595719 |
All six corresponding-coordinate comparisons
| Saved operation | Input t | Input d | Input sourceIndex | Input right | Input expected | Result difference |
|---|---|---|---|---|---|---|
| compare_0_0 | 0 | 0 | 2 | 0.7517449217422769 | 0.7517449217422769 | 0 |
| compare_0_1 | 0 | 1 | 2 | 0.7517449217422769 | 0.7517449217422769 | 0 |
| compare_1_0 | 1 | 0 | 0 | 0.8022241853595719 | 0.8022241853595719 | 0 |
| compare_1_1 | 1 | 1 | 0 | 0.5988879073202141 | 0.5988879073202141 | 0 |
| compare_2_0 | 2 | 0 | 1 | 0.5988879073202141 | 0.5988879073202141 | 0 |
| compare_2_1 | 2 | 1 | 1 | 0.8022241853595719 | 0.8022241853595719 | 0 |
Expected
B=1 × T=3 × D=2 · float64 · display precision 8. LeftO gathered by pi along the query rows, retaining each value-feature coordinate.
| New slot (batch 0) | Feature 0 | Feature 1 |
|---|---|---|
| 0 | 0.7517449217422769 | 0.7517449217422769 |
| 1 | 0.8022241853595719 | 0.5988879073202141 |
| 2 | 0.5988879073202141 | 0.8022241853595719 |
Difference
B=1 × T=3 × D=2 · float64 · display precision 8. Actual recomputed RightO minus Expected, without rounding or zero suppression.
| New slot (batch 0) | Feature 0 | Feature 1 |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 2 | 0 | 0 |
With signals off, unmasked attention is permutation equivariant in real arithmetic: rearranging inputs rearranges outputs in the same way. It does not leave each row unchanged. Reordering the key summation can leave a small stored residual, so this lab never forces equality. Fixed slot signals generally break that identity; an identity permutation or uniform attention can still agree. A fixed causal mask does not meet the arbitrary-permutation premise unless the mask is permuted too.
Every number above comes from a saved tensor or operation record. The full-precision inspector also lists all scalar aliases, named axes, dtypes, provenance and detached row-major storage. Changing an input creates a new trace and resets the graded answers.
Inspect tensor shapes and full precision
All computed outputs
- maxAbsDifference
- 0
- difference00
- 0
- difference01
- 0
- difference10
- 0
- difference11
- 0
- difference20
- 0
- difference21
- 0
- B
- 1
- T
- 3
- D
- 2
- permutation
- 4
- signal
- 0
- left_B
- 1
- left_T
- 3
- left_Dk
- 2
- left_Dv
- 2
- left_q000
- 1
- left_q001
- 0
- left_q010
- 0
- left_q011
- 1
- left_q020
- 1
- left_q021
- 1
- left_k000
- 1
- left_k001
- 0
- left_k010
- 0
- left_k011
- 1
- left_k020
- 1
- left_k021
- 1
- left_v000
- 1
- left_v001
- 0
- left_v010
- 0
- left_v011
- 1
- left_v020
- 1
- left_v021
- 1
- left_raw000
- 1
- left_score000
- 0.7071067811865475
- left_raw001
- 0
- left_score001
- 0
- left_raw002
- 1
- left_score002
- 0.7071067811865475
- left_raw010
- 0
- left_score010
- 0
- left_raw011
- 1
- left_score011
- 0.7071067811865475
- left_raw012
- 1
- left_score012
- 0.7071067811865475
- left_raw020
- 1
- left_score020
- 0.7071067811865475
- left_raw021
- 1
- left_score021
- 0.7071067811865475
- left_raw022
- 2
- left_score022
- 1.414213562373095
- left_p000
- 0.4011120926797859
- left_p001
- 0.1977758146404282
- left_p002
- 0.4011120926797859
- left_p010
- 0.1977758146404282
- left_p011
- 0.4011120926797859
- left_p012
- 0.4011120926797859
- left_p020
- 0.2482550782577231
- left_p021
- 0.2482550782577231
- left_p022
- 0.5034898434845538
- left_o000
- 0.8022241853595719
- left_o001
- 0.5988879073202141
- left_o010
- 0.5988879073202141
- left_o011
- 0.8022241853595719
- left_o020
- 0.7517449217422769
- left_o021
- 0.7517449217422769
- left_setup_B
- 1
- left_setup_T
- 3
- left_setup_D
- 2
- left_setup_Dk
- 2
- left_setup_Dv
- 2
- left_project_Q_0_0_0_product0
- 1
- left_project_Q_0_0_0_product1
- 0
- left_project_Q_0_0_0_value
- 1
- left_project_Q_0_0_1_product0
- 0
- left_project_Q_0_0_1_product1
- 0
- left_project_Q_0_0_1_value
- 0
- left_project_Q_0_1_0_product0
- 0
- left_project_Q_0_1_0_product1
- 0
- left_project_Q_0_1_0_value
- 0
- left_project_Q_0_1_1_product0
- 0
- left_project_Q_0_1_1_product1
- 1
- left_project_Q_0_1_1_value
- 1
- left_project_Q_0_2_0_product0
- 1
- left_project_Q_0_2_0_product1
- 0
- left_project_Q_0_2_0_value
- 1
- left_project_Q_0_2_1_product0
- 0
- left_project_Q_0_2_1_product1
- 1
- left_project_Q_0_2_1_value
- 1
- left_project_K_0_0_0_product0
- 1
- left_project_K_0_0_0_product1
- 0
- left_project_K_0_0_0_value
- 1
- left_project_K_0_0_1_product0
- 0
- left_project_K_0_0_1_product1
- 0
- left_project_K_0_0_1_value
- 0
- left_project_K_0_1_0_product0
- 0
- left_project_K_0_1_0_product1
- 0
- left_project_K_0_1_0_value
- 0
- left_project_K_0_1_1_product0
- 0
- left_project_K_0_1_1_product1
- 1
- left_project_K_0_1_1_value
- 1
- left_project_K_0_2_0_product0
- 1
- left_project_K_0_2_0_product1
- 0
- left_project_K_0_2_0_value
- 1
- left_project_K_0_2_1_product0
- 0
- left_project_K_0_2_1_product1
- 1
- left_project_K_0_2_1_value
- 1
- left_project_V_0_0_0_product0
- 1
- left_project_V_0_0_0_product1
- 0
- left_project_V_0_0_0_value
- 1
- left_project_V_0_0_1_product0
- 0
- left_project_V_0_0_1_product1
- 0
- left_project_V_0_0_1_value
- 0
- left_project_V_0_1_0_product0
- 0
- left_project_V_0_1_0_product1
- 0
- left_project_V_0_1_0_value
- 0
- left_project_V_0_1_1_product0
- 0
- left_project_V_0_1_1_product1
- 1
- left_project_V_0_1_1_value
- 1
- left_project_V_0_2_0_product0
- 1
- left_project_V_0_2_0_product1
- 0
- left_project_V_0_2_0_value
- 1
- left_project_V_0_2_1_product0
- 0
- left_project_V_0_2_1_product1
- 1
- left_project_V_0_2_1_value
- 1
- left_score_0_0_0_product0
- 1
- left_score_0_0_0_product1
- 0
- left_score_0_0_0_raw
- 1
- left_score_0_0_0_score
- 0.7071067811865475
- left_score_0_0_1_product0
- 0
- left_score_0_0_1_product1
- 0
- left_score_0_0_1_raw
- 0
- left_score_0_0_1_score
- 0
- left_score_0_0_2_product0
- 1
- left_score_0_0_2_product1
- 0
- left_score_0_0_2_raw
- 1
- left_score_0_0_2_score
- 0.7071067811865475
- left_score_0_1_0_product0
- 0
- left_score_0_1_0_product1
- 0
- left_score_0_1_0_raw
- 0
- left_score_0_1_0_score
- 0
- left_score_0_1_1_product0
- 0
- left_score_0_1_1_product1
- 1
- left_score_0_1_1_raw
- 1
- left_score_0_1_1_score
- 0.7071067811865475
- left_score_0_1_2_product0
- 0
- left_score_0_1_2_product1
- 1
- left_score_0_1_2_raw
- 1
- left_score_0_1_2_score
- 0.7071067811865475
- left_score_0_2_0_product0
- 1
- left_score_0_2_0_product1
- 0
- left_score_0_2_0_raw
- 1
- left_score_0_2_0_score
- 0.7071067811865475
- left_score_0_2_1_product0
- 0
- left_score_0_2_1_product1
- 1
- left_score_0_2_1_raw
- 1
- left_score_0_2_1_score
- 0.7071067811865475
- left_score_0_2_2_product0
- 1
- left_score_0_2_2_product1
- 1
- left_score_0_2_2_raw
- 2
- left_score_0_2_2_score
- 1.414213562373095
- left_row_0_0_max
- 0.7071067811865475
- left_row_0_0_denominator
- 2.49306869139524
- left_row_0_0_shifted0
- 0
- left_row_0_0_shifted1
- -0.7071067811865475
- left_row_0_0_shifted2
- 0
- left_row_0_0_term0
- 1
- left_row_0_0_term1
- 0.49306869139523984
- left_row_0_0_term2
- 1
- left_row_0_0_p0
- 0.4011120926797859
- left_row_0_0_p1
- 0.1977758146404282
- left_row_0_0_p2
- 0.4011120926797859
- left_row_0_1_max
- 0.7071067811865475
- left_row_0_1_denominator
- 2.49306869139524
- left_row_0_1_shifted0
- -0.7071067811865475
- left_row_0_1_shifted1
- 0
- left_row_0_1_shifted2
- 0
- left_row_0_1_term0
- 0.49306869139523984
- left_row_0_1_term1
- 1
- left_row_0_1_term2
- 1
- left_row_0_1_p0
- 0.1977758146404282
- left_row_0_1_p1
- 0.4011120926797859
- left_row_0_1_p2
- 0.4011120926797859
- left_row_0_2_max
- 1.414213562373095
- left_row_0_2_denominator
- 1.9861373827904796
- left_row_0_2_shifted0
- -0.7071067811865475
- left_row_0_2_shifted1
- -0.7071067811865475
- left_row_0_2_shifted2
- 0
- left_row_0_2_term0
- 0.49306869139523984
- left_row_0_2_term1
- 0.49306869139523984
- left_row_0_2_term2
- 1
- left_row_0_2_p0
- 0.2482550782577231
- left_row_0_2_p1
- 0.2482550782577231
- left_row_0_2_p2
- 0.5034898434845538
- left_mix_0_0_0_product0
- 0.4011120926797859
- left_mix_0_0_0_product1
- 0
- left_mix_0_0_0_product2
- 0.4011120926797859
- left_mix_0_0_0_running0
- 0.4011120926797859
- left_mix_0_0_0_running1
- 0.4011120926797859
- left_mix_0_0_0_running2
- 0.8022241853595719
- left_mix_0_0_0_value
- 0.8022241853595719
- left_mix_0_0_1_product0
- 0
- left_mix_0_0_1_product1
- 0.1977758146404282
- left_mix_0_0_1_product2
- 0.4011120926797859
- left_mix_0_0_1_running0
- 0
- left_mix_0_0_1_running1
- 0.1977758146404282
- left_mix_0_0_1_running2
- 0.5988879073202141
- left_mix_0_0_1_value
- 0.5988879073202141
- left_mix_0_1_0_product0
- 0.1977758146404282
- left_mix_0_1_0_product1
- 0
- left_mix_0_1_0_product2
- 0.4011120926797859
- left_mix_0_1_0_running0
- 0.1977758146404282
- left_mix_0_1_0_running1
- 0.1977758146404282
- left_mix_0_1_0_running2
- 0.5988879073202141
- left_mix_0_1_0_value
- 0.5988879073202141
- left_mix_0_1_1_product0
- 0
- left_mix_0_1_1_product1
- 0.4011120926797859
- left_mix_0_1_1_product2
- 0.4011120926797859
- left_mix_0_1_1_running0
- 0
- left_mix_0_1_1_running1
- 0.4011120926797859
- left_mix_0_1_1_running2
- 0.8022241853595719
- left_mix_0_1_1_value
- 0.8022241853595719
- left_mix_0_2_0_product0
- 0.2482550782577231
- left_mix_0_2_0_product1
- 0
- left_mix_0_2_0_product2
- 0.5034898434845538
- left_mix_0_2_0_running0
- 0.2482550782577231
- left_mix_0_2_0_running1
- 0.2482550782577231
- left_mix_0_2_0_running2
- 0.7517449217422769
- left_mix_0_2_0_value
- 0.7517449217422769
- left_mix_0_2_1_product0
- 0
- left_mix_0_2_1_product1
- 0.2482550782577231
- left_mix_0_2_1_product2
- 0.5034898434845538
- left_mix_0_2_1_running0
- 0
- left_mix_0_2_1_running1
- 0.2482550782577231
- left_mix_0_2_1_running2
- 0.7517449217422769
- left_mix_0_2_1_value
- 0.7517449217422769
- right_B
- 1
- right_T
- 3
- right_Dk
- 2
- right_Dv
- 2
- right_q000
- 1
- right_q001
- 1
- right_q010
- 1
- right_q011
- 0
- right_q020
- 0
- right_q021
- 1
- right_k000
- 1
- right_k001
- 1
- right_k010
- 1
- right_k011
- 0
- right_k020
- 0
- right_k021
- 1
- right_v000
- 1
- right_v001
- 1
- right_v010
- 1
- right_v011
- 0
- right_v020
- 0
- right_v021
- 1
- right_raw000
- 2
- right_score000
- 1.414213562373095
- right_raw001
- 1
- right_score001
- 0.7071067811865475
- right_raw002
- 1
- right_score002
- 0.7071067811865475
- right_raw010
- 1
- right_score010
- 0.7071067811865475
- right_raw011
- 1
- right_score011
- 0.7071067811865475
- right_raw012
- 0
- right_score012
- 0
- right_raw020
- 1
- right_score020
- 0.7071067811865475
- right_raw021
- 0
- right_score021
- 0
- right_raw022
- 1
- right_score022
- 0.7071067811865475
- right_p000
- 0.5034898434845538
- right_p001
- 0.2482550782577231
- right_p002
- 0.2482550782577231
- right_p010
- 0.4011120926797859
- right_p011
- 0.4011120926797859
- right_p012
- 0.1977758146404282
- right_p020
- 0.4011120926797859
- right_p021
- 0.1977758146404282
- right_p022
- 0.4011120926797859
- right_o000
- 0.7517449217422769
- right_o001
- 0.7517449217422769
- right_o010
- 0.8022241853595719
- right_o011
- 0.5988879073202141
- right_o020
- 0.5988879073202141
- right_o021
- 0.8022241853595719
- right_setup_B
- 1
- right_setup_T
- 3
- right_setup_D
- 2
- right_setup_Dk
- 2
- right_setup_Dv
- 2
- right_project_Q_0_0_0_product0
- 1
- right_project_Q_0_0_0_product1
- 0
- right_project_Q_0_0_0_value
- 1
- right_project_Q_0_0_1_product0
- 0
- right_project_Q_0_0_1_product1
- 1
- right_project_Q_0_0_1_value
- 1
- right_project_Q_0_1_0_product0
- 1
- right_project_Q_0_1_0_product1
- 0
- right_project_Q_0_1_0_value
- 1
- right_project_Q_0_1_1_product0
- 0
- right_project_Q_0_1_1_product1
- 0
- right_project_Q_0_1_1_value
- 0
- right_project_Q_0_2_0_product0
- 0
- right_project_Q_0_2_0_product1
- 0
- right_project_Q_0_2_0_value
- 0
- right_project_Q_0_2_1_product0
- 0
- right_project_Q_0_2_1_product1
- 1
- right_project_Q_0_2_1_value
- 1
- right_project_K_0_0_0_product0
- 1
- right_project_K_0_0_0_product1
- 0
- right_project_K_0_0_0_value
- 1
- right_project_K_0_0_1_product0
- 0
- right_project_K_0_0_1_product1
- 1
- right_project_K_0_0_1_value
- 1
- right_project_K_0_1_0_product0
- 1
- right_project_K_0_1_0_product1
- 0
- right_project_K_0_1_0_value
- 1
- right_project_K_0_1_1_product0
- 0
- right_project_K_0_1_1_product1
- 0
- right_project_K_0_1_1_value
- 0
- right_project_K_0_2_0_product0
- 0
- right_project_K_0_2_0_product1
- 0
- right_project_K_0_2_0_value
- 0
- right_project_K_0_2_1_product0
- 0
- right_project_K_0_2_1_product1
- 1
- right_project_K_0_2_1_value
- 1
- right_project_V_0_0_0_product0
- 1
- right_project_V_0_0_0_product1
- 0
- right_project_V_0_0_0_value
- 1
- right_project_V_0_0_1_product0
- 0
- right_project_V_0_0_1_product1
- 1
- right_project_V_0_0_1_value
- 1
- right_project_V_0_1_0_product0
- 1
- right_project_V_0_1_0_product1
- 0
- right_project_V_0_1_0_value
- 1
- right_project_V_0_1_1_product0
- 0
- right_project_V_0_1_1_product1
- 0
- right_project_V_0_1_1_value
- 0
- right_project_V_0_2_0_product0
- 0
- right_project_V_0_2_0_product1
- 0
- right_project_V_0_2_0_value
- 0
- right_project_V_0_2_1_product0
- 0
- right_project_V_0_2_1_product1
- 1
- right_project_V_0_2_1_value
- 1
- right_score_0_0_0_product0
- 1
- right_score_0_0_0_product1
- 1
- right_score_0_0_0_raw
- 2
- right_score_0_0_0_score
- 1.414213562373095
- right_score_0_0_1_product0
- 1
- right_score_0_0_1_product1
- 0
- right_score_0_0_1_raw
- 1
- right_score_0_0_1_score
- 0.7071067811865475
- right_score_0_0_2_product0
- 0
- right_score_0_0_2_product1
- 1
- right_score_0_0_2_raw
- 1
- right_score_0_0_2_score
- 0.7071067811865475
- right_score_0_1_0_product0
- 1
- right_score_0_1_0_product1
- 0
- right_score_0_1_0_raw
- 1
- right_score_0_1_0_score
- 0.7071067811865475
- right_score_0_1_1_product0
- 1
- right_score_0_1_1_product1
- 0
- right_score_0_1_1_raw
- 1
- right_score_0_1_1_score
- 0.7071067811865475
- right_score_0_1_2_product0
- 0
- right_score_0_1_2_product1
- 0
- right_score_0_1_2_raw
- 0
- right_score_0_1_2_score
- 0
- right_score_0_2_0_product0
- 0
- right_score_0_2_0_product1
- 1
- right_score_0_2_0_raw
- 1
- right_score_0_2_0_score
- 0.7071067811865475
- right_score_0_2_1_product0
- 0
- right_score_0_2_1_product1
- 0
- right_score_0_2_1_raw
- 0
- right_score_0_2_1_score
- 0
- right_score_0_2_2_product0
- 0
- right_score_0_2_2_product1
- 1
- right_score_0_2_2_raw
- 1
- right_score_0_2_2_score
- 0.7071067811865475
- right_row_0_0_max
- 1.414213562373095
- right_row_0_0_denominator
- 1.9861373827904796
- right_row_0_0_shifted0
- 0
- right_row_0_0_shifted1
- -0.7071067811865475
- right_row_0_0_shifted2
- -0.7071067811865475
- right_row_0_0_term0
- 1
- right_row_0_0_term1
- 0.49306869139523984
- right_row_0_0_term2
- 0.49306869139523984
- right_row_0_0_p0
- 0.5034898434845538
- right_row_0_0_p1
- 0.2482550782577231
- right_row_0_0_p2
- 0.2482550782577231
- right_row_0_1_max
- 0.7071067811865475
- right_row_0_1_denominator
- 2.49306869139524
- right_row_0_1_shifted0
- 0
- right_row_0_1_shifted1
- 0
- right_row_0_1_shifted2
- -0.7071067811865475
- right_row_0_1_term0
- 1
- right_row_0_1_term1
- 1
- right_row_0_1_term2
- 0.49306869139523984
- right_row_0_1_p0
- 0.4011120926797859
- right_row_0_1_p1
- 0.4011120926797859
- right_row_0_1_p2
- 0.1977758146404282
- right_row_0_2_max
- 0.7071067811865475
- right_row_0_2_denominator
- 2.49306869139524
- right_row_0_2_shifted0
- 0
- right_row_0_2_shifted1
- -0.7071067811865475
- right_row_0_2_shifted2
- 0
- right_row_0_2_term0
- 1
- right_row_0_2_term1
- 0.49306869139523984
- right_row_0_2_term2
- 1
- right_row_0_2_p0
- 0.4011120926797859
- right_row_0_2_p1
- 0.1977758146404282
- right_row_0_2_p2
- 0.4011120926797859
- right_mix_0_0_0_product0
- 0.5034898434845538
- right_mix_0_0_0_product1
- 0.2482550782577231
- right_mix_0_0_0_product2
- 0
- right_mix_0_0_0_running0
- 0.5034898434845538
- right_mix_0_0_0_running1
- 0.7517449217422769
- right_mix_0_0_0_running2
- 0.7517449217422769
- right_mix_0_0_0_value
- 0.7517449217422769
- right_mix_0_0_1_product0
- 0.5034898434845538
- right_mix_0_0_1_product1
- 0
- right_mix_0_0_1_product2
- 0.2482550782577231
- right_mix_0_0_1_running0
- 0.5034898434845538
- right_mix_0_0_1_running1
- 0.5034898434845538
- right_mix_0_0_1_running2
- 0.7517449217422769
- right_mix_0_0_1_value
- 0.7517449217422769
- right_mix_0_1_0_product0
- 0.4011120926797859
- right_mix_0_1_0_product1
- 0.4011120926797859
- right_mix_0_1_0_product2
- 0
- right_mix_0_1_0_running0
- 0.4011120926797859
- right_mix_0_1_0_running1
- 0.8022241853595719
- right_mix_0_1_0_running2
- 0.8022241853595719
- right_mix_0_1_0_value
- 0.8022241853595719
- right_mix_0_1_1_product0
- 0.4011120926797859
- right_mix_0_1_1_product1
- 0
- right_mix_0_1_1_product2
- 0.1977758146404282
- right_mix_0_1_1_running0
- 0.4011120926797859
- right_mix_0_1_1_running1
- 0.4011120926797859
- right_mix_0_1_1_running2
- 0.5988879073202141
- right_mix_0_1_1_value
- 0.5988879073202141
- right_mix_0_2_0_product0
- 0.4011120926797859
- right_mix_0_2_0_product1
- 0.1977758146404282
- right_mix_0_2_0_product2
- 0
- right_mix_0_2_0_running0
- 0.4011120926797859
- right_mix_0_2_0_running1
- 0.5988879073202141
- right_mix_0_2_0_running2
- 0.5988879073202141
- right_mix_0_2_0_value
- 0.5988879073202141
- right_mix_0_2_1_product0
- 0.4011120926797859
- right_mix_0_2_1_product1
- 0
- right_mix_0_2_1_product2
- 0.4011120926797859
- right_mix_0_2_1_running0
- 0.4011120926797859
- right_mix_0_2_1_running1
- 0.4011120926797859
- right_mix_0_2_1_running2
- 0.8022241853595719
- right_mix_0_2_1_value
- 0.8022241853595719
- setup_B
- 1
- setup_T
- 3
- setup_D
- 2
- setup_permutation
- 4
- setup_signal
- 0
- left_input_0_0_value
- 1
- left_input_0_1_value
- 0
- left_input_1_0_value
- 0
- left_input_1_1_value
- 1
- left_input_2_0_value
- 1
- left_input_2_1_value
- 1
- right_input_0_0_value
- 1
- right_input_0_1_value
- 1
- right_input_1_0_value
- 1
- right_input_1_1_value
- 0
- right_input_2_0_value
- 0
- right_input_2_1_value
- 1
- compare_0_0_difference
- 0
- compare_0_1_difference
- 0
- compare_1_0_difference
- 0
- compare_1_1_difference
- 0
- compare_2_0_difference
- 0
- compare_2_1_difference
- 0
Values below are stored binary64 numbers, shown without display rounding. Axes specify what each dimension counts; flattened storage is in row-major order.
RawX
B=1 × T=3 × D=2 · float64 · display precision 8 · Original three editable token rows, before slot signals or reordering.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
SlotSignals
B=1 × T=3 × D=2 · float64 · display precision 8 · Fixed slot vectors: all zero, or (0,0),(1,0),(0,1). They do not move with tokens.
| Storage index | Value |
|---|---|
| 0 | 0 |
| 1 | 0 |
| 2 | 0 |
| 3 | 0 |
| 4 | 0 |
| 5 | 0 |
Permutation
NewSlot=3 · int32 · display precision 8 · pi[new slot] is the old token row, in lexicographic permutation order.
| Storage index | Value |
|---|---|
| 0 | 2 |
| 1 | 0 |
| 2 | 1 |
LeftX
B=1 × T=3 × D=2 · float64 · display precision 8 · Active input token rows, selected without padding or broadcasting.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
LeftWQ
D=2 × Dk=2 · float64 · display precision 8 · Both input rows; leading Dk query columns of the editable WQ.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
LeftWK
D=2 × Dk=2 · float64 · display precision 8 · Both input rows; leading Dk key columns of the editable WK.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
LeftWV
D=2 × Dv=2 · float64 · display precision 8 · Both input rows; leading Dv value columns of the editable WV.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
LeftQ
B=1 × T=3 × Dk=2 · float64 · display precision 8 · Q=XWQ, with each coordinate traced as two products and one sum.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
LeftK
B=1 × T=3 × Dk=2 · float64 · display precision 8 · K=XWK, with each coordinate traced as two products and one sum.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
LeftV
B=1 × T=3 × Dv=2 · float64 · display precision 8 · V=XWV, available for later value mixing; not mixed in IV-22–24.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
Leftraw
B=1 × Query=3 × Key=3 · float64 · display precision 8 · QK transpose: explicit feature products followed by their sum, within each batch.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 1 |
| 3 | 0 |
| 4 | 1 |
| 5 | 1 |
| 6 | 1 |
| 7 | 1 |
| 8 | 2 |
Leftscores
B=1 × Query=3 × Key=3 · float64 · display precision 8 · Raw query-key agreement divided by sqrt(Dk); not softmax probabilities.
| Storage index | Value |
|---|---|
| 0 | 0.7071067811865475 |
| 1 | 0 |
| 2 | 0.7071067811865475 |
| 3 | 0 |
| 4 | 0.7071067811865475 |
| 5 | 0.7071067811865475 |
| 6 | 0.7071067811865475 |
| 7 | 0.7071067811865475 |
| 8 | 1.414213562373095 |
Leftallowed
B=1 × Query=3 × Key=3 · bool · display precision 8 · True means this key may contribute to this query; key validity is shared across batches.
| Storage index | Value |
|---|---|
| 0 | true |
| 1 | true |
| 2 | true |
| 3 | true |
| 4 | true |
| 5 | true |
| 6 | true |
| 7 | true |
| 8 | true |
Leftlogits
B=1 × Query=3 × Key=3 · float64 · display precision 8 · Finite score+common shift for every active key, including forbidden keys; no mask sentinel.
| Storage index | Value |
|---|---|
| 0 | 0.7071067811865475 |
| 1 | 0 |
| 2 | 0.7071067811865475 |
| 3 | 0 |
| 4 | 0.7071067811865475 |
| 5 | 0.7071067811865475 |
| 6 | 0.7071067811865475 |
| 7 | 0.7071067811865475 |
| 8 | 1.414213562373095 |
Leftprobabilities
B=1 × Query=3 × Key=3 · float64 · display precision 8 · Allowed-key stable softmax along the key axis only. Forbidden keys have exactly zero; allowed exponential underflow is separately possible.
| Storage index | Value |
|---|---|
| 0 | 0.4011120926797859 |
| 1 | 0.1977758146404282 |
| 2 | 0.4011120926797859 |
| 3 | 0.1977758146404282 |
| 4 | 0.4011120926797859 |
| 5 | 0.4011120926797859 |
| 6 | 0.2482550782577231 |
| 7 | 0.2482550782577231 |
| 8 | 0.5034898434845538 |
LeftO
B=1 × Query=3 × Dv=2 · float64 · display precision 8 · O=PV: one weighted sum over keys per query and value feature, with every product and sequential running sum recorded.
| Storage index | Value |
|---|---|
| 0 | 0.8022241853595719 |
| 1 | 0.5988879073202141 |
| 2 | 0.5988879073202141 |
| 3 | 0.8022241853595719 |
| 4 | 0.7517449217422769 |
| 5 | 0.7517449217422769 |
RightX
B=1 × T=3 × D=2 · float64 · display precision 8 · Active input token rows, selected without padding or broadcasting.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 1 |
| 2 | 1 |
| 3 | 0 |
| 4 | 0 |
| 5 | 1 |
RightWQ
D=2 × Dk=2 · float64 · display precision 8 · Both input rows; leading Dk query columns of the editable WQ.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
RightWK
D=2 × Dk=2 · float64 · display precision 8 · Both input rows; leading Dk key columns of the editable WK.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
RightWV
D=2 × Dv=2 · float64 · display precision 8 · Both input rows; leading Dv value columns of the editable WV.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
RightQ
B=1 × T=3 × Dk=2 · float64 · display precision 8 · Q=XWQ, with each coordinate traced as two products and one sum.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 1 |
| 2 | 1 |
| 3 | 0 |
| 4 | 0 |
| 5 | 1 |
RightK
B=1 × T=3 × Dk=2 · float64 · display precision 8 · K=XWK, with each coordinate traced as two products and one sum.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 1 |
| 2 | 1 |
| 3 | 0 |
| 4 | 0 |
| 5 | 1 |
RightV
B=1 × T=3 × Dv=2 · float64 · display precision 8 · V=XWV, available for later value mixing; not mixed in IV-22–24.
| Storage index | Value |
|---|---|
| 0 | 1 |
| 1 | 1 |
| 2 | 1 |
| 3 | 0 |
| 4 | 0 |
| 5 | 1 |
Rightraw
B=1 × Query=3 × Key=3 · float64 · display precision 8 · QK transpose: explicit feature products followed by their sum, within each batch.
| Storage index | Value |
|---|---|
| 0 | 2 |
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 0 |
| 6 | 1 |
| 7 | 0 |
| 8 | 1 |
Rightscores
B=1 × Query=3 × Key=3 · float64 · display precision 8 · Raw query-key agreement divided by sqrt(Dk); not softmax probabilities.
| Storage index | Value |
|---|---|
| 0 | 1.414213562373095 |
| 1 | 0.7071067811865475 |
| 2 | 0.7071067811865475 |
| 3 | 0.7071067811865475 |
| 4 | 0.7071067811865475 |
| 5 | 0 |
| 6 | 0.7071067811865475 |
| 7 | 0 |
| 8 | 0.7071067811865475 |
Rightallowed
B=1 × Query=3 × Key=3 · bool · display precision 8 · True means this key may contribute to this query; key validity is shared across batches.
| Storage index | Value |
|---|---|
| 0 | true |
| 1 | true |
| 2 | true |
| 3 | true |
| 4 | true |
| 5 | true |
| 6 | true |
| 7 | true |
| 8 | true |
Rightlogits
B=1 × Query=3 × Key=3 · float64 · display precision 8 · Finite score+common shift for every active key, including forbidden keys; no mask sentinel.
| Storage index | Value |
|---|---|
| 0 | 1.414213562373095 |
| 1 | 0.7071067811865475 |
| 2 | 0.7071067811865475 |
| 3 | 0.7071067811865475 |
| 4 | 0.7071067811865475 |
| 5 | 0 |
| 6 | 0.7071067811865475 |
| 7 | 0 |
| 8 | 0.7071067811865475 |
Rightprobabilities
B=1 × Query=3 × Key=3 · float64 · display precision 8 · Allowed-key stable softmax along the key axis only. Forbidden keys have exactly zero; allowed exponential underflow is separately possible.
| Storage index | Value |
|---|---|
| 0 | 0.5034898434845538 |
| 1 | 0.2482550782577231 |
| 2 | 0.2482550782577231 |
| 3 | 0.4011120926797859 |
| 4 | 0.4011120926797859 |
| 5 | 0.1977758146404282 |
| 6 | 0.4011120926797859 |
| 7 | 0.1977758146404282 |
| 8 | 0.4011120926797859 |
RightO
B=1 × Query=3 × Dv=2 · float64 · display precision 8 · O=PV: one weighted sum over keys per query and value feature, with every product and sequential running sum recorded.
| Storage index | Value |
|---|---|
| 0 | 0.7517449217422769 |
| 1 | 0.7517449217422769 |
| 2 | 0.8022241853595719 |
| 3 | 0.5988879073202141 |
| 4 | 0.5988879073202141 |
| 5 | 0.8022241853595719 |
Expected
B=1 × T=3 × D=2 · float64 · display precision 8 · LeftO gathered by pi along the query rows, retaining each value-feature coordinate.
| Storage index | Value |
|---|---|
| 0 | 0.7517449217422769 |
| 1 | 0.7517449217422769 |
| 2 | 0.8022241853595719 |
| 3 | 0.5988879073202141 |
| 4 | 0.5988879073202141 |
| 5 | 0.8022241853595719 |
Difference
B=1 × T=3 × D=2 · float64 · display precision 8 · Actual recomputed RightO minus Expected, without rounding or zero suppression.
| Storage index | Value |
|---|---|
| 0 | 0 |
| 1 | 0 |
| 2 | 0 |
| 3 | 0 |
| 4 | 0 |
| 5 | 0 |
Begin with slot signals off and permutation 4, which moves old rows 2,0,1 into new slots 0,1,2. Read RightO alongside Expected: the comparison follows corresponding rows. Edit any token coordinate or any of the three projection matrices to recompute both full attention calls. All 20 controls are validated; token features and weights each stay in [−2,2]. The view selectors inspect saved coordinates and leave the inputs unchanged.
For the reset inputs and identity projections, Q=K=V=X. Write a=1/sqrt(2) and r=exp(a). The three unmasked score rows are (a,0,a), (0,a,a), (a,a,2a). Their real softmax rows are (r,1,r)/(2r+1), (1,r,r)/(2r+1), and (1,1,r)/(2+r). Weighted sums give O0=(2r/(2r+1),(r+1)/(2r+1)), O1=((r+1)/(2r+1),2r/(2r+1)), and O2=((1+r)/(2+r),(1+r)/(2+r)). Permutation 4 expects these output rows in order O2,O0,O1. These are exact real formulas; the tables show stored binary64 results from the current inputs.
Now turn the fixed slot signals on without changing anything else. Left receives (1,0),(1,1),(1,2); Right receives (1,1),(2,0),(0,2). Right query 0 has scores (2a,2a,2a), so its uniform weighted output is (1,1) in real arithmetic. Its expected partner is left query 2, whose scores are (a,3a,5a). That left output has second coordinate (exp(3a)+2exp(5a))/(exp(a)+exp(3a)+exp(5a)), strictly greater than 1 because exp(5a)>exp(a). The saved compare_0_1 subtraction exposes the actual disagreement. This counterexample uses fixed slot signals and identity projections; other edits must be read from the recomputed records.
Reordering information and losing information are different issues. Unmasked attention without position follows a rearrangement consistently, but that alone does not give it an absolute slot label. The next chapter constructs additive position vectors more systematically. These hand-set parameters are an inspectable example; no training or language understanding is demonstrated.
Check your understanding
Work from the starting inputs shown above. Each answer includes the reasoning; editing the example resets your answers.
Reset selects permutation 4 and disables slot signals. Compare the right result against Expected, the corresponding reordered left output. Then enable slot signals while keeping the same tokens, weights and permutation. This changes inputs and recomputes both complete attention calculations. Reset returns to the no-signal example below. Numeric edits, rather than a picture of moving arrows, determine the new results. Open the native groups Original token rows X, WQ projection weights, WK projection weights and WV projection weights to edit their entries. The Token / new slot to inspect and Feature coordinate to inspect selectors change the view only. Calculation step exposes the selected saved operation and marks its row in the full tables.
A permutation rearranges rows without deleting or duplicating any. Our list π maps a new slot to its old row. Permutation 4 is π=(2,0,1): right slot 0 takes old token 2, slot 1 takes old token 0, and slot 2 takes old token 1. The six choices are (0,1,2), (0,2,1), (1,0,2), (1,2,0), (2,0,1), (2,1,0), in that order. Read the index mapping before interpreting a difference.
A token is a sequence item; its feature row is a short list of numbers. A tensor is an array whose axes have named meanings. RawX has shape [1,3,2], axes Batch B, Token T, Feature D: one sequence, three positions, two features. SlotSignals has the same shape. Permutation has shape [3], axis NewSlot, and integer entries. Indices start at zero. For readability the hand calculation suppresses the fixed batch axis and writes X as a 3×2 matrix.
Each weight matrix WQ, WK and WV is 2×2. Multiplying a feature row by one of these matrices produces a query Q, key K or value V row. Queries and keys set scores; values provide the numbers mixed by attention. For example Q[i,0]=X[i,0]·WQ[0,0]+X[i,1]·WQ[1,0]. The two input features match the two weight rows, so this multiplication is legal. Q,K,V have shape [1,3,2]. Raw scores, scaled scores and attention probabilities have shape [1,3,3], axes B,Query,Key. Outputs have shape [1,3,2].
This chapter deliberately uses unmasked attention: all three keys are allowed for every query, with no logit shift. A logit is a score supplied to softmax. Softmax subtracts the row maximum, exponentiates the results, and divides each term by the sum to form probabilities. We reuse IV-25’s calculation with its unmasked setting; we do not change its protected causal default.
Work every row of the no-signal example
Reset X has rows (1,0),(0,1),(1,1), and all three weight matrices are the identity I₂. Each role Q,K,V therefore has the same rows. For each of the three roles, the six projection sums are:
Let a=1/√2 and r=exp(a). These are symbolic real numbers, not decimals observed from the lab. Each raw score multiplies corresponding query/key features and adds them; division by √2 gives the scaled score:
| Query | Key 0 product sum | Key 1 product sum | Key 2 product sum | Scaled row |
|---|---|---|---|---|
| 0 | 1·1+0·0=1 | 1·0+0·1=0 | 1·1+0·1=1 | (a,0,a) |
| 1 | 0·1+1·0=0 | 0·0+1·1=1 | 0·1+1·1=1 | (0,a,a) |
| 2 | 1·1+1·0=1 | 1·0+1·1=1 | 1·1+1·1=2 | (a,a,2a) |
For rows 0 and 1 the maximum is a; for row 2 it is 2a. The code computes shifted exponentials, accumulates the denominator in ascending key order, then divides:
| Query | Subtract maximum | Exponential terms | Denominator, starting at zero | Probabilities after exact simplification |
|---|---|---|---|---|
| 0 | (0,−a,0) | (1,1/r,1) | ((0+1)+1/r)+1 | (r,1,r)/(2r+1) |
| 1 | (−a,0,0) | (1/r,1,1) | ((0+1/r)+1)+1 | (1,r,r)/(2r+1) |
| 2 | (−a,−a,0) | (1/r,1/r,1) | ((0+1/r)+1/r)+1 | (1,1,r)/(2+r) |
The simplified quotients multiply both numerator and denominator by r. They explain the result but do not replace the saved floating-point operation order. Multiply these probabilities by value features and accumulate keys 0,1,2, starting from zero. With Z=2r+1 and H=2+r, all six final sums are:
Permutation 4 makes the right input rows (1,1),(1,0),(0,1). The right raw-score matrix has rows (2,1,1),(1,1,0),(1,0,1). Its stable probability rows simplify to (r,1,1)/H, (r,r,1)/Z and (r,1,r)/Z, respectively. The right value columns are (1,1,0) and (1,0,1). Their weighted sums are (r/H+1/H+0,r/H+0+1/H), (r/Z+r/Z+0,r/Z+0+1/Z), and (r/Z+1/Z+0,r/Z+0+r/Z). Thus the right output rows are exactly O₂,O₀,O₁ in real arithmetic. Comparing right row 0 to left row 0 would ask the wrong question.
Why reordering commutes with this attention operation
Call the full unmasked attention function F. Equivariance means F(ΠX)=ΠF(X): the output moves along with the input. It does not mean invariance, F(ΠX)=F(X), which would leave row positions unchanged. Π is the 3×3 permutation matrix whose row t selects old row π[t]; its transpose Πᵀ reverses the rearrangement, so ΠᵀΠ=I.
Shared projection weights give Q′=ΠXWQ=ΠQ, and likewise K′=ΠK and V′=ΠV. With S=QKᵀ/√2, transpose reverses multiplication order:
Both query rows and key columns move. In a row, permuting scores permutes their exponentials and leaves the real denominator sum unchanged. Calling the probability matrix A, rowwise softmax therefore gives A′=ΠAΠᵀ. Finally,
This proof works for nonidentity shared projections too. It requires no fixed slot information and an unchanged all-allowed key relation. An arbitrary permutation with a fixed causal mask generally breaks its premise: “earlier than this slot” changes when tokens move. To extend the proof to a general mask, the mask must move on both query and key axes too. The causal mask itself supplies order-dependent permissions, so this unmasked theorem must not be claimed for every decoder unchanged.
Fixed slot signals: calculate an actual counterexample
Enable signals P with rows (0,0),(1,0),(0,1). The left input is X+P; the right input is ΠX+P. P stays attached to slots, whereas Π(X+P) would move the signals with tokens. All six additions on each side give:
These are inputs to fresh attention computations, not signals added to an already calculated output. Identity projections preserve each displayed row. Their dot-product matrices are
For instance left query 2 against keys 0,1,2 gives 1·1+2·0=1, 1·1+2·1=3, 1·1+2·2=5. Right query 0 gives 1·1+1·1=2, 1·2+1·0=2, 1·0+1·2=2. Dividing by √2 and softmaxing gives the complete symbolic outputs below. Each numerator lists the weighted-value contributions in key order; its denominator is the unshifted exponential sum, algebraically equivalent to stable softmax.
| Side, query | Denominator | Output feature 0 | Output feature 1 |
|---|---|---|---|
| Left 0 | r+r+r | (r·1+r·1+r·1)/(3r)=1 | (r·0+r·1+r·2)/(3r)=1 |
| Left 1 | r+r²+r³ | (r·1+r²·1+r³·1)/(r+r²+r³)=1 | (r·0+r²·1+r³·2)/(r+r²+r³) |
| Left 2 | r+r³+r⁵ | (r·1+r³·1+r⁵·1)/(r+r³+r⁵)=1 | (r·0+r³·1+r⁵·2)/(r+r³+r⁵) |
| Right 0 | r²+r²+r² | (r²·1+r²·2+r²·0)/(3r²)=1 | (r²·1+r²·0+r²·2)/(3r²)=1 |
| Right 1 | r²+r⁴+1 | (r²·1+r⁴·2+1·0)/(r²+r⁴+1) | (r²·1+r⁴·0+1·2)/(r²+r⁴+1) |
| Right 2 | r²+1+r⁴ | (r²·1+1·2+r⁴·0)/(r²+1+r⁴) | (r²·1+1·0+r⁴·2)/(r²+1+r⁴) |
For the crucial left row 2, stable softmax actually uses maximum 5a, shifted logits (−4a,−2a,0), terms (r⁻⁴,r⁻²,1), and denominator ((0+r⁻⁴)+r⁻²)+1. Right row 0 uses maximum 2a, three zero shifted logits, three unit terms, and denominator 3. Its output is (1,1). The expected corresponding left row is left query 2, whose output is (1,L), where
because a>0 implies r>1. Thus compare_0_1 computes right-minus-expected, 1−L, which is strictly negative in real arithmetic. That is the position-sensitive counterexample. No invented decimal or forced zero is needed.
Signals do not guarantee a difference for every state. The identity permutation compares identical inputs. With WQ=WK=0, every score is zero; both sides uniformly average the same total token features plus the same total signals, and the outputs can still agree. “Generally breaks equivariance” is therefore the precise claim.
Follow the maintained Python and the saved records
The wrapper below and its helper are the actual maintained files. NumPy supplies shaped float64 arrays. Float64, also called binary64, rounds arithmetic to finite precision. Reordering a sum can change its last bits even when the real-valued theorem holds. Read Book II’s VIII.2 — Rounding and representation error for that distinction. The lab computes differences from saved results rather than overwriting them with mathematical zero.
Read the complete executable Python / NumPy source
This is the actual reference file, imported directly from the repository. Comments explain each operation. It is provided for later execution; no validation run is claimed.
"""IV-34 — Why Position Matters to Attention.
X[1,3,2] stores token rows. pi[new_slot] names the old row to copy.
Compare F(pi X+P) with pi F(X+P), keeping P attached to the SLOT. Both
calls use the actual unchanged p05 IV-25 implementation in UNMASKED mode.
Without slot signals, the real identity is F(pi X)=pi F(X). Floating-point
key-summation order can leave a residual; never replace it with a forced zero.
An unchanged causal mask does not satisfy the arbitrary-permutation premise.
Hand default: a=1/sqrt(2), r=exp(a). The unmasked left rows are
(2r/(2r+1),(r+1)/(2r+1)), its coordinate reverse, and
((1+r)/(2+r),(1+r)/(2+r)). pi=(2,0,1) permutes the OUTPUT rows too.
With signal=1, left inputs are (1,0),(1,1),(1,2), right inputs
(1,1),(2,0),(0,2). Right row0 gives (1,1), while expected left row2
has second coordinate (exp(3a)+2exp(5a))/(exp(a)+exp(3a)+exp(5a))>1.
These are exact real hand expressions, not observed runtime values.
Keep position_reference.py here and the original p05 sibling directory.
Imports use this file's location, independent of the process working directory.
Source only: no import, execution or numerical verification was performed.
"""
import importlib.util
from pathlib import Path
from types import MappingProxyType
import numpy as np
_helper_spec = importlib.util.spec_from_file_location(
"_p08_position_reference", Path(__file__).resolve().with_name("position_reference.py"))
_helper = importlib.util.module_from_spec(_helper_spec)
_helper_spec.loader.exec_module(_helper)
DEFAULT_IV34 = MappingProxyType(dict(_helper.PERMUTATION_DEFAULTS))
@_helper.guarded
def derive_iv34(state):
"""Assemble, recompute both canonical attention paths, then compare rows."""
s = _helper.position_state(state, 34)
trace = _helper.position_trace()
trace.add("setup", "Validate the token permutation and fixed slot signals",
"Left=X+P; Right=pi X+P; compare F(Right) with pi F(Left)",
"pi maps each new slot to its old token row; both attention paths are unmasked.",
s, dict(B=1, T=3, D=2, permutation=s["permutation"], signal=s["signal"]))
X = np.empty((1, 3, 2), dtype=np.float64)
P = np.empty((1, 3, 2), dtype=np.float64)
pi = np.array(_helper.PERMUTATIONS[s["permutation"]], dtype=np.int32)
for t in range(3):
for d in range(2):
X[0, t, d] = s[f"x0{t}{d}"]
P[0, t, d] = 1.0 if s["signal"] == 1 and (t, d) in ((1, 0), (2, 1)) else 0.0
left_input = np.empty((1, 3, 2), dtype=np.float64)
right_input = np.empty((1, 3, 2), dtype=np.float64)
# Assemble every left coordinate before any right coordinate.
for name, target in (("left", left_input), ("right", right_input)):
for t in range(3):
source_index = t if name == "left" else int(pi[t])
for d in range(2):
token, signal = float(X[0, source_index, d]), float(P[0, t, d])
value = _helper.finite(token + signal, "assembled attention input")
target[0, t, d] = value
trace.add(f"{name}_input_{t}_{d}", f"{name.capitalize()} input [{t},{d}]",
"value=token+signal",
"Copy the selected token row, then add the signal of the destination slot.",
dict(t=t, d=d, sourceIndex=source_index, token=token, signal=signal), dict(value=value))
left = _helper.protected_attention(s, left_input)
left_saved = _helper.append_attention(trace, left, "left", "Left")
right = _helper.protected_attention(s, right_input)
right_saved = _helper.append_attention(trace, right, "right", "Right")
expected = np.empty((1, 3, 2), dtype=np.float64)
difference = np.empty((1, 3, 2), dtype=np.float64)
maximum = 0.0
for t in range(3):
source_index = int(pi[t])
for d in range(2):
wanted = left["outputs"][f"o0{source_index}{d}"]
actual = right["outputs"][f"o0{t}{d}"]
delta = _helper.finite(actual - wanted, "equivariance difference")
expected[0, t, d], difference[0, t, d] = wanted, delta
maximum = max(maximum, abs(delta))
trace.add(f"compare_{t}_{d}", f"Compare permuted output [{t},{d}]",
"difference=right-expected; expected=LeftO[pi[t],d]",
"Compare against the corresponding permuted left output, not the unchanged row label.",
dict(t=t, d=d, sourceIndex=source_index, right=actual, expected=wanted), dict(difference=delta))
summary = dict(maxAbsDifference=maximum)
for t in range(3):
for d in range(2):
summary[f"difference{t}{d}"] = float(difference[0, t, d])
summary.update(B=1, T=3, D=2, permutation=s["permutation"], signal=s["signal"])
summary.update(left_saved["aliases"])
summary.update(right_saved["aliases"])
tensors = [
_helper.tensor("RawX", [1, 3, 2], ["B", "T", "D"], X, "Original token rows before permutation or slot addition."),
_helper.tensor("SlotSignals", [1, 3, 2], ["B", "T", "D"], P, "Fixed signals of destination slots, not token identities."),
_helper.tensor("Permutation", [3], ["NewSlot"], pi, "Each new slot stores its old token row index.", "int32"),
*left_saved["tensors"], *right_saved["tensors"],
_helper.tensor("Expected", [1, 3, 2], ["B", "T", "D"], expected, "Actual LeftO rows gathered with pi[new_slot]."),
_helper.tensor("Difference", [1, 3, 2], ["B", "T", "D"], difference, "Actual RightO minus permuted actual LeftO; no residual is forced to zero."),
]
return trace.result(summary, tensors)
if __name__ == "__main__":
_helper.run(derive_iv34, DEFAULT_IV34)
Read the complete executable Python / NumPy source
This is the actual reference file, imported directly from the repository. Comments explain each operation. It is provided for later execution; no validation run is claimed.
"""Part VIII common boundaries: shaped NumPy storage and ordered scalar records.
The three lesson wrappers contain the calculations. This helper validates every
stored input (even an inactive one), detaches saved records, and loads the actual
protected IV-25 source by its file location. No attention algorithm is copied.
Python floats perform the arithmetic; NumPy gives arrays their explicit axes.
This is executable educational source, authored without importing or running it.
"""
import argparse
from functools import lru_cache, wraps
import importlib.util
import json
import math
from pathlib import Path
import sys
from types import MappingProxyType
import numpy as np
class NumericalFault(ValueError):
def __init__(self, code, reason):
super().__init__(reason)
self.code = code
def finite(value, label):
"""Accept real numeric scalars, never a bool, string, NaN or infinity."""
if isinstance(value, (bool, np.bool_)) or not isinstance(value, (int, float, np.integer, np.floating)):
raise NumericalFault("NONFINITE", f"{label} must be finite.")
try:
value = float(value)
except (ValueError, OverflowError) as error:
raise NumericalFault("NONFINITE", f"{label} must be finite.") from error
if not math.isfinite(value):
raise NumericalFault("NONFINITE", f"{label} must be finite.")
return value
PERMUTATION_DEFAULTS = MappingProxyType(dict(
permutation=4, signal=0,
x000=1, x001=0, x010=0, x011=1, x020=1, x021=1,
wq00=1, wq01=0, wq10=0, wq11=1,
wk00=1, wk01=0, wk10=0, wk11=1,
wv00=1, wv01=0, wv10=0, wv11=1,
))
ENCODING_DEFAULTS = MappingProxyType(dict(
kind=1, base=10000, p0=0, p1=1, p2=2,
x00=1, x01=0, x02=0, x03=0,
x10=0, x11=1, x12=0, x13=0,
x20=0, x21=0, x22=1, x23=0,
l00=0, l01=0, l02=0, l03=0,
l10=1, l11=0, l12=0, l13=0,
l20=0, l21=1, l22=0, l23=0,
l30=0, l31=0, l32=1, l33=0,
))
ROPE_DEFAULTS = MappingProxyType(dict(
D=4, base=10000, m=1, n=3,
q0=1, q1=2, q2=0, q3=1, k0=3, k1=-1, k2=2, k3=0,
))
PERMUTATIONS = ((0, 1, 2), (0, 2, 1), (1, 0, 2),
(1, 2, 0), (2, 0, 1), (2, 1, 0))
def position_state(state, chapter):
"""Raw validation precedes learned-table and even-width semantic checks."""
if type(chapter) is not int or chapter not in (34, 35, 36):
raise NumericalFault("INVALID_INPUT", "Use position chapter 34, 35 or 36.")
defaults = {34: PERMUTATION_DEFAULTS, 35: ENCODING_DEFAULTS, 36: ROPE_DEFAULTS}[chapter]
if type(state) not in (dict, MappingProxyType):
raise NumericalFault("INVALID_INPUT", "Use a plain object containing exactly the named scalar fields.")
if set(state) != set(defaults):
raise NumericalFault("INVALID_INPUT", "Provide every own scalar field and no extra fields, including inactive slots.")
integer_bounds = (dict(permutation=(0, 5), signal=(0, 1)) if chapter == 34 else
dict(kind=(0, 1), p0=(0, 8), p1=(0, 8), p2=(0, 8)) if chapter == 35 else
dict(D=(2, 4), m=(0, 8), n=(0, 8)))
result = {}
for key in defaults:
value = finite(state[key], key)
bounds = (1, 10000) if key == "base" else (-2, 2) if chapter == 34 else (-4, 4)
low, high = integer_bounds.get(key, bounds)
if value < low or value > high:
raise NumericalFault("INVALID_INPUT", f"{key} must be between {low} and {high}.")
if key in integer_bounds and not value.is_integer():
raise NumericalFault("INVALID_INPUT", f"{key} must be an integer choice.")
result[key] = int(value) if key in integer_bounds else value
if chapter == 35 and result["kind"] == 0 and any(result[f"p{t}"] > 3 for t in range(3)):
raise NumericalFault("UNSUPPORTED_SIZE", "The learned table supports positions 0..3 only; no extrapolation, clamping or wrapping.")
if chapter == 36 and result["D"] % 2:
raise NumericalFault("SHAPE_MISMATCH", "RoPE requires an even feature width (D=2 or D=4).")
return result
def guarded(derive):
@wraps(derive)
def call(state):
try:
return derive(state)
except NumericalFault as error:
return dict(status="unavailable", code=error.code, reason=str(error))
except (OverflowError, FloatingPointError) as error:
return dict(status="unavailable", code="NONFINITE", reason=str(error))
return call
def numbers(values):
return {key: finite(value, key) for key, value in values.items()}
class PositionTrace:
def __init__(self):
self.outputs = {}
self.steps = []
def add(self, identifier, label, equation, explanation, inputs, values):
inputs, values = numbers(inputs), numbers(values)
if len(self.steps) >= 512:
raise NumericalFault("UNSUPPORTED_SIZE", "At most 512 trace steps are supported.")
self.steps.append(dict(id=identifier, label=label, equation=equation,
explanation=explanation, inputs=inputs, outputs=values))
self.outputs.update({f"{identifier}_{key}": value for key, value in values.items()})
def result(self, summary, tensors):
# Python dict insertion order keeps aliases before the flattened trace.
return dict(status="defined", outputs=numbers({**summary, **self.outputs}),
steps=self.steps, tensors=tensors)
def position_trace():
return PositionTrace()
def tensor(identifier, shape, axes, values, provenance, dtype="float64"):
"""Require actual shaped storage; serialize a detached, dense named tensor."""
if type(shape) is not list or type(axes) is not list or not 1 <= len(shape) <= 4 or len(shape) != len(axes):
raise NumericalFault("SHAPE_MISMATCH", f"{identifier}: name each of 1–4 axes uniquely.")
if any(type(axis) is not str or not axis for axis in axes) or len(set(axes)) != len(axes):
raise NumericalFault("SHAPE_MISMATCH", f"{identifier}: each axis needs a unique name.")
if any(type(d) is not int or not 1 <= d <= 64 for d in shape) or math.prod(shape) > 4096:
raise NumericalFault("UNSUPPORTED_SIZE", f"{identifier}: dimensions 1–64 and at most 4096 elements required.")
if dtype not in ("float64", "int32", "bool"):
raise NumericalFault("INVALID_INPUT", f"{identifier}: unsupported dtype.")
array = np.asarray(values)
if array.shape != tuple(shape):
raise NumericalFault("SHAPE_MISMATCH", f"{identifier}: storage must match the named dimensions.")
flat = []
for index, value in enumerate(array.reshape(-1)):
if dtype == "bool":
if not isinstance(value, (bool, np.bool_)):
raise NumericalFault("INVALID_INPUT", f"{identifier}[{index}] must be boolean.")
flat.append(bool(value))
else:
value = finite(value, f"{identifier}[{index}]")
if dtype == "int32":
if not value.is_integer() or not -2147483648 <= value <= 2147483647:
raise NumericalFault("INVALID_INPUT", f"{identifier}[{index}] must be int32.")
value = int(value)
flat.append(value)
return dict(id=identifier, shape=list(shape), axes=list(axes), dtype=dtype,
values=flat, provenance=provenance, precision=8)
def _load_source(identifier, path):
spec = importlib.util.spec_from_file_location(identifier, path)
if spec is None or spec.loader is None:
raise ImportError(f"Cannot load canonical Python source at {path}.")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
@lru_cache(maxsize=1)
def _protected_iv25():
"""Load only this Book's p05 sources; restore temporary legacy import names."""
root = Path(__file__).resolve().parent.parent / "p05"
attention = _load_source("_p08_p05_attention", root / "attention_reference.py")
# value_reference and iv25 use legacy sibling imports. Bind BOTH names to
# these exact file-loaded modules, then restore any caller's existing names.
names = ("attention_reference", "value_reference")
missing = object()
previous = {name: sys.modules.get(name, missing) for name in names}
try:
sys.modules["attention_reference"] = attention
values = _load_source("_p08_p05_values", root / "value_reference.py")
sys.modules["value_reference"] = values
return _load_source("_p08_p05_iv25", root / "iv25.py")
finally:
for name in names:
if previous[name] is missing:
sys.modules.pop(name, None)
else:
sys.modules[name] = previous[name]
def protected_attention(s, X):
"""Compose the valid 33-field child state and call unchanged derive_iv25."""
canonical = _protected_iv25()
child = dict(canonical.ATTENTION_DEFAULTS)
child.update(B=1, T=3, Dk=2, Dv=2, mode=0, valid0=1, valid1=1, valid2=1, shift=0)
for t in range(3):
for d in range(2):
child[f"x0{t}{d}"] = float(X[0, t, d])
for prefix in ("wq", "wk", "wv"):
for d in range(2):
for f in range(2):
child[f"{prefix}{d}{f}"] = s[f"{prefix}{d}{f}"]
result = canonical.derive_iv25(child)
if result["status"] == "unavailable":
# The adapter keeps the child's known fault, never any partial tensors.
raise NumericalFault(result["code"], result["reason"])
return result
def append_attention(trace, child, prefix, label):
"""Retain every child step, INCLUDING setup, and clone tensor metadata."""
for step in child["steps"]:
trace.add(f"{prefix}_{step['id']}", f"{label}: {step['label']}",
step["equation"], step["explanation"], step["inputs"], step["outputs"])
tensors = [dict(id=f"{label}{record['id']}", shape=list(record["shape"]),
axes=list(record["axes"]), dtype=record["dtype"], values=list(record["values"]),
provenance=record["provenance"], precision=record["precision"])
for record in child["tensors"]]
aliases = {f"{prefix}_{key}": value for key, value in child["outputs"].items()}
return dict(tensors=tensors, aliases=aliases)
_JSON_INT = int
def run(derive, defaults):
"""No argument uses defaults; JSON replaces the full state; '-' reads stdin."""
class ParseFault(ValueError):
"""Only locally owned JSON profile/conversion faults."""
def _members(pairs):
value = {}
for key, member in pairs:
if key in value:
raise ParseFault("Duplicate JSON object members are not allowed.")
value[key] = member
return value
def _constant(token):
raise ParseFault(f"Nonstandard JSON constant {token} is not allowed.")
def _integer(token):
if token == "-0":
return -0.0
try:
return _JSON_INT(token)
except ValueError as fault:
if type(fault) is not ValueError:
raise
raise ParseFault("JSON integer exceeds the interpreter's conversion capacity.") from fault
parser = argparse.ArgumentParser(description=derive.__doc__)
parser.add_argument("state", nargs="?")
args = parser.parse_args()
if args.state is not None:
source = sys.stdin.read() if args.state == "-" else args.state
try:
state = json.loads(source, object_pairs_hook=_members,
parse_constant=_constant, parse_int=_integer)
except (json.JSONDecodeError, ParseFault) as error:
result = dict(status="unavailable", code="INVALID_INPUT", reason=str(error))
else:
result = derive(state)
else:
result = derive(dict(defaults))
print(json.dumps(result, allow_nan=False, separators=(",", ":")))
The attention wrapper and both numerical helpers reused from Part V are displayed as well; no second attention algorithm is hidden in the chapter.
Read the complete executable Python / NumPy source
This is the actual reference file, imported directly from the repository. Comments explain each operation. It is provided for later execution; no validation run is claimed.
"""IV25: the complete single-head causal self-attention numerical trace.
X -> Q,K,V -> QK transpose -> scale -> mask -> stable softmax -> O=PV.
All 33 stored scalar inputs are validated, including inactive slots.
With a=1/sqrt(2), r=exp(a), the default causal output rows are
(1,0), (1/(1+r),r/(1+r)), ((1+r)/(2+r),(1+r)/(2+r)).
These are real-arithmetic identities, not exact binary64 serializations.
Keep attention_reference.py and value_reference.py beside this program.
"""
from types import MappingProxyType
from attention_reference import ATTENTION_DEFAULTS, attention_trace, guarded, normalize, project, run, score, validated_state
from value_reference import mix_values
DEFAULT_IV25 = MappingProxyType(dict(ATTENTION_DEFAULTS))
@guarded
def derive_iv25(state):
"""Recompute the full chain; return no partial record for an invalid row."""
s = validated_state(state, attention=True)
trace = attention_trace()
# Each stage consumes the real arrays produced by its predecessor.
projection = project(s, trace)
scored = score(s, projection, trace)
normalized = normalize(s, scored, trace)
mixed = mix_values(s, projection, normalized, trace)
# Aliases precede ALL flattened trace outputs, including the new mix steps.
summary = dict(B=s["B"], T=s["T"], Dk=s["Dk"], Dv=s["Dv"])
summary.update(projection["aliases"])
summary.update(scored["aliases"])
summary.update(normalized["aliases"])
summary.update(mixed["aliases"])
return trace.result(summary, [*projection["tensors"], *scored["tensors"],
*normalized["tensors"], *mixed["tensors"]])
if __name__ == "__main__":
run(derive_iv25, DEFAULT_IV25)
Read the complete executable Python / NumPy source
This is the actual reference file, imported directly from the repository. Comments explain each operation. It is provided for later execution; no validation run is claimed.
"""Shared IV22–24 source: strict states, explicit scalar loops, NumPy storage.
X uses row features: Q[b,t,f] = X[b,t,0]*WQ[0,f] + X[b,t,1]*WQ[1,f].
This is the transpose convention of a single column-vector map. No matmul,
BLAS reduction, broadcasting, learned parameters or value mixing is hidden here.
Keep this helper beside the lesson programs. Authored, never executed under hold.
"""
import argparse
from functools import wraps
import json
import math
import sys
from types import MappingProxyType
import numpy as np
class NumericalFault(ValueError):
def __init__(self, code, reason):
super().__init__(reason)
self.code = code
def finite(value, label):
# Accept actual numeric scalars, never booleans or numeric strings.
if isinstance(value, (bool, np.bool_)) or not isinstance(value, (int, float, np.integer, np.floating)):
raise NumericalFault("NONFINITE", f"{label} must be finite.")
try:
value = float(value)
except (ValueError, OverflowError) as error:
raise NumericalFault("NONFINITE", f"{label} must be finite.") from error
if not math.isfinite(value):
raise NumericalFault("NONFINITE", f"{label} must be finite.")
return value
PROJECTION_DEFAULTS = MappingProxyType(dict(
B=1, T=3, Dk=2, Dv=2,
x000=1, x001=0, x010=0, x011=1, x020=1, x021=1,
x100=1, x101=1, x110=-1, x111=0, x120=0, x121=2,
wq00=1, wq01=0, wq10=0, wq11=1,
wk00=1, wk01=0, wk10=0, wk11=1,
wv00=1, wv01=0, wv10=0, wv11=1,
))
ATTENTION_DEFAULTS = MappingProxyType(dict(
**PROJECTION_DEFAULTS, mode=1, valid0=1, valid1=1, valid2=1, shift=0,
))
def validated_state(state, attention=False):
defaults = ATTENTION_DEFAULTS if attention else PROJECTION_DEFAULTS
if type(state) not in (dict, MappingProxyType):
raise NumericalFault("INVALID_INPUT", "Use a plain object containing exactly the named scalar fields.")
if set(state) != set(defaults):
raise NumericalFault("INVALID_INPUT", "Provide every named scalar field and no extra fields, including inactive slots.")
integer_bounds = dict(B=(1, 2), T=(1, 3), Dk=(1, 2), Dv=(1, 2),
mode=(0, 3), valid0=(0, 1), valid1=(0, 1), valid2=(0, 1))
result = {}
# Defaults determine record order, regardless of the incoming object's order.
for key in defaults:
value = finite(state[key], key)
low, high = integer_bounds.get(key, (-10000, 10000) if key == "shift" else (-4, 4))
if value < low or value > high:
raise NumericalFault("INVALID_INPUT", f"{key} must be between {low} and {high}.")
if key in integer_bounds and not value.is_integer():
raise NumericalFault("INVALID_INPUT", f"{key} must be an integer choice.")
result[key] = int(value) if key in integer_bounds else value
return result
def guarded(derive):
@wraps(derive)
def call(state):
try:
return derive(state)
except NumericalFault as error:
return {"status": "unavailable", "code": error.code, "reason": str(error)}
except (OverflowError, FloatingPointError) as error:
return {"status": "unavailable", "code": "NONFINITE", "reason": str(error)}
return call
def numbers(values):
return {key: finite(value, key) for key, value in values.items()}
class AttentionTrace:
def __init__(self):
self.outputs = {}
self.steps = []
def add(self, identifier, label, equation, explanation, inputs, values):
inputs, values = numbers(inputs), numbers(values)
self.outputs.update({f"{identifier}_{key}": value for key, value in values.items()})
self.steps.append({"id": identifier, "label": label, "equation": equation,
"explanation": explanation, "inputs": inputs, "outputs": values})
def result(self, summary, tensors):
return {"status": "defined", "outputs": numbers({**summary, **self.outputs}),
"steps": self.steps, "tensors": tensors}
def attention_trace():
return AttentionTrace()
def tensor(identifier, shape, axes, values, provenance):
array = np.asarray(values, dtype=np.float64)
if array.size != math.prod(shape) or len(shape) != len(axes) or len(set(axes)) != len(axes):
raise NumericalFault("SHAPE_MISMATCH", f"{identifier}: storage must match the named dimensions.")
# Flatten into detached Python scalars; no record retains a view of an array.
flat = [finite(value, identifier) for value in array.reshape(-1)]
return {"id": identifier, "shape": list(shape), "axes": list(axes), "dtype": "float64",
"values": flat, "provenance": provenance, "precision": 8}
def project(s, trace):
"""Build real arrays, then trace Q, K, V in that order, each b,t,f."""
B, T, Dk, Dv = s["B"], s["T"], s["Dk"], s["Dv"]
# D stays 2; smaller Dk/Dv select leading weight COLUMNS, never input rows.
X = np.empty((B, T, 2), dtype=np.float64)
WQ = np.empty((2, Dk), dtype=np.float64)
WK = np.empty((2, Dk), dtype=np.float64)
WV = np.empty((2, Dv), dtype=np.float64)
for b in range(B):
for t in range(T):
for d in range(2):
X[b, t, d] = s[f"x{b}{t}{d}"]
for weights, prefix, width in ((WQ, "wq", Dk), (WK, "wk", Dk), (WV, "wv", Dv)):
for d in range(2):
for f in range(width):
weights[d, f] = s[f"{prefix}{d}{f}"]
Q = np.empty((B, T, Dk), dtype=np.float64)
K = np.empty((B, T, Dk), dtype=np.float64)
V = np.empty((B, T, Dv), dtype=np.float64)
trace.add("setup", "Validate all scalar inputs and select active dimensions", "D=2; X[B,T,D]; WQ,WK[D,Dk]; WV[D,Dv]",
"All stored slots are validated. Active tensors use only the selected batches, time prefix and leading output columns; neither input-feature row is removed.",
s, dict(B=B, T=T, D=2, Dk=Dk, Dv=Dv))
aliases = {}
for name, weights, output, width in (("Q", WQ, Q, Dk), ("K", WK, K, Dk), ("V", WV, V, Dv)):
for b in range(B):
for t in range(T):
for f in range(width):
x0, x1 = float(X[b, t, 0]), float(X[b, t, 1])
w0, w1 = float(weights[0, f]), float(weights[1, f])
product0 = finite(x0 * w0, "projection product0")
product1 = finite(x1 * w1, "projection product1")
value = finite(product0 + product1, "projection value")
output[b, t, f] = value
aliases[f"{name.lower()}{b}{t}{f}"] = value
trace.add(f"project_{name}_{b}_{t}_{f}", f"{name}[{b},{t},{f}]: two input-feature contributions",
"product0=x0*w0; product1=x1*w1; value=product0+product1",
"One token row times one weight column. Both products are computed separately, then added; no bias, activation or training is hidden.",
dict(b=b, t=t, f=f, x0=x0, x1=x1, w0=w0, w1=w1),
dict(product0=product0, product1=product1, value=value))
tensors = [
tensor("X", [B, T, 2], ["B", "T", "D"], X, "Active input token rows, selected without padding or broadcasting."),
tensor("WQ", [2, Dk], ["D", "Dk"], WQ, "Both input rows; leading Dk query columns of the editable WQ."),
tensor("WK", [2, Dk], ["D", "Dk"], WK, "Both input rows; leading Dk key columns of the editable WK."),
tensor("WV", [2, Dv], ["D", "Dv"], WV, "Both input rows; leading Dv value columns of the editable WV."),
tensor("Q", [B, T, Dk], ["B", "T", "Dk"], Q, "Q=XWQ, with each coordinate traced as two products and one sum."),
tensor("K", [B, T, Dk], ["B", "T", "Dk"], K, "K=XWK, with each coordinate traced as two products and one sum."),
tensor("V", [B, T, Dv], ["B", "T", "Dv"], V, "V=XWV, available for later value mixing; not mixed in IV-22–24."),
]
return dict(X=X, WQ=WQ, WK=WK, WV=WV, Q=Q, K=K, V=V, aliases=aliases, tensors=tensors)
def score(s, projection, trace):
"""Compute one feature product at a time; scaling is not normalization."""
B, T, Dk = s["B"], s["T"], s["Dk"]
Q, K = projection["Q"], projection["K"]
raw = np.empty((B, T, T), dtype=np.float64)
scores = np.empty((B, T, T), dtype=np.float64)
divisor = finite(math.sqrt(Dk), "score divisor")
aliases = {}
for b in range(B):
for i in range(T):
for j in range(T):
q0, k0 = float(Q[b, i, 0]), float(K[b, j, 0])
inputs = dict(b=b, i=i, j=j, Dk=Dk, divisor=divisor, q0=q0, k0=k0)
product0 = finite(q0 * k0, "score product0")
values = dict(product0=product0)
dot = product0
if Dk == 2:
q1, k1 = float(Q[b, i, 1]), float(K[b, j, 1])
inputs.update(q1=q1, k1=k1)
product1 = finite(q1 * k1, "score product1")
values["product1"] = product1
dot = finite(product0 + product1, "raw score")
scaled = finite(dot / divisor, "scaled score")
raw[b, i, j], scores[b, i, j] = dot, scaled
values.update(raw=dot, score=scaled)
aliases[f"raw{b}{i}{j}"] = dot
aliases[f"score{b}{i}{j}"] = scaled
trace.add(f"score_{b}_{i}_{j}", f"Batch {b}: query {i} against key {j}",
"product0=q0*k0; raw=product0; score=raw/sqrt(Dk)" if Dk == 1 else
"product0=q0*k0; product1=q1*k1; raw=product0+product1; score=raw/sqrt(Dk)",
"Compare matching query/key features in the same batch. The divisor uses key-feature width Dk, not time length T or value width Dv. A signed score is not a probability.",
inputs, values)
tensors = [tensor("raw", [B, T, T], ["B", "Query", "Key"], raw, "QK transpose: explicit feature products followed by their sum, within each batch."),
tensor("scores", [B, T, T], ["B", "Query", "Key"], scores, "Raw query-key agreement divided by sqrt(Dk); not softmax probabilities.")]
return dict(raw=raw, scores=scores, aliases=aliases, tensors=tensors)
def stable_softmax(logits, allowed):
"""Scalar counterpart of platform stableSoftmax; reject an empty support."""
if len(logits) != len(allowed) or not 1 <= len(logits) <= 64:
raise NumericalFault("SHAPE_MISMATCH", "A boolean allowed mask must match 1–64 logits.")
logits = [finite(value, f"logit {j}") for j, value in enumerate(logits)]
if any(type(value) is not bool for value in allowed):
raise NumericalFault("INVALID_INPUT", "Every mask entry must be boolean.")
candidates = [value for j, value in enumerate(logits) if allowed[j]]
if not candidates:
raise NumericalFault("FULLY_MASKED_ROW", "This query has no allowed keys; no probability distribution exists.")
maximum = max(candidates)
# Match Math.max zero ties without erasing an all-negative-zero maximum.
if maximum == 0.0 and any(value == 0.0 and math.copysign(1.0, value) > 0.0 for value in candidates):
maximum = 0.0
terms = []
denominator = 0.0
for j in range(len(logits)):
# An allowed exp can underflow to 0; the boolean mask still says allowed.
term = math.exp(finite(logits[j] - maximum, "shifted logit")) if allowed[j] else 0.0
terms.append(finite(term, "softmax term"))
denominator = finite(denominator + term, "softmax denominator")
probabilities = []
for term in terms:
probabilities.append(finite(term / denominator, "softmax probability"))
return dict(max=maximum, terms=terms, denominator=denominator, probabilities=probabilities)
def normalize(s, scored, trace):
"""Retain every query; mask keys, then normalize along each row's key axis."""
B, T = s["B"], s["T"]
# Keep real finite logits for forbidden keys too; never invent -infinity.
allowed = np.empty((B, T, T), dtype=np.bool_)
logits = np.empty((B, T, T), dtype=np.float64)
probabilities = np.empty((B, T, T), dtype=np.float64)
aliases = {}
causal = s["mode"] in (1, 3)
padding = s["mode"] in (2, 3)
for b in range(B):
for i in range(T):
row_logits, row_allowed = [], []
inputs = dict(b=b, i=i, mode=s["mode"], shift=s["shift"])
for j in range(T):
value = float(scored["scores"][b, i, j])
inputs[f"score{j}"] = value
permit = (not causal or j <= i) and (not padding or s[f"valid{j}"] == 1)
allowed[b, i, j] = permit
logit = finite(value + s["shift"], "shifted score")
logits[b, i, j] = logit
row_logits.append(logit)
row_allowed.append(permit)
for j in range(T):
inputs[f"allowed{j}"] = 1 if row_allowed[j] else 0
if not any(row_allowed):
raise NumericalFault("FULLY_MASKED_ROW", f"Batch {b}, query {i} has no allowed keys; no probability distribution exists.")
row = stable_softmax(row_logits, row_allowed)
values = dict(max=row["max"], denominator=row["denominator"])
# These are the actual shifted operands passed to exp; forbidden keys
# have no shifted operand and therefore no fabricated shifted field.
for j in range(T):
if row_allowed[j]:
values[f"shifted{j}"] = finite(row_logits[j] - row["max"], "shifted logit")
for j in range(T):
values[f"term{j}"] = row["terms"][j]
for j in range(T):
probability = row["probabilities"][j]
values[f"p{j}"] = probability
probabilities[b, i, j] = probability
aliases[f"p{b}{i}{j}"] = probability
trace.add(f"row_{b}_{i}", f"Batch {b}: masked key-axis softmax for query {i}",
"logit_j=score_j+shift; max=max(allowed logits); term_j=allowed_j?exp(logit_j-max):0; denominator=sum_j term_j; p_j=term_j/denominator",
"Keys alone are masked; every query remains. Terms sum in increasing key order. Forbidden keys have exact zero probability; allowed terms can also underflow to zero in binary64. The common shift preserves real softmax but can change rounded results.",
inputs, values)
allowed_record = tensor("allowed", [B, T, T], ["B", "Query", "Key"], allowed.astype(np.float64),
"True means this key may contribute to this query; key validity is shared across batches.")
# Validate 0/1 storage through tensor first, then expose actual JSON booleans.
allowed_record["values"] = [bool(value) for value in allowed_record["values"]]
allowed_record["dtype"] = "bool"
tensors = [allowed_record,
tensor("logits", [B, T, T], ["B", "Query", "Key"], logits, "Finite score+common shift for every active key, including forbidden keys; no mask sentinel."),
tensor("probabilities", [B, T, T], ["B", "Query", "Key"], probabilities,
"Allowed-key stable softmax along the key axis only. Forbidden keys have exactly zero; allowed exponential underflow is separately possible.")]
return dict(allowed=allowed, logits=logits, probabilities=probabilities, aliases=aliases, tensors=tensors)
_JSON_INT = int
def run(derive, defaults):
"""No argument: defaults. A JSON object fully replaces them; '-' reads stdin."""
class ParseFault(ValueError):
"""Only locally owned JSON profile/conversion faults."""
def _members(pairs):
value = {}
for key, member in pairs:
if key in value:
raise ParseFault("Duplicate JSON object members are not allowed.")
value[key] = member
return value
def _constant(token):
raise ParseFault(f"Nonstandard JSON constant {token} is not allowed.")
def _integer(token):
if token == "-0":
return -0.0
try:
return _JSON_INT(token)
except ValueError as fault:
if type(fault) is not ValueError:
raise
raise ParseFault("JSON integer exceeds the interpreter's conversion capacity.") from fault
parser = argparse.ArgumentParser(description=derive.__doc__)
parser.add_argument("state", nargs="?")
args = parser.parse_args()
if args.state is not None:
source = sys.stdin.read() if args.state == "-" else args.state
try:
state = json.loads(source, object_pairs_hook=_members,
parse_constant=_constant, parse_int=_integer)
except (json.JSONDecodeError, ParseFault) as error:
result = {"status": "unavailable", "code": "INVALID_INPUT", "reason": str(error)}
else:
result = derive(state)
else:
result = derive(dict(defaults))
print(json.dumps(result, allow_nan=False, separators=(",", ":")))
Read the complete executable Python / NumPy source
This is the actual reference file, imported directly from the repository. Comments explain each operation. It is provided for later execution; no validation run is claimed.
"""IV25–26 weighted values: real NumPy storage, Python-float scalar loops.
The shared attention helper owns validation, projections, scores and softmax.
This continuation contracts only the key axis: O[b,i,f]=sum_j P[b,i,j]*V[b,j,f].
The signed value coordinates are not probabilities. No extra average is taken.
"""
import numpy as np
from attention_reference import finite, tensor
def mix_values(s, projection, normalized, trace):
"""Append every actual product, running sum and output in b,i,f order."""
B, T, Dv = s["B"], s["T"], s["Dv"]
probabilities, V = normalized["probabilities"], projection["V"]
O = np.empty((B, T, Dv), dtype=np.float64)
aliases = {}
for b in range(B):
for i in range(T):
for f in range(Dv):
inputs = dict(b=b, i=i, f=f)
products, running = {}, {}
value = 0.0
for j in range(T):
p = float(probabilities[b, i, j])
v = float(V[b, j, f])
inputs[f"p{j}"] = p
inputs[f"v{j}"] = v
# Masked probabilities still take the actual 0*V path.
product = finite(p * v, f"O[{b},{i},{f}] key {j} product")
products[f"product{j}"] = product
value = finite(value + product, f"O[{b},{i},{f}] running sum through key {j}")
running[f"running{j}"] = value
O[b, i, f] = value
aliases[f"o{b}{i}{f}"] = value
trace.add(f"mix_{b}_{i}_{f}", f"O[{b},{i},{f}]: weighted value coordinate",
"product_j=p_j*v_j; running starts at 0; running_j=previous+product_j; value=last running sum",
"Use the saved probability row and the same value feature across all keys in this batch. Each product is computed before its running sum in ascending key order, including actual 0 times V for forbidden keys. There is no extra division by T or Dv. Value coordinates and the output may be signed.",
inputs, {**products, **running, "value": value})
tensors = [tensor("O", [B, T, Dv], ["B", "Query", "Dv"], O,
"O=PV: one weighted sum over keys per query and value feature, with every product and sequential running sum recorded.")]
return dict(O=O, aliases=aliases, tensors=tensors)
Follow setup, all left-input additions, all right-input additions, all left child attention records including its setup, then all right child records including its setup, then six comparisons. The complete trace has 93 records. Prefixes left_ and right_ distinguish calculations; compare_t_d saves the actual right and expected operands. Expected gathers LeftO at π[t], not at t. RawX, SlotSignals, Permutation, both sets of 13 child tensors, Expected and Difference give 31 stored tensors. Precision eight is tensor metadata; full saved-value tables use String(value) without display rounding, and the computation retains its actual saved numbers.
Raw features and weights must be finite within [−2,2]; permutation and signal selectors must be supported integers. Every stored field validates, including settings whose contribution happens to be zero. Unsupported or malformed input makes the result unavailable, with no partial successful output. Input addition can reach magnitude 3 here, within the reused attention editor’s bounds. This is an inspectable three-token example, not evidence that a trained language model understands grammar.
Five graded questions
For the live question, choose the value and operation together. Two options can contain the same number in a special state while proposing different calculations; the saved operation determines the correct method.
The lab grades these five questions in order and explains the mechanism after each answer. The fixed reasoning below matches the actual questions; current numeric operands always come from the saved result.
equivariance-meaning: What follows a permutation? The output rows follow the input rearrangement: F(ΠX)=ΠF(X). They do not stay at their old row labels, and this does not force every token to have the same output. Real equivariance also does not require a computed binary64 residual to be exactly zero.permutation-gather: Read π=[2,0,1]. Expected at new slot 0 gathers left row 2, keeping features 0 and 1 together. π maps new slots to old rows; reversing that meaning or keeping row 0 would compare different tokens.live-difference: Subtract the current saved operands.compare_0_1always asks for Difference[0,0,1], batch zero, new slot zero, feature one. Compute its saved right−expected. At reset this is zero in real arithmetic; with the default slot-signal edit it is 1−L, where L=(r³+2r⁵)/(r+r³+r⁵)>1. Use the actual saved operands after any edit, including a possible rounding residual. View selectors do not move this question to another coordinate.slot-signal-edit: Turn fixed signals on. Both attention paths recompute from their changed inputs. Since ΠX+P can differ from ΠX+ΠP, their corresponding-output comparison can change. It need not change for every state: an identity permutation or suitable uniform attention can still agree. No rule adds one to each final output.causal-mask-premise: Keep a causal mask fixed? The arbitrary-permutation proof requires the permission matrix to move on both query/key axes too. A fixed triangular mask generally changes which token pairs are allowed after reordering, so it does not satisfy that proof’s premise. Comparing unchanged output row numbers does not repair it.
Recap and bridge
Unmasked attention with shared projections moves its outputs with permuted input rows. Its probabilities move on both query and key axes. Fixed slot signals change the inputs differently on the two sides, and a fixed causal mask also changes the theorem’s premises. Exact real equalities and stored binary64 residuals are different claims. IV-35 — Learned and Sinusoidal Position Embeddings next builds additive signals from a learned table or two explicit sine/cosine frequencies.