31B Dense Open-Source LLM Deployment: VRAM Budgeting and Long-Context Practices
This article explains how to plan memory for deploying a 31B dense open-source language model, covering weight, KV cache, and activation costs; single-GPU and production serving configurations; long-context options such as tensor parallelism, 8-bit KV cache, and weight quantization; and how to interpret vendor-reported benchmark results.
1. Understand the Model’s Positioning First
This article discusses a dense open-source model with roughly 31 billion parameters (31B). “Dense” means that all parameters participate in computation during every inference pass. By contrast, a mixture-of-experts (MoE) model activates only a subset of experts per pass, reducing computation per request, but all parameters still remain resident in VRAM.
The advantages of a dense architecture are stable behavior, a mature fine-tuning workflow, and broad support across inference frameworks. The cost is that VRAM usage is proportional to the total parameter count. If a team prioritizes per-request quality and predictable behavior, a dense model is a reasonable choice. If the primary requirement is high-concurrency throughput, compare the deployment cost of MoE variants first.
Model specifications should be based on the official model card published by the vendor. The values cited in this article come from the source material and have not been independently reproduced. Verify them on the official page before citing them.
2. The Memory Budget: Weights, KV Cache, and Activations
Three memory calculations are needed before deployment.
2.1 Weight Memory
Weight memory can be estimated with the following formula:
Weight memory ≈ parameter count × bytes per parameter
In bfloat16, each parameter takes 2 bytes:
31B × 2 bytes ≈ 62 GB
After 4-bit quantization, each parameter takes about 0.5 bytes, for roughly 16 GB of weights. After 8-bit quantization, weights are about 31 GB. These are pure weight estimates. Actual loading also includes quantization metadata, temporary buffers, and other overhead.
2.2 KV Cache: The Main Memory Cost of Long Contexts
During inference, the model must store Key and Value for every processed token. This is called the KV cache. Its size grows linearly with context length and concurrency. The formula is:
KV cache bytes = 2 × layers × KV heads × head dimension × bytes per element × total tokens
The coefficient 2 represents the two copies of data, K and V. The number of KV heads depends on whether the model uses grouped-query attention (GQA), a design that significantly reduces KV cache size. The number of layers, KV heads, and head dimension can all be found in the model configuration file, config.json.
The following calculation uses a set of assumed configurations to demonstrate the process. Actual values should be based on the official configuration. Assume the model has 64 layers, 8 KV heads, a head dimension of 128, and stores the KV cache in bfloat16.
Per token: 2 × 64 × 8 × 128 × 2 bytes = 262,144 bytes, or 256 KiB.
KV cache for 256K tokens (262,144 tokens): 262,144 × 256 KiB = 64 GiB.
Adding roughly 62 GB of bfloat16 weights brings the total requirement to more than 120 GB. Under these assumptions, a single 80 GB GPU cannot hold one request that fills a 256K window.
This shows that a single 80 GB card is suitable for short-context, low-concurrency scenarios. As context grows, the KV cache will exhaust VRAM before the weights do.
2.3 Activations and Concurrency
Activations are generated temporarily during forward computation, and long sequences use more during the prefill stage. The more concurrent requests there are, the more KV cache each request holds. Therefore, when serving externally, plan VRAM based on “maximum context length × maximum concurrency.” Looking only at a single request will underestimate actual requirements.
3. Deployment Options and Configuration
3.1 Short-Context Single-GPU Deployment
In debugging scenarios with short contexts and a single request, you can load the model directly with Transformers:
from transformers import AutoModelForCausalLM, AutoTokenizermodel_id = "<local or repository model path>"tokenizer = AutoTokenizer.from_pretrained(model_id)model = AutoModelForCausalLM.from_pretrained(model_id,torch_dtype="bfloat16",device_map="auto", # Split automatically across multiple GPUs; place entirely on one GPU for single-GPU use)
This code only ensures that the weights can be loaded. Out-of-memory errors can still occur when inputs become longer or the batch size increases.
3.2 Production Serving Deployment
For production environments, use a dedicated inference framework such as vLLM. Below is an example command for a single GPU and a medium context length:
vllm serve <model path> \--dtype bfloat16 \--max-model-len 32768 \--gpu-memory-utilization 0.90 \--tensor-parallel-size 1
Here, --max-model-len limits the maximum length of a single request; --gpu-memory-utilization sets the proportion of VRAM the framework may use; and --tensor-parallel-size sets the number of GPUs for tensor parallelism. Parameter names and defaults vary by version. Check the documentation for the version you use before deployment.
To support contexts close to 256K, there are three common approaches:
- Use multi-GPU tensor parallelism to distribute weights and KV cache across multiple GPUs.
- Store the KV cache in 8-bit (for example,
--kv-cache-dtype fp8, which requires support from both the framework and the hardware). - Quantize weights to 4-bit or 8-bit to free up space for the KV cache.
These approaches can be combined. Using the assumed configuration above as an example, 4-bit weights (about 16 GB) plus an 8-bit KV cache (about 32 GiB) total roughly 50 GB, leaving some headroom on an 80 GB GPU. Actual headroom still needs to be confirmed with real workload tests.
3.3 Quantization Tradeoffs
Quantization introduces accuracy loss, and the extent depends on the task and quantization method. 4-bit schemes are better suited to latency-sensitive scenarios with higher tolerance for accuracy loss. For code generation, mathematical reasoning, or high-risk outputs such as medical or legal content, compare results before and after quantization on your own business data before deciding whether to launch.
Different inference frameworks support different quantization formats, and the same weights may perform differently across frameworks. After switching frameworks, rerun regression evaluation.
4. How to Read Performance Data
The source material lists several benchmark results covering general knowledge, scientific reasoning, coding contests, math contests, and multimodal understanding. These figures are vendor-reported. Test-set versions, prompt templates, and decoding parameters also matter when interpreting those numbers.
