Understanding Large Model Technical Choices: Architecture, Training, and Inference Efficiency

    This article breaks down the key technical decisions behind modern large language models (LLMs), covering sparse Mixture-of-Experts (MoE) design, attention head configuration and KV cache impact, optimizer and training stability, and token efficiency via data strategy. It provides a practical evaluation framework and implementation guidance for teams selecting or customizing models under real-world constraints.

    Background: Converging Technical Approaches

    Current mainstream large language models share many architectural similarities. Mixture-of-Experts (MoE), attention mechanisms with compressed key-value caches, and pre-training pipelines centered on high-quality corpora have become common choices. The reason is that these solutions strike a practical balance among compute cost, GPU memory usage, and training stability.

    When comparing models, the key question is not what architecture is used, but rather how each design parameter is traded off under specific constraints. This article examines four dimensions: sparsity design, attention head allocation, optimizer and training stability, and token efficiency.

    Mixture-of-Experts: The Sparsity Trade-off

    MoE splits the feed-forward network into multiple expert sub-networks, where each token activates only a few experts. Two key scale metrics define a model:

    • Total parameters: Determines knowledge capacity.
    • Active parameters: Determines the actual computation per token.

    The ratio between the two is called sparsity. Increasing sparsity grows total parameters while keeping per-token computation roughly constant. Scaling law research suggests that adding more experts generally reduces loss, but the benefit per additional expert diminishes. At the same time, more experts introduce engineering challenges such as routing imbalance and increased cross-device communication.

    The routing layer typically uses a Top-k gating mechanism. A simplified pseudocode example:

    1. def moe_forward(x, gate_weights, experts, k=2):
    2. # Compute routing score for each expert
    3. scores = softmax(x @ gate_weights)
    4. # Select the top-k experts
    5. topk_idx, topk_scores = select_topk(scores, k)
    6. # Normalize weights and combine expert outputs
    7. topk_scores = topk_scores / topk_scores.sum()
    8. output = 0
    9. for idx, w in zip(topk_idx, topk_scores):
    10. output += w * experts[idx](x)
    11. return output

    Three issues deserve special attention when designing MoE models:

    1. Expert load balancing: If some experts remain idle for long periods, effective capacity drops. Common solutions include auxiliary loss functions or dynamic bias adjustment in routing.
    2. Communication cost: When experts are distributed across multiple accelerators, tokens must be routed across devices, and network bandwidth often becomes a bottleneck.
    3. Small-batch inference efficiency: At inference time, batch sizes are small and only a few experts are activated per token, which lowers the utilization of expert weight reads, hurting latency and throughput.

    Attention Head Count and Inference Cost

    The number of attention heads directly affects the key-value (KV) cache size during inference. Each token must store key and value vectors for every layer, so the cache size can be estimated as:

    Cache bytes per token = 2 × layers × KV heads × head dimension × bytes per element

    A concrete example (60 layers, head dimension 128, half precision with 2 bytes per element):

    1. layers, head_dim, bytes_per_elem = 60, 128, 2
    2. def kv_cache_per_token(num_kv_heads):
    3. return 2 * layers * num_kv_heads * head_dim * bytes_per_elem
    4. print(kv_cache_per_token(64) / 1024) # 64 KV heads: ~1920 KB/token
    5. print(kv_cache_per_token(8) / 1024) # 8 KV heads: ~240 KB/token

    In long-context and high-concurrency scenarios, the KV cache often becomes the memory bottleneck before compute does. Reducing the number of attention heads or using grouped shared-key-value designs significantly lowers memory usage, allowing higher concurrent batch sizes per accelerator.

    This design has a cost. With fewer heads, the model can attend to fewer semantic subspaces simultaneously, potentially reducing expressiveness. Engineering mitigation includes increasing head dimension, adding more layers, or validating different configurations during training. Whether a head count is appropriate should be judged by evaluation results on target tasks, not by parameter count alone.

    Optimizers and Training Stability

    Optimizer Selection

    Adaptive optimizers (such as AdamW) remain the baseline for large-scale training. Recent research explores structured weight updates, such as approximately orthogonalizing the update matrix so that update magnitudes are more uniform across directions. The main claimed benefit is reaching the same loss with fewer training tokens.

    Note that such gains are usually observed under specific model sizes, data mixes, and learning rates. Evaluations should fix other variables, compare training curves under the same budget, and check stability across multiple random seeds rather than relying on a single run.

    Attention Logit Explosion and Clipping

    A common problem in large-scale training is that attention scores (dot products of queries and keys) grow continuously, saturating the softmax, causing abnormal gradients, and eventually leading to divergence. One direct approach is to monitor the maximum attention logit per layer and scale the query and key projection weights when it exceeds a threshold:

    1. def clip_qk_logits(W_q, W_k, max_logit, tau):
    2. # max_logit: observed maximum attention logit in the current batch
    3. # tau: predefined threshold
    4. if max_logit > tau:
    5. scale = tau / max_logit
    6. # Scale both projection matrices by sqrt(scale) so the dot product scales by scale
    7. W_q *= scale ** 0.5
    8. W_k *= scale ** 0.5
    9. return W_q, W_k

    The advantage of this method is that it intervenes only when anomalies occur, having minimal impact on normal training. The threshold and trigger frequency should be tuned based on training logs, and each clipping event should be recorded for later analysis.

    Token Efficiency and Data Strategy

    The Problem

    High-quality human text is finite. When the available corpus grows slowly, model capability increasingly depends on how much can be learned from each token—i.e., token efficiency. Three main paths improve token efficiency:

    • Optimize the training process: Use more efficient optimizers or improved learning rate schedules to better leverage gradient information per token.
    • Improve data quality: Reduce low-value samples through deduplication, quality filtering, and domain mix adjustment.
    • Supplement with synthetic data: Generate rewritten, Q&A, or reasoning samples from existing high-quality text to expand the training distribution.

    Risks of Synthetic Data

    Synthetic data can broaden coverage but introduces clear risks:

    • Generated content may contain factual errors, which are then amplified during training.
    • Text style may become monotonous, reducing output diversity.
    • Synthetic samples may overlap with evaluation sets, inflating scores.

    Mitigations include fact-checking synthetic data, controlling the proportion of different styles and sources, and decontaminating the training set against the evaluation set.

    Analyzing a Technical Route: An Evaluation Framework

    The table below lists common dimensions for evaluating a technical route.

    Dimension Key Metrics Typical Questions
    Model capacity Total parameters, active parameters Does the per-compute budget meet the knowledge needs of target tasks?
    Inference cost Memory per token, latency, throughput Does it meet service-level requirements under target concurrency?
    Training stability Loss curve, gradient norm, clipping events Are results consistent across multiple runs?
    Data efficiency Tokens needed to reach a target loss Does extra data bring a measurable improvement?
    Task performance Offline evaluation and human review on target tasks Do general benchmarks reflect real business effectiveness?

    When using this framework, first clarify your own constraints (e.g., memory limit, latency budget, data size), then compare alternatives under those constraints.

    Implementation Recommendations

    For teams that need to select a model or develop their own, the following steps are recommended:

    1. Define tasks and metrics: List core tasks and set quantifiable evaluation sets for each.
    2. Measure performance under real load: Test latency, throughput, and memory usage at target concurrency and context lengths; do not rely on paper parameters.
    3. Assess fine-tuning and deployment compatibility: Confirm whether the inference framework, quantization method, and hardware platform fit your existing infrastructure.
    4. Verify licensing and compliance: Check model usage terms, data provenance statements, and output safety policies.
    5. Establish continuous evaluation: After model version updates, run regression tests with the same evaluation set to prevent capability degradation.

    Technical reports and paper results can serve as design references, but final decisions should be based on experimental data directly relevant to your own business.