MoE Inference Cost: Why Activated Parameters Aren't the Whole Story

    Activating fewer parameters per token doesn't automatically mean lower inference costs. This article breaks down the full cost picture of Mixture of Experts (MoE) models across three dimensions: per-token compute, memory footprint of the KV cache, and token consumption at the task level, with practical formulas and evaluation guidance.

    Why Activated Parameters Alone Can Mislead Cost Estimates

    When evaluating large language models, many teams start by looking at how many parameters are activated per token. Fewer activated parameters usually means less compute per step and potentially faster inference. This reasoning holds in some scenarios, but it only describes per-step computation—it cannot answer the question “how much will it cost to complete a task?”

    The total cost of a task consists of at least three parts: compute cost per step, the memory and bandwidth consumed by context caching, and the actual number of input and output tokens consumed during the task. If any one of these dominates, the final conclusion changes. Two models whose activated parameter counts differ by 2x can end up with reversed total costs if the differences in cache size or token consumption are larger.

    So when comparing inference costs, it’s best to split the metrics into three layers: compute per token, memory footprint per unit of context, and total tokens per task. The following sections cover each in turn.

    The Cost Structure of MoE Architectures

    Mixture of Experts (MoE) models split the feed-forward network into multiple experts, and each token is routed to only a few of them. Two parameter metrics need to be distinguished:

    • Total parameters: determine the storage and loading memory footprint of model weights. All experts must remain resident.
    • Activated parameters: determine the parameters actually involved in computing each token, affecting compute requirements and per-step latency.

    This means memory pressure and compute pressure in MoE models come from different places. A model with a large total parameter count needs enough storage to hold all weights, even if its activation count is small. During deployment, if memory is insufficient, you can consider quantization, offloading to host memory, or tensor parallelism to distribute weights across multiple GPUs. Each approach introduces bandwidth or communication overhead, which is especially noticeable at small batch sizes.

    The routing mechanism also affects real throughput. Load imbalance across experts can leave some GPUs idle while others queue up. When benchmarking, observe the expert load distribution under real requests rather than relying on theoretical activation counts alone.

    KV Cache: The Hidden Cost of Long Contexts

    During autoregressive generation, the model caches the keys and values of historical tokens at every layer. This data is called the KV Cache. Its size grows linearly with context length, according to this formula:

    KV Cache bytes = 2 × layers × KV heads × head dimension × sequence length × bytes per element × batch size

    The factor of 2 reflects storing keys and values separately.

    Here’s an illustrative example. Suppose a model has 32 layers, 8 KV heads, a head dimension of 128, uses 16-bit floats, and processes a single sequence of 8,192 tokens. Plugging in the numbers:

    2 × 32 × 8 × 128 × 8192 × 2 = 1,073,741,824 bytes, roughly 1 GiB

    This figure is meant to illustrate the order of magnitude; actual values depend on the model’s architecture. It highlights a key fact: the KV cache grows with both sequence length and the number of concurrent requests. With long contexts plus high concurrency, the cache can easily become the dominant consumer of GPU memory.

    Common techniques for reducing KV Cache size include:

    1. Grouped-query attention, which lets multiple query heads share a smaller set of key-value heads.
    2. Sparse attention or sliding windows, where some layers retain only a limited range of historical cache.
    3. Cache quantization, storing keys and values at lower precision.
    4. Prefix caching, reusing computed results for identical system prompts or document prefixes.

    When a model uses sparse attention and only some layers need a full global cache, cache size grows more slowly with length. The difference becomes more pronounced at longer sequences. When evaluating models, measure memory footprint at your target context length rather than relying on short-context benchmarks.

    Task-Level Token Consumption

    The cost of a single request is typically billed by input and output tokens:

    Task cost = input tokens × input price + output tokens × output price

    The key variable is the token count within a task. For the same coding problem, different models may differ in reasoning length, number of tool calls, retries, and output verbosity. A model with heavier per-step compute may consume fewer tokens overall if it completes the task in fewer steps.

    The following function estimates the total cost of a batch of tasks and computes key metrics:

    1. from dataclasses import dataclass
    2. from statistics import mean
    3. @dataclass
    4. class TaskRecord:
    5. input_tokens: int
    6. output_tokens: int
    7. tool_calls: int
    8. succeeded: bool
    9. def estimate_cost(records, in_price_per_m, out_price_per_m):
    10. """Estimate the cost of a batch of tasks using per-million-token prices
    11. and return key statistics."""
    12. total_in = sum(r.input_tokens for r in records)
    13. total_out = sum(r.output_tokens for r in records)
    14. cost = (total_in * in_price_per_m + total_out * out_price_per_m) / 1_000_000
    15. successes = sum(r.succeeded for r in records)
    16. return {
    17. "total_cost": round(cost, 4),
    18. "avg_output_tokens": round(mean(r.output_tokens for r in records), 1),
    19. "avg_tool_calls": round(mean(r.tool_calls for r in records), 2),
    20. "success_rate": round(successes / len(records), 3),
    21. "cost_per_success": round(cost / max(1, successes), 4),
    22. }

    cost_per_success is more informative than raw total cost. A solution with a low unit price but a high failure rate may actually cost more in practice.

    Large Resident Lookup Structures

    Some inference approaches introduce large static lookup tables, such as n-gram statistical mappings, that let part of the prediction be read directly from the table, reducing computation in deeper network layers. These tables can be very large and typically reside in host memory, accessed on demand.

    This design involves clear trade-offs. It saves some computation but introduces host memory usage, data transfer between host memory and GPU memory, and lookup latency. If server memory is tight or the data transfer path is slow, the gains can be negated. The benefit is significant only when the table has a high hit rate and the transfer path is fast.

    When evaluating such structures, focus on three questions: what is the table’s hit rate on your business text; how much host memory does it require; and how does the added lookup latency compare to the compute savings it delivers?