Four pairs are enough to catch a sign mistake in a two-dimensional rotary position embedding (RoPE) example. The interesting part is the check that still passes when the sign is wrong.

A test that lets both implementations through

Give the query vector (1, 0) position 0 and the key vector (0, 1) position 1. Rotate each vector counterclockwise by 30 degrees per position. The key turns from straight up toward the left. Its horizontal component is −0.5. Since the query points right, that component is also their dot product.

Now move the positions to 4 and 5. Both vectors turn four extra steps, keeping the angle between them, so the dot product stays −0.5. Reverse the rotation convention everywhere and the first pair scores +0.5. The shifted pair *also* scores +0.5. An assertion that only compares the two scores happily accepts either implementation.

Open the full-size comparison of all four measured dot products

Our Python run produced the two columns above. Read the rows in pairs. Positions (0, 1) and (4, 5) test the shared shift. Positions (0, 1) and (1, 0) test the direction under the stated convention. At (0, 0), the unrotated vectors are perpendicular and the score is zero.

Reproduce the four numbers

Save this as probe.py and run python3 probe.py. We used Python 3.12.13 and the standard library. Each number is a raw dot product before scaling, masking or softmax.

from math import cos, sin, pi, isclose


def rotate(vector, angle):
    x, y = vector
    return x * cos(angle) - y * sin(angle), x * sin(angle) + y * cos(angle)


def score(m, n, step=pi / 6):
    q = rotate((1, 0), m * step)
    k = rotate((0, 1), n * step)
    return sum(x * y for x, y in zip(q, k))

for m, n, expected in [(0, 1, -0.5), (4, 5, -0.5), (1, 0, 0.5), (0, 0, 0)]:
    actual = score(m, n)
    print(m, n, round(actual, 3))
    assert isclose(actual, expected, abs_tol=1e-12)

For a negative control, change the default step from pi / 6 to -pi / 6. The first assertion fails. If you temporarily print the scores without asserting, the first two rows both become +0.5. Starting with two identical vectors would hide this particular sign error because their score would depend on cosine, which is the same for opposite angles.

Where to use this check

Use the four expectations for a vector pair with a known layout and frequency, before testing the complete attention head. If the shared shift passes but the signed value fails, inspect the direction of rotation and the order of the pair against your chosen reference. Other coordinate conventions can be mathematically equivalent when used consistently. This probe does not test a model’s weights, cache offsets, context length, or answer quality.

Sebastian Raschka’s article prompted this experiment. It explains how positions enter attention and how real models vary. The original RoFormer paper develops the relative-position dot-product property. Boloop supplied the numerical fixture, negative control and figure.

Read Raschka’s explanation · RoFormer paper