A model is trained on a fixed window — maybe 4k tokens. Yet the same model can read 128k. It isn't retrained; its RoPE rotations are quietly rescaled so far-away positions land on angles it already understands. Here's the break, the fix, and the three ways labs do it.
RoPE turns each token's vector by an angle set by its position. Train only to 4k tokens and the model only ever sees a slice of those angles — go further and it rotates into territory it has never seen.
m·θ, where m is the position and θ is that pair's fixed turn rate.The fix needs no retraining. Divide the rotation frequency by a scale factor s, and position m now turns by m·θ ⁄ s — as if it sat at m⁄s. Far positions get pulled back into the wedge the model already knows.
s makes the model read position s·4k the way it used to read 4k — every angle stays inside the seen wedge.s · 4k. Want 128k from a 4k model? Use s = 32. Slide s and watch the red arrow get dragged back into the green.Linear scaling squeezes every frequency the same, which is why it blurs nearby tokens. The better methods stretch the slow pairs hard and leave the fast pairs mostly alone. Each strip below shows how much a method rescales each pair, fast to slow.
s. Simplest, biggest reach, but the fast pairs get squashed, so local detail suffers. Usually needs fine-tuning.You can now feed the model 128k tokens — but attention compares every token with every other, and at 128k that's about seventeen billion pairs. Next, flash attention: the trick that computes all of it without ever storing that giant grid, so long context is actually affordable to run.