EasyDeepLearn

What is the context window and what tricks extend it?

medium

Answer

  • The context window is the maximum number of tokens (prompt + response) the model can attend to.
  • Extending it: RoPE scaling (position interpolation, YaRN), sparse/linear attention, sliding-window attention, retrieval-augmented long-context, and KV-cache tricks.
  • Longer context helps but is not free — attention is quadratic in sequence length, and quality often degrades far from the beginning ('lost in the middle').
Check yourself — multiple choice
  • Attention scales linearly with sequence length by default
  • Standard attention scales quadratically with sequence length
  • Longer context always improves quality uniformly
  • The KV cache is unrelated to context length

Vanilla attention is O(n2)O(n^{2}) in the sequence length.

#long-context#architecture#inference

Practise LLMs & GenAI

214 interview questions in this topic.

Related questions