The plain version
A model's context is everything it can "see" while writing the next token: the system prompt, your messages, its replies, any pasted documents. It's measured in tokens (roughly ¾ of an English word each). When a conversation outgrows the context, the oldest parts fall off, or the app trims them.
Three different numbers get called "context length":
- Trained (native): what the model saw during training. Qwen3-30B-A3B: 32,768 tokens.
- Extended: what the model card says it supports with RoPE scaling. Qwen3-30B-A3B with YaRN: 131,072.
- Configured: what your runtime actually allocated. Ollama picks this from your VRAM, and below 24 GiB it's 4K tokens.
What's RoPE? Transformers need to know word order. Most modern models use rotary position embeddings (RoPE): each position rotates parts of the attention vectors by angles that grow with distance, so the model can tell how far apart two tokens are. Past the trained length, the model meets rotation angles it has never seen, and quality collapses.
What's YaRN? RoPE scaling methods squeeze longer sequences into the angle range the model knows. Simple "linear" scaling compresses everything evenly, which blurs fine-grained position. YaRN compresses the slow-rotating dimensions more and the fast ones less, and adjusts attention temperature. Its paper reports reaching long contexts with 10× fewer training tokens than earlier methods. Many models ship already trained for it, and you switch it on at load time.
An everyday analogy. A ruler marked to 30 cm. Linear scaling relabels it as 120 cm, with every mark four times further apart, so you lose precision everywhere. YaRN keeps the millimetre marks sharp and stretches only the coarse ones.
Long context isn't long memory. Even within their window, models recall facts from the middle of very long prompts less reliably than from the beginning or the end. For large document collections, RAG usually beats pasting everything in.
RoPE in one line
For a pair of dimensions i at position m, rotate by θᵢ·m with θᵢ = base^(−2i/d). Linear scaling divides m by factor s. YaRN interpolates per dimension according to wavelength, and scales attention logits by a temperature that grows with s.
Turning it on in llama.cpp
llama-server -m Qwen3-30B-A3B-Q4_K_M.gguf -c 131072 \ --rope-scaling yarn --rope-scale 4 --yarn-orig-ctx 32768 --port 8080-csets the allocated context (0 means take it from the model).--rope-scale 4expands by 4×, and--yarn-orig-ctxis the native length. Many GGUFs carry the right settings in their metadata, so try plain-cfirst.Ollama
OLLAMA_CONTEXT_LENGTH=32768 ollama serveOr set
num_ctxper request or in a Modelfile. Check what was really allocated, and whether the model spilled to the CPU, withollama ps.Memory per token
KV_bytes/token = 2 × layers × kv_heads × head_dim × bytes_per_elementQwen3-30B-A3B (48 layers, 4 KV heads, head_dim 128, f16): 2 × 48 × 4 × 128 × 2 ≈ 96 KB per token, or about 12 GB at 128K. With
-ctk q8_0 -ctv q8_0it's about half that.Pitfalls
- Silent truncation. Many apps drop old messages without telling you. If a model "forgets" the start of a document, check the configured context first.
- Sliding-window models. Gemma 3 uses local attention on most layers, so its cache grows more slowly, but those layers can only see recent tokens.
- Don't scale past the card. A factor beyond what the model was trained for produces fluent nonsense.