How to Estimate MoE Inference Costs Before Deploying a Decision LLM
This article explains how to build an evaluation set for decision-making LLMs and combine it with MoE parameter accounting, KV cache sizing, continuous batching, paged KV cache, and cost-aware scheduling. It provides formulas, reusable tables, illustrative calculations, and a launch checklist for deciding whether a deployment is technically and economically viable.
How to Estimate MoE Inference Costs Before Deploying a Decision LLM
1. Build Your Own Evaluation Set First
Decision-making LLMs must produce actionable conclusions across multi-step reasoning, constraint satisfaction, and trade-offs. Evaluation therefore cannot focus only on whether the answer is fluent; it must also test whether the model makes sound judgments consistently.
Measure four dimensions:
- Reasoning consistency: Whether the same question, asked in a different way, leads to the same conclusion. Consistency rate = number of samples with the same conclusion under two phrasings ÷ total samples.
- Constraint adherence: Whether outputs violate given budgets, preconditions, or business rules. Constraint violation rate = number of samples violating any constraint ÷ total samples.
- Multi-step planning quality: Check whether steps are complete, ordered sensibly, and executable. Score subtask coverage and executability from 1 to 5 each, then take the average.
- Cost sensitivity: How much decision quality drops when latency or compute budgets are tightened. Drop = (full-budget score − reduced-budget score) ÷ full-budget score × 100%.
Public leaderboards are only a rough reference. Different benchmarks have very different question distributions and scoring criteria, and a small lead on a single score does not prove better business performance. If you use public results, first compare the benchmark’s task types with your own business distribution. When comparing two models, use the bootstrap method to estimate confidence intervals for the metrics. If the intervals overlap, do not draw a conclusion.
An evaluation set can be built in four steps:
- Sample sources: Prefer de-identified real business requests, covering high-frequency and high-risk scenarios. Mark synthetic samples separately and report them separately from real samples.
- Annotation rules: Define the judgment criteria for each task type, then have at least two annotators label independently. Use Cohen’s kappa to measure inter-annotator agreement, preferably no lower than 0.6; for tasks involving funds or compliance, aim for 0.8 or higher. If the threshold is not met, revise the annotation rules before using the data.
- Metric thresholds: Set thresholds based on business risk. The table below is a starting example and should be calibrated against pilot results.
| Scenario | Initial constraint violation threshold | Initial consistency threshold | Adjustment approach |
|---|---|---|---|
| Funds, compliance | No higher than 0.5% | No lower than 95% | Review after any violation during pilot operation |
| Internal assistance | No higher than 5% | No lower than 85% | Track weekly; consider relaxing manual review only after two consecutive compliant weeks |
- Regression mechanism: After every change to model version, inference parameters, or quantization method, rerun the full evaluation set and record changes in each metric.
The table below is a reusable template for samples and regression records:
| Field | Description | Example |
|---|---|---|
| sample_id | Unique sample ID | ds-0001 |
| source | Real or synthetic | Real |
| scenario | Scenario category | Risk-control review |
| risk_level | High, medium, low | High |
| label_rule_version | Annotation rule version | v1.2 |
| annotator_results | Conclusions from each annotator | A: pass, B: pass |
| kappa_batch | Kappa value for this batch | 0.72 |
| model_version | Model under test and version | Model A, 2026-10 |
| quant_and_params | Quantization method and inference parameters | INT8, temperature=0 |
| metrics | Consistency rate, violation rate, planning score, drop | See above |
| run_date | Run date | 2026-11-20 |
2. How to Calculate MoE Model Costs
A Mixture of Experts (MoE) model splits the network into multiple expert subnetworks, and each token passes through only a subset of them. Total parameters determine knowledge capacity and the lower bound of memory usage; active parameters determine the compute per token. Cost estimation must calculate these two parts separately.
Key parameters:
- Number of routed experts N: total experts selectable at each layer.
- top-k: number of experts actually activated per token.
- Parameters per expert P_e: number of weights in one routed expert.
- Shared parameters P_s: total weights in attention layers, embedding layers, shared experts, and dense layers.
Use these two approximations, ignoring a small number of routing and normalization parameters:
Total parameters ≈ P_s + N × P_e
Active parameters ≈ P_s + k × P_e
If the model has multiple MoE layers, sum P_e and P_s across all layers.
For compute, each generated token during decoding requires roughly 2 × active parameters floating-point operations in the forward pass. The prefill stage, which processes the input, also adds an attention component that grows with sequence length; longer sequences increase this part.
For memory, weight usage = total parameters × bytes per parameter. FP16 uses 2 bytes, INT8 uses 1 byte, and INT4 uses about 0.5 bytes. KV cache usage = 2 × layers × KV heads × head dimension × sequence length × batch size × bytes per element. In addition, activations, communication buffers, and framework overhead also consume memory. In general, reserve 10% to 20% headroom and confirm it with real-load stress testing.
The following example uses assumed parameters to demonstrate the calculation. These numbers are not measured results; they only illustrate the formulas. Assume a model with 120B total parameters and 20B active parameters, using FP16, batch size 16, sequence length 4096, 48 layers, 8 KV heads, and head dimension 128.
- Weight memory: 120 × 10^9 × 2 bytes = 240 GB. With INT8, this drops to 120 GB.
- KV cache memory: 2 × 48 × 8 × 128 × 4096 × 16 × 2 bytes ≈ 12.9 GB.
- Decode compute per token: 2 × 20 × 10^9 = 40 GFLOP.
- Decode latency lower bound with batch size 1: each step must read about 40 GB of active weights. If a single GPU has 2 TB/s memory bandwidth, the single-step latency is no lower than 40 ÷ 2000 ≈ 0.02 seconds. With tensor parallelism, the read load per GPU can be approximated as divided by the number of GPUs.
As batch size increases, different tokens hit different experts, so more expert weights are read. The latency lower bound above cannot be directly extrapolated to large-batch scenarios.
The table below compares a dense model with the same active scale and an MoE model:
| Metric | Dense model (20B) | MoE model (120B total, 20B active) |
|---|---|---|
| Weight memory (FP16) | About 40 GB | About 240 GB |
| Compute per token | About 40 GFLOP | About 40 GFLOP |
| Deployment difficulty | Lower; can fit on a single machine | Requires multiple GPUs or expert parallelism |
| Knowledge capacity | Smaller | Larger |
This comparison shows that MoE mainly saves compute, not memory. Expert parallelism also introduces cross-GPU all-to-all communication. Communication volume grows with batch size and token count and is often the latency bottleneck in MoE deployments.
3. Continuous Batching
Static batching waits until every request in a batch finishes, so short requests occupy slots while waiting. Continuous batching checks at each decoding step: completed requests exit immediately, and new requests fill the freed slots. When output lengths vary widely, throughput gains are usually significant.
There are three key parameters:
- max_num_seqs: Limits the number of requests in the batch at the same time. Increasing it can improve throughput, but each step performs more computation, which increases per-request latency.
- max_num_batched_tokens: Limits the total number of tokens processed in one step.
- Chunked prefill: Splits long inputs into smaller chunks and interleaves them with decoding requests. Without chunking, a long input can block decoding for other requests and increase tail latency.
Applicability: The benefit is large when request concurrency is high and output lengths vary. If the service handles only a small number of requests, batching brings limited throughput improvement, and the focus should be on single-request latency.
4. Paged KV Cache
If KV cache is preallocated according to each request’s maximum length, a large amount of space sits idle. Paging divides the cache into fixed-size blocks and allocates them on demand, similar to virtual memory in an operating system. This reduces fragmentation and allows requests with the same prefix, such as the same system prompt, to share blocks.
There are three key parameters:
- Block size: A common value is 16 tokens. Smaller blocks waste less space internally but add management overhead; larger blocks improve memory access efficiency but waste more space in the final block.
- GPU memory utilization: The proportion of GPU memory reserved for KV cache. If set too high, traffic peaks can easily cause OOM; if set too low, the number of concurrent requests that can be accommodated decreases.
- Maximum sequence length: Requests exceeding the limit should be rejected directly, or truncated with clear notification to the caller.
The risk is that when memory is insufficient, the scheduler preempts some requests and releases their cache. Preempted requests later need recomputation or swapping in and out, which appears as a sudden increase in tail latency.
5. Cost-Aware Scheduling and Joint Decisions
Unit cost is simple to calculate: unit cost = GPU cost per hour ÷ tokens produced per hour. For an assumed example, a single GPU costs CNY 10 per hour, and aggregate throughput is 2,000 tokens/s. Hourly output is 2,000 × 3,600 = 7,200,000 tokens, so unit cost is approximately 10 ÷ 7.2 ≈ CNY 1.39 per million tokens.
Consider another trade-off example, also with assumed values. Increase maximum concurrency from 32 to 64, raising throughput from 2,000 tokens/s to 3,000 tokens/s. Unit cost drops to approximately 10 ÷ 10.8 ≈ CNY 0.93 per million tokens. However, p95 latency rises from 2 seconds to 4 seconds. If the business SLO requires p95 no higher than 3 seconds, this configuration cannot go live, no matter how low the cost.
Joint decisions can follow this process:
- Define constraints: p95 latency ceiling, budget per million tokens, and quality threshold from the evaluation set.
- Run the evaluation set for each candidate configuration (quantization method, number of GPUs, maximum concurrency, block size) to obtain quality drop and constraint violation rate.
- Stress-test the same configurations and record throughput, p95 latency, and peak memory.
- Remove configurations that fail quality or latency constraints, then choose the lowest unit cost among the remaining configurations.
- Roll out gradually to a small traffic share and compare online and offline metrics. Roll back if deviation exceeds the threshold.
Scheduling can also route by risk. Send high-risk requests to the larger model with manual review retained, and route simple or low-risk requests to a smaller model. The routing rules themselves should also be included in evaluation-set regression.
6. Launch Checklist and Monitoring Metrics
Confirm each item before launch:
- Evaluation set: Real and synthetic samples are reported separately, kappa meets the threshold, and thresholds are set by scenario.
- Cost: Total parameters, active parameters, and memory (weights, KV cache, headroom) are calculated with the formulas and verified under real load.
- Scheduling: Maximum concurrency, tokens per step, block size, and GPU memory utilization limit are determined through stress testing.
- Regression: After every change to the model, quantization method, or inference parameters, both evaluation and stress testing are rerun.
After launch, monitor these metrics:
| Metric | Meaning | What to watch |
|---|---|---|
| TTFT | Time to first token | Whether long inputs block new requests |
| TPOT | Average latency per output token | Whether it slows significantly as batch size grows |
| p95 / p99 latency | Tail latency | Effect of preemption and chunking strategy |
| Peak memory and block utilization | KV cache pressure | Scale out or rate-limit before approaching the limit |
| Preemption count | Number of requests swapped out or recomputed | Continuous growth indicates insufficient memory |
| Online constraint violation rate (sampling) | Decision quality | Compare with offline evaluation results |
| Unit token cost | Cost level | Compare with the budget line |
