Chinese LLM Selection: Long-Context vs. MoE Trade-offs

    This article explains how to select a Chinese large language model by starting with compliance, cost, and service constraints, then choosing among long-context, retrieval, MoE, multimodal, and quantized deployment options. It covers KV-cache estimation for long sequences, MoE gating and routing considerations, multimodal token costs, and a pre-launch checklist for lightweight deployment.

    1. Which Constraints Come First?

    Technical metrics only show how a model performs on certain tests. What really determines whether it can go live is usually compliance, cost, and service conditions. Before selecting a model, confirm the following five types of constraints.

    Constraint Question to verify Consequence if not met
    License Whether commercial use is allowed, whether a fine-tuned model can be republished, whether user scale is restricted The service may be forced offline or require migration after launch
    Data compliance Whether training data sources are documented, whether user data leaves the region, whether a public-facing service has completed required filing or registration A public-facing service may not be able to launch legally
    Chinese capability Test on Chinese samples from your own business, not only public leaderboards High leaderboard scores but low business QA accuracy
    Toolchain maturity Whether existing inference frameworks, quantization formats, and fine-tuning tools support the model architecture Longer deployment cycle and need to maintain adaptation code
    Service SLA Availability, rate limits, response time limits, and failure compensation terms Requests throttled during peak periods, affecting business continuity

    Data compliance requires legal involvement. For management requirements for generative AI services, refer to the Interim Measures for the Management of Generative Artificial Intelligence Services. SLA figures should be based on the supplier contract, not numbers on marketing pages.

    After constraints are determined, review the technical dimensions. This article focuses on four questions: sequence length, concurrency volume, latency requirements, and budget. These four determine trade-offs among long context, retrieval, MoE, multimodal, and quantization.

    2. Choose the Technical Route by Scenario

    The table below gives starting approaches for common scenarios. They are only starting points; final conclusions should be validated with your own data.

    Business scenario Recommended route Main reason
    Problem involves only a single passage Retrieval chunks plus short context Short single input, low cost, more stable results
    Long document requires cross-passage reasoning, low concurrency Long-context model Reduces the risk of losing passage associations after chunking
    Long documents, high concurrency, strict latency Retrieval plus reranking, short-context input Long inputs significantly reduce throughput
    Many task types, sufficient budget MoE model Large total parameter count, but each token activates only a few experts
    Limited GPU memory, slight accuracy change acceptable Quantized deployment Requires answer-consistency regression; check numbers, entities, and negation words

    When deciding, look at three things at the same time. First, whether the long document really needs whole-document understanding. Second, what the peak concurrency is, not the average concurrency. Third, what the upper bound on time to first token is. If any one of the three is strict, long context should be considered after retrieval.

    3. Long Context: How to Estimate KV Cache

    The computation of standard self-attention scales with the square of sequence length n. When sequence length doubles, attention computation increases to about four times. During inference, the model needs to store key and value vectors for every layer and every token, namely the KV cache. Its memory usage scales linearly with sequence length. The KV cache for a single request can be estimated as follows:

    1. KV cache bytes = 2 × layers × KV heads × head dimension × sequence length × bytes per element

    The coefficient 2 corresponds to the key and value tensors. Consider a hypothetical configuration: 32 layers, 8 KV heads, head dimension 128, 16-bit floating point (2 bytes per element), and sequence length 131,072 tokens. The calculation is:

    1. 2 × 32 × 8 × 128 × 131072 × 2 = 17,179,869,184 bytes ≈ 16 GiB

    This result represents only the KV cache for a single request. When using it, note the following scope:

    • It does not include model weights, activations, or memory fragmentation.
    • KV heads should use the actual value in the model configuration file. Models using grouped-query attention usually have fewer KV heads than query heads.
    • Inference frameworks often preallocate cache space, so actual usage may be higher than the formula result.
    • When sequence length doubles, KV cache doubles linearly.

    Under concurrency, memory demand grows by batch size. Suppose batch size is 8; with 16-bit floating point, KV cache is 8 × 16 GiB = 128 GiB, before adding model weights. If KV cache is quantized to 4 bits, at 0.5 bytes per element:

    1. 2 × 32 × 8 × 128 × 131072 × 0.5 = 4,294,967,296 bytes = 4 GiB (single request)
    2. batch = 8: 8 × 4 GiB = 32 GiB

    This does not include extra overhead such as quantization constants and scaling factors; actual usage will be slightly higher.

    The main optimization methods for KV cache are as follows. Each method needs corresponding validation metrics.

    Method Memory benefit Main cost Applicable scenario Validation metric
    Grouped-query attention (GQA) Directly reduces the number of KV heads; cache shrinks proportionally Must be adopted during training; already trained models cannot be switched simply Long-document QA, high-concurrency services Long-document recall, peak memory
    Sliding window or sparse attention Each token stores only information within a window Cross-window dependencies may be lost Tasks with strong local text structure Recall when key information is outside the window
    KV cache quantization 16-bit to 8-bit roughly halves; to 4-bit roughly quarters Accuracy loss; error accumulates as sequence length grows Memory-constrained services that can accept slight accuracy changes Answer consistency before and after quantization, throughput

    Long context is not always the better fit. Prefer retrieval plus short context in the following cases:

    • The problem involves only a single passage; chunk retrieval is cheaper and more stable.
    • Information is scattered across a large amount of text; long input adds distraction, and retrieval followed by reranking is usually more accurate.
    • Concurrency is high and latency requirements are strict; long context significantly reduces throughput.
    • The original document contains a large amount of duplicate or irrelevant content; clean it before input.

    4. MoE: Gating Routing, Temperature, and Cost Boundaries

    A mixture-of-experts (MoE) model contains multiple expert networks. Each token activates only a subset of experts. The total parameter count can be large, but each forward pass uses only a small number of parameters. The gating network computes scores for each expert for every token, selects the top-k experts, and then performs a weighted sum using normalized weights:

    1. g = softmax(W_g · x / T)
    2. output = Σ (over top-k experts) g_i · E_i(x)

    Here x is the hidden representation of the token, W_g is the gating weight, E_i is the i-th expert, and T is the temperature coefficient.

    The role of temperature depends on two cases. The smaller T is, the sharper the softmax distribution, and the more weight concentrates on the highest-scoring experts. The larger T is, the flatter the distribution, and the weights of multiple experts approach each other.

    In deterministic top-k routing, temperature does not change which experts are selected. Dividing by a positive T does not change score ordering, so the selected expert set remains unchanged. Temperature only changes the mixing weights of those experts. In sampling routing, or in scenarios where random noise is added to gate scores, temperature changes the probability that each expert is sampled, and expert selection changes accordingly.

    There is no universal optimal temperature value. Do not fix a number directly based on experience. Scan several values on your validation set and observe three metrics: entropy of gate weights, distribution of selection counts across experts, and task output quality.

    MoE has several clear boundaries in cost and engineering:

    • Load imbalance: some experts are selected frequently while others remain idle for long periods. Load-balancing mechanisms are usually needed to constrain this.
    • Routing collapse: most tokens concentrate on a few experts, and model capacity is not fully used.
    • Communication overhead: when experts are distributed across multiple GPUs, tokens need to be transferred between GPUs, and communication may become a bottleneck.
    • Memory footprint: inactive experts still need to reside in GPU memory, so total parameter count directly affects deployment memory requirements.
    • Parallel complexity: expert parallelism requires dedicated scheduling and debugging capabilities; the team’s engineering capacity should be included in the evaluation.

    When choosing MoE, start with whether a single GPU or single node can hold all expert weights, then estimate the cost of communication and load balancing.

    5. Trade-offs for Multimodal Input

    Multimodal input introduces three additional costs. First, images are converted into visual tokens; the higher the resolution, the more tokens. Second, the vision encoder requires additional computation time, increasing time to first token. Third, image tokens also occupy KV cache; with long images or multiple images, memory pressure rises significantly.

    The number of image tokens depends on the specific model’s chunking rules and is generally related to resolution and chunk side length. For estimation, use the following approximation:

    1. image tokens ≈ (width ÷ chunk side length) × (height ÷ chunk side length) ÷ merge factor

    Specific rules follow the documentation of the model used. During selection, handle it as follows:

    • Set several fixed resolution tiers for the business, such as small, regular, and high-definition, to avoid uncontrolled memory caused by arbitrary resolutions.
    • Set an upper limit on the number of images per request and calculate the corresponding maximum token count.
    • Compare direct multimodal input with OCR followed by text input. For document images, the latter is often cheaper and easier to audit.
    • Measure the latency of the vision encoding stage and include it in the time-to-first-token budget.

    If the business is mainly text and only occasionally needs image reading, consider placing vision capability in an independent service and calling it on demand, so that not all requests bear the extra cost.

    6. Lightweight Deployment Checklist

    Before launch, check each item in the following list. Each item should have an actual measurement, not an estimate.

    • Memory budget: whether the sum of weights, KV cache, activations, and fragmentation is within the available memory of the target GPU, with headroom reserved. The headroom ratio should be based on inference framework measurements.
    • Quantization regression: compare answer consistency on business samples before and after quantization; focus on numbers, entity names, and negation words.
    • Concurrency stress test: test according to the real request length distribution and arrival rhythm, not only single requests.
    • Latency metrics: record P50, P95, and P99 for time to first token, as well as the average time per output token.
    • Throughput metrics: record requests per second and output tokens per second, and note the input length range.