Your team wants an open model to read whole contracts or codebases at once. The model card says 128K tokens, but it does not say what that costs in GPU memory. How much GPU memory do you need to serve 128K-token requests, or longer ones?
Long context inference memory: the weights plus the KV cache
Long context inference memory has two parts: the weights, which stay fixed, and the KV cache, which grows with every token. While a model reads text, each of its layers stores two short lists of numbers for every token, a key and a value. Later tokens look back at these, so the model never has to read the earlier text again. That stored record is the KV cache.
The running example is Llama 3.1 70B Instruct, Meta's open model with a 128K-token context window. A context window is the most text one request may hold, prompt and answer together. Its configuration file gives every number the cache needs:
layers (num_hidden_layers) 80
attention heads (num_attention_heads) 64
KV heads (num_key_value_heads) 8
hidden size (hidden_size) 8,192
head size = 8,192 / 64 128
Each layer splits its work over 64 attention heads: parallel parts that each look back at earlier tokens in their own way. The hidden size is the width of the model's internal numbers: 8,192 per token, shared evenly across the 64 heads. So each head works with 128 numbers, its head size.
Llama 3.1 70B uses grouped-query attention, where several attention heads share one stored key and value. Here, groups of eight heads share one, so only 8 KV heads store anything. That makes the cache eight times smaller than it would be with 64.
KV cache per token = 2 (key and value) × 80 layers × 8 KV heads × 128 × 2 bytes
= 327,680 bytes = 320 KiB (1 KiB = 1,024 bytes)
The last factor is 2 bytes because the cache stores 16-bit numbers. So every token a request holds takes 327,680 bytes of GPU memory. The weights are 70,553,706,496 parameters at 2 bytes each in 16-bit, which is 141.1 GB. In this calculated example, 1 GB is a billion bytes.
KV cache size per request at 8K, 32K and 128K tokens
One request's KV cache is its token count times 327,680 bytes. A token is a piece of a word, and a request counts prompt and answer. FP8 is an 8-bit number format: a cache stored in FP8 takes one byte per number instead of two, so it halves.
| Request length | 16-bit cache | FP8 cache |
|---|---|---|
| 8,192 tokens (8K) | 2.7 GB | 1.3 GB |
| 32,768 tokens (32K) | 10.7 GB | 5.4 GB |
| 131,072 tokens (128K) | 42.9 GB | 21.5 GB |
The table is calculated from the configuration above. At 128K tokens, one request needs about a third of the memory the weights take.
A hypothetical model with Llama 3.1 70B's layout and a 1M-token window would need 343.6 GB for one request.
Which GPU setups fit 128K-token requests
vLLM, an open-source serving engine for LLMs, uses 92% of each GPU's memory by default. Whatever is left after the weights becomes the cache. Tensor parallelism splits the model across several GPUs in one server. Each GPU then holds a slice of every layer and stores the cache for its share of the 8 KV heads. Every request's cache is split the same way, so the per-GPU caches add up to the totals in the table below.
usable memory = number of GPUs × memory per GPU × 0.92
cache memory = usable memory − weights
long requests = cache memory ÷ 42.9 GB (or ÷ 21.5 GB with an FP8 cache), rounded down
| Setup | Usable memory | Left for the cache | 128K requests, 16-bit cache | 128K requests, FP8 cache |
|---|---|---|---|---|
| 2 × H100 80 GB | 147.2 GB | 6.1 GB | 0 | 0 |
| 4 × H100 80 GB | 294.4 GB | 153.3 GB | 3 | 7 |
| 8 × H100 80 GB | 588.8 GB | 447.7 GB | 10 | 20 |
| 2 × H200 141 GB | 259.4 GB | 118.3 GB | 2 | 5 |
| 1 × B200 192 GB, 8-bit weights | 176.6 GB | 106.1 GB | 2 | 4 |
H100, H200 and B200 are NVIDIA data-centre GPUs. The B200 row stores the weights in 8-bit too, which halves them to 70.6 GB. 8-bit weights can change the model's answers, so test them on your own prompts.
These counts are upper bounds, not measurements. The example counts no memory for activations, the intermediate results each layer passes to the next. It also leaves out the exchange buffers, the memory GPUs reserve to pass partial results to each other under tensor parallelism. Both omissions make every row look better than reality, most of all the multi-GPU rows: each extra GPU adds buffer memory we left out. So measure on your own setup.
All five setups match our GPU virtual machine profiles: H100 80 GB, H200 141 GB and B200 192 GB. Each runs with 1, 2, 4 or 8 GPUs per machine. Our GPU compute page has a Size a model tool for your own case. You enter a Hugging Face model, a context length up to 128K and the requests at once, and it shows the memory the model needs.
vLLM settings that make room for long requests
Four vLLM settings decide how much of the cache each long request can claim:
--max-model-lencaps how far one request may grow, prompt and answer together. It frees no memory, but each request can then reserve only up to the cap, so the same cache holds more of them. With a 32K cap, a request needs at most 10.7 GB instead of 42.9 GB.--kv-cache-dtype fp8stores the cache in FP8. vLLM's docs say this stores more tokens in memory and supports longer context windows.--max-num-seqscaps how many requests vLLM runs at once. In each step, the engine writes the next token for every running request, so fewer requests need less cache.--tensor-parallel-sizesets how many GPUs share the model. Each GPU then holds less of the weights and keeps more memory for the cache.
The command below serves the 4 × H100 row with an FP8 cache, so it holds up to 7 requests of 128K tokens:
vllm serve meta-llama/Llama-3.1-70B-Instruct \
--tensor-parallel-size 4 \
--max-model-len 131072 \
--kv-cache-dtype fp8
If your requests stay under 32K tokens, set --max-model-len 32768 instead. The same four GPUs then have room for up to four times as many requests. If vLLM fails at startup with an out-of-memory error, our vLLM CUDA out of memory guide shows which setting fixes which error.
Why long prompts wait before the first token
Before a model writes its first token, it reads the whole prompt and builds the cache for it. This step is called prefill. A 128K-token prompt makes prefill long, and short requests on the same GPU can wait behind it.
vLLM handles this with chunked prefill, which is on by default in V1, the current version of vLLM's engine. It cuts a long prefill into smaller pieces and runs them alongside requests that are already writing answers. Throughput is the number of tokens a server produces per second, and latency is the wait per request. The vLLM docs say chunked prefill improves both.
The setting --max-num-batched-tokens sets the size of those pieces. Smaller values keep other users' answers flowing, and larger ones bring the long prompt's first token sooner. Our status page shows live availability for the models on our API.
Past 128K tokens: call a 1M-token model per token
Llama 3.1 70B reads at most 131,072 tokens per request, so a 500,000-token document does not fit it at any GPU count. For documents that long, a hosted 1M-token model spares you the cache sizing. MiniMax M3 on our API has a 1M-token context window, and our models page lists it for long documents.
The example below prices one question about a hypothetical 500,000-token document, with a 200-token question and a 1,000-token answer:
first question: 500,200 input tokens × $0.40 per 1M = $0.2001
1,000 output tokens × $2.00 per 1M = $0.0020
total = $0.2021
follow-up: 500,000 cached tokens × $0.10 per 1M = $0.0500
200 input tokens × $0.40 per 1M = $0.0001
1,000 output tokens × $2.00 per 1M = $0.0020
total = $0.0521
These are MiniMax M3's list prices of 30 October 2026, in US dollars per million tokens. A follow-up gets the cached price only while the document's start is still in GPU memory. We keep recent prompt prefixes, the opening part of a prompt, there until newer requests replace them. So put the document first and the question after it. The example shows token prices only: it does not show how long prefill takes for half a million tokens, so time your own documents.
Lyceum is a sovereign European AI inference provider for open-source models: built and run in Europe, with serverless models in Paris and Finland. MiniMax M3's model page lists it as EU-hosted. Prompts and outputs are processed, not stored, and never used for training. We recommend a 1M-token model on our API past 128K tokens, rather than GPUs sized for a cache that Llama 3.1 70B cannot hold.
Send your first long document to MiniMax M3 with the OpenAI Python SDK. Set LYCEUM_API_KEY to your API key, then run:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["LYCEUM_API_KEY"],
base_url="https://api.lyceum.technology/openai/v1",
)
with open("contract.txt") as f:
document = f.read()
response = client.chat.completions.create(
model="minimax/minimax-m3",
messages=[{"role": "user", "content": document + "\n\nWhich clauses set the notice period?"}],
)
print(response.choices[0].message.content)
print(response.usage)
Frequently asked questions
Does the answer add to the KV cache too?
Yes. Every token the model writes joins the cache, so a request's cache covers its prompt and its answer. On Llama 3.1 70B, a 1,000-token answer adds 0.33 GB.
Does a smaller model fit 128K tokens on one GPU?
Llama 3.1 8B does. Its configuration has 32 layers, 8 KV heads and a head size of 128. So it stores 131,072 bytes per token, and a 128K-token request needs 17.2 GB. Its 16-bit weights take 16.1 GB, which leaves room for at most 3 such requests on one 80 GB H100.