Notes

Long-Context Extension

A model trained with a 4,000-token window does not degrade politely at token 4,001 — it falls apart, because the position signals it is seeing are unlike anything in its training. Long-context extension is the set of techniques that move an already-trained model to a far longer window without starting training over.

Rescaling position rather than relearning it

Most methods work on RoPE, the rotary position encoding whose rotation frequencies are what go out of distribution. Instead of extrapolating, they compress the position scale, then settle the model with a short fine-tune on long documents costing a tiny fraction of the original compute:

  • Position interpolation scales positions down so a 32k sequence occupies the range the model was trained on;
  • NTK-aware scaling and YaRN do this unevenly, stretching the low frequencies that carry long-range order while leaving the high frequencies that distinguish neighbouring tokens intact.
What it costs at inference

The KV cache grows linearly with context, so a single 128k-token conversation can demand more memory than the weights of a small model. Sliding-window attention, cache quantization and paged memory in servers such as vLLM are what make the long window affordable rather than merely possible.

A long window is not a used window

Finding one planted fact in 100,000 tokens works well; reasoning over several facts scattered through them degrades, and attention concentrates on the start and end of the input. An extended model that passes a needle-in-a-haystack test can still answer a real question about a long document worse than a RAG pipeline that hands it the five relevant pages.

Long-context extension is the set of techniques that stretch a model's usable sequence length well past the window it was pretrained on, without training a new model: rescaling the frequencies of RoPE position embeddings, position interpolation, YaRN, and a short fine-tune on long documents. It is how a model trained at 4K tokens is shipped at 128K. Without it, accuracy collapses the moment the input passes the length the position encoding ever saw.

A model learns to read on passages of a certain length — think a few pages at a time. Hand it a 300-page contract and it loses its footing, because nothing that long was ever on its syllabus. Long-context extension is the retrofit that fixes this: a few adjustments to how the model keeps track of word order, plus a short spell of extra practice on very long texts. Nothing is rebuilt from scratch. This is why an assistant that once choked halfway through a long report can now take the whole thing in one go and answer a question about page 200.