Platforms
How Rotary Position Embeddings Change an Attention Score
With fixed projected query and key vectors and matching rotary blocks, their raw dot product depends on the relative position n − m. Shifting both positions equally preserves that score. Changing the relative offset can change it while preserving both vector norms. In the illustrative RP72 case, positions (0, 1) and (1, 2) both give 2; (0, 2) gives −11. Comparing numerical traces therefore requires the actual position indices, coordinate pairing, rotation orientation and frequency assigned to each block.
01
Start with the projected vectors entering the rotation
Let q and k be the already-projected query and key for one head, before rotary position encoding. Hold their numerical components fixed. The question is what happens to their pair score when the positions supplied to the rotation change.
This boundary matters. A token-embedding lookup selects learned rows; the query and key here are later projected operands. Holding token IDs fixed would not by itself establish these same projected values throughout an arbitrary model. RP72 supplies the values directly so the positional operation can be examined on its own.
The historical definition used here is RoFormer, arXiv:2104.09864v5, revised November 8, 2023; its PDF cover is dated November 9. Sections 3.2.1–3.2.2 define two-dimensional rotations and their paired-block extension. The calculations below are illustrative exact mathematics, with no model, framework or GPU execution. Pair membership is held fixed; the position indices do not specify a causal mask.
References: [R1]
02
The transpose leaves the relative angle
Use column vectors and the rotation R(a) = [[cos(a), −sin(a)], [sin(a), cos(a)]], where a is in radians. It maps (x, y) to (x cos(a) − y sin(a), x sin(a) + y cos(a)). Define q_m = R(mθ)q and k_n = R(nθ)k, using the same angular rate θ on both sides.
The raw pair score is s(m, n) = q_mᵀk_n = qᵀR(mθ)ᵀR(nθ)k. A rotation's transpose is its inverse: R(mθ)ᵀ = R(−mθ). Composing the rotations gives s(m, n) = qᵀR((n − m)θ)k. With this convention, the remaining angle is key position minus query position.
Replace m and n by m + c and n + c while retaining q, k and θ. Their difference remains n − m, so the score remains unchanged. The two rotated vectors can each change; their dot product is preserved because the same additional rotation acts on both.
Orthogonality also gives ||R(a)q||² = qᵀR(a)ᵀR(a)q = ||q||². Each vector keeps its own norm even when the pair's relative angle changes. Preserving two lengths does not fix the angle between them, which is why preserved norms can accompany a changed score.
References: [R1]
03
RP72: two position pairs give 2; another gives −11
Supply q = (1, 2), k = (3, 4) and θ = π/2 radians per integer position. Their unrotated dot product is 1×3 + 2×4 = 11. Their squared norms are 1² + 2² = 5 and 3² + 4² = 25.
The quarter-turn rate is chosen to keep every rotated component integral. It is an illustration, not a named model default. RoFormer's general schedule beside Eq. 15 is θ_i = 10000^(−2(i − 1)/d), with i starting at 1. At d = 2 that schedule gives 1 radian per position, rather than π/2.
At (m, n) = (0, 1), the query is unchanged and the key turns through π/2 to (−4, 3). Their score is 1×(−4) + 2×3 = 2.
At (1, 2), the query turns to (−2, 1), while the key turns through π to (−3, −4). Their score is (−2)×(−3) + 1×(−4) = 2. This is the first pair shifted by one position on both sides.
At (0, 2), the query stays (1, 2) and the key is (−3, −4). Their score is 1×(−3) + 2×(−4) = −11. The relative offset has changed from 1 to 2. The projected content, dimensions and individual norms have not.
References: [R1]
| Query m / key n | Offset n − m | Rotated q_m | Rotated k_n | Raw dot | Squared norms q / k | Source |
|---|---|---|---|---|---|---|
| 0 / 1 | 1 | (1, 2) | (−4, 3) | 2 | 5 / 25 | Planning analysis |
| 1 / 2 | 1 | (−2, 1) | (−3, −4) | 2 | 5 / 25 | Planning analysis |
| 0 / 2 | 2 | (1, 2) | (−3, −4) | −11 | 5 / 25 | Planning analysis |
Supplied illustrative operands and positions, independently calculated in exact arithmetic. These are raw pair scores, not recorded model results.
04
A different offset can also return the same score
Expanding RP72's relative rotation gives s(Δ) = 11 cos(Δπ/2) + 2 sin(Δπ/2), where Δ = n − m. The cosine coefficient is the original dot product, 11. The sine coefficient is q₂k₁ − q₁k₂ = 2×3 − 1×4 = 2.
This formula explains both the changed score and its limits. At offset 0 the score is 11; at 1 it is 2; at 2 it is −11. A changed offset can alter the result, but the dependence is not one-to-one.
At (m, n) = (0, 5), the key turns through 5π/2 and again becomes (−4, 3). The score is again 2. Offsets 1 and 5 differ by a full turn in this schedule. The sequence also returns from −11 at offset 2 to 11 at offset 4.
Consequently, shared shifts guarantee equality under the stated assumptions, while changed offsets only permit a different score. Neither strict decrease with distance nor a unique offset can be inferred from a raw score. The paper's separate long-distance discussion must not be substituted for a pointwise ordering of this illustrative sequence.
References: [R1]
05
Two rotary blocks contribute two relative-offset scores
Now supply a separate four-dimensional case: q = (1, 2, 1, 1) and k = (3, 4, 2, 0). Use zero-based coordinate pairs (0, 1) and (2, 3). Both Q and K use θ₁ = π/2 on the first pair and θ₂ = π on the second. This block assignment is stipulated for the example; it is not the paper's general frequency schedule.
The complete raw dot is the sum of the two block dots. For fixed blocks j, it can be written as the sum of q_jᵀR((n − m)θ_j)k_j. Each block retains its relative-angle identity even though different blocks use different rates.
At (0, 1), offset 1, the rotated query is (1, 2, 1, 1) and the rotated key is (−4, 3, −2, 0). The first block contributes 2; the second contributes 1×(−2) + 1×0 = −2. The complete score is 0.
At (1, 2), offset 1, the rotated query is (−2, 1, −1, −1) and the rotated key is (−3, −4, 2, 0). The block contributions remain 2 and −2, giving 0. Both positions have advanced by one, preserving each block's relative angle.
At (0, 2), offset 2, the rotated query is (1, 2, 1, 1) and the rotated key is (−3, −4, 2, 0). The contributions are −11 and 2, giving −9.
In all three rows, the query's squared norm is 1 + 4 + 1 + 1 = 7 and the key's is 9 + 16 + 4 + 0 = 29. The transformed vectors give the same totals. Matching dimensions and norms therefore coexist with the complete scores 0, 0 and −9. Frequencies must match between Q and K within each corresponding block; they need not match across different blocks.
References: [R1]
06
Different Q and K rates remove the shared-shift guarantee
Return to the two-dimensional q = (1, 2) and k = (3, 4), but deliberately change the premise: rotate Q at α = π/2 radians per position and K at β = π. The score becomes qᵀR(nβ − mα)k. Equal n − m no longer determines that angle.
At (0, 1), the rotated vectors are (1, 2) and (−3, −4), giving −11. At (1, 2), they are (−2, 1) and (3, 4), giving −6 + 4 = −2. Both offsets are 1 and both squared norms remain 5 and 25, yet the scores differ.
A common shift c now adds c(β − α) to the relative angle. That extra term explains the lost guarantee. This countercase violates the matching-rate premise intentionally; it is not evidence of a failure in a particular implementation.
07
A comparable trace identifies the actual positional operation
A useful trace starts with the ordered Q/K components at a named boundary, such as immediately after projection and before rotation, for an identified query/key pair and head. Reporting only the post-rotation norms would discard precisely the directional change RP72 exposes.
For the rotary part, identify the coordinates paired together, the rate assigned to each pair and the angle units. State whether vectors are columns with R(a) acting on the left, or give the corresponding row-vector rule. A row representation must transpose the applied matrix to express the same rotation. Changing signs without reconciling that orientation can change the score.
Give the actual position values used for Q and K, their indexing convention and the chosen offset sign. A tensor slot is not a substitute for its supplied position value. In RP72, recording m = 0, n = 1 and Δ = n − m fixes the relative angle. Merely writing distance 1 omits its direction. A shared change of origin preserves the score under the matching schedule; changing only one side's origin can change the relative angle.
If positions undergo another mapping before rotation, the trace needs that mapping or the resulting per-block angles for both sides. The simple cancellation above assumes angles mθ_j and nθ_j. It cannot be carried over unchanged to unspecified angle functions.
Keep the coordinate layout attached to the ordered values. Another layout can express equivalent mathematics when the vectors and rotations are transformed consistently. Silently applying this example's adjacent-pair assignment to the same ordered numbers in an arbitrary model does not establish equivalence.
These declarations make a concrete comparison possible: RP72's (0, 1) and (1, 2) traces describe the same raw pair score; its (0, 2) trace describes a different one. The mismatched-rate traces require a different formula before their equal offsets can be interpreted.
08
Stop the conclusion at the raw pair score
Conventional scaled dot-product attention divides a raw dot by the square root of the query/key head width before softmax. For the complete two-dimensional example, the three scaled values would be 2/√2, 2/√2 and −11/√2. For the four-dimensional example they would be 0, 0 and −9/2. These scale choices are stated separately from the raw arithmetic.
A normalized attention weight also depends on the other participating keys and their scores. An attention output depends on the corresponding values. A negative raw dot is therefore neither a negative probability nor enough information to calculate an output.
The related mask article owns participating-key membership, and the normalization article explains why the denominator population matters. FlashAttention owns the workspace and common-normalization mechanism; GQA owns query/KV-head sharing and retained-state counts. None replaces the position-indexed rotation calculated here.
The result is conditional pair-score equivalence with fixed projected operands and the specified rotations. It establishes no complete attention-output equality, causal membership, whole-model shift invariance, cache interoperability, longer-context support or quality, or performance result.
References: [AT1]
09
Connect a separate equipment requirement to physical preparation
If the wider project independently requires equipment receiving, preparation or rack assembly, Leviathan's Rack Assembly & Preparation service and related project inquiry address that physical package. Share a nonconfidential equipment and configuration summary, appointed suppliers, proposed location and required physical handoff to discuss scope, resources and availability.
Model implementation, positional conventions, software commissioning and workload acceptance remain with the appointed platform and application owners. The inquiry concerns the separately identified equipment work.
10Sources
Primary sources
- [R1]Su et al. — RoFormer: Enhanced Transformer with Rotary Position Embedding, arXiv:2104.09864v5Checked 2026-10-22. Historical v5, revised November 8, 2023; PDF cover November 9. Sections 3.2.1–3.2.2 and 3.4.1–3.4.2 define the rotations, paired blocks and factorization. Eq. 15 supplies the separately identified general schedule. RP72 uses stipulated rates and exact derived arithmetic; experiments and current model support are outside its evidence.
- [AT1]Vaswani et al. — Attention Is All You Need, arXiv:1706.03762v7Checked 2026-10-22. Section 3.2.1 defines scaling by √d_k, softmax weights and the value-weighted output. Used only to distinguish these quantities from the raw pair dot product.
11Related
Related Leviathan resources
Token-embedding tables and request-position vectors
Query heads, shared KV heads and retained-state population
Attention masks and the participating-key contract
Softmax axes and the normalization population
FlashAttention workspace and common softmax normalization
Rack Assembly & Preparation for a separate equipment requirement
Discuss a separate receiving, preparation or rack-assembly project
Contact
Does the wider project need equipment preparation?
Share a nonconfidential equipment and configuration summary, proposed location and physical handoff needs to discuss receiving, preparation or rack assembly.