VRAM Planning Guide for Deploying a 30B-Parameter Dense Model

    Learn how to calculate GPU memory requirements for a ~31B dense model. This guide covers weight memory, KV cache estimation formulas, long-context deployment at 256K, quantization trade-offs (INT8/INT4), loading code, and the key factors—precision, context length, concurrency, and framework overhead—that determine whether your model fits on a single GPU.

    A dense model with around 30 billion parameters (roughly 31B) sits in a common sweet spot: it can potentially fit on a single GPU while still handling fairly complex reasoning and coding tasks. But whether it actually “fits” depends on several conditions, including weight precision, context length, concurrency, and framework overhead. This article walks through what you need to verify at each stage: VRAM, long context, quantization, loading code, cloud deployment, and fine-tuning. All figures here are derived from formulas and should be re-measured with your actual model and workload before going to production.

    Characteristics of Dense Models

    A dense model uses all of its parameters in every forward pass. Compared with Mixture-of-Experts (MoE) models, it performs more computation per step, but its inference pipeline is simpler—there is no routing overhead, and the behavior of each layer is easier to predict. For tasks that demand stable output, such as code generation, multi-step reasoning, and tool calling, this predictability has real value. The trade-off is equally clear: every generated token requires reading all the weights, which means higher per-request latency and greater pressure on memory bandwidth.

    What Makes Up VRAM Usage

    VRAM consumption during deployment comes mainly from four components:

    1. Model weights: parameter count multiplied by bytes per parameter. In bf16, each parameter takes 2 bytes, so 31B parameters require about 62GB (in decimal gigabytes, roughly 57.7GiB).
    2. KV Cache: stores the Key and Value vectors of historical tokens; its size grows linearly with context length and the number of concurrent requests.
    3. Activations: intermediate results produced during the forward pass, related to batch size and sequence length.
    4. Framework overhead: CUDA context, memory fragmentation, and the inference framework’s own buffers.

    The KV cache can be estimated with the following formulas:

    Bytes per token = 2 × number of layers × number of KV heads × head_dim × bytes per element
    Total KV cache = bytes per token × context length × concurrent requests

    Suppose a model has 64 layers, 8 KV heads, and head_dim of 128. In bf16, the KV cache per token is 2 × 64 × 8 × 128 × 2 = 262,144 bytes, or 256KB. A single 256K request (262,144 tokens) needs about 64GiB of KV cache. Weights (~58GiB) plus KV cache (~64GiB) total more than 120GiB, which a single 80GB GPU cannot hold. Always check the actual model’s config file for layer count and KV head count, then substitute and recalculate.

    The table below estimates VRAM requirements for different scenarios under the assumed architecture above. Use it only for order-of-magnitude judgment:

    Scenario Context length Concurrency Weights KV Cache Estimated total (excl. activations & framework overhead) Single 80GB GPU
    Short chat 4K 1 ~58GiB ~1GiB ~59GiB Headroom available; verify by measurement
    Medium document 32K 1 ~58GiB ~8GiB ~66GiB Tight margin; verify by measurement
    Very long text 256K 1 ~58GiB ~64GiB ~122GiB Not feasible; requires multi-GPU or quantization plus KV optimization

    How to Deploy with a 256K Context

    A 256K context makes the KV cache the dominant source of VRAM pressure. There are three common approaches:

    • Multi-GPU tensor parallelism: splits weights and KV cache across multiple GPUs, at the cost of inter-GPU communication latency.
    • Quantizing weights and the KV cache: weight quantization directly reduces VRAM, and KV cache quantization (e.g., FP8) can save roughly another half of the space—but you need to evaluate quality changes on long-text tasks.
    • Limiting the actual context: if your workload only needs 32K, don’t provision for 256K. Setting the limit based on your true maximum input length greatly reduces VRAM and scheduling pressure.

    Also note that the maximum length in a config file only indicates what the model architecture allows—it does not mean the model performs reliably at that length. Whether a model can stably handle 256K input depends on its training data and position encoding scheme; refer to the long-text evaluation results in the model card.

    How Much Can Quantization Save, and at What Cost?

    With weight-only quantization, the weights of a 31B model are approximately: INT8 ~31GB, INT4 ~16GB. These figures assume 1 byte and 0.5 byte per parameter respectively, and exclude metadata such as quantization scaling factors.

    Take a consumer GPU with 24GB of VRAM as an example: INT4 weights take about 16GB, leaving roughly 8GB for the KV cache, activations, and the framework. Both context length and concurrency must be kept low, or you will easily hit OOM errors.

    Quantization methods (such as GPTQ, AWQ, and similar) typically require calibration data, which should closely match the input distribution of your real workload. Accuracy loss after quantization should be measured against the full-precision version using the same evaluation set. Evaluation can include code test pass rates, math problem accuracy, and long-text QA accuracy, while also recording throughput and time-to-first-token. If the drop on any metric exceeds what your application can tolerate, roll back to the INT8 or bf16 version.

    Loading Code and Troubleshooting

    The code below shows the basic pattern for loading the model on a single GPU. Replace the path with your local weights directory.

    1. import torch
    2. from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
    3. model_path = "/data/models/dense-31b" # Replace with your local weights directory
    4. config = AutoConfig.from_pretrained(model_path)
    5. # Only modify this if the model card explicitly supports this length
    6. config.max_position_embeddings = 262144
    7. tokenizer = AutoTokenizer.from_pretrained(model_path)