31B Dense LLMs: Model Selection, KV Cache, and Deployment

    A practical engineering guide to selecting and deploying 31B-class dense open models, covering benchmark interpretation, long-context KV cache costs, 3-bit KV compression, single-GPU memory budgets, scheduling for long-context and high-concurrency serving, multimodal/document caveats, and a POC checklist.

    31B Dense LLMs: Model Selection, KV Cache, and Deployment

    1. How to choose: Why mid-sized dense models are back on the engineering radar

    Over the past two years, open-source large models have continued to diverge in both scale and architecture. At one end are trillion-parameter mixture-of-experts (MoE) models that trade sparse activation for larger capacity. At the other end are small-parameter models aimed at on-device and lightweight tasks. Between these extremes, dense models with 20B to 40B parameters are once again becoming a focus for engineering teams.

    The core advantage of mid-sized dense models is that activated parameters equal total parameters. This gives them a deterministic inference path and regular operator shapes, which generally improves compatibility with inference frameworks, quantization tools, and operator libraries. Compared with MoE models, they usually do not need to deal with expert-routing imbalance or within-batch activation fluctuation. Compared with small models, they still offer more headroom for capability.

    Take a 31B-class open dense model as an example: the series also offers a small-parameter version, a 26B-class MoE version, and a 31B-class dense version. The value of this stepped specification matrix is that small models cover edge and high-concurrency lightweight tasks, the MoE version pursues a capability ceiling at comparable active-parameter cost, and the dense version targets production environments that can be hosted on a single GPU while keeping precision controllable and migration cost low.

    From an engineering perspective, selection should not be based only on “which model is stronger.” It should also consider whether the business can accept the deployment cost, latency, and operational complexity. The value of mid-sized dense models lies in providing a predictable middle ground among capability, cost, and determinism.

    2. Capability profile: How to read benchmark scores without being misled

    The following scores are illustrative and are only meant to explain evaluation dimensions. For a formal selection process, use the official model card, evaluation date, leaderboard name, and your own business evaluations.

    Evaluation dimension Illustrative score Conclusion that cannot be drawn
    Broad academic understanding, MMLU Pro-style About 85% Does not mean all business-knowledge questions will be reliable
    Graduate-level scientific reasoning, GPQA-style About 84% Does not mean complex experimental scenarios can be used directly
    Math competition questions, MATH-style About 89% Does not mean cross-file code or long-dependency tasks are equally strong
    Real-time code generation, HumanEval-style About 80% Does not mean complex engineering code will pass on the first attempt
    Equivalent online programming-contest rating About 2150 Does not equal business-code success rate
    Multimodal academic understanding, MMMU-style About 77% Does not mean chart, receipt, or layout understanding is error-free

    Public benchmarks can only serve as an initial screening signal; they cannot replace business evaluations. There are three reasons.

    First, benchmark contamination risk. Public leaderboard questions can enter pre-training corpora, so a high score may not reflect true capability.

    Second, capability dimensions are discontinuous. Math competition questions are often single-turn, verifiable, and deterministic; business code often spans files, has long dependencies, and includes implicit conventions. The two cannot be simply used to infer each other.

    Third, leaderboards change quickly. In August 2026, another 30B-class open model had already surpassed some models on certain benchmarks. The competitive landscape in this range may reshuffle every few months, and any “strongest model” conclusion has a short half-life.

    Therefore, the recommended approach is to use public benchmarks as exclusion criteria and self-built business evaluations as ranking criteria. Only task success rate, tail latency, and cost performance on real business samples should be the final basis for selection.

    3. How to calculate long-context cost: KV cache, 3-bit compression, and the boundary of acceleration

    The real bottleneck for long context is often not compute, but the KV cache. During autoregressive decoding, every generated token needs to read the historical KV cache, which significantly increases memory-bandwidth pressure.

    The KV cache size can be approximated as:

    1. KV_bytes ≈ 2 × L_layers × H_kv × D_head × S_seq × B × kv_bits / 8

    Here, 2 represents K and V, L_layers is the number of layers, H_kv is the number of KV heads, D_head is the dimension per head, S_seq is the sequence length, B is the batch size, and kv_bits is the cache bit width.

    Increasing context from 4K to 256K theoretically increases cache usage by 64x. Without compression, long contexts will quickly exhaust GPU memory and can turn the decoding phase into a memory-bandwidth-bound task.

    Engineering implications of 3-bit KV compression

    A 31B-class model adopts a 3-bit KV compression approach. The key point is not simply compressing the cache from 16 bits to 3 bits; it is balancing precision, operator implementation, and scheduling efficiency.

    Three points need attention.

    First, 3 bits is not a power-of-two bit width, so it cannot be directly mapped using standard INT8 or INT4 operators. Engineering implementations usually need bit packing, bit unpacking, group-wise scale factors, and related mechanisms.

    Second, group-wise quantization is key to error control. A common approach is to divide every several elements into a group, share a scale factor, and add a zero point when necessary.

    A simplified bit-packing illustration:

    1. def pack_int3_group(x, group_size=16):
    2. groups = split_into_groups(x, group_size)
    3. packed = []
    4. for g in groups:
    5. scale = compute_scale(g) # Shared scale factor per group
    6. codes = quantize_to_3bit(g / scale)
    7. packed.append((scale, codes))
    8. return packed

    Third, the benefit of compression is not only saving memory. Once K and V enter compute units at a lower bit width, effective bandwidth pressure drops, which may push decoding that was originally memory-bound toward higher compute utilization.

    For the claim of “about 8x attention acceleration,” the condition should be stated explicitly: that number usually depends on a specific test environment, such as an 80GB-class mainstream GPU, long-context single-request or small-batch decoding, sequence length above 32K, a fixed inference-framework version, and a measurement scope that includes unpacking and scheduling overhead. If batch size increases, prefill ratio rises, operators are not fused, or the framework version differs, actual gains can change significantly. Therefore, 8x should be treated as a reference value under specific conditions, not a universal performance guarantee.

    4. Single-GPU memory budget: How to fit a 31B model on an 80GB card

    If a 31B-parameter model is stored in bfloat16, the weights alone require about 62GB, not counting activations, CUDA context, framework runtime, and KV cache overhead. Loading all bfloat16 weights directly while retaining long context or high concurrency will make a single 80GB GPU very tight.

    There are usually three feasible routes.

    First, keep bfloat16 weights but reduce context length or batch size while enabling KV compression.

    Second, quantize weights offline to INT8 or FP8, compressing weights to about 31GB and leaving more memory for KV cache and concurrent requests.

    Third, use a full-speed FP8 weight path when both the inference framework and hardware support it. FP8 inference is not a universal capability; it depends on the framework, operators, GPU architecture, batch size, and specific computation graph. Before load testing, it should not be treated as a general performance guarantee.

    Below is a reusable memory-budget script. It estimates in decimal GB, making it easier to align with common GPU nominal capacities.

    1. def budget(params_b=31, bytes_w=2, layers=48, kv_heads=8,
    2. head_dim=128, ctx=32768, batch=8, kv_bits=3, card_gb=80):
    3. weights_gb = params_b * 1e9 * bytes_w / 1e9
    4. kv_gb = (2 * layers * kv_heads * head_dim * ctx * batch * kv_bits / 8) / 1e9
    5. runtime_gb = 6.0 # Empirical reserve for framework, context, activations, and fragmentation
    6. total_gb = weights_gb + kv_gb + runtime_gb
    7. return {
    8. "weights_gb": round(weights_gb, 1),
    9. "kv_gb": round(kv_gb, 1),
    10. "runtime_gb": round(runtime_gb, 1),
    11. "total_gb": round(total_gb, 1),
    12. "margin_gb": round(card_gb - total_gb, 1),
    13. "fits_80gb": total_gb < card_gb - 2
    14. }
    15. print(budget())
    16. # 3-bit: KV cache about 9.7GB, total about 77.7GB, margin about 2.3GB
    17. print(budget(kv_bits=16))
    18. # Uncompressed: KV cache about 51.5GB, total about 119.5GB, does not fit on one GPU

    The value of this script is that it turns “can it run on a single GPU?” from an experience-based judgment into an auditable capacity plan. Changing any of ctx, batch, kv_bits, or bytes_w immediately shows where the boundary is.

    The conclusion is that an 80GB single GPU can run bfloat16 weights, but context length and concurrency must be controlled. To carry 256K context and high concurrency at the same time, KV compression, weight quantization, or both are usually required.

    5. High concurrency and long context: Treat the two cost centers separately

    Long context and high concurrency are two different cost centers and should not be handled with the same strategy.

    Technique Main problem solved Cost or risk Suitable scenario
    Chunked prefill Reduces blocking of short requests by long prefill Requires scheduler support; may increase scheduling complexity Online serving with mixed short and long requests
    Prefix cache reuse Skips repeated computation for system prompts, long documents, and codebase indexes Requires cache-hit management and invalidation policy Fixed prompts, long-document QA, codebase understanding
    KV paging Reduces KV cache fragmentation Requires inference-framework support Multiple requests and context lengths
    Continuous batching Improves overall throughput Memory usage fluctuates with the longest sequence in the batch High-concurrency online serving

    The cost of long context mainly comes from attention complexity and cache capacity. Prefill attention computation is often approximately O(S²), and 256K-level prefill can lead to second-level time-to-first-token latency. Chunked prefill can be used to slice long prefill and schedule it together with decoding requests, avoiding starvation of short requests by long ones.

    The cost of high concurrency mainly comes from scheduling and memory contention. Continuous batching allows requests to enter and leave batches at the token level, improving throughput, but memory usage fluctuates with the longest sequence in the batch. Production systems usually need request queuing, maximum sequence-length limits, and independent rate limiting for long-context requests.

    A simplified scheduler idea:

    1. class Scheduler:
    2. LONG_CTX_THRESHOLD = 64 * 1024
    3. def schedule(self, ready_queue, running_batch, mem_budget):
    4. short, long = [], []
    5. for req in ready_queue:
    6. if req.prompt_len > self.LONG_CTX_THRESHOLD:
    7. long.append(req)
    8. else:
    9. short.append(req)
    10. picked = []
    11. used = self.estimate_mem(running_batch)
    12. for req in short + long[: self.long_concurrency]:
    13. need = self.estimate_mem([req])
    14. if used + need > mem_budget:
    15. break
    16. used += need
    17. picked.append(req)
    18. for req in picked:
    19. req.chunk = min(req.remaining, self.prefill_chunk_size)
    20. return running_batch.merge(picked)

    The key point is not any single pseudocode snippet, but isolating long-context requests from ordinary short requests so that a single 256K request does not drag down the online SLA.

    6. Multimodal and document understanding: What to watch for with native input

    The model natively accepts image and video input and has OCR and chart-analysis capabilities. “Native multimodal” means visual input enters the model directly rather than first going through an external OCR service and then passing text to a language model.

    The advantage of native multimodal is that layout structure, coordinates, and visual relationships are preserved. For tasks such as table understanding, flowchart reasoning, and chart reading, the error-propagation chain is shorter.

    However, production deployment needs to pay attention to three points.

    First, visual tokens can significantly amplify prefill overhead. A high-resolution chart may be equivalent to thousands of text tokens, so context budget must be reserved in advance.

    Second, video-input cost rises with duration and sampling frame rate. Production environments should default to frame extraction, keyframe filtering, or segment-based processing rather than full-frame input.

    Third, OCR-style tasks still need deterministic validation. For fields such as amounts, IDs, dates, and contract terms, rule-based checks, field-level comparison, and secondary confirmation are recommended; outputs should not rely solely on a single model response.

    7. Deployment checklist: How to test, estimate cost, and stay compliant

    Model weights can usually be obtained through official code repositories, model hubs, cloud inference services, open-source model communities, and local inference runtimes. At the hardware level, mainstream GPUs and cloud tensor processing units can run the model, but specific performance depends on operator compatibility and framework version.

    In practice, common cloud building blocks—GPU instances, object storage, logging, monitoring and alerting, and container orchestration—can support model hosting, weight storage, autoscaling, and staged rollout.

    For a POC phase, follow this checklist:

    1. Capability-ranking evaluation: Build 200 to 500 real business samples, covering boundary and adversarial cases. Run blind evaluations on 2 to 3 candidate models and focus on task success rate rather than average score.

    2. Long-context evaluation: Test 32K, 64K, and 128K contexts separately and observe the inflection point of capability degradation. Tasks can include needle-in-a-haystack, cross-document multi-hop QA, and long-codebase localization.

    3. Throughput and cost stress testing: Fix an SLA, for example P99 time-to-first-token below 1.5 seconds and decoding speed above 30 tokens/s, then stress-test single-GPU QPS at different concurrency levels and convert the result into cost per million tokens rather than looking only at list price.

    4. Memory planning: Use the budget script to confirm feasible combinations of weight precision, context length, batch size, and KV bit width, and reserve at least 20% headroom for peak load.

    5. Quantization regression: If FP8, INT8, or KV compression is enabled, it must be compared against a bfloat16 baseline to confirm that aggregate metrics and business success rates remain within an acceptable range.

    6. RAG threshold judgment: When the knowledge base far exceeds the model’s reliable context, content updates frequently, citation/source tracing is required, or long-context cost is clearly higher than a retrieval solution, RAG should be prioritized. The evaluation method is to compare long-context direct reading against retrieval-augmented short context on the same QA set for accuracy, latency, and cost.

    7. Compliance and licensing: Check commercial terms, attribution requirements, and usage policies of the open-source license, and clarify the responsibility boundary for output content.

    8. Common pitfalls

    • Treating more parameters as necessarily stronger capability: At the same parameter scale, data quality, post-training strategy, and inference-time enhancement may affect business results more than parameter differences.

    • Looking only at peak throughput while ignoring tail latency: Long-context requests are a major source of tail latency, so queue isolation and rate limiting are required.

    • Ignoring inference-runtime version differences: The same weights can show significantly different throughput under different frameworks and quantization formats. POC work must fix versions and record them.

    • Assuming long context can replace retrieval: The longer the context, the higher the risk that key information is diluted. For massive knowledge-base scenarios, RAG is usually still a more controllable cost-and-effect balance.

    • Treating vendor speedup figures as universal conclusions: KV compression, FP8 inference, and attention acceleration all depend heavily on hardware, framework, batch size, and sequence length. They must be validated with self-built load tests.

    Conclusion

    The engineering value of 31B-class dense open models is not a single benchmark score, but the fact that they compress the capability ceiling, single-GPU capacity, and deployment determinism into a predictable balance point. 3-bit KV compression alleviates the memory-access wall in long-context scenarios, while weight and cache quantization alleviate the single-GPU capacity wall. What ultimately determines launch success is whether the team has built three engineering guardrails: self-built evaluations, memory budgeting, and quantization regression. Models will continue to be surpassed, but this methodology remains reusable.