320B Sparse MoE Model: VRAM Estimation and Agent Interface Considerations
This article explains how a 320B sparse Mixture-of-Experts (MoE) model actually behaves in production: why per-token compute is closer to an 18B dense model, how to estimate VRAM requirements across BF16, 8-bit, and 4-bit precision, and how KV Cache arithmetic scales when context extends to 1M tokens. You will learn how to calculate total memory from weights, KV Cache, activations, and communication buffers, and how many 80GB GPUs different configurations realistically require.
1. Activation Ratio and Compute
The key takeaway first: per-token compute is close to an 18B dense model, not 320B.
18 divided by 320 is roughly 5.6%. For each token, only the small number of experts selected by the gating network at each layer participate in the computation; the parameters of all other experts are not used. The gating network scores each token, typically selects the Top-k experts (k is usually a small integer between 1 and 8), and merges these experts’ outputs according to their weights.
By the standard rule of thumb, the floating-point operations for one forward pass are approximately 2 × activated parameters × number of tokens. With 18B activated parameters, each token requires about 36 GFLOPs, comparable to an 18B dense model. If a 320B model of the same total scale ran in dense mode, each token would require about 640 GFLOPs — roughly 17.8× more. Note that this comparison targets a dense 320B model. Compared with a dense 18B model, the MoE model is not faster; its advantage is greater parameter capacity within the same compute budget.
36 GFLOPs is theoretical compute, not end-to-end throughput. Actual throughput is limited by:
- The gating computation itself
- Token dispatch and combine between experts (all-to-all communication)
- Waiting caused by uneven token distribution across experts
- Attention computation and KV Cache reads/writes
In deployment, always rely on measured tokens/s.
Routing also introduces load imbalance. If the gate keeps assigning tokens to a few experts, the GPUs hosting those experts stay busy queuing while other devices idle. Three common countermeasures exist:
- Add an auxiliary load-balancing term to the training loss.
- Use noisy Top-k selection in gating scores, giving low-frequency experts a chance to be chosen.
- Set a capacity limit per expert, usually expressed as a capacity factor. For example, 1.25 means a single expert can receive at most 1.25× the average load; excess tokens are dropped or handed to other experts.
If the load-balancing coefficient is set too high, model quality suffers; if too low, expert collapse may occur, where most tokens concentrate on a very small number of experts.
2. VRAM Is the First Deployment Hurdle: How Much Does a 320B MoE Need?
MoE saves compute, but not weight storage. All weights must reside in VRAM, or be quickly swappable, because any token can be routed to any expert.
The following table estimates weight VRAM for 320B parameters, in decimal GB (1 GB = 10^9 bytes):
| Precision | Bytes per Parameter | Weight VRAM | Theoretical Minimum (80GB GPUs, weights only) | Recommended GPUs (80GB, leaving room for KV Cache and buffers) |
|---|---|---|---|---|
| BF16 | 2 | 640 GB | 8 GPUs, no headroom | 16 GPUs |
| 8-bit | 1 | 320 GB | 4 GPUs | 8 GPUs |
| 4-bit | 0.5 | 160 GB | 2 GPUs | 4 GPUs |
Quantization metadata such as scaling factors adds slight overhead not included in the table.
Estimate total VRAM by summing the following:
Total VRAM ≈ Weight VRAM + KV Cache for concurrent requests + Activations and temporary buffers + Communication buffers
Each term can be estimated as follows:
- Weights: Look up the value for your precision in the table above.
- KV Cache: Per-token size × context length × concurrency. Using the example configuration in Section 3 (60 layers, 8 KV heads, 128 dimensions, BF16), each token takes about 245.76 KB. At 8K context and 32 concurrent requests, that is roughly 64 GB. A single 128K request requires about 32 GB.
- Activations and temporary buffers: There is no exact formula. Start by reserving about 10% of the first two terms combined, then adjust based on measurements.
- Communication buffers: In expert parallelism, each layer performs one dispatch and one combine transfer. Each send is approximately batch tokens × Top-k × hidden dimension × bytes per element. Intra-node communication relies on NVLink; cross-node communication requires high-speed networks such as InfiniBand or RoCE. The hidden dimension must be obtained from the model card.
- GPU count and parallelism strategy: First determine how many GPUs are needed to fit the weights, then use KV Cache requirements to decide how many more to add, and finally choose a combination of expert parallelism and tensor parallelism.
Taking 8-bit quantization on 8 × 80GB GPUs (640 GB total) as an example: weights take 320 GB, buffers reserved at 10% take about 64 GB, leaving roughly 256 GB. At 245.76 KB per token, this space can hold roughly 1 million tokens of KV Cache in total, distributable across all concurrent requests.
3. 1M Context: KV Cache Arithmetic and Position Encoding Extrapolation
Extending context to 1M tokens raises two problems. First, attention compute grows quadratically with length. FlashAttention-family kernels speed this up through tiled computation and reduced memory reads/writes, but the compute remains quadratic. Second, KV Cache memory grows linearly with length, and it typically becomes the bottleneck sooner than the weights.
Here is an illustrative example. Assume the model has 60 layers, 8 KV heads, 128 dimensions per head, stored in BF16. Each token’s KV Cache size is 2 (K and V) × 60 layers × 8 heads × 128 dimensions × 2 bytes = 245,760 bytes, i.e., 240 KiB.
The size of 1M tokens depends on how you count:
- At 1,048,576 tokens (1Mi): about 257.7 GB, or 240 GiB.
- At 1,000,000 tokens: about 245.8 GB, or 229 GiB.
This article uses GB for decimal bytes and GiB for binary bytes. 1 GiB ≈ 1.074 GB.
Eight 80GB GPUs provide 640 GB total. At 1Mi tokens, a single request’s KV Cache takes about 40% of that, and weights still need space on top. With only 8 × 32GB GPUs (256 GB total), a single such request’s cache would already slightly exceed the total. Therefore, when citing numbers like these, always state the GPU type and precision, otherwise readers cannot verify them.
These figures depend on the model’s actual layer count, KV head count, and precision, and cannot be applied directly to any specific model.
Reducing KV Heads
The article above breaks off here, but the direction it points to is clear: reducing the number of KV heads (for example, through grouped-query attention or multi-head latent compression techniques) directly shrinks per-token KV Cache size and is one of the main levers for supporting very long contexts. When evaluating any large-context deployment, combine this with the VRAM estimation method in Section 2 and always validate with measured throughput and memory usage rather than theoretical numbers alone.
