Million-Token Context Windows: Memory, Cost, and Model Selection Essentials
Many large language models now advertise context windows of one million tokens (1M). Before using one, developers should confirm which model it is, under what conditions the window is available, and how much memory, latency, and cost it adds. This article explains the background knowledge and verification methods needed to answer those questions, and it covers the memory and cost tradeoffs of long context and how to test them with your own data.
Million-token context windows are a useful capability, but they do not solve problems with information organization, retrieval quality, or cost control on their own. The key questions are: what the model is, under what conditions the long window is available, and what memory, latency, and cost it requires.
Why Long Context Consumes Memory
During Transformer inference, the model stores a key-value (KV) cache for every token it has already processed. The model reads this cache repeatedly during generation. The cache size is roughly:
Cache bytes ≈ 2 × number of layers × number of KV heads × head dimension × bytes per element × sequence length
Consider a model with 60 layers, 8 KV heads, a head dimension of 128, and 16-bit floating-point storage. Each token then takes about 245,760 bytes (roughly 240 KB). At a context length of 1M tokens, the KV cache for a single sequence is about 246 GB, not counting the model weights. This is only an example. Real models differ in layer count, KV head count, and other settings, so the actual numbers will differ. The example still shows the main point: doubling the context length roughly doubles the cache size, so the memory pressure of long context grows linearly with length.
Total Parameters and Active Parameters Are Different
Mixture-of-experts (MoE) models split the feed-forward network into multiple experts. Each token passes through only a few of them. When you evaluate these models, check two numbers:
- Total parameters: these determine how much memory the weights require. Even when only some experts run for each token, the full set of weights usually must be loaded into GPU memory or system memory.
- Active parameters: these determine the compute per token, which directly affects generation speed and the cost of each inference call.
Looking only at a large total parameter count or a small active parameter count does not fully describe a model’s resource needs. When selecting a model, consider both numbers, then estimate cost based on concurrency and your hardware.
Common Approaches to Sparse Attention and Compressed Cache
To reduce compute and memory costs on long sequences, the industry commonly uses several methods. Sliding-window attention attends only to nearby tokens. Sparse attention computes relationships between only some pairs of tokens. KV compression or quantization reduces the cache size per token.
Each method has tradeoffs. Skipped long-range information may be lost, and compression can reduce accuracy on long-distance retrieval. Which mechanisms a given model uses, and in which layers, should be confirmed in the official technical report and model configuration files, not only in promotional articles.
Multi-Token Prediction (MTP) Can Speed Up Inference, but Results Vary
Multi-token prediction (MTP) lets the model propose several candidate tokens in one forward pass. A verification step then confirms which of those tokens can be kept. The speedup depends on the acceptance rate of the candidates. When the acceptance rate is low, the extra computation can slow inference down. For this reason, throughput numbers published by vendors should state the input length, batch size, and type of generated content used in the test.
Five Items Developers Should Verify
- The model name, version, and provider, along with a link to the official technical report or model card.
- Whether the context limit is the same across different versions, interfaces, and pricing tiers.
- The pricing structure, including per-unit prices for input, output, and cache hits, and whether long inputs have tiered pricing.
- License terms, especially commercial use restrictions and redistribution conditions.
- Published long-context benchmark results and their test methods, such as how the needle-in-a-haystack tasks were designed.
Measuring With Your Own Data
Public benchmarks cannot replace testing on your own workload. Use real inputs and record the following metrics:
- Time to first token (TTFT) as input length changes.
- Output tokens per second, and queueing time under high concurrency.
- Peak server-side memory, to check for cache eviction or failed requests.
- Cost per request, broken down into input, output, and cache hits.
- Task accuracy, especially recall when the answer appears in the middle of a long input.
Test at least three input lengths, for example 32K, 128K, and a length close to the model’s limit. Repeat each length several times, and record the mean and the P95 tail latency.
Choosing Between Long Context and RAG
Passing the full text directly into the model suits tasks that need holistic understanding, such as code comprehension across multiple files, comparing clauses in a long contract, or analyzing a complete meeting transcript. Retrieval-augmented generation (RAG) suits knowledge bases that are large, change often, or require source citations. Retrieval sends only relevant excerpts to the model, so each request costs less, and the results are easier to trace to their sources.
In practice, many systems combine the two. They first retrieve a set of candidate documents, then place the relevant long documents into the context in full. In many scenarios, this approach is more reliable than relying on either method alone.
Common Failure Modes
- Missed information in the middle: models tend to focus on the beginning and end of long inputs, so information in the middle can be overlooked.
- Costs above expectations: sending a very long conversation history with every request makes cumulative costs grow quickly.
- Timeouts and rate limits: prefill on long inputs takes considerable time, so gateways and clients may need longer timeout settings.
- Inference framework limits: some serving frameworks impose extra constraints on scheduling, batching, and memory management for very long sequences, so load testing is needed before launch.
Conclusion
Million-token context is a useful capability, but it does not solve problems with information organization, retrieval quality, or cost control on its own. Under the test conditions the provider discloses, it can reduce the information loss caused by chunking and state loss. For a specific application, measure latency, memory, and cost with your own data, then decide whether to pass long documents directly into the context or use a retrieval-augmented approach.
