The Technical Path to Low-Cost Large Language Models

    This article breaks down the engineering path behind low-cost large language models, focusing on how scale and cost can be decoupled through system-level optimization rather than a single trick. It covers sparse activation with Mixture-of-Experts (MoE), low-precision training and memory management, combined data/pipeline/tensor/expert parallelism, data engineering and training stability at the 14.8 trillion token scale, inference-side speedups, capability evaluation, and a practical deployment checklist. Readers will gain a structured understanding of the methods that let teams keep iterating under limited compute.

    1. The Starting Point: Why Training Cost Became a Core Metric

    Over the past few years, the main axis of large model competition has shifted from “parameter scale” to “the cost of acquiring a unit of intelligence.” A sparse model with roughly 670 billion total parameters that activates only about 37 billion parameters per token can complete pre-training on a corpus of around 14.8 trillion tokens, while the overall compute investment is compressed to the scale of a few thousand accelerators and a few million accelerator-hours, bringing the effective R&D cost into the range of a few million US dollars. The significance of these numbers is not that it is “cheap,” but that it demonstrates a reproducible engineering path: scale and cost are not linearly coupled.

    It is worth emphasizing that the cost advantage comes from system-level optimization, not a single-point technique. It depends simultaneously on model architecture, numerical precision, parallel partitioning, communication scheduling, and inference-side caching strategy. If any one link is missing, the cost model quickly breaks down.

    2. Sparse Activation: Decoupling Total Capacity from Per-Compute

    The core idea of Mixture-of-Experts (MoE) is to separate the total number of model parameters from the compute used per token. A gating network selects a few experts to participate in computation for each token, while the remaining parameters stay “dormant.” This yields two direct benefits:

    • The floating-point operations for training and inference drop significantly;
    • Model capacity (knowledge carrying) can still expand as the number of experts grows.

    Engineering-wise, three typical challenges must be handled. First is load imbalance: popular experts get over-selected while cold experts receive no gradient. A common approach is to introduce an auxiliary balancing loss and cap expert capacity, with overflow tokens routed through a residual connection. Second is routing jitter: tiny perturbations in the gating output can cause expert switching and hurt training stability, so routing noise and temperature need to be controlled. Third is communication amplification: when experts are spread across devices, tokens must be rearranged across cards, and All-to-All communication easily becomes a bottleneck.

    The illustrative gating and capacity-control logic is as follows (pseudocode, expressing only the general idea):

    1. logits = gate(x) # [tokens, num_experts]
    2. probs = softmax(logits, dim=-1)
    3. topk_val, topk_idx = topk(probs, k=2)
    4. # Capacity cap: prevent a single expert from being overwhelmed
    5. capacity = int(tokens * k / num_experts * factor)
    6. mask = one_hot(topk_idx) * topk_val
    7. counts = mask.sum(dim=0)
    8. overflow = (counts - capacity).clamp(min=0)
    9. mask = mask * (counts <= capacity).float()
    10. y = dispatch_and_expert_compute(x, mask) # cross-device rearrange + expert forward
    11. y = combine(y, mask) + x # overflow goes through residual
    12. loss = task_loss(y) + aux_balance_loss(counts)

    3. Precision and Memory: Fitting Huge Models into Limited Compute

    Low-precision training is the key lever for cost compression. The industry commonly adopts a mixed-precision strategy: matrix multiplications accumulate in low precision, the master copy of weights and optimizer states are kept at higher precision, and loss scaling is used to avoid gradient underflow. The key point is “which tensors must be high precision”—normalization layers, residual accumulation, and the first- and second-order optimizer moments usually need more careful numerical handling.

    The classic memory-usage estimate can be written as:

    1. Memory ≈ params × (weight bytes + gradient bytes + optimizer state bytes) + activations + communication buffers

    Under mixed precision and common optimizer configurations, the training-side overhead per parameter often reaches the scale of a dozen-plus bytes, so sharding and offloading must be combined: optimizer state sharding, gradient sharding, activation recomputation, and temporarily sinking part of the state to host memory or high-speed storage. Activation recomputation trades compute for memory and is an almost-mandatory capability in long-sequence scenarios.

    4. Combining Parallelism Strategies: Data, Pipeline, Tensor, and Expert Parallelism

    A single parallelism method cannot cover huge models; a mature solution is a four-dimensional combination:

    • Data parallelism: scales throughput, but must handle gradient synchronization and replica consistency;
    • Pipeline parallelism: partitions by layer across devices and fills the pipeline with micro-batches, with attention to bubble ratio;
    • Tensor parallelism: partitions within a single layer with frequent communication, usually confined to high-speed interconnect within a single machine;
    • Expert parallelism: places different experts on different devices, with the most complex communication pattern when coupled with data parallelism.

    The practical principle is “minimize communication first”: put the most bandwidth-tight partitioning inside the machine and unfold the lower-bandwidth partitioning across machines; at the same time, jointly tune micro-batch count, recomputation granularity, and pipeline depth to avoid bubbles and memory peaks worsening simultaneously.

    5. Data and Training Stability: What 14.8 Trillion Tokens Means in Engineering

    Training at the trillion-token scale is not simply “feeding more data,” but a data engineering problem: deduplication and quality filtering, domain mixing ratios, curriculum-style sampling, and multi-stage context-length extension. A common practice is to first absorb general knowledge quickly with a shorter context, then gradually lengthen the window to strengthen long-text reasoning and code understanding.

    For stability, key things to monitor include: gradient-norm spikes, loss spikes, routing-entropy collapse, and overall slowdown caused by an individual slow device. Engineering measures include gradient clipping, skipping and rolling back anomalous batches, periodic checkpoints, and resuming training with data-order alignment from a checkpoint. The checkpoint strategy must balance “write amplification” against “recovery time,” usually with layered saving: high-frequency lightweight snapshots plus low-frequency full snapshots.

    6. The Inference Side: Where the 3x Generation Speed Comes From

    The generation speedup usually comes from four stacked sources: the per-token compute drop from sparse activation; higher device utilization from batch scheduling and continuous batching; lower fragmentation from key-value caching and paged memory management; and shorter per-step latency from speculative decoding, quantization, and operator fusion. For long-context serving, prefix cache reuse can significantly reduce repeated computation.

    When serving, it is recommended to break the metrics apart: time to first token, time per output token, throughput, and cost per token. These four often conflict, so the optimization target should be chosen by business shape—dialogue workloads lean toward latency, batch workloads lean toward throughput.

    1. Effective throughput ≈ concurrent batch size × tokens generated per step / per-step latency
    2. Unit cost ≈ accelerator-hour price × number of cards / effective throughput

    7. Capability Evaluation: Why Math and Chinese Tend to Show Bigger Gaps

    Evaluation should cover dimensions such as general knowledge, reasoning and math, code, long context, multilingual, and Chinese semantic understanding, and should distinguish “benchmark scores” from “real business testing.” Strong performance on math and Chinese tasks usually benefits from high-quality corpus mixing and reasoning-chain data construction; but benchmark gains do not equal online stability, so be sure to run regression on a self-built business set, watching hallucination rate, format adherence, and long-text consistency.

    8. Deployment Checklist and Working with General Cloud Capabilities

    1. First run small-scale convergence validation, then scale up the cluster, to avoid “not converging after scaling up”;
    2. Establish compute and cost baselines, accounting across three lenses: accelerator-hours, throughput, and cost per token;
    3. Unify training logs, metrics, and checkpoints into object storage, and combine with logging services and monitoring alerts for anomaly localization;
    4. Use a container platform for elastic scaling at the inference layer, scheduling resources by peak and trough;
    5. Version and isolate permissions for model and data assets to meet compliance requirements.

    Under the general cloud product system of Baidu AI Cloud, the above steps can map respectively to general capability categories such as object storage, container platforms, logging services, and monitoring alerts, letting the team refocus on data quality and training strategy itself. Overall, a low-cost large model is not the victory of a single-point technique, but the result of coordinated structural sparsification, numerical precision, parallel scheduling, and inference acceleration; mastering this methodology is what lets a team keep iterating under limited compute.