Memory and Cost Calculations for Deploying a 31B Dense Open-Source Model on a Single GPU

    Deploying a 31-billion parameter dense model on a single GPU requires careful memory and cost planning. This article explores the advantages of 31B dense models, details how to calculate the VRAM budget for model weights and KV Cache, and examines the impact of quantization on performance and space. It also provides guidance on building custom capability evaluations, a step-by-step deployment guide using vLLM, licensing considerations, and a comprehensive pre-launch checklist to ensure a stable production environment.

    1. Why Focus on 31B Dense Models?

    Choosing the right parameter scale involves a trade-off between performance, cost, and deployment flexibility. Small models are easy to deploy but have a lower capability ceiling. Mixture of Experts (MoE) models have a large total parameter count but only activate a subset of experts per token, resulting in lower inference costs. However, all expert weights must reside in VRAM, placing higher demands on scheduling and hardware.

    Dense models utilize all parameters to generate each token. They feature a simple architecture, stable inference latency, and mature full-parameter fine-tuning and Parameter-Efficient Fine-Tuning (PEFT) solutions like LoRA, making them suitable as a foundation for enterprise domain models. A scale of around 31 billion parameters sits at a compromise between capability and deployment cost: the model weights can fit into a single high-end datacenter GPU without requiring multi-GPU partitioning.

    2. Verify Specifications: Rely on the Model Card

    Within the same model family, different variants may vary in parameter count, context length, multimodal capabilities, training languages, and licenses. Do not mix specifications from different family members, or you won’t be able to determine exactly which model you are deploying.

    Before making a selection, confirm the following information item by item from the official model card:

    1. Model name, version number, and release date.
    2. Parameter count and architecture type (Dense or MoE).
    3. Maximum context length and the corresponding field value in the configuration file.
    4. Supported input modalities (e.g., text, image, video).
    5. Range of languages covered during training.
    6. Specific license name and terms of use.
    7. Original precision of the weights and available quantized versions.

    Record this information in your team’s deployment documentation. Subsequent evaluations and go-live audits should be based on this record.

    3. VRAM Budget: Allocations Beyond Weights

    First, calculate the weights. A 31B model stored in bf16 (2 bytes per parameter) occupies about 31×10⁹×2 bytes, or roughly 62GB. It can fit into an 80GB GPU, but there isn’t much space left.

    vLLM defaults to using 90% of VRAM as the inference budget. 90% of 80GB is about 72GB. Subtracting the 62GB for weights leaves only about 10GB for the KV Cache, activations, and framework overhead. The actual remaining space is further affected by the CUDA context, memory fragmentation, and batch size, so the usable space in practice is often less than the theoretical value.

    KV Cache is the primary VRAM overhead for long contexts. The calculation formula is as follows:

    Bytes per token = 2 × Number of Layers × Number of KV Heads × Head Dimension × Bytes per Element

    Total KV Cache = Bytes per token × Context Length × Number of Concurrent Requests

    Let’s demonstrate the calculation using hypothetical parameters: 64 layers, 8 KV heads, 128 head dimension, and bf16 precision. Each token occupies 2×64×8×128×2 = 262,144 bytes, or about 256KB.

    • A single request using a 32K context occupies roughly 256KB × 32,768 ≈ 8GB. Given the remaining space mentioned above, it can barely accommodate one such request.
    • A single request using a 256K context occupies roughly 256KB × 262,144 ≈ 64GB, far exceeding the remaining space on a single card.

    These numbers are merely for demonstration. The actual number of layers and KV heads for a real model must be read from the model’s config.json. The calculation illustrates one point: the theoretical capability of a 256K context window does not equate to being able to stably serve 256K-length requests on a single GPU using bf16. In a production environment, the usable context length must be determined based on measured KV Cache usage.

    4. Quantization: Trading Space for Serviceable Concurrency

    Quantization compresses the weight size, leaving more VRAM for the KV Cache. As a rough estimate, INT8 weights take about 31GB, and INT4 weights take about 16GB. The actual size may increase slightly due to scaling parameters and unquantized layers in the quantization scheme.

    The cost of quantization is a degradation in quality, the extent of which varies by task. Code generation, mathematical reasoning, and long-context information extraction can be sensitive to precision changes. Before adopting a quantization scheme, you should:

    1. Test the output quality of both the bf16 and quantized versions using the same batch of business samples.
    2. Record Time to First Token (TTFT), tokens generated per second, and peak VRAM usage.
    3. Only switch to the quantized version if the quality degradation is acceptable.

    Note that the weight format of a quantized model must match the parameters of the inference engine. For example, AWQ pre-quantized weights must be used with AWQ-related parameters; you cannot directly apply them to original bf16 weights.

    5. Capability Evaluation: Make Judgments with Your Own Data

    Public leaderboards can provide a reference, but directly citing leaderboard scores for selection carries risks. When reviewing evaluation results, confirm the following: evaluation set name and version, model version, prompt template, sampling parameters, evaluation date, and by whom and under what conditions the scores were measured.

    A more reliable approach is to build your own evaluation set:

    1. Categorize by business scenario, such as customer service Q&A, contract extraction, code completion, and chart understanding.
    2. Prepare 50 to 200 real samples for each category and annotate the expected outputs.
    3. Run the same set of samples on candidate models and quantized versions, comparing accuracy, format compliance rate, and latency.
    4. Re-run regression tests every time you change the model, quantization scheme, or inference engine version.

    During selection, you can also compare the dense 31B model with a similar-tier MoE model. An MoE model has a larger total parameter count and typically requires more VRAM, but the computation per token is lower. Deploying and fine-tuning a dense 31B model is simpler, and its latency is easier to predict. Which approach is more suitable depends on your concurrency requirements, VRAM budget, and fine-tuning plans.

    6. Deployment Steps: From Environment to Service

    The following workflow is based on vLLM. The inference engine version, CUDA version, and model path should be replaced with the values you have verified on your test machine.

    1. # 1. Create an isolated Python environment and pin the inference engine version
    2. python -m venv .venv
    3. source .venv/bin/activate
    4. pip install "vllm==<your_verified_version>"
    5. # 2. Set the model path (can be a local directory or a model identifier from a hosting platform)
    6. export MODEL_PATH="/path/to/model"
    7. # 3. Start the service: single-GPU deployment, 32768 context limit, 0.90 GPU memory utilization
    8. # Do not add comments after the line continuation character "\"
    9. vllm serve "$MODEL_PATH" \
    10. --tensor-parallel-size 1 \
    11. --max-model-len 32768 \
    12. --gpu-memory-utilization 0.90 \
    13. --port 8000

    If using pre-quantized weights like AWQ, you need to add the --quantization parameter to the command, matching the weight format.

    After the service starts, confirm the model is loaded before sending a test request:

    1. curl http://localhost:8000/v1/models

    Common startup issues and troubleshooting steps are as follows:

    1. Out of Memory (OOM): First, lower --max-model-len, then reduce the number of concurrent requests, and finally consider a quantized version.
    2. Insufficient KV Cache capacity: vLLM startup logs will display the number of available cache blocks. If the capacity is clearly smaller than what the business requires, it means the context limit or concurrency target is set too high.
    3. Missing quantization operators: Check if the inference engine version, CUDA version, and driver version match, and confirm that you have installed a version that supports the quantization format.
    4. Model loading failure: Check the model path, file integrity, and whether the fields in the configuration file are compatible with the inference engine version.

    7. Licensing and Compliance

    The license determines whether you can use the model in commercial products, and whether you can modify and redistribute it. Many open-source models use permissive licenses like Apache 2.0 or MIT, but specific models may attach additional usage terms, such as user scale limits or prohibited use cases.

    Please refer to the license name and full text stated on the model card, and save the license file in your project repository. If you are unsure about the license terms, you should consult legal counsel before deciding to go live.

    8. Pre-Launch Checklist

    1. Model name, version, and license have been recorded in the deployment documentation.
    2. VRAM budget is determined based on measured results with sufficient buffer.
    3. Context limit and maximum concurrency have been verified through stress testing.
    4. The quantized version has been evaluated with business samples, and the quality degradation is acceptable.
    5. Inference engine version, CUDA version, and model files are pinned, with a rollback plan in place.
    6. A business evaluation set has been established, and regression tests are run after every change.
    7. Sensitive data in inputs and outputs has been handled in accordance with compliance requirements.

    9. Conclusion

    A 31-billion parameter dense model is suitable for teams looking to achieve strong capabilities on a single GPU while retaining the flexibility for private deployment and fine-tuning. During deployment, the factors that truly determine success are the VRAM budget, context limit, quantization quality, and business evaluation. Measuring these numbers clearly before deciding on the model scale and hardware configuration is more reliable than relying solely on raw parameter counts or public leaderboards.