How to Estimate GPU Memory for Deploying a MoE Model on 8 GPUs
Estimating whether an 8-GPU server can run a large MoE model requires evaluating three variables together: numerical precision, maximum context length, and concurrent requests. This article breaks down memory requirements for weights and KV Cache, provides estimation formulas and a Python screening script, and shows how different GPU memory configurations compare for a 600B-parameter MoE model.
1. Break the Problem Down First
“Can our existing 8-GPU server run a given large model?” is an incomplete question. A complete question must pin down three variables at once: numerical precision, maximum context length, and the number of concurrent requests. Any change in one of these significantly changes the memory requirement. Estimating each factor separately makes the conclusion much clearer.
2. Distinguish Active Parameters from Total Parameters
A MoE (Mixture of Experts) model activates only a subset of its expert networks during each inference step. Model descriptions typically list two numbers—“total parameters” and “active parameters”—and they mean different things:
- Active parameters determine the computation per token, affecting the compute cost and latency of a single request.
- Total parameters determine the storage footprint of the weights. Weights for all experts usually need to stay resident on the GPU node; if experts were swapped in on demand when routed, the latency would generally be unacceptable.
Sizing hardware based on active parameters alone therefore severely underestimates the requirement. Take a hypothetical model with 600B total parameters and 35B active parameters: its per-step compute is close to a 35B dense model, but its weights occupy the equivalent of 600B parameters.
3. Estimating Weight Memory
Weight memory ≈ parameter count × bytes per parameter
| Data format | Bits per parameter | Bytes per parameter | Weight footprint for a 600B model |
|---|---|---|---|
| BF16 | 16 | 2 | ~1,200 GB |
| FP8 / INT8 | 8 | 1 | ~600 GB |
| 4-bit quantization | 4 | 0.5 | ~300 GB, usually larger once quantization metadata is included |
Two caveats:
- The actual size of 4-bit quantized weights depends on group size, whether some layers retain higher precision, and other factors—use the actual weight file size as the ground truth.
- Keep units consistent. This article defines 1 GB as 10^9 bytes. Mixing GB and GiB introduces a discrepancy of roughly 7%.
4. Budgeting Memory Across Each GPU
Total memory of 8 GPUs equals single-GPU memory multiplied by 8. The usable portion is reduced by a reserve for activations, communication buffers, memory fragmentation, and framework overhead. Assume a usable ratio of 85%, i.e., a 15% reserve.
| Single-GPU memory | Total for 8 GPUs | Usable memory (85%) | Remaining for KV Cache after deducting 600 GB of FP8 weights |
|---|---|---|---|
| 80 GB | 640 GB | 544 GB | Insufficient—the weights don’t fit |
| 96 GB | 768 GB | 653 GB | ~53 GB |
| 141 GB | 1,128 GB | 959 GB | ~359 GB |
This shows that even with 8 GPUs, an 80 GB configuration cannot even hold the weights; a 96 GB configuration barely fits them but leaves little room for the context cache; only the 141 GB configuration offers a comfortable margin.
After the weights are sharded across 8 GPUs, the load per card is not perfectly even. Tensor parallelism sharding and the actual distribution of experts both introduce imbalance, so the headroom should be wider than the average suggests.
5. KV Cache: The Main Pressure from Context Length and Concurrency
The KV Cache stores attention intermediate results for every token during inference, and its size grows linearly with both context length and concurrency. For standard multi-head attention, the bytes per token can be estimated as:
Bytes per token = 2 × layers × KV heads × head dimension × bytes per element
The factor of 2 accounts for the K and V caches. Some models use compressed attention architectures with different formulas—always rely on the architecture parameters in the model’s configuration file.
As a hypothetical example: 60 layers, 8 KV heads, head dimension 128, BF16 (2 bytes per element). Then:
- ~240 KB per token.
- A single request with 128K context uses ~32 GB.
- 4 concurrent requests use ~128 GB.
These numbers show that long context and concurrency are the primary sources of memory pressure. Switching the KV Cache to FP8 halves the footprint, but you need to confirm that your inference framework supports it and assess the precision impact.
6. Quick Screening with a Script
The following script wraps the formulas above into functions, letting you quickly check whether a configuration is viable before purchasing or scaling out. It is for initial screening only and cannot replace real measurements.
def weight_gb(total_params_b: float, bits_per_param: float) -> float:"""Weight memory (GB, based on 10^9 bytes)."""return total_params_b * bits_per_param / 8def kv_cache_gb(layers: int, kv_heads: int, head_dim: int,bytes_per_elem: float, context_len: int,concurrency: int) -> float:"""KV Cache memory (GB), estimated for standard multi-head attention."""per_token = 2 * layers * kv_heads * head_dim * bytes_per_elemreturn per_token * context_len * concurrency / 1e9def check_fit(gpu_mem_gb: float, num_gpus: int,weight: float, kv: float, usable_ratio: float = 0.85) -> bool:"""Check whether weights plus KV Cache fit within usable memory."""usable = gpu_mem_gb * num_gpus * usable_rationeed = weight + kvprint(f"Usable {usable:.0f} GB, required {need:.0f} GB")return need <= usablew = weight_gb(600, 8) # FP8 weightskv = kv_cache_gb(layers=60, kv_heads=8, head_dim=128,bytes_per_elem=2, context_len=131072, concurrency=4)print(check_fit(96, 8, w, kv)) # 8x 96GB GPUs
Running the script shows that the 8× 96 GB configuration exceeds usable memory under “128K context, 4 concurrent requests, BF16 KV Cache.” Reducing concurrency to 1, or storing the KV Cache in FP8, changes the conclusion.
7. Trade-offs: Precision, Context, and Concurrency
Precision. FP8 is usually a common balance point between quality and memory. 4-bit quantization significantly reduces weight memory, but the quality loss must be evaluated on your target tasks—don’t judge by memory numbers alone.
Context. Long context is the main driver of KV Cache size. If most requests in your workload stay within 8K tokens, there is no need to size the entire cluster for the maximum context. You can route extra-long requests to a separate queue or apply dedicated rate-limiting policies.
Concurrency. Concurrency directly multiplies KV Cache usage. Validate with low concurrency and estimate production capacity separately—don’t extrapolate production capacity from validation results.
Parallelism. For a single 8-GPU node, tensor parallelism is the common approach. In MoE scenarios, it may be combined with expert parallelism. The right combination depends on your inference framework’s support and the actual communication overhead.
8. Verification Steps Before Going Live
- Load the model at the target precision, record the resident memory of each GPU after startup, and compare it against your estimates.
- Run single-request tests using the input length distribution of your real workload, and record the first-token latency and per-request memory usage.
