Cutting LLM Inference Costs: Choosing Models by Verifiable Cost per Effective Request

    This article explains four ways to reduce LLM inference costs: sparse activation (MoE), low-bit quantization, knowledge distillation, and attention kernel optimization. For each, it covers the conditions under which it works and the checks needed before deployment. It then proposes cost per effective request as a common metric for comparing options, and offers guidance on deployment settings, monitoring thresholds, troubleshooting, and a selection table.

    1. Four Technical Paths to Lower Inference Cost and Their Limits

    Four main techniques reduce inference cost: sparse activation, low-bit quantization, knowledge distillation, and attention operator optimization. Each delivers real savings, and each has specific prerequisites. Verify both before choosing one.

    1. Mixture of Experts (MoE)

    MoE splits the feed-forward layer into multiple expert networks. A gating router selects a few experts for each token. A dense model activates all of its parameters in every forward pass. An MoE model activates only a subset. As a result, the total parameter count can be very large while the compute per inference stays relatively small.

    The limits of this approach are as follows:

    • The gains mainly appear in high-concurrency, throughput-first scenarios. With a single request or low concurrency, the overhead of expert scheduling can offset the compute savings.
    • In multi-GPU deployments, experts sit on different devices, so routing tokens between devices adds communication overhead. When network bandwidth is insufficient, latency rises noticeably.
    • If routing is unbalanced, some experts stay overloaded while others sit idle. Mainstream models usually use an auxiliary loss or other mechanisms to reduce this problem, but evaluation should still track the load distribution across experts.

    During evaluation, record output tokens per second, P99 latency, and the standard deviation of expert load. Compute the load standard deviation over 5-minute windows, then divide it by the average expert load to get a relative value. This makes results comparable across batch sizes.

    2. Low-Bit Quantization

    Quantization converts weights from FP16 to INT8 or INT4, which directly reduces the memory used by weights. For example, INT4 weights need about one quarter of the memory of FP16 weights. This ratio does not include the KV Cache or activations. In long-context and large-batch workloads, the KV Cache often takes up most of the memory, so the actual savings should be judged from memory monitoring data.

    Do not assume accuracy loss is acceptable. Validate it with these steps:

    1. Run the FP16 baseline model and the quantized model on your business evaluation set.
    2. Compare task accuracy, focusing on tasks sensitive to small errors, such as code generation and mathematical reasoning.
    3. Confirm that the calibration data used by the quantization method (such as AWQ or GPTQ) matches the distribution of your business data. The calibration set should cover the main input length ranges and task types. If coverage is poor, quantization errors will show up in production.
    4. Define rollback conditions. For example, if accuracy on a critical task drops more than 2 percentage points from baseline, stop the rollout of the quantized version.

    3. Knowledge Distillation

    Distillation trains a smaller model to learn the output distribution or generated results of a larger model. The smaller model keeps part of the larger model’s capability at a lower inference cost. The result depends on the quality and coverage of the training data. Small models usually perform well on tasks similar to their training data, but they can degrade significantly on out-of-distribution tasks.

    Distillation also carries compliance risks. Check the following before deployment:

    • If you train your own model on outputs from a closed-source model, confirm that the provider’s terms of service allow this.
    • If you use an open-source model, check its license for restrictions on commercial use, derivative models, and output use.
    • Confirm whether the training data includes content that requires authorization, and keep records of data sources.

    Do not use a distilled model as the default production option until these checks are complete.

    4. Attention Operators and Long Context

    LLM inference is often limited by memory bandwidth. FlashAttention reduces reads and writes to high-bandwidth GPU memory by computing attention in blocks, which improves throughput. It depends on specific GPU architectures and matching CUDA and PyTorch versions. FlashAttention 2 generally requires NVIDIA GPUs based on the Ampere architecture or newer. Check the official documentation for the version you use for exact requirements.

    Keep the following in mind during installation and rollout:

    • Pin the combination of CUDA driver, PyTorch, and FlashAttention versions, and record it in your deployment manifest. Version mismatches typically cause compilation failures or runtime errors.
    • On the target GPU, compare outputs with and without FlashAttention enabled, and check that numerical error falls within an acceptable range.
    • Keep a fallback switch. If problems occur, change the inference framework configuration back to the standard attention implementation and restart the service.
    • When combining with quantization, confirm that the framework supports the combination of quantized kernels, KV Cache data types, and attention kernels. Validate output quality separately for long contexts.

    2. Evaluating Cost per Effective Request

    Looking at GPU hourly price or tokens per second alone does not show whether a option is cost-effective. Use cost per effective request to compare options on the same basis.

    1. Formula

    Cost per effective request = (Hourly price per GPU × Number of GPUs used × Measurement period (hours)) ÷ Number of effective requests in the period

    Where:

    • Number of GPUs used is the number of GPUs the deployment actually occupies, including GPUs reserved to meet memory requirements.
    • Measurement period includes idle time. If the service sits idle during off-peak hours, the cost still accrues.
    • Effective requests = Total requests × Quality pass rate. An effective request must meet all of the following: a normal HTTP status code, no timeout, and output that passes business quality evaluation.

    2. Measurement Rules

    • Use the same billing period for all prices, including on-demand and reserved pricing from cloud providers.
    • Measure the quality pass rate on the same evaluation set and over the same time period, so changes in the evaluation set do not distort the comparison.
    • The measurement period should cover at least one full business peak, ideally 24 hours or more.

    3. Example

    The table below illustrates the calculation. The figures are hypothetical and do not represent any measured results. For real selection, replace them with data from your own load tests and evaluations. This example assumes an hourly price of 10 yuan (CNY) per GPU and a measurement period of 1 hour.

    Option GPUs Used Requests per Hour Quality Pass Rate Effective Requests Cost per Effective Request (CNY)
    A: Dense FP16 4 36,000 95% 34,200 0.00117
    B: INT4 quantized 2 30,000 91% 27,300 0.00073
    C: MoE 4 52,000 93% 48,360 0.00083

    The example shows that cost comparisons must account for throughput, GPU count, and pass rate together. Option B has the lowest price per GPU, but its conclusion does not hold if its pass rate is unacceptable for critical tasks.

    3. Deployment Configuration and Monitoring Thresholds

    1. Deployment Configuration

    Determine the following settings from load test results. The values in this section are only starting points:

    • Maximum concurrency: Increase load gradually from low concurrency. Stop increasing before P99 latency reaches the service level objective (SLO).
    • Maximum sequence length: Set it based on the 95th percentile of input plus output length for your workload, not the maximum length the model supports.
    • GPU memory utilization cap: Reserve space for the KV Cache and activations. Start testing around 85%.
    • Batching strategy: When continuous batching is enabled, observe how queuing time and throughput trade off, and choose a configuration that balances both.
    • Version manifest: Record the version numbers of the inference framework, CUDA, driver, PyTorch, FlashAttention, and quantization tools.

    2. Monitoring Metrics and Alert Thresholds

    Metric Suggested Starting Threshold Alert Action
    GPU memory usage Above 90% for 5 consecutive minutes Reduce maximum concurrency or maximum sequence length
    KV Cache occupancy Above 85% Limit new requests, check the share of long requests
    P99 latency Above 1.5× SLO for 10 consecutive minutes Check queuing time, batching parameters, and the network
    Request error rate Above 1% Check for OOM errors, timeouts, and upstream dependencies
    Relative standard deviation of expert load (MoE) Above 0.3 Check routing distribution, evaluate the auxiliary loss or expert scaling
    Quality spot-check pass rate Drops more than 2 percentage points below baseline Roll back to the previous version, pause the quantized or distilled model

    Calibrate these thresholds during load testing and canary rollout. Different business requirements for latency or quality call for different thresholds.

    4. Troubleshooting Checklist

    1. Out-of-Memory (OOM) Errors

    Investigation steps:

    1. Check the concurrency, input length, and output length at the time of the OOM event. Determine whether a small number of very long requests caused it.
    2. Compare the KV Cache memory with the memory used by model weights.
    3. Reduce the maximum sequence length or maximum concurrency, and check whether the problem goes away.

    Fallback: Switch to a lower-concurrency configuration, or use a quantized version. Rerun quality evaluation after any change.

    2. Rising P99 Latency

    Investigation steps:

    1. Separate queuing time from inference time. High queuing time usually means concurrency exceeds capacity.
    2. Check whether the batch wait time parameter is set too high.
    3. For MoE models, check cross-GPU communication bandwidth and whether expert load is unbalanced.
    4. Check whether long-context requests are consuming resources.

    Fallback: Apply temporary rate limiting, and route long requests to a separate instance.

    3. Unbalanced Expert Load (MoE)

    Investigation steps:

    1. Calculate the share of requests per expert over 5-minute windows, then compute the relative standard deviation.
    2. Break the statistics down by input type to see whether the imbalance concentrates on specific tasks.
    3. Check whether an auxiliary loss or another load-balancing mechanism is in use, and confirm that its version and configuration are correct.

    Fallback: If the imbalance persists, reduce the scale of expert parallelism, or route latency-sensitive traffic to a dense model.

    4. Accuracy Drop After Quantization

    Investigation steps:

    1. Compare the FP16 baseline with the quantized model on the business evaluation set, and identify the task types with the largest drops.
    2. Check whether the calibration data covers the affected task types and input length ranges.
    3. Try a higher-bit quantization scheme, or keep higher precision for only some layers.

    Fallback: When a rollback condition is met, switch back to FP16 or the last stable version immediately, and record the incident and evaluation results.

    5. Selection Decision Table

    Scenario Preferred Option Main Risk Verification Method
    High concurrency, throughput first, multi-GPU with sufficient network bandwidth MoE Unbalanced expert load, cross-GPU communication overhead Load test throughput and P99, record expert load
    Low concurrency, latency sensitive Dense model, quantized if appropriate Expert scheduling overhead may offset gains (if using MoE) Compare single-request latency and cost
    Tight memory, tasks tolerant of precision loss INT8 or INT4 quantization Accuracy drop, KV Cache still uses memory Compare on business evaluation set, define rollback conditions
    Need a smaller model, with sufficient training data Knowledge distillation Degradation on out-of-distribution tasks, compliance risk Check terms of service and licenses, evaluate by task
    Long context or long output FlashAttention with KV Cache management Version incompatibility, numerical error Pin the version combination, compare results with and without it enabled

    Start selection by screening options with cost per effective request, then confirm the choice with business evaluation and monitoring data. Record the scheme, versions, evaluation results, and rollback conditions for every change so later reviews can trace each decision.