haotianblog
VRAM Calculator
Search
Ask the AI

VRAM Calculator

VRAM Calculator

Enter GPU memory, target context and concurrency to compare estimated weights, KV cache and runtime overhead for Gemma 4 configurations. Use the results to choose trial configurations, then check actual allocations and headroom in the target engine’s startup logs.

Checkpoint sizes use the file bytes queried from the HuggingFace API, not parameter-count estimates. File size, GPU model buffers, KV allocation and peak runtime memory are different quantities; check the selected checkpoint and loading path.

Model sizes are real file byte counts from the HuggingFace API converted to GiB, not estimates from parameter counts. When running GGUF, the E-series PLE table and token embedding stay in system RAM, and that share is already deducted here — which is why "Weights" is much smaller than the file size. KV cache is computed from each variant's layer count, KV heads, shared layers and sliding window. The whole formula was calibrated against measured VRAM for E4B at 8K/32K/64K/128K context on an 8 GB laptop, landing within 0.15 GB; other variants are extrapolated from the same architecture, so if a row says "Tight", try a smaller context first. Multi-GPU is modeled as pooled VRAM with a separate compute buffer per card and has not been verified on real hardware — actual results also depend on interconnect bandwidth and how the model is split.

How to read the numbers

Weights estimates model tensors placed on the GPU. The E4B q4_0 file is about 4.8 GiB; after deducting CPU-resident tensors, the estimator assigns about 2.2 GiB to the GPU. That is an empirical deduction, not an independently measured GPU-weight size. The PLE table’s roughly 2.8B parameters do not imply fixed encoded bytes. Check tensor placement in the selected version’s loading logs.

KV cache stores historical keys and values. The E-series combines cross-layer sharing and 512-token windows; memory depends on the actual cached layers, local/global head dimensions, cache precision and allocation policy. Windowed caches still have a nonzero constant cost. The table’s 8K run omits mmproj while 32K and above include it, so those totals do not establish the old claim that 8K to 128K adds only about 1.1 GB of KV.

Overhead covers compute buffers, fragmentation and backend costs. The old estimator takes the maximum of a constant term and a context-dependent term as an empirical fit; fixed costs and activation memory can coexist. See the estimator’s design notes for calibration and slope-attribution conditions.

How far off can it be

The formula was calibrated on a laptop with 8 GB of VRAM, running E4B quantized to q4_0 through llama.cpp’s Vulkan backend with the KV cache quantized to q8_0. Predicted versus measured across four context lengths:

Context Predicted Measured Error
8K2.96 GiB2.90 GiB+0.06
32K4.16 GiB4.25 GiB−0.09
64K4.52 GiB4.54 GiB−0.02
128K5.26 GiB5.14 GiB+0.12

These are calibration residuals for one variant on one software stack using the fitted data, not independent validation errors. Other variants and multiple GPUs were not individually verified. “Fits” and “Tight” are classifications from the old formula. Actual use still depends on current occupancy, target requests and runtime peaks. Start with a smaller context and check the logs.

The quantization size trap

The easiest mistake when picking a variant is assuming that 4-bit quantization roughly halves a model to a size proportional to its parameter count. Google’s official Gemma 4 QAT checkpoints use the compressed-tensors format, whose config specifies targets: ["Linear"] — only linear layers get quantized, and embeddings stay in bf16. For models where embeddings are a large fraction of the parameters, the quantized result is far bigger than expected.

In these records, E4B QAT W4A16 is 10.72 GiB and 12B Unified is 9.56 GiB, despite roughly three times the effective parameter count. The E-series’ uncompressed PLE affects checkpoint size; the size comparison alone does not establish an inference-speed ranking.

The compared GGUF q4_0 also quantizes embeddings, giving an E4B file of about 4.8 GiB. Compare llama.cpp and vLLM for the actual checkpoint, CPU offload, backend and workload. File format alone does not determine capacity, latency or throughput in every setting.

Two constraints on multi-GPU

The multi-GPU branch adds card capacities and reserves overhead per card as an unverified approximation. Actual feasibility also depends on tensor placement, replication, interconnect and engine support; summed capacity does not establish that each tensor fits.

Check tensor sharding and replication rules. In the reviewed vLLM v0.19.0 QKVParallelLinear, fewer KV heads than TP ranks can be handled by replication, with ranks divisible by KV heads; other cases shard the heads. Query heads, MLP dimensions, quantization kernels and the full model retain their own constraints. One KV head does not itself exclude multiple GPUs, and power-of-two counts do not automatically satisfy every rule. Recheck the calculator’s simple-divisibility messages against these conditions.

Layer placement and tensor parallelism are different strategies. Layer splitting avoids some within-layer sharding constraints but still requires layers to fit their assigned cards. One request traverses the layers in order; multiple requests can gain throughput through pipeline scheduling. Microbatches, interconnect and the engine determine the benefit. Layer splitting does not imply that multiple GPUs can never help speed.

The original overhead model scales by card count without a multi-GPU measurement. Cards may need independent buffers, while sharing, replication and fixed costs depend on the backend. The empirical coefficient is not a universal allocation rule.

How much headroom to leave

Enter the occupancy actually observed before the run. The original 0.3-to-1-GB desktop/browser range is only a rough example. A headless card can still hold driver or other-process allocations, so zero is not automatic.

Image input can require mmproj and image-activation memory. Savings from omitting it depend on the variant and actual file; roughly 0.9 GB is not a fixed size for every Gemma 4 projector. Record loaded projector memory separately from request peaks.

Related reading

The calculator gives an initial memory budget. Check loading success, time to first token, generation speed and concurrent throughput on the target engine and requests. The tutorial series retains the related measurement methods and configuration records.

Scroll down