How to Select, Deploy, and Fine-Tune a 31B Dense Open-Source LLM

    This guide explains what a 31B dense large language model is, how to estimate GPU memory for different quantization levels, and how to start a local inference server with vLLM. It also covers fine-tuning strategies, cloud deployment considerations, and a pre-launch checklist, along with answers to common selection questions.

    What Is a Dense Model?

    A dense model activates all of its parameters on every forward pass. This is different from a Mixture-of-Experts (MoE) architecture, which only activates a subset of experts per pass — MoE models have high total parameter counts but lower per-inference compute. Both designs have trade-offs. For dense models, inference cost scales directly with parameter count, and the compute path is fixed, making output behavior more reproducible. This is useful for regression testing and capacity planning.

    A 31B model sits between small models like 7B or 13B and very large models with hundreds of billions of parameters. Compared to 13B-class models, a 31B dense model usually offers stronger performance on multi-step reasoning, code generation, and long-context understanding. Compared to extremely large models, it can run on a single multi-GPU server, which makes it a common starting point for private deployment.

    Memory Requirements and Quantization Choices

    GPU memory is consumed by three main components: model weights, KV cache, and runtime overhead. Weights can be estimated directly: multiply the parameter count by the number of bytes per parameter.

    • FP16/BF16: Each parameter uses 2 bytes, so weights require about 62 GB. An 80 GB-class professional GPU can hold the weights, but leaves little room for KV cache. In practice, dual-GPU or larger-memory setups are often used.
    • INT8: Each parameter uses about 1 byte, so weights require about 31 GB, fitting comfortably on a 40 GB-class GPU.
    • INT4: Each parameter uses about 0.5 bytes, so weights require about 16 GB. With KV cache and framework overhead, a 24 GB GPU can run the model, but context length must be limited.

    KV cache size grows linearly with both context length and the number of concurrent requests. In long-context scenarios, memory can be exhausted by KV cache even if the weights fit. Grouped-query attention (GQA) reduces this overhead by sharing a smaller number of key-value heads among multiple query heads.

    Quantization introduces accuracy loss. Before going live, evaluate the quantized model against your own test set. Pay special attention to code pass rate, formatting stability of structured output, and error rate on factual questions. Relying only on an overall average score can hide these issues.

    Local Startup Example

    Using the open-source inference engine vLLM, the following command starts a BF16-precision service on a single 80 GB GPU:

    1. vllm serve ./31b-dense-model \
    2. --dtype bfloat16 \
    3. --max-model-len 32768 \
    4. --gpu-memory-utilization 0.90 \
    5. --max-num-seqs 16 \
    6. --port 8000

    Parameter explanation:

    • --max-model-len: Limits the total length of a single request, directly affecting KV cache usage.
    • --gpu-memory-utilization: Sets the fraction of GPU memory vLLM may use, leaving 10% for other processes.
    • --max-num-seqs: Limits the number of concurrently processed requests.

    If using a 24 GB GPU, you need to obtain or generate AWQ-quantized weights first, then add the --quantization awq flag and gradually lower --max-model-len based on available memory.

    After startup, check the model name with curl http://127.0.0.1:8000/v1/models, then send a short request to verify output. The service exposes an OpenAI-compatible interface by default, so existing clients usually only need to change the endpoint URL.

    Fine-Tuning Approaches

    Full-parameter fine-tuning updates all parameters and requires storing optimizer states, making memory demands much higher than inference. It typically requires multi-GPU training with distributed strategies and is suitable for teams with large datasets and strict performance targets.

    LoRA freezes the original weights and trains only low-rank matrices. QLoRA additionally quantizes the base model to 4-bit. With shorter sequences and smaller batch sizes, QLoRA fine-tuning of a 31B model can often fit in around 24 GB of memory. Actual usage depends on sequence length, batch size, and gradient checkpointing settings, so run a small test sample first and record peak memory usage.

    Data quality matters more than quantity. A few thousand clean, uniformly formatted examples are often more effective than tens of thousands of noisy ones. Keep aside a validation set that does not participate in training, and after each epoch compare general capabilities to detect potential catastrophic forgetting.

    Cloud Deployment Path

    Without local compute, you can store weights in object storage and have a container platform launch the inference service. Keep the following in mind:

    • Choose GPU instances based on memory specifications, and verify that the driver and CUDA versions are compatible with the inference engine.
    • Configure health checks and automatic restarts so the inference process recovers quickly after an abnormal exit.
    • Monitor time-to-first-token, tokens generated per second, memory usage, and queue length.
    • Set elastic scaling rules. Loading 31B weights takes time, so trigger scaling before actual peak usage.

    Pre-Deployment Checklist

    Before going live, verify each item below:

    1. Memory degradation strategy: If memory runs out, take actions in order — shorten context, switch to INT8, move to a smaller model — and define trigger conditions in advance.
    2. Quantization validation: Confirm post-quantization performance with a business-specific evaluation set, not just public benchmarks.
    3. Rollback plan: Keep the previous version of weights and configuration. First roll out the new version to a small percentage of traffic, and switch back quickly if issues appear.
    4. Access control: Expose the inference port only to the internal network, manage API keys centrally, and sanitize request logs.

    Common Selection Questions

    How to choose between 31B, 32B, and 70B?
    Memory usage of 31B and 32B is similar; the difference lies mainly in training data and architecture details, so you should rely on your own evaluation set. 70B requires multiple GPUs or higher-end servers. Upgrade to 70B only if 31B results do not meet business requirements and budget permits.

    Can a 24 GB GPU run a 31B model?
    Yes. With INT4 quantization it can run, but context length and concurrency are limited, making it suitable for single-user or low-concurrency internal tools.

    What tasks are well-suited for 31B?
    Complex multi-step reasoning, code assistance, structured extraction from long documents, and agent tool calling. For simple classification or fixed-format extraction, a smaller model is more cost-effective.