Selecting and Deploying a 31B Dense Model: How to Calculate VRAM Requirements
This article explains how to estimate GPU memory requirements for a 31-billion-parameter dense model before deployment. It covers the difference between dense and Mixture-of-Experts (MoE) architectures, weight memory usage across bf16, INT8, and INT4 precisions, and a step-by-step formula for calculating KV Cache overhead during inference. Practical examples show why a single 80GB GPU may be insufficient for long-context scenarios.
Understanding Dense Models First
A dense model activates all of its parameters for every token generated, unlike a Mixture-of-Experts (MoE) model, which only activates a subset of expert networks. This distinction directly affects deployment decisions. In a dense model, computational cost scales with parameter count, and all parameters must reside permanently in VRAM. MoE models may have a larger total parameter count, but each inference step only consumes a fraction of the compute.
Therefore, when selecting a dense model with 31 billion parameters (31B), resource estimation must assume that all parameters remain resident in GPU memory at all times. Parameter count alone does not indicate model quality—whether a model meets business requirements depends on its performance on your specific tasks.
How Much VRAM Is Needed: Start with Weight Memory
Weight size is determined by parameter count and storage precision. Under bf16, each parameter occupies 2 bytes; under INT8, 1 byte; under INT4, roughly half a byte. For a 31B model, the table below provides estimated weight sizes.
| Precision | Weight Size (Estimated) | Single-GPU Feasibility | Key Trade-off |
|---|---|---|---|
| bf16 | ~62 GB | Fits on an 80 GB GPU, with very little headroom | Highest VRAM usage |
| INT8 | ~31 GB | A 48 GB GPU can hold the weights | Precision loss is usually less than INT4 |
| INT4 | ~16 GB (including quantization parameters, slightly higher in practice) | A 24 GB GPU can hold the weights | Precision loss must be measured empirically |
INT8 weights cannot be compressed below 25 GB. The precision loss from INT4 depends on the quantization method and calibration data. Common quantization approaches include GPTQ, AWQ, and K-quant in the GGUF format. These methods vary significantly in effectiveness, so you should compare them on your own evaluation set before making a final choice.
What Actually Consumes VRAM During Inference: KV Cache
Weight size is fixed. During text generation, the model also maintains a key-value cache (KV Cache) for every token processed so far. Its size can be estimated with the following formula:
Bytes per token = 2 × number of layers × KV heads × head dimension × bytes per element
Total usage equals the per-token footprint multiplied by the context length, then multiplied by the number of concurrent requests. The layer count, KV head count, and head dimension must be read from the model configuration file—do not rely on rough guesses.
Assume a model has 60 layers, 8 KV heads, a head dimension of 128, and uses bf16 storage. Each token occupies approximately 240 KB (2 × 60 × 8 × 128 × 2 = 245,760 bytes). Under this assumption:
- A single request with 8K context requires about 2 GB of KV Cache.
- A single request with a full 256K context requires about 64 GB of KV Cache.
A full 256K context alone needs roughly 64 GB, and adding 62 GB of weights means a single 80 GB GPU will face severe capacity pressure in long-context deployment scenarios. This makes it essential to calculate both weight memory and KV Cache growth when planning hardware resources for dense models.
