Metadata-Version: 2.4
Name: gpu-fit
Version: 1.2.0
Summary: Will this LLM fit on this GPU? vLLM memory maths: weights, KV cache, context, concurrency and shared GPUs. Calibrated on real runs.
Author: Kiran Tallapragada
License-Expression: MIT
Project-URL: Homepage, https://github.com/KiranTallapragada/gpu-fit
Project-URL: Calculator, https://kirantallapragada.com/gpu-fit/
Project-URL: Changelog, https://github.com/KiranTallapragada/gpu-fit/releases
Project-URL: Issues, https://github.com/KiranTallapragada/gpu-fit/issues
Keywords: llm,vllm,gpu,kv-cache,inference,vram,self-hosting,capacity-planning,quantization
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# gpu-fit

[![PyPI](https://img.shields.io/pypi/v/gpu-fit)](https://pypi.org/project/gpu-fit/) [![Tests](https://github.com/KiranTallapragada/gpu-fit/actions/workflows/test.yml/badge.svg)](https://github.com/KiranTallapragada/gpu-fit/actions/workflows/test.yml) [![Python](https://img.shields.io/pypi/pyversions/gpu-fit)](https://pypi.org/project/gpu-fit/) [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)

**[Try it in your browser →](https://kirantallapragada.com/gpu-fit/)** · no install, the calculation runs in your browser

**Will this LLM fit on this GPU, at this context length, for this many users, and how fast?**

`gpu-fit` answers that before you rent the GPU. It reads the model's config and weight sizes
from Hugging Face and works out vLLM's memory budget: weights, runtime overhead, KV cache, how
many requests fit at full context, and the longest single request. Then it prints the
`vllm serve` command.

**New in 1.2:** sizes for vLLM 0.34's extensible KV cache by default, calibrated on measured runs
(`--vllm-version 0.33` keeps the earlier rule). **Coming next: gpu-fit 2, "Plan it. Check it. Prove it."**
`plan` (today's `gpu-fit MODEL`, renamed), `check` (compare a running vLLM server with the plan) and
`probe` (tokens per second against a healthy baseline), with each finding labelled by the layer it
belongs to, in January 2027. [Announcement](https://kirantallapragada.com/2026/11/gpu-fit-2-which-layer-is-failing/) ·
open an issue with the failure you most want `check` to catch.

**Sharing the GPU with something else?** `--reserve-gib` shows what still fits beside the other
processes, and on vLLM 0.33 and earlier the `--gpu-memory-utilization` that leaves them room
([details](#sharing-the-gpu-with-something-else)).

```
$ gpu-fit Qwen/Qwen3-32B --context 32k --concurrency 4

  GPU          smallest setup    requests at full ctx     KV tokens
  L4           8× L4                             10.9       356,624
  L40S         4× L40S                           12.9       421,878
  A100-80      2× A100-80                        11.4       372,777
  H100         2× H100                           11.3       369,889
  H200         1× H200                            9.4       308,814
  ...
```

```
$ gpu-fit deepseek-ai/DeepSeek-V3 --gpu H200 --tp 8 --context 128k

  vLLM budget per GPU             138.6 GiB
    weights                        80.2 GiB
    runtime overhead                2.7 GiB
    left for KV cache              55.7 GiB
  Kept free by vLLM (margin)        1.1 GiB
  KV cache capacity              851,742 tokens
  Requests at full context       6.5
  Longest single request         163,840 tokens

✓ Fits. Suggested command:

  vllm serve deepseek-ai/DeepSeek-V3 \
  --max-model-len 131072 \
  --tensor-parallel-size 8 \
  --max-num-seqs 256
```

## Install

```
pip install gpu-fit        # no dependencies, Python 3.10+
```

## What gpu-fit models

A parameters-times-bytes estimate is a good start. Newer architectures change the answer, so gpu-fit reads them:

| Architecture | What changes | gpu-fit |
|---|---|---|
| Grouped-query attention | KV per token depends on KV heads, not attention heads | ✓ |
| Hybrid (linear attention + full attention, e.g. Qwen3-Next family) | Only full-attention layers grow with context; the rest hold fixed state per request | ✓ |
| MLA (DeepSeek) | Compact latent KV, but **copied to every** tensor-parallel GPU | ✓ |
| Sliding window (Gemma, Mistral) | Window layers stop growing past the window | ✓ |
| FP8 / AWQ / GPTQ checkpoints | Exact weight size from the safetensors metadata | ✓ |
| Tensor parallel beyond KV heads | KV heads get replicated, not split | ✓ |
| Hybrid `--max-num-seqs` limit | vLLM refuses to start above the state-slot count | ✓ warns first |
| FP8 KV cache | About twice the KV-token capacity: `--kv-cache-dtype fp8` | ✓ |

## Options

```
gpu-fit MODEL [--gpu L40S | --gpu-mem-gib 48] [--tp 2] [--context 128k]
              [--concurrency 8] [--max-num-seqs 32] [--kv-cache-dtype fp8] [--util 0.92]
              [--reserve-gib 12] [--overhead-gib 2.0] [--bandwidth-gbs 864] [--json]
```

- `MODEL`: a Hugging Face id, or a local folder with `config.json` and `*.safetensors`.
  Gated models need `HF_TOKEN` in the environment.
- Leave out `--gpu` to compare every GPU in the catalog with the smallest tensor-parallel size that works.
- `--json` for scripts and CI.

## Sharing the GPU with something else

vLLM grabs a fixed share of the GPU at startup and doesn't coordinate with anything else on
the card: an OCR model, an embedding server, a second vLLM, or the old pod during a rolling
deploy. With estimate-based sizing (vLLM 0.33 and earlier) it refuses to start if free memory
is below `total × gpu_memory_utilization`. vLLM 0.34's extensible KV cache skips that startup
check, but the budget still caps vLLM's memory. Either way, if the other process grows later,
an out-of-memory error can follow.

Tell gpu-fit how much the other processes need per GPU (`--reserve-gib`) and it works out what
still fits in what's left. What it suggests depends on the vLLM version:

- **vLLM 0.34 and later (default):** vLLM sizes the KV cache from the memory that is actually free
  after its warmup, so start the other processes first and leave `--gpu-memory-utilization` unset.
  If they may grow after vLLM starts, cap vLLM with `--util`, and gpu-fit adds the flag.
- **vLLM 0.33 and earlier (`--vllm-version 0.33`):** gpu-fit estimates the highest
  `--gpu-memory-utilization` that leaves room for the other processes, keeping about 0.5 GiB back
  for vLLM's own CUDA context.

```
gpu-fit Qwen/Qwen3-8B --gpu L40S --reserve-gib 12 --context 16k --concurrency 6 --vllm-version 0.33
...
✓ Fits. Suggested command:

  vllm serve Qwen/Qwen3-8B \
  --max-model-len 16384 \
  --max-num-seqs 6 \
  --gpu-memory-utilization 0.72
```

Size `--reserve-gib` for the other processes' peak, not their idle use.

## How the maths works

vLLM 0.33 and earlier take `gpu_memory_utilization` × GPU memory, load the weights, profile a
forward pass (activations, CUDA graphs), and give the rest to the KV cache. vLLM 0.34 instead
measures the memory free after warmup and keeps the activation peak plus a margin free. `gpu-fit`
mirrors both:

```
0.33 and earlier:  KV pool = memory × utilization − weights / tp − overhead
0.34 and later:    KV pool = memory − CUDA context − weights / tp − overhead − margin
                   margin  = max(1 GiB, 0.75 × activation peak)
KV/token  = 2 × full-attention layers × KV heads per GPU × head dim × dtype bytes
requests  = KV pool / (context × KV/token + sliding-window KV + recurrent state)
```

## Speed estimates

gpu-fit also estimates decode speed (tokens per second): for one user, and per user at your
concurrency. Decoding is usually limited by memory bandwidth, so the estimate divides the GPU's memory
bandwidth by what each step reads: the weights (for mixture-of-experts models, only the experts
in use) plus every active request's KV cache, with a fixed per-layer cost that matters for small
MoE models. Prompt processing is not included. It's a planning estimate: real numbers from your
hardware are welcome (see CONTRIBUTING.md).

## Accuracy, measured

gpu-fit sizes for vLLM 0.34 by default (`--vllm-version 0.34`) and keeps the earlier rule for
vLLM 0.29 to 0.33 (`--vllm-version 0.33`). Both are checked against real runs.

### vLLM 0.34 (extensible KV cache)

Predicted vs what vLLM 0.34.0 reported on an AWS **L40S 48 GB** (g6e), 32K context, measured
29 Nov 2026. Raw data: [`bench/results/l40s-vllm0.34.0.tsv`](bench/results/l40s-vllm0.34.0.tsv).

| Model | Type | `--max-num-seqs` | KV tokens (vLLM) | KV tokens (gpu-fit) | Error |
|---|---|---|---|---|---|
| Qwen/Qwen3-4B | dense | 32 | 250,368 | 250,280 | −0.0% |
| Qwen/Qwen3-8B | dense | 32 | 190,976 | 189,703 | −0.7% |
| Qwen/Qwen3-8B | dense | 256 | 186,880 | 185,508 | −0.7% |
| Qwen/Qwen3-14B | dense | 32 | 88,576 | 88,015 | −0.6% |
| Qwen/Qwen3-14B | dense | 256 | 84,992 | 83,239 | −2.1% |
| Qwen/Qwen3-8B-FP8 | dense, FP8 weights | 32 | 237,056 | 236,801 | −0.1% |
| Qwen/Qwen3-30B-A3B-FP8 | MoE | 32 | 140,288 | 119,246 | −15.0% (cautious) |
| Qwen/Qwen2.5-VL-7B-Instruct | vision | 32 | 384,000 | 378,734 | −1.4% (provisional, one run) |

- Accuracy is judged on KV tokens. In that file the `kv_pool_gib` column holds vLLM's preliminary
  KV figure, not the final allocation (fixed in `bench/measure.sh` for future runs).
- **Dense models:** at or below what vLLM reported, within 2.1%. The constants (CUDA context
  0.70 GiB, 0.0024 GiB per extra request slot) were fitted to these runs.
- **Vision models** keep a much larger activation peak free on 0.34; one run so far, so the
  estimate is deliberately cautious and labelled provisional.
- **FP8 KV cache on the L40S failed to start** in our runs on both vLLM 0.31 and 0.34 (it worked
  on L4 and A10G); gpu-fit says so when you ask for it on an L40S.

### vLLM 0.29 to 0.33

Predicted vs what vLLM 0.31 actually allocated on three AWS GPUs across two generations: **L40S 48 GB**
(g6e, Ada), **A10G 24 GB** (g5, Ampere) and **L4 24 GB** (g6, Ada). 32K context unless noted,
`--max-num-seqs 32`. Raw data and method: [`bench/`](bench/).

| Model | Type | GPU | KV cache | KV tokens (vLLM) | KV tokens (gpu-fit) | Error |
|---|---|---|---|---|---|---|
| Qwen/Qwen3-8B | dense | L40S (Ada) | default | 175,696 | 175,874 | +0.1% |
| Qwen/Qwen3-14B | dense | L40S (Ada) | default | 75,888 | 75,569 | −0.4% |
| Qwen/Qwen3.8-27B-FP8 | hybrid + vision | L40S (Ada) | default | 137,216 | 134,077 | −2.3% |
| Qwen/Qwen3.6-35B-A3B-FP8 | hybrid MoE + vision | L40S (Ada) | default | 179,361 | 158,477 | −11.6% (cautious) |
| Qwen/Qwen3-4B | dense | A10G (Ampere) | default | 85,712 | 85,719 | +0.0% |
| Qwen/Qwen3-8B-FP8 | dense, FP8 weights | A10G (Ampere) | default | 72,496 | 72,240 | −0.4% |
| Qwen/Qwen3-4B | dense | A10G (Ampere) | FP8 | 178,736 | 171,438 | −4.1% |
| Qwen/Qwen3-8B-FP8 | dense, FP8 weights | A10G (Ampere) | FP8 | 158,240 | 144,480 | −8.7% (cautious) |
| Qwen/Qwen3-8B | dense | A10G (Ampere), 16K | default | 26,256 | 25,142 | −4.2% |
| Qwen/Qwen3-8B | dense | A10G (Ampere), 16K | FP8 | 51,200 | 50,284 | −1.8% |
| Qwen/Qwen3-4B | dense | L4 (Ada) | default | 85,632 | 85,758 | +0.1% |
| Qwen/Qwen3-8B-FP8 | dense, FP8 weights | L4 (Ada) | default | 72,432 | 72,279 | −0.2% |
| Qwen/Qwen3-4B | dense | L4 (Ada) | FP8 | 178,448 | 171,516 | −3.9% |
| Qwen/Qwen3-8B-FP8 | dense, FP8 weights | L4 (Ada) | FP8 | 158,080 | 144,558 | −8.6% (cautious) |
| Qwen/Qwen3-8B | dense | L4 (Ada), 16K | default | 26,192 | 25,181 | −3.9% |
| Qwen/Qwen3-8B | dense | L4 (Ada), 16K | FP8 | 51,072 | 50,362 | −1.4% |

- **Dense models, default KV cache, 32K:** within 0.5% of what vLLM reported on all three GPUs
  (at most 0.15% above). At 16K and with an FP8 KV cache the estimates are more cautious (up to 9% below).
- **Same behaviour on Ampere and Ada:** A10G and L4 results agree within 0.4%, and vLLM's runtime
  overhead is the same on both. FP8 weights and the FP8 KV cache both work on the Ampere A10G.
- Qwen3-8B (16-bit) at 32K context does not start on a 24 GB GPU: gpu-fit predicts this and says so.

- Weights come from the checkpoint's file sizes and KV per token from the model config; vLLM's
  runtime allocation can differ slightly from the file sizes.
- Runtime overhead (activations, CUDA graphs, non-torch memory) is calibrated from these runs at
  vLLM's default `gpu_memory_utilization` of 0.92. For dense text models it grows with the model's
  width: about 0.5 + 0.37 GiB per 1,024 of hidden size. That was measured on Qwen3 models with hidden
  sizes from 2,560 to 5,120; outside that range, and for sliding-window models, it's an extrapolation.
  Mixture-of-experts, hybrid and vision models use fixed values measured on the L40S. A bit more is
  added per `--max-num-seqs` slot. Override it with `--overhead-gib`. With an FP8 KV cache, vLLM's
  overhead is sometimes lower, so those estimates are cautious.
- **vLLM 0.34 changed this.** On CUDA it sizes the KV cache from memory actually free after
  warm-up ("extensible KV cache") and uses the whole GPU unless you set `--gpu-memory-utilization`.
  On the same L40S that is 8.7% (Qwen3-8B) to 16.7% (Qwen3-14B) more KV tokens than 0.31. gpu-fit
  1.2 sizes for 0.34 by default; pass `--vllm-version 0.33` for older servers, and its suggested
  command then sets `--gpu-memory-utilization` explicitly.
- **Hybrid models have a hard limit on `--max-num-seqs`.** Each request needs one
  recurrent-state slot. Ask for more slots than fit and vLLM refuses to start; gpu-fit
  tells you the limit first (it predicted 156 where vLLM reported 164).
- Treat the output as a planning estimate and confirm on the real GPU before you commit money.

**Help improve the calibration:** share what vLLM printed on your hardware (see [CONTRIBUTING.md](CONTRIBUTING.md)).
Measurements from more GPUs and models help refine the defaults for everyone.

## Compatibility

From 1.0, the command-line flags and the fields in `--json` output stay compatible across 1.x
releases; new options and fields may be added. `--json` prints one object for a single GPU
(`--gpu` or `--gpu-mem-gib`) and a list of objects, one per GPU, when comparing all GPUs; `speed`
is `null` when no estimate is available. Memory values are GiB, contexts are tokens. Estimates can change between releases as new
measurements improve the calibration; the accuracy section above always says what has been measured.

## Roadmap

- [x] Memory model calibrated on real hardware (L40S)
- [x] Hybrid `--max-num-seqs` limit warning
- [x] Browser calculator
- [x] Decode speed estimate, MoE-aware
- [x] Shared-GPU budgeting (`--reserve-gib`)
- [x] Measured on vLLM 0.34 (extensible KV cache), L40S, 29 Nov 2026
- [x] 1.2: vLLM 0.34 sizing with `--vllm-version`
- [ ] 2.0: `gpu-fit check` and `gpu-fit probe`, findings labelled by layer (January 2027)
- [ ] Workload mode: safe concurrency, throughput and cost per 1,000 requests
- [ ] Speed calibrated against measured vLLM throughput
- [x] Measured on three GPUs across Ampere and Ada (A10G, L4, L40S)
- [ ] More GPUs measured (A100, H100, B200) and models (Llama, Gemma, Mistral)
- [ ] Prompt-processing (prefill) time and time-to-first-token
- [ ] Cost per million tokens for cloud GPUs
- [ ] SGLang and TensorRT-LLM memory models
- [ ] LoRA adapters and speculative decoding

## License

MIT
