Understanding Mixture of Experts (MoE) Models: How to Calculate Compute, Memory, and Cost

    Mixture of Experts (MoE) architectures let large language models hold massive total parameters while activating only a fraction per token. This article explains how MoE works, how to estimate training FLOPs, GPU-hours, and cost, the engineering challenges in training and inference—load balancing, expert parallelism, precision, and long context—and provides practical criteria for choosing between MoE and dense models for deployment.

    1. Why the MoE Architecture Matters

    The capabilities of large language models generally grow with parameter count and training data volume, but more parameters also mean higher compute costs for training and inference. A dense model activates all of its parameters in every forward pass, so its compute cost scales roughly linearly with parameter count. Mixture of Experts (MoE) offers an alternative path: the model has a very large total parameter count, but each input token is processed by only a small fraction of those parameters.

    This design allows teams to approach the knowledge capacity of a large dense model within an acceptable compute budget. The key to understanding it is distinguishing between two parameter counts. Total parameters determine how much knowledge the model can store; activated parameters determine the cost of a single computation. Conflating the two is the most common mistake when evaluating cost.

    2. How MoE Works

    A typical MoE layer consists of two parts.

    1. Expert networks (Experts): multiple parallel feed-forward subnetworks with identical structure but independent parameters.
    2. Router (Gating): computes a weight for each expert per token and selects the top-k highest-scoring experts to participate in the computation.

    Routers typically use a top-k strategy. A smaller k reduces per-token computation but also limits the model’s expressive flexibility. Here is a simplified illustration of routing:

    1. import torch
    2. import torch.nn.functional as F
    3. def topk_route(hidden, gate_weight, k=2):
    4. # hidden: [num_tokens, d_model]
    5. # gate_weight: [d_model, num_experts]
    6. logits = hidden @ gate_weight
    7. probs = F.softmax(logits, dim=-1)
    8. topk_p, topk_idx = probs.topk(k, dim=-1)
    9. # Renormalize the selected expert weights so they sum to 1
    10. topk_p = topk_p / topk_p.sum(dim=-1, keepdim=True)
    11. return topk_idx, topk_p

    This code omits distributed communication, capacity limits, and the load-balancing loss, showing only the basic routing logic. In real systems, those omitted parts determine training stability and throughput.

    3. What Total Parameters and Activated Parameters Each Determine

    Take an MoE model with roughly 671 billion total parameters and about 37 billion activated per token. The activation ratio is about 5.5%, meaning a single forward pass uses only around one-twentieth of the total parameters.

    Training compute can be roughly estimated with a rule-of-thumb formula:

    Training FLOPs ≈ 6 × activated parameters × training tokens

    Plugging in 37 billion activated parameters and 14.8 trillion training tokens gives 6 × 3.7×10^10 × 1.48×10^13 ≈ 3.29×10^24 FLOPs. This is an order-of-magnitude estimate that provides only a lower bound on compute. It excludes routing computation, All-to-All communication, activation recomputation, optimizer updates, and losses from suboptimal accelerator utilization. Actual training cost adds these overheads on top.

    Still, this formula makes one direction clear: training compute is driven primarily by activated parameters, not total parameters.

    Total parameters still affect memory usage. At inference time, even though only a subset of experts is activated per step, all expert parameters must reside in GPU memory or in quickly accessible storage. Therefore, MoE models are cheaper in compute but not necessarily cheaper in memory and bandwidth. This matters greatly when planning hardware.

    4. Estimating Training Resources and Cost

    Training resources are typically measured in GPU-hours. Using publicly disclosed figures as an example:

    • Training used 2,048 accelerators of the same specification;
    • Total consumption was about 2.788 million GPU-hours, of which pretraining accounted for roughly 2.664 million GPU-hours;
    • Averaged per card, that is about 1,361 hours, or roughly 56.7 days of continuous operation.

    Dividing cost by GPU-hours reveals the implied unit price. $5.576 million divided by 2.788 million GPU-hours is about $2 per GPU-hour. This figure can serve as a reference baseline for estimating other scenarios.

    1. gpu_hours = 2_788_000
    2. num_gpus = 2048
    3. total_cost_usd = 5_576_000
    4. hours_per_gpu = gpu_hours / num_gpus # ~1361 hours
    5. days_per_gpu = hours_per_gpu / 24 # ~56.7 days
    6. implied_rate = total_cost_usd / gpu_hours # ~2 USD/GPU-hour
    7. print(f"{hours_per_gpu:.0f} h, {days_per_gpu:.1f} d, {implied_rate:.2f} USD/GPU-h")

    When using publicly reported cost figures, keep the following in mind:

    1. Reported costs usually cover only the final training run and may not include earlier experiments, ablation studies, data cleaning, or personnel.
    2. GPU unit prices vary widely with procurement method, discounts, power, and facility conditions, so they cannot be applied directly to your own cluster.
    3. Within the total GPU-hours, the portion outside pretraining (about 124,000 GPU-hours) is not broken down in public information and should be noted separately in estimates.

    When estimating your own training budget, use this checklist to confirm which costs have been included:

    • Small-scale experiments and hyperparameter search;
    • Ablation studies and failed training runs;
    • Data collection, cleaning, and deduplication;
    • Engineering and research labor;
    • Power, facilities, networking, and cooling;
    • Reruns after interruptions and checkpoint storage.

    If even one item is missing, the final budget will be underestimated.

    5. Engineering Considerations in Training and Inference

    1. Load Balancing

    If the router always assigns tokens to a small set of experts, those experts become overloaded while others receive almost no training. Two common approaches are adding an auxiliary balancing term to the loss function, or setting a capacity limit per expert, with excess tokens dropped or rerouted according to a policy.

    Both parameters require careful tuning. If the auxiliary loss weight is too large, routing is forced toward uniformity, weakening expert specialization and hurting model quality. If it is too small, expert collapse can occur, where most tokens concentrate on a few experts. A capacity factor set too low drops many tokens; set too high, it increases memory usage and communication volume. When tuning, monitor both the expert load distribution and validation metrics.

    2. Expert Parallelism and Communication

    Different experts can be distributed across different devices. Tokens must be sent to their target experts via All-to-All communication, and results are aggregated back after computation. Communication volume grows with the top-k value and token count and often becomes the bottleneck. Reducing cross-node communication and overlapping communication with computation are the main levers for improving throughput.

    3. Precision and Memory

    Low-precision training (such as FP8 or BF16) reduces memory footprint and improves compute utilization. However, it requires loss scaling and keeping certain critical operators in higher precision to ensure numerical stability.

    4. Long Context

    Extending context length usually requires adjusting how positional encodings extrapolate, combined with more efficient attention implementations. The longer the context, the more memory the key-value cache (KV Cache) consumes. Inference services need to plan batching and caching strategies based on actual traffic, or memory will run out before compute does.

    6. Deployment and Selection Recommendations

    Whether to choose an MoE model or a dense model should be judged against your own conditions. The table below lists several key dimensions:

    Dimension When MoE fits better When a dense model fits better
    Workload High request volume with long average inputs/outputs; compute is the main cost Low request volume, or highly variable load that makes fixed costs hard to amortize
    Memory budget Cluster memory is sufficient to hold all expert parameters Limited memory cannot fit all experts
    Latency requirements Can tolerate extra latency from routing and cross-device communication Sensitive to time-to-first-token; needs stable responses
    Operational capability Team can manage distributed inference frameworks and failure recovery Team prefers to minimize infrastructure work
    Unit cost Measured cost per million tokens is lower Measured cost shows the dense model is cheaper

    Self-hosting versus using cloud services also needs comparison. Cloud deployments typically combine several general capabilities: GPU compute instances for inference and training, container orchestration platforms for scheduling and scaling, object storage for model files and checkpoints, and logging services with monitoring and alerting for observability. These capabilities are available on major cloud platforms. Selection should be based on measured throughput, latency, and unit cost rather than nominal specifications.

    The recommended evaluation order is: first confirm whether memory can hold all experts, then stress-test throughput and latency with real traffic, and finally compute unit cost.

    7. Frequently Asked Questions

    Is MoE always cheaper than a dense model?

    Not necessarily. MoE training usually requires less compute, but memory demands are higher, and routing and communication add overhead. If your cluster lacks sufficient memory or has weak communication bandwidth, actual costs may rise rather than fall. The deciding criterion is measured cost at equal quality, not parameter count.

    Are more total parameters always better?

    Not necessarily. Total parameters determine how much knowledge the model can store, but capability also depends on training data quality, post-training methods, and architecture design. Models with the same parameter count can perform very differently. Capabilities your use case does not need are wasted no matter how many parameters back them, while still increasing deployment cost.

    Can published training costs be used directly to estimate my own budget?

    Not directly. Public figures only indicate the magnitude of a single training run and typically exclude preliminary experiments, data work, and labor. Hardware unit prices and power conditions also vary by region and procurement method. List your cost items first, then fill in your own data for each.

    Which deserves more attention: training cost or inference cost?

    For services serving large numbers of users, inference cost usually matters more. Training is a one-time expense, while inference cost accumulates continuously with service scale and request volume, often dominating over the long term. Selection decisions should therefore focus on comparing per-unit inference cost.

    Understanding these principles and estimation methods gives you a verifiable basis for decisions in model selection, resource planning, and cost accounting.