Local Deployment of Large MoE Models: How to Calculate VRAM and Cost

    This article explains how to estimate VRAM and deployment cost for large MoE models. It covers why all expert weights must remain resident in memory, how quantization precision sets the lower bound, how to budget for KV cache and runtime workspace, why high-speed interconnect matters, and how to compare owned versus rented infrastructure.

    1. MoE VRAM Is Based on Total Parameters

    Many people see that “only a small fraction of parameters is activated per token” and assume the VRAM requirement is also low. That understanding is only half correct.

    A MoE (Mixture of Experts) model splits the feed-forward layers into many experts, and each token passes through only a few experts selected by routing. Take a model with 896 experts that activates 16 experts per token. The expert activation ratio is about 16/896 ≈ 1.79%. This ratio determines the amount of computation per inference, but it does not determine VRAM usage.

    During inference, the weights of all experts must remain resident in memory, because routing results are determined at runtime. The system cannot know in advance which experts the next token will invoke. Therefore, the lower bound of deployment VRAM is determined by the total parameter count and storage precision.

    Note that the expert activation ratio is not strictly equal to the parameter activation ratio. Embedding layers, normalization layers, attention modules, and other parts participate in computation for every token, and their parameter counts do not decrease because of routing. Therefore, “activation ratio” can only serve as a rough indicator for compute estimation.

    2. Quantization Precision Determines the VRAM Lower Bound

    The formula for weight memory is:

    Weight memory (GB) = Total parameters × Actual bits per parameter ÷ 8 ÷ 10⁹

    Here, “actual bits per parameter” is not necessarily an integer. Take a microscaling 4-bit floating-point format as an example. It groups every 32 4-bit elements and shares one 8-bit scale factor. On average, the actual bits per element are 4 + 8/32 = 4.25 bit. This extra overhead is easy to overlook, but it accumulates into a significant number on very large models.

    The following code quickly estimates weight memory at different precisions:

    1. def weight_memory_gb(total_params: float, bits_per_param: float,
    2. block_size: int | None = None, scale_bits: int = 8) -> float:
    3. """Estimate weight memory in GB (decimal)."""
    4. bits = bits_per_param
    5. if block_size: # For block quantization, each block stores an extra scale factor
    6. bits += scale_bits / block_size
    7. return total_params * bits / 8 / 1e9
    8. TOTAL = 2.8e12 # Total parameters: 2.8 trillion
    9. for name, bits, block in [
    10. ("BF16", 16, None),
    11. ("FP8", 8, None),
    12. ("4-bit integer quantization", 4, None),
    13. ("Microscaling 4-bit (block size 32)", 4, 32),
    14. ]:
    15. print(f"{name:24s} {weight_memory_gb(TOTAL, bits, block):>10.1f} GB")

    Based on the code above, the results are:

    Precision Bits per parameter Weight memory
    BF16 16 5600 GB
    FP8 8 2800 GB
    4-bit integer quantization 4 1400 GB
    Microscaling 4-bit (block size 32) 4.25 1487.5 GB

    This result is only the lower bound for the weights themselves. Actual deployment also requires the following:

    • Non-4-bit tensors: Embedding layers, output layers, normalization parameters, and similar components are usually kept at higher precision, so their memory usage will be higher than a pure 4-bit estimate.
    • Metadata and alignment: Memory alignment and format metadata introduce additional overhead.
    • KV cache: The longer the context and the higher the concurrency, the larger the KV cache usage.
    • Runtime workspace: Operator caches, communication buffers, and temporary tensors in the inference framework all require VRAM.

    3. How to Estimate a Complete VRAM Budget

    When planning hardware, it is recommended to use the following breakdown:

    Total VRAM requirement ≈ (Weights + KV cache + Activations and workspace) × (1 + Fragmentation and headroom ratio)

    The fragmentation and headroom ratio is typically 10% to 20%.

    The size of the KV cache depends on the model architecture and can generally be estimated with the following formula:

    KV cache (bytes) ≈ 2 × Layers × KV heads × Head dimension × Context length × Concurrent requests × Bytes per element

    The specific design of the attention architecture changes the parameters in this formula. If the model uses variants such as compressed KV or linear attention, actual usage may be significantly lower than the estimate for standard multi-head attention. The model’s official implementation and configuration files should be used as the reference.

    4. Same-Scale Reference: Practical Experience from a 670B-Class Model

    You can refer to a MoE model with about 671 billion parameters at a similar scale to calibrate expectations.

    • FP8 precision: The main parameters are about 671 GB. Adding the approximately 14B parameters of the multi-token prediction module brings the total to about 685 GB. This exceeds the 640 GB total VRAM of eight 80 GB accelerators, so it cannot be fully loaded.
    • 4-bit quantization: The weights are about 335 GB. After adding activations and workspace, the total requirement is about 400 GB. Eight 80 GB accelerators can accommodate it, but the remaining space for KV cache is very small, which limits concurrency and long contexts.

    This example shows that quantization precision is often the decisive factor in whether a model can run on a single machine. Once precision drops from FP8 to 4-bit, the number of required cards may be halved.

    5. Why Very Large MoE Models Need High-Speed Interconnect

    Having enough VRAM does not mean inference will run smoothly. A MoE model performs a “dispatch—compute—combine” communication step in every layer:

    1. The routing module selects several experts for each token.
    2. The system sends the token’s activation values to the accelerators where the experts reside.
    3. After the experts finish computation, the results are sent back to the original cards.

    When experts are distributed across a large number of accelerators, this all-to-all communication occurs frequently and involves large amounts of data. Cross-node network bandwidth is usually much lower than the high-speed interconnect within a single node, and communication latency can easily exceed computation time, becoming a throughput bottleneck.

    Therefore, in practice, such models often require 64 or more accelerators to form a high-speed interconnect domain, so that most communication stays within the same communication domain. If only multiple servers connected by ordinary Ethernet are available, inference speed often drops significantly, and trade-offs are needed by reducing the scale of expert parallelism, adjusting batching strategies, and similar measures.

    6. A Framework for Estimating Deployment Cost

    Cost can be divided into three parts: one-time hardware investment, ongoing operating expenses, and engineering labor.

    6.1 Hardware Investment

    Hardware investment = Number of accelerators × Unit price per card + Servers + High-speed interconnect network + Storage + Racks and supporting facilities

    Unit prices vary by supply channel, volume, and timing, so this article does not provide specific numbers. Before purchasing, use actual quotes and include network and storage as total amounts, rather than counting only the accelerators themselves.

    6.2 Operating Expenses

    Electricity is the main ongoing cost and can be estimated with the following formula:

    Annual electricity cost = System power (kW) × Annual operating hours × Electricity price per kWh × PUE

    PUE is the data center energy efficiency factor, reflecting the additional overhead of cooling and power delivery. Assuming 7×24 operation all year, annual operating hours are about 8760.

    The following code quickly compares owned and rented options:

    1. def yearly_cost_own(hw_capex: float, years: int, annual_opex: float) -> float:
    2. """Annualized cost of an owned deployment."""
    3. return hw_capex / years + annual_opex
    4. def yearly_cost_rent(hourly_price: float, gpu_count: int,
    5. utilization: float) -> float:
    6. """Annual cost of a rental option; utilization is the share of the year in use."""
    7. return hourly_price * gpu_count * 8760 * utilization
    8. # Example: replace parameters with actual quotes and estimates
    9. own = yearly_cost_own(hw_capex=0, years=3, annual_opex=0)
    10. rent = yearly_cost_rent(hourly_price=0, gpu_count=64, utilization=0.5)
    11. print(f"Owned annualized cost: {own}")
    12. print(f"Rental annual cost: {rent}")

    When business load fluctuates significantly and the peak differs clearly from the average, on-demand rental of elastic compute is often more cost-effective. If you are evaluating cloud options, you can assess GPU instances from providers such as Baidu AI Cloud, and verify billing methods, network specifications, and availability zones against official documentation.

    6.3 Hidden Costs

    • Engineering effort: Inference framework adaptation, quantization calibration, and performance tuning all require specialized personnel and may take weeks.
    • Operations cost: Troubleshooting, driver upgrades, and cooling monitoring require ongoing investment.
    • Opportunity cost: Business delays during the deployment period should also be included in the total cost.

    7. Pre-Deployment Checklist

    1. Confirm the model’s total parameter count, number of experts, number of experts activated per token, and whether there are additional modules such as multi-token prediction.
    2. Determine the target precision and check the block size and scale-factor overhead of the quantization format.
    3. Estimate KV cache based on the target context length and concurrency, and reserve 10% to 20% headroom.
    4. Evaluate single-node loading capacity. If it exceeds a single node, confirm the scale of the high-speed interconnect domain.
    5. Test all-to-all communication bandwidth and latency on the real network, rather than looking only at theoretical peak values.
    6. Compare the full lifecycle cost of owned versus rented infrastructure and make a decision based on the business load curve.

    8. Optimization Directions

    Once hardware is fixed, you can reduce cost or improve throughput in the following ways:

    • Quantization calibration: Use representative data for calibration to reduce bit width while maintaining accuracy as much as possible.
    • Expert parallelism strategy: Divide the distribution of experts across cards reasonably to reduce cross-node communication.
    • Batching and scheduling: Combine requests and use dynamic batching to improve accelerator utilization.
    • KV cache management: Use paged management and cache reuse to reduce fragmentation and repeated computation.

    In summary, the cost of local large model deployment is mainly determined by total parameter count, storage precision, and communication topology. First use formulas to calculate the VRAM lower bound, then evaluate communication and operating costs, and finally choose between owned and rented infrastructure. This makes the decision basis more reliable.