Large Model Training and Inference: The Hardware, Sparsity, and Batching Logic Behind AI Systems

    This article reconstructs the engineering logic behind large model training and inference, from rack-level hardware boundaries and interconnect topology to sparse mixture-of-experts design, pretraining data strategy, and service pricing. It explains why cross-rack communication penalties constrain model scale, why a 256-expert model activating only 32 experts per token depends on the size of the high-bandwidth domain, why pretraining data often far exceeds the scaling-law optimum, and why batch size is the hidden switch behind per-token inference cost and tiered pricing. Readers will gain a unified framework for evaluating accelerators, designing inference services, and separating academic optima from business optima.

    1. Why a Blackboard View of Large Models Matters

    Most discussions of large models stay at the level of leaderboards, parameter counts, and marketing language. Very few people can connect chips, compilers, model architecture, and service pricing into a single causal chain. A recent in-depth technical conversation, conducted mainly at a blackboard, offered a different perspective: an engineer who has long worked on accelerator architecture and compiler optimization used equations and diagrams to unfold the training and inference process of frontier models layer by layer, and then worked backward from publicly disclosed service pricing to infer undisclosed architectural trade-offs.

    The value of this kind of reasoning is that once you understand the underlying constraints, many product phenomena that look accidental become inevitable outcomes of the same constraint set: why inference batches requests, why pretraining is deliberately over-fed with data, why sparsification has a physical ceiling, and why a “fast tier” costs disproportionately more. The chain below is rebuilt in the order of hardware boundaries → communication topology → sparse architecture → training strategy → service pricing.

    2. Hardware Boundaries: The Rack Is the First Gate on Model Scale

    Modern large model inference runs on clusters of accelerator cards. Inside a single machine, inside a single rack, across racks, and across data centers form four distinct tiers of communication cost. The key fact is that once communication crosses a rack boundary, effective bandwidth and latency characteristics degrade sharply, with an order-of-magnitude gap commonly observed in the industry of roughly 8x.

    That 8x gap is not noise that tuning can smooth away. It is a hard constraint that enters the cost function and the parallelism strategy directly. It determines:

    • Which parallelism schemes (tensor parallelism, expert parallelism, pipeline parallelism) can stay inside a rack;
    • Which ones must tolerate slow links and therefore accept lower efficiency;
    • The maximum feasible size of a single “layer,” which in turn caps overall model scale.

    In other words, the physical dimensions of a rack and its internal interconnect topology are boundary conditions for model architecture design, not something to be optimized after the fact.

    3. Communication Topology: Why All-to-All Favors In-Rack Interconnect

    Take a sparse expert architecture as an example. The most natural deployment is expert parallelism: place different experts on different accelerator cards, and after routing, send each token to the device holding its selected expert. The communication pattern is a classic all-to-all, where any device may send data to any other device.

    High-bandwidth in-rack interconnect, such as a fully connected fabric or a high-radix switching structure, matches the all-to-all communication matrix closely: short paths, few hops, high bandwidth utilization. But once experts are split across two racks, roughly half of the token traffic must traverse the network that is about 8x slower, communication immediately becomes the main bottleneck, and compute utilization drops.

    This yields an important corollary: the number of accelerator cards a rack can hold directly limits how large an expert layer you can build. It also explains a long-discussed phenomenon: accelerator systems with a larger scale-up domain, meaning a wider range over which all-to-all communication is possible, can deploy models with higher sparsity while maintaining inference efficiency, and therefore show an advantage earlier in the pretraining stage. The key here is not single-card compute, but how large the efficiently interconnected domain is.

    4. Sparse Architecture: What 256 Experts with 32 Activated Actually Means

    The core idea of sparse mixture-of-experts (MoE) is that the total parameter count is very large, but each token passes through only a small subset of experts. A configuration frequently cited in public material is 256 experts, with only 32 activated per inference pass.

    This design brings three benefits and three costs.

    Benefits:

    • Parameter capacity is decoupled from compute, so a model’s “knowledge capacity” can far exceed the compute cost of a single forward pass;
    • At an equal compute budget, stronger expressiveness and memory capacity are attainable;
    • The number of experts can be scaled up or down as needed.

    Costs:

    • Routing imbalance overloads some devices while others idle;
    • All-to-all communication pressure grows with the number of experts;
    • Deployment is strictly constrained by rack boundaries, and efficiency drops sharply across racks.

    Common engineering mitigations include capacity factors and dropping policies, load-balancing auxiliary losses, expert grouping and hierarchical routing, and keeping frequently activated experts within the same communication domain as much as possible. But all of these optimize within physical boundaries; none can break the fundamental constraint that the rack is the ceiling.

    Illustrative pseudocode (expressing routing and communication structure only, not any specific product interface):

    1. # Conceptual illustration: token routing + expert parallelism + all-to-all
    2. logits = router(x) # [tokens, num_experts]
    3. topk_idx, topk_w = topk(logits, k=32)
    4. # Send tokens to the devices holding their target experts (all-to-all semantics)
    5. x_to_experts = all_to_all_dispatch(x, topk_idx)
    6. # Each device computes the experts assigned to it locally
    7. y_local = local_experts(x_to_experts)
    8. # Return results and merge them weighted by routing weights
    9. y = all_to_all_combine(y_local, topk_w)

    5. Training Strategy: Why Pretraining Data Often Reaches 100x the Theoretical Optimum

    Scaling laws describe the optimal data ratio for a given compute budget and model size. In practice, however, frontier models often go well beyond that optimum, with the order of magnitude mentioned in public discussion being around 100x. The reason is not waste, but the stacking of several practical objectives:

    1. Inference cost and knowledge coverage: more data means better coverage of long-tail knowledge and rare patterns, reducing the burden of downstream fine-tuning and retrieval;
    2. Training stability and generalization: excess data helps smooth the loss surface and reduces overfitting and catastrophic forgetting;
    3. Strategic redundancy: when compute and data availability are uncertain, over-pretraining is a hedge;
    4. Product requirements: real workloads demand far more in factual accuracy, timeliness, and instruction following than a pure benchmark optimum does.

    So the “theoretical optimum” is an efficiency point in the academic sense, while industrial practice is a compromise among efficiency, robustness, and product metrics. Understanding this explains why compute investment can look unprofitable yet keeps increasing.

    6. Service Pricing: Batch Size Is the Hidden Switch for Per-Request Cost

    A common puzzle: a coding assistant or chat product offers a “fast mode” priced about 6x higher while being only about 2.5x faster. Conversely, can a “slow mode” buy a lower price?

    The core variable in the answer is batch size. The cost structure of an inference service can be simplified as:

    • Fixed overhead: weight loading, memory footprint, scheduling, and network round trips;
    • Marginal overhead: the compute for each additional token.

    When requests are batched, fixed overhead is amortized across many requests and per-token cost can drop by an order of magnitude. If requests are processed one at a time in real time, fixed overhead cannot be amortized and per-request cost can be roughly 1000x higher. This explains:

    • Why the fast-mode premium far exceeds the speed gain: low latency means small batches or even single-request processing, sacrificing the amortization effect;
    • Why a slow or offline mode can in principle be cheaper: batching and queuing are allowed, pushing cost toward the optimum;
    • Why the same model can carry very different prices across tiers.

    Expressed as a minimal model (not a real billing formula, only an illustration of cost structure):

    1. cost_per_token ≈ (FixedCost / BatchSize + MarginalCost) / TokensPerRequest

    As BatchSize rises from 1 to tens or hundreds, the FixedCost term is significantly diluted and per-token cost falls sharply. Fast mode, in order to guarantee tail latency, can only sustain a very small batch, so its cost naturally stays high.

    7. Connecting the Chain: A Unified Explanation of Architecture, Pricing, and Progress

    Combining the pieces above yields a self-consistent explanation chain:

    1. Physical rack boundaries limit the size of the efficiently interconnected domain;
    2. The size of that domain determines the feasible sparsity and expert layer size;
    3. Sparsity and data over-provisioning shape training cost and the capability ceiling;
    4. Batch size determines per-request inference cost and product tier pricing;
    5. Together, these determine why large models look the way they do today.

    The practical implications for enterprises and developers are clear:

    • When selecting hardware, evaluate the efficiently interconnected domain first, not peak single-card compute;
    • Inference service design should build batching strategy, queuing, and degradation paths into the architecture rather than tuning them afterward;
    • Cost optimization should start with amortizing fixed overhead, not simply shrinking the model;
    • On the training side, distinguish the academic optimum from the business optimum and decide data redundancy per scenario.

    8. Mapping to General Cloud Capabilities

    To reproduce this line of thinking in a cloud environment, you can rely on general capability categories rather than proprietary interfaces: a container platform to host elastic inference clusters, object storage for training corpora and model artifacts, a message queue for request buffering and peak shaving, and logging plus monitoring and alerting to observe batch hit rates, tail latency, and the share of cross-rack communication. Baidu AI Cloud can support the full chain from training to inference with these general capabilities, helping teams turn blackboard constraints into measurable engineering metrics.

    Large models feel mysterious largely because information is opaque. Once you return to three measuring sticks, communication cost, batching economics, and physical boundaries, architectural choices, pricing strategies, and the pace of progress stop being hard to understand.