LLM inference is running a trained language model to turn a prompt into output tokens. It has two phases: prefill processes the whole prompt in parallel and is compute-bound; decode generates one token at a time and is limited by GPU memory bandwidth. VRAM, bandwidth and batching decide its speed and cost.
- Two phases
- Prefill (compute-bound) and decode (memory-bandwidth-bound)
- Weights in memory
- Parameters (billions) × bytes per parameter: BF16 2, FP8 1, 4-bit about 0.5–0.6
- Llama 3.3 70B KV cache
- About 0.33 MB per token in FP16; 32k tokens ≈ 10.7 GB per sequence
- Single-stream decode rule
- tokens/s ≈ 0.6–0.75 × bandwidth ÷ bytes read per token (estimate)
- Llama 3.3 70B FP8 on one H100 PCIe
- About 17–21 tokens/s single stream (estimate)
- Biggest cost lever
- Batching many requests: often 10× or more cheaper per token than single-stream
- Common serving stack
- vLLM with an OpenAI-compatible API
LLM inference is the part of a language model's life that you actually pay for every day: the model is already trained, and now a GPU has to turn prompts into answers, quickly, for as many people as you can fit on it. This guide explains what happens inside that process, why it is limited by memory more often than by compute, and how to turn those mechanics into decisions about GPUs, software and cost.
Every number here is either a published specification, a rule of thumb with the maths shown, or an estimate labelled as one. If you want the hands-on versions, the cluster links out to tutorials for Llama, DeepSeek and Qwen, and to a guide to building your own API.
What is LLM inference?
LLM inference is running a trained large language model forwards, with its weights frozen, to generate output tokens from an input prompt. Nothing is learned during inference; the model only computes.
That makes it a different workload from training. Training runs data forwards, computes a loss, sends gradients backwards and updates billions of weights, so it needs optimiser state, activations and many GPU-hours. Inference needs only the weights plus some working memory, and its job is latency and throughput: how quickly one user sees an answer, and how many users one GPU can serve. If you are new to renting GPUs for any of this, start with what GPU cloud computing is and how it is billed.
A few terms used throughout:
- Token: a chunk of text the model reads or writes, roughly three-quarters of an English word on average for modern tokenisers.
- Parameters: the model's weights. Llama 3.3 70B has about 70 billion.
- Context: all the tokens the model can see at once: system prompt, conversation history, retrieved documents and its own output so far.
- Serving engine: the software that loads the model onto the GPU and handles requests, such as vLLM, SGLang, TGI or Ollama.
What happens when you send a prompt to an LLM?
A request goes through five steps: tokenise, prefill, decode, sample and detokenise. Prefill happens once per request; decode repeats once per output token, which is why long answers take longer than long questions.
- Tokenise. The text is split into token IDs by the model's tokeniser. A 1,500-word document becomes roughly 2,000 tokens.
- Prefill. The model processes every prompt token in one parallel pass through all its layers. Along the way it writes each token's attention keys and values into the KV cache. The output of prefill is the probability distribution for the first new token.
- Decode. The model generates one token, appends it, and runs a forward pass for just that token, reading the KV cache to attend to everything before it. This repeats until it emits a stop token or hits the length limit.
- Sample. At each step a sampler picks the next token from the distribution, shaped by temperature, top-p, top-k and repetition penalties.
- Detokenise and stream. Token IDs turn back into text and are streamed to the client, usually as server-sent events.
Two latency figures fall straight out of this. Time to first token (TTFT) is mostly queueing plus prefill. Time per output token (TPOT), also called inter-token latency, is the cost of one decode step. A request's total latency is roughly TTFT + TPOT × output tokens.
Why do prefill and decode behave so differently?
Prefill is compute-bound because it multiplies the weights against thousands of tokens at once; decode is memory-bound because it rereads every weight to produce a single token. That one difference explains most inference tuning.
The useful idea is arithmetic intensity: how many floating-point operations a step does per byte it reads from memory. A forward pass costs about 2 FLOPs per parameter per token. During decode at batch size 1, an FP8 model reads 1 byte per parameter and does 2 FLOPs with it, so the intensity is about 2 FLOPs per byte. An H100 PCIe offers roughly 1,513 dense FP8 TFLOPS against 2.0 TB/s of bandwidth, so it only becomes compute-bound at around 750 FLOPs per byte. At batch 1 the tensor cores sit idle more than 99% of the time, waiting for weights to arrive.
Prefill flips this. Processing 8,000 prompt tokens reuses each weight 8,000 times, so the intensity is in the thousands and compute is the bottleneck. A worked example for Llama 3.3 70B in FP8 on one H100 PCIe:
| Step | Formula | Result (estimate) |
|---|---|---|
| Prefill FLOPs for an 8,000-token prompt | 2 × 70 × 10⁹ × 8,000 | 1.12 × 10¹⁵ FLOPs |
| Effective compute at 40–60% of 1,513 TFLOPS | 0.4–0.6 × 1,513 | 605–908 TFLOPS |
| Prefill time (drives TTFT) | 1.12 PFLOP ÷ 605–908 TFLOPS | about 1.2–1.9 s |
| Decode speed, single stream | 0.6–0.75 × 2,000 GB/s ÷ 70 GB | about 17–21 tokens/s |
| Time to generate 500 tokens | 500 ÷ 17–21 | about 24–29 s |
The answer, not the question, dominates latency. The prefill vs decode guide goes further into chunked prefill, disaggregated serving and why long-prompt workloads such as RAG feel different from chat.
What limits LLM inference speed?
For one user at a time, memory bandwidth limits speed: each new token needs the whole set of active weights streamed from VRAM to the cores. For many users, the limit moves to how many sequences fit in VRAM and, eventually, to compute.
The rule of thumb for single-stream decode:
tokens/s ≈ (0.6 to 0.75) × memory bandwidth (GB/s) ÷ bytes read per token (GB)
bytes read per token ≈ parameters (billions) × bytes per parameter
(for mixture-of-experts models, use the active parameters only)The 0.6–0.75 factor covers real-world efficiency: kernels never hit peak bandwidth, and the KV cache and activations are read too. Applied to Llama 3.3 70B:
| GPU | Bandwidth | Precision | GB read per token | Single-stream tokens/s (estimate) |
|---|---|---|---|---|
| L40S | 864 GB/s | 4-bit (~40 GB) | 40 | 13–16 |
| A100 80GB PCIe | 1,935 GB/s | 4-bit (~40 GB) | 40 | 29–36 |
| H100 80GB PCIe | 2,000 GB/s | FP8 | 70 | 17–21 |
| RTX PRO 6000 Blackwell | 1,800 GB/s | FP8 | 70 | 15–19 |
| H200 | 4,800 GB/s | FP8 | 70 | 41–51 |
| B200 | 8,000 GB/s | FP8 | 70 | 69–86 |
Two things follow. Bandwidth, not the FLOPS headline, decides how fast one user's answer streams. And precision matters as much as the card: halving bytes per parameter roughly doubles single-stream speed. The tokens per second guide unpacks the metrics (TTFT, TPOT, throughput, goodput) and how to measure them yourself.
How much GPU memory does LLM inference need?
You need room for three things: the weights, the KV cache for every token of every active sequence, and 10–20% headroom for activations, the CUDA context and the serving engine. If the total does not fit in VRAM, the model either fails to load or spills to system memory and slows to a crawl.
VRAM ≈ (weights + KV cache) × 1.1 to 1.2
weights (GB) ≈ parameters (billions) × bytes per parameter
KV cache per token = 2 × layers × KV heads × head dim × bytes per valueEstimates for one 8k-token sequence with an FP16 KV cache and 15% headroom:
| Model | Precision | Weights | KV for 8k tokens | Total with headroom | Smallest sensible fit |
|---|---|---|---|---|---|
| Llama 3.1 8B | BF16 | 16 GB | 1.1 GB | ~20 GB | RTX 4090 (24 GB) |
| Qwen3 32B | AWQ 4-bit | ~19 GB | 2.1 GB | ~24 GB | L40S (48 GB) for real contexts |
| Qwen3 32B | BF16 | ~66 GB | 2.1 GB | ~78 GB | A100 or H100 (80 GB), tight |
| Llama 3.3 70B | FP8 | ~70 GB | 2.7 GB | ~84 GB | RTX PRO 6000 (96 GB); H100 80 GB with FP8 KV and short context |
| Llama 3.3 70B | BF16 | ~140 GB | 2.7 GB | ~164 GB | 2× H100/A100 (short context) or 2× H200 |
| Qwen3 235B-A22B | FP8 | ~235 GB | 1.5 GB | ~272 GB | B300 (288 GB) or 4× H100 |
| DeepSeek-R1 (671B) | FP8 | ~671 GB | 0.6 GB | ~773 GB | 8× H200 or 8× B200 |
The GPU memory for LLMs guide works through these sums for more models, context lengths and concurrency levels.
What is the KV cache and why does it matter?
The KV cache is the stored attention keys and values for every token the model has already seen, kept in VRAM so decode does not recompute them. It grows with every token of context and every concurrent sequence, and it is usually what limits how many users one GPU can serve.
For Llama 3.x 70B (80 layers, 8 KV heads, head dimension 128):
2 × 80 × 8 × 128 × 2 bytes = 327,680 bytes ≈ 0.33 MB per token
32,768 tokens × 0.33 MB ≈ 10.7 GB per sequenceThat is per sequence. Twenty users each holding 8k tokens of context need about 54 GB of KV cache, more than most of a second H100. Three techniques shrink it:
- Grouped-query attention (GQA): Llama 3 shares 8 KV heads across 64 query heads, an 8× saving built into the model.
- FP8 KV cache: storing keys and values in 1 byte halves the cache. In vLLM this is
--kv-cache-dtype fp8. - Multi-head latent attention (MLA): DeepSeek-V3 and R1 compress keys and values into a small latent vector, about 70 KB per token across 61 layers, roughly a fifth of Llama 70B's figure.
How do servers handle many users at once?
Serving engines batch requests so that one pass over the weights produces a token for many sequences at once. Because decode is memory-bound, adding sequences to a batch costs little extra time per step, so aggregate throughput rises many times over while each user's speed drops only modestly.
Three ideas make this work in modern engines:
- Continuous batching. Requests join and leave the batch at every decode step instead of waiting for the slowest request in a fixed batch. This is the main reason vLLM, SGLang and TGI outperform naive Hugging Face
generate()loops. - PagedAttention. vLLM allocates the KV cache in fixed-size blocks, like virtual memory pages, so it wastes almost none to fragmentation and can pack more sequences into the same VRAM. The design is described in the vLLM PagedAttention paper.
- Prefix caching. Requests that share a prefix, such as the same system prompt or document, reuse its cached KV blocks and skip that part of prefill.
The trade-off is latency against throughput. A batch of 64 delivers far more tokens per second in total than a batch of 1, but each user's TPOT rises and TTFT rises when prefills queue behind decodes. Most production tuning sets a concurrency cap or a TPOT target and maximises throughput under it.
What is quantisation and does it hurt quality?
Quantisation stores weights (and sometimes activations and the KV cache) in fewer bits, such as FP8, INT8 or 4-bit, instead of 16-bit. It cuts VRAM and bytes read per token, so the same model fits on a smaller GPU and decodes faster.
For most open models, FP8 is close to lossless on common benchmarks, and good 4-bit methods (AWQ, GPTQ, GGUF Q4_K_M) lose a little: usually acceptable for chat and coding, sometimes noticeable on maths, long-context retrieval and non-English text. Hopper, Ada and Blackwell GPUs run FP8 natively; the A100 does not, so FP8 checkpoints on an A100 fall back to slower weight-only kernels. The quantisation guide compares formats, quality loss and which engines support which.
Which metrics matter for LLM inference?
Measure what your users feel and what you pay for. Users feel TTFT and TPOT; you pay for throughput per GPU-hour.
| Metric | What it measures | Driven mainly by | Typical target for chat |
|---|---|---|---|
| TTFT | Wait before the first token | Queueing + prefill (compute) | Under 1 s |
| TPOT / inter-token latency | Gap between tokens while streaming | Decode (bandwidth) and batch size | Under 50–100 ms (10–20+ tokens/s) |
| Output throughput | Total tokens/s across all users | Batch size, KV room, compute | As high as possible within latency targets |
| Requests per second | Completed requests per second | Throughput ÷ average output length | Depends on traffic |
| p95 / p99 latency | Tail experience | Queueing under load | Set per product |
| Goodput | Requests per second that meet latency targets | All of the above | The number to optimise |
Human reading speed is roughly 4–8 tokens per second, so a stream above about 15–20 tokens/s feels fast for chat. Agents and batch jobs care far more about throughput than about any one stream.
Which software should you use to serve an LLM?
For serving more than one user, use vLLM or SGLang; for one person on one machine, Ollama or llama.cpp is simpler. All of them can expose an OpenAI-compatible API, so client code does not change when you switch.
| Engine | Best for | Strengths | Watch out for |
|---|---|---|---|
| vLLM | Multi-user serving, APIs | Continuous batching, PagedAttention, prefix caching, tensor parallelism, FP8/AWQ/GPTQ | Python dependency weight; tuning flags matter |
| SGLang | High-throughput and structured output | RadixAttention prefix reuse, fast scheduler | Smaller community than vLLM |
| Ollama | One user, quick local setup | One command, GGUF models, runs on modest GPUs | Not built for many concurrent users |
| llama.cpp | CPU/GPU hybrid, edge, GGUF | Runs almost anywhere, fine-grained quantisation | Lower throughput under load |
| Hugging Face TGI | Existing TGI deployments | Mature, Rust router | Now in maintenance mode; check its README |
| TensorRT-LLM | Maximum NVIDIA performance | Compiled engines, top-end speed | More build steps per model |
The vLLM vs Ollama vs TGI comparison covers setup, concurrency behaviour and when each fits. The vLLM documentation is the reference for every flag used in this cluster.
How do you run Llama, DeepSeek and Qwen yourself?
The pattern is the same for every open model: pick a GPU with enough VRAM for weights plus KV cache, start a serving engine with the right context length and memory settings, and call it through an OpenAI-compatible endpoint. The details that differ are model IDs, licences, chat templates and reasoning output.
A minimal vLLM launch looks like this:
pip install -U vllm
vllm serve Qwen/Qwen3-32B \
--max-model-len 32768 \
--gpu-memory-utilization 0.90 \
--api-key "$MY_API_KEY"And any OpenAI client can call it:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="your-key")
r = client.chat.completions.create(
model="Qwen/Qwen3-32B",
messages=[{"role": "user", "content": "Explain the KV cache in two sentences."}],
)
print(r.choices[0].message.content)Step-by-step guides for each family:
- How to run Llama on a cloud GPU: Llama 3.1 8B and 3.3 70B with vLLM and Ollama, single-GPU FP8 and two-GPU BF16.
- How to run DeepSeek on your own GPU: the R1 distills on one card, full R1 on eight, and handling the reasoning output.
- How to run Qwen models on a cloud GPU: Qwen3 dense and mixture-of-experts models, thinking mode and the 235B model on one B300.
Should you self-host inference or use a hosted API?
Use a pay-per-token API when traffic is low or spiky and you are happy with the provider's models and data terms. Self-host when traffic is steady enough to keep a GPU busy, when prompts must stay on hardware you control, or when you need a specific open or fine-tuned model.
The economics turn on utilisation. A rented GPU costs the same per hour whether it handles one request or fifty, so its cost per token falls as concurrency rises. A hosted API charges the same per token whether you send one request a day or a million. The crossover depends on your traffic shape, which is why the next section shows cost at both ends.
If you go the self-hosted route, building your own open-source LLM API covers keys, TLS, streaming and monitoring on top of vLLM. For a comparison of where to rent the GPU, see the best GPU cloud providers for LLM inference.
How much does LLM inference cost on a rented GPU?
Cost per million tokens is the hourly price divided by millions of tokens generated per hour. Single-stream, a 70B model costs tens of dollars per million output tokens; with healthy batching, the same GPU gets to a few dollars or less.
cost per million tokens = hourly price ÷ (tokens per hour ÷ 1,000,000)
tokens per hour = tokens per second × 3,600The table uses Wandering Giants Compute list prices. Single-stream speeds come from the bandwidth rule above. Batched throughput is an assumption for a chat workload (about 1,000-token prompts, 300-token replies, 16–64 concurrent requests); real numbers can be half or double depending on prompt length, output length and concurrency.
| Model on GPU | Our price | Single-stream tok/s (est.) | $ per M tokens, single stream | Assumed batched tok/s | $ per M tokens, batched |
|---|---|---|---|---|---|
| Llama 3.1 8B BF16 on RTX 4090 | $1.59/hr | 42 | $10.52 | 800 | $0.55 |
| Qwen3 32B AWQ on L40S | $1.89/hr | 30 | $17.50 | 300 | $1.75 |
| Llama 3.3 70B FP8 on H100 | $4.99/hr | 19 | $72.95 | 250 | $5.54 |
| Llama 3.3 70B FP8 on RTX PRO 6000 | $4.89/hr | 17 | $79.90 | 300 | $4.53 |
| Llama 3.3 70B FP8 on H200 | $9.09/hr | 46 | $54.89 | 900 | $2.81 |
Derived dollar figures are each row's live price × 1,000,000 ÷ (tokens/s × 3,600), so they move with the price column. Note the H200 row: it costs more per hour than an H100, but its extra 61 GB holds far more KV cache, so it batches more sequences and comes out cheaper per token. For a deeper treatment of one card, see H100 cost per hour vs cost per million tokens.
Which GPU should you choose for LLM inference?
Choose the smallest GPU that holds your model at an acceptable precision plus the KV cache for your target context and concurrency, then move up in bandwidth if single-stream speed matters. Too small means it will not load; too large wastes money on idle VRAM.
| What you want to run | Good starting GPU | Why |
|---|---|---|
| 7–14B models, one or a few users | RTX 4090 (24 GB) | Cheapest per hour; 1 TB/s is plenty for small models |
| 32B models, or 70B at 4-bit for testing | L40S (48 GB) | Room for AWQ 32B with long context; native FP8 |
| 70B at 4-bit with long context, no FP8 needed | A100 80GB | High bandwidth for 4-bit decode |
| 70B in FP8 for a team | H100 80GB or RTX PRO 6000 (96 GB) | One card; the PRO 6000's extra 16 GB is KV headroom |
| 70B with long contexts and heavy batching | H200 (141 GB) | 4.8 TB/s and a large KV pool on one card |
| 235B-class MoE in FP8 | B300 (288 GB) | Fits on one GPU, no tensor-parallel overhead |
| DeepSeek-R1 671B | 8× H200 or 8× B200 | Needs about 700 GB just for FP8 weights |
How to choose a GPU applies the same reasoning to training and image work too.
When do you need more than one GPU for inference?
You need several GPUs when the weights plus a workable KV cache exceed one card, or when you need more throughput than one card can give. Within one machine, tensor parallelism is the usual answer; across machines, pipeline and expert parallelism come in.
- Tensor parallelism (TP) splits every layer's matrices across GPUs, so each card holds a slice of every layer and they exchange activations at every layer. In vLLM:
--tensor-parallel-size 2. It cuts per-card memory and adds bandwidth, but the all-reduce traffic means PCIe-connected cards scale less well than NVLink-connected ones. - Pipeline parallelism (PP) puts different layers on different GPUs. It needs less communication but adds latency per token. In vLLM:
--pipeline-parallel-size. - Data parallelism runs independent copies of a model that fits on one card, behind a load balancer. It scales throughput almost linearly with no communication overhead, so prefer it whenever the model fits on one GPU.
- Expert parallelism spreads a mixture-of-experts model's experts across GPUs, as used for DeepSeek-V3 and R1.
A 70B model in BF16 across two 80 GB cards works. The same model in FP8 on one 96 GB or 141 GB card usually serves more users per pound, because there is no cross-GPU traffic and no duplicated overhead.
When renting from Wandering Giants Compute fits
Wandering Giants Compute rents one GPU, or 2, 4 or 8 of the same card in one machine, from a 24 GB RTX 4090 at $1.59/hr to a 288 GB B300 at $18.09/hr, billed by the minute from prepaid credit. There are three ways in. Chat downloads an open model to your GPU and gives you a private chat in the dashboard. API serves the model with vLLM behind an OpenAI-compatible endpoint with your own key, so existing code changes one line, the base URL. Root gives you the whole machine over SSH or Jupyter to run any engine or model in this guide.
It fits when you want to try a 70B or 235B model without setting up a serving stack, when prompts must stay on a machine that is yours alone, when you want prices in your own currency with VAT shown, or when you want a hard spending cap: if credit runs out, the machine stops and its disk is kept free for 7 days. It does not fit if you need serverless scale-to-zero endpoints, multi-node clusters with InfiniBand, reserved-capacity discounts or an uptime SLA; other providers offer those, and the GPU cloud for LLM inference comparison lists them. See current GPUs and prices and how billing works.
Frequently asked questions
What is the difference between LLM training and inference?
Training adjusts a model's weights by running data forwards and gradients backwards, which needs far more memory and many GPU-hours. Inference only runs the model forwards with fixed weights to produce output. A model trained once on thousands of GPUs can be served for inference on one or a few.
Is LLM inference compute-bound or memory-bound?
Both, in different phases. Prefill processes the prompt in large matrix multiplications and is limited by compute (FLOPS). Decode generates one token at a time, rereading all the weights for each token, so at small batch sizes it is limited by memory bandwidth.
How much GPU memory do I need to run an LLM?
Roughly the weights (parameters × bytes per parameter) plus the KV cache for your context and concurrency, plus 10–20% headroom. An 8B model in BF16 fits a 24 GB card; Llama 3.3 70B needs about 80 GB in FP8 or about 160 GB in BF16.
What is the KV cache?
The KV cache stores the attention keys and values for every token already processed, so the model does not recompute them for each new token. It grows linearly with context length and with the number of concurrent sequences, and on long contexts it can rival the weights in size.
Why is my self-hosted LLM so slow?
Usually because a single request uses only a sliver of the GPU's compute while waiting on memory bandwidth, or because the model spilled out of VRAM onto the CPU. Use a serving engine with continuous batching such as vLLM, keep the whole model in VRAM, and quantise if it does not fit.
Is self-hosted inference cheaper than an API?
It depends on utilisation. A rented GPU costs the same per hour whether it serves one request or fifty, so cost per token falls sharply as concurrency rises. Low, bursty traffic is often cheaper on a pay-per-token API; steady traffic, privacy needs or custom models favour your own GPU.
What software do people use to serve LLMs?
vLLM is the most common open-source engine for multi-user serving, with continuous batching and an OpenAI-compatible API. Ollama is the easiest for one user on one machine. SGLang, TensorRT-LLM, llama.cpp and Hugging Face TGI are the other usual choices.
Rent the GPU for this, by the minute.
Launch a GPU with Llama 3.3 70B, Qwen3 or DeepSeek R1 Distill already served behind an OpenAI-compatible API, billed by the minute from prepaid credit.
Prepaid credit, billed by the minute, stops itself when credit runs out. Prices in £, $, €, ¥, CA$, A$, CHF and S$; UK prices include VAT.
Keep reading
- ComparisonBest GPU Cloud Providers for LLM Inference
- Complete guideWhat Is GPU Cloud Computing? The Complete Guide
- GuideHow Much GPU Memory Do You Need to Run LLMs?
- GuidePrefill vs Decode: Understanding LLM Inference
- Head to headvLLM vs Ollama vs TGI: Which LLM Serving Framework Should You Use?
- TutorialHow to Build Your Own Open-Source LLM API
About this article. Written by the Wandering Giants Compute team, the people who run Wandering Giants Compute. Hardware figures are the manufacturers’ published specifications. Speeds and costs marked as estimates are worked out from those specifications and our current prices, with the method shown; they are not measured benchmarks. Wandering Giants prices are taken live from our price list each time this page is built.
Last reviewed 25 November 2026.