LLM Deployment GPU Memory Planning: Weight and KV Cache Estimation

    This article explains how to plan GPU memory for large language model deployment. It covers why parameter count alone cannot determine GPU requirements, how to estimate weight footprint across precisions, per-GPU load after tensor parallelism, KV cache sizing for long contexts, activation and runtime overhead, hardware comparison beyond memory capacity, and a practical capacity-planning workflow with code examples.

    1. Why Parameter Count Does Not Translate Directly to GPU Count

    A common mistake in hardware selection is to estimate the number of GPUs directly from model parameter count, or to judge whether a model can run based only on the memory capacity of an accelerator card. Both approaches are error-prone.

    Memory usage in model deployment has at least three components: model weights, the KV cache used during inference, and activations, communication buffers, and framework runtime overhead. These components scale with different factors, so they need to be estimated separately.

    Consider a sparse model with about 744B total parameters that activates about 40B parameters per forward pass. The activated parameters determine the amount of computation per pass and directly affect latency and throughput. The total parameters determine how much storage the weights require. During deployment, all weights must be loaded into memory or distributed across multiple cards, because the router may select any expert during inference. Therefore, storage planning should be based on total parameters, while compute planning should be based on activated parameters.

    2. Calculating Weight Footprint

    Weight footprint can be estimated with a simple formula:

    Weight footprint (GB) ≈ Parameters (billions) × Bytes per parameter

    Different numeric precisions use different byte counts. FP16 and BF16 use 2 bytes per parameter, FP8 and INT8 use 1 byte per parameter, and INT4 uses about 0.5 bytes per parameter. For a model with 744B total parameters, FP8 weights are about 744GB; with BF16, they are about 1,488GB. The choice of precision directly changes the GPU count requirement.

    Note that this is a theoretical lower bound. In actual deployment, some layers such as embeddings and output layers may remain at higher precision, and quantization schemes may introduce additional scaling parameters. Actual usage is therefore usually slightly higher than the estimate.

    3. Per-GPU Load After Tensor Parallelism

    Tensor parallelism splits the weight matrices of a layer across multiple cards. Each card stores only a portion of the weights and combines results through inter-card communication during computation. Assuming 8-way tensor parallelism, 744GB of FP8 weights average about 93GB per card.

    On this basis, you can calculate the remaining space per card:

    • Accelerator card with 141GB memory: 141 − 93 ≈ 48GB remaining
    • Accelerator card with 180GB memory: 180 − 93 ≈ 87GB remaining

    The remaining space must hold the KV cache, activations, communication buffers, and framework overhead at the same time. Actual usable space also depends on the memory utilization limit configured by the framework, and a safety margin is usually reserved. Therefore, “the weights fit” is only a necessary condition, not a sufficient one.

    4. KV Cache: The Main Increment for Long Contexts

    The KV cache stores the Key and Value vectors for each generated token for subsequent attention computation. The longer the context and the more concurrent requests, the larger the KV cache footprint. The estimation formula is as follows:

    1. def estimate_kv_cache_gb(layers, kv_heads, head_dim, seq_len, batch,
    2. bytes_per_elem=2):
    3. """Estimate KV cache footprint in GB.
    4. The factor 2 accounts for one copy each of Key and Value.
    5. """
    6. total_bytes = (2 * layers * kv_heads * head_dim
    7. * seq_len * batch * bytes_per_elem)
    8. return total_bytes / 1e9

    The number of layers, number of KV heads, and head dimension come from the model architecture configuration, and they vary widely across architectures. Attention designs such as grouped-query attention and compressed KV representations can significantly reduce the per-token cache cost, so the same context length may require several times more or less memory on different models.

    For very long contexts, such as millions of tokens, a single request’s KV cache may fill the remaining memory even if the weights fit. Options in this case include increasing per-card memory, adding more cards to reduce the per-card burden, limiting the maximum context length, lowering KV cache precision, or reducing the number of concurrent requests served. Each option affects cost and quality of service and needs to be balanced against the business scenario.

    5. Activations and Runtime Overhead

    In addition to weights and KV cache, inference also requires activations, intermediate computation results, communication buffers, and the framework’s own memory pools. This overhead depends on batch size, sequence length, and operator implementation, and it is difficult to estimate precisely.

    A common engineering practice is to first calculate theoretical values for weights and KV cache, then reserve 15% to 25% for activations and runtime overhead, and finally validate peak memory with real-load stress testing. If memory runs out or swapping occurs frequently during stress testing, adjust the batch size, maximum sequence length, or parallelism strategy.

    6. Same Memory Capacity Does Not Mean Same Performance

    Two accelerator cards with the same 141GB memory capacity may perform very differently in deployment. Memory capacity only indicates how many weights can fit. Factors that determine actual throughput also include:

    1. Peak compute capability: Compute metrics differ greatly across precisions such as FP8 and BF16. Confirm the actual value for the target precision.
    2. Memory bandwidth: The decoding phase is limited by the speed of reading weights and KV cache, and bandwidth is often the throughput bottleneck.
    3. Inter-card interconnect bandwidth: Tensor parallelism and expert parallelism both depend on inter-card communication, and communication overhead is significant in multi-card scenarios.
    4. Power and cooling: Power consumption under sustained high load affects data center planning and long-term operating costs.
    5. Software stack support: The degree to which drivers, compilers, and inference frameworks optimize for the hardware directly affects measured performance.

    Therefore, hardware comparisons should use real tests with the same model, precision, context length, and load pattern. Record time to first token, tokens generated per second, peak memory, and power consumption rather than comparing specification sheets only.

    7. Capacity Planning Workflow

    The following workflow is recommended for pre-deployment capacity evaluation:

    1. Determine precision and model architecture: Specify weight precision and read the number of layers, number of KV heads, and head dimension from the configuration.
    2. Calculate weight footprint: Multiply parameter count by bytes per parameter to get total weight volume.
    3. Choose a parallelism strategy: Calculate the weight shard size per card based on per-card memory and the target number of cards.
    4. Estimate KV cache: Plug the target maximum context and maximum concurrency into the formula.
    5. Reserve runtime margin: After deducting activations and framework overhead, check whether the remaining space meets requirements.
    6. Validate with stress testing: Measure peak memory, latency, and throughput with a real request distribution, and return to step 3 to adjust based on the results.

    Below is an illustrative check function for quickly judging whether a per-card configuration meets requirements:

    1. def check_fit(total_weight_gb, num_cards, card_mem_gb,
    2. kv_cache_gb_per_card, reserve_ratio=0.2):
    3. weight_per_card = total_weight_gb / num_cards
    4. usable = card_mem_gb * (1 - reserve_ratio)
    5. free = usable - weight_per_card - kv_cache_gb_per_card
    6. return {
    7. "weight_per_card_gb": round(weight_per_card, 1),
    8. "free_per_card_gb": round(free, 1),
    9. "fits": free > 0,
    10. }
    11. print(check_fit(744, 8, 141, kv_cache_gb_per_card=20))

    This function is only an estimation tool, and the results should be validated with stress-test data. Partitioning is not perfectly even, and some components may not be splittable, so actual usage should leave a margin.

    8. Common Misconceptions

    • Misconception 1: GPU count equals parameter count divided by per-card capacity. This ignores the effects of precision, KV cache, activations, and parallel partitioning.
    • Misconception 2: Small activated parameter count means small hardware requirements. Activated parameters affect only computation volume; storage still needs to hold all expert weights.
    • Misconception 3: Enough memory means production requirements are met. Memory is only an admission condition. Throughput and latency also depend on bandwidth, interconnect, and software optimization.
    • Misconception 4: Specification-sheet data directly represents business performance. Specifications describe theoretical upper limits, while actual performance depends on the load pattern.

    9. Conclusion

    The core issue in large model deployment is the memory budget. Weights, KV cache, and runtime overhead together determine whether the system can go live, while compute capability, bandwidth, and interconnect determine how fast it can run after launch. Planning should start with formula-based theoretical estimates and then use real-load stress testing to correct the results. This is how the resulting GPU count and configuration can balance cost, stability, and quality of service.