Skip to main content
Apidly

Optional cookies only if you accept. Cookie policy

Pick a GPU for LLM inference: VRAM and speed

Size a GPU from public model facts: weight memory, KV cache, quantization and the memory-bandwidth limit on decode speed.

Published December 3, 20266 min read

Choosing a GPU for a language model comes down to three questions. Does the model fit? Does it fit with room for the number of users you expect? And is the decode speed good enough? You can answer all three on paper before you start a server, using numbers that are published by the model authors and the hardware makers. This post shows the arithmetic, with a table you can check yourself. Nothing here is a benchmark: where a figure is a ceiling or an estimate, it says so.

1. Weights: parameters times bytes

The weights are the largest fixed cost. Memory is the parameter count times the bytes per parameter: 2 bytes at 16-bit, 1 byte at 8-bit and about 0.5 byte at 4-bit. The parameter counts below come from the Hugging Face model pages of the Qwen2.5 Instruct family (the safetensors total shown on each page). The 4-bit column is nominal: real 4-bit checkpoints also store scales and some layers in higher precision, so add 10 to 20 percent.

Model Parameters 16-bit 8-bit 4-bit (nominal)
Qwen2.5-1.5B-Instruct 1.54 B 3.1 GB 1.5 GB 0.8 GB
Qwen2.5-7B-Instruct 7.62 B 15.2 GB 7.6 GB 3.8 GB
Qwen2.5-14B-Instruct 14.77 B 29.5 GB 14.8 GB 7.4 GB
Qwen2.5-32B-Instruct 32.76 B 65.5 GB 32.8 GB 16.4 GB
Qwen2.5-72B-Instruct 72.71 B 145.4 GB 72.7 GB 36.4 GB

Sources: the model pages at huggingface.co/Qwen/Qwen2.5-<size>-Instruct. Sizes are in decimal gigabytes.

2. KV cache: the part that grows with your users

While a model answers, it keeps the attention keys and values of every token it has seen, so it does not recompute them. This is the KV cache, and it is where your concurrency goes. For each token it holds:

2 (keys and values) x layers x KV heads x head dimension x bytes per value

The layer count, KV head count and hidden size are in each model's public config.json. With a 16-bit cache and a head dimension of 128 (hidden size divided by attention heads, 128 for all five models here):

Model Layers KV heads KV cache per token One 8,192-token sequence 8 such sequences
1.5B 28 2 28 KiB 0.22 GiB 1.8 GiB
7B 28 4 56 KiB 0.44 GiB 3.5 GiB
14B 48 8 192 KiB 1.50 GiB 12.0 GiB
32B 64 8 256 KiB 2.00 GiB 16.0 GiB
72B 80 8 320 KiB 2.50 GiB 20.0 GiB

These models use grouped-query attention: many query heads share a few KV heads, which is why the cache is far smaller than the number of attention heads would suggest. A model with full multi-head attention would need several times more per token. When you evaluate another model, read its config.json and plug in the same four numbers.

A serving engine such as vLLM manages this memory in blocks (the PagedAttention design, Kwon et al., 2023, arXiv 2309.06180) so that it is not wasted on padding, but the total you can hold is still bounded by what is left after the weights. By default vLLM uses 90 percent of GPU memory (gpu_memory_utilization) and logs the size of the KV cache it could allocate when it starts. That log line is the most honest sizing number you can get: read it on your first run.

3. Which GPU fits: a worked table

Here is the smallest option that holds the weights plus a KV cache for 8 concurrent sequences of 8,192 tokens, using 90 percent of the memory and allowing the 10 to 20 percent checkpoint overhead above. "2 x 80" means two 80 GB cards with the model split across them, which only works if your serving software supports it.

Model 16-bit 8-bit 4-bit
1.5B 24 GB 24 GB 24 GB
7B 24 GB 24 GB 24 GB
14B 48 GB 48 GB 24 GB
32B 2 x 80 GB 80 GB 48 GB
72B more than 2 x 80 GB 2 x 80 GB 80 GB

Read it as a starting point. The 7B at 16-bit needs about 14.2 GiB for weights and 3.5 GiB of cache, which is 17.7 GiB against about 21.6 GiB usable on a 24 GB card, so there is room for more sequences. The 14B at 4-bit works out at roughly 20 GiB against the same 21.6 GiB: it fits, but a longer context or more users will not. Halve the context or the concurrency and the cache halves too.

4. Quantization: what you trade

Quantization stores weights in fewer bits. It cuts weight memory by half (8-bit) or to about a quarter (4-bit), and it also cuts the data read per token, which helps speed. The cost is some loss of quality that depends on the model, the method and the task. Widely used 4-bit methods include GPTQ (Frantar et al., 2022, arXiv 2210.17323) and AWQ (Lin et al., 2023, arXiv 2306.00978). Two practical rules:

  • Prefer a larger model at 4-bit over a smaller one at 16-bit only after you have tested both on your own prompts. Published averages do not tell you about your task.
  • Quantize the weights first. Reducing the KV cache precision is a separate switch with its own quality trade-off; test it separately.

5. Throughput: a ceiling, not a promise

Generating one token requires reading essentially all the weights from GPU memory once. When a single stream is generating, speed is limited by memory bandwidth, so an upper bound on tokens per second is:

memory bandwidth / weight bytes

Bandwidth figures are from the public NVIDIA product pages: RTX 4090 about 1,008 GB/s, L40S 864 GB/s, A100 80 GB (SXM) 2,039 GB/s, H100 (SXM) 3.35 TB/s. Dividing them by the weight sizes in section 1 gives these ceilings for one stream:

Weights read per token RTX 4090 L40S A100 80 GB H100
7B at 16-bit (15.2 GB) 66 57 134 220
14B at 8-bit (14.8 GB) 68 58 138 227
32B at 4-bit (16.4 GB, nominal) 61 53 124 204
72B at 4-bit (36.4 GB, nominal) no fit 24 56 92

Tokens per second, upper bounds. Real engines come in below them, and the gap depends on software, kernels and batch size. Two things follow, though. First, a card with twice the bandwidth is at most about twice as fast per stream, whatever its other specifications say. Second, when many requests are batched together, the weights are read once for all of them, so total throughput across users rises well above the single-stream ceiling until the GPU becomes compute-bound. That is why a serving engine with continuous batching is worth it even for modest traffic.

Prompt processing (prefill) behaves differently: it is compute-bound, so long prompts favour GPUs with more compute, not just more bandwidth.

6. Turning this into a decision

  1. Pick the model by quality on your own test prompts, then take its parameter count.
  2. Compute weights at the precision you will use, plus 10 to 20 percent for quantized files.
  3. Compute KV cache per token from config.json, multiply by your context length and by the number of requests you want in flight at once.
  4. Add them and divide by 0.9. Pick the smallest GPU above that number, or the smallest multi-GPU setup if none is.
  5. Use the bandwidth ceiling to check that single-stream speed is acceptable for chat. If it is not, move up in bandwidth, not only in memory size.

On Apidly the GPU list can be filtered by memory, and the endpoint wizard's "From a model" option estimates GPU memory from the model's weights, context and a margin before you create anything. Servers and serverless workers are billed by the second, so the cheapest way to confirm any of this is a short test: start the model, read the KV cache line in the log, send a realistic load and stop the server. The figures you measure on your own prompts replace every estimate above.

Try what this guide shows

Start one of these templates on a cloud GPU server. You see the price per hour before you start, and you pay by the second.

  • Language modelsOpens in your browser

    vLLM (OpenAI-compatible)

    High-throughput LLM inference server exposing an OpenAI-compatible API on port 8000.

    Minimum GPU memory
    16 GB
    Default disk
    100 GB

Try it on a real GPU server

Create a free account and add a balance from $10. Servers are billed by the second, and the review step shows the price per hour before you request one.

Related guides