Rotary Positions

Experimental alpha. Expect breaking changes and major bugs. Your feedback is much appreciated.

Rotary Positions

Says where a token is by turning it. Each pair of its numbers turns by an angle that grows with its place in the sequence, the first pair fastest. Put one on queries and one on keys, after a Head Splitter: a query and a key then score each other by how far apart they are, wherever in the sequence they stand.

rotary positions

Shapes

[…×T×C] in, the same shape out. C must be even: each head's width, on a head.

Parameters

None: unlike a Position Table, it has no table to fill and no longest sequence.

In PyTorch

z = torch.view_as_complex(x.reshape(*x.shape[:-1], -1, 2))
y = torch.view_as_real(z * freqs_cis[:T]).flatten(-2)

Notes

A query and a key learn how far apart they are this way, and never where they stand. A job that asks where, such as Survey, wants a Position Table as well: see The Modern Block.

Making it

The Fabricator makes it from a photomask of Rotary Positions: verify the spec on a Bench, or find a salvaged mask in the ruins, which makes it unfused. See The Bench and the Fabricator.