How LLM Training and Inference Work: A Bottom-Up Breakdown of Physical and Economic Constraints
This article breaks down large language model training and inference from the ground up, starting from hardware interconnect topology and moving through parallelism strategies, architecture sparsity, cost drivers, and product pricing. It explains why an intra-rack versus inter-rack bandwidth gap constrains expert layer size, why pretraining data often far exceeds the theoretical optimum, and why batch size is the main switch for inference cost. Readers will find a practical engineering checklist covering interconnect boundaries, all-to-all communication modeling, batch scheduling, and observability.
1. Why Use a “Blackboard Derivation” to Understand LLMs
The most effective way to understand the shape of frontier large models is not to look at parameter leaderboards, but to return to the constraints imposed by physics and mathematics. A blackboard and a few equations are enough to derive why models are sparse, why inference must be batched, and why an expensive “fast mode” coexists with a cheaper standard mode. Once these constraints are clear, architecture, pricing, and the pace of progress stop being isolated phenomena and become projections of the same set of constraints from different angles.
The main thread of this article is: physical interconnect topology → parallelism strategy → architecture sparsity → training and inference cost → product pricing.
2. The Starting Point Is Hardware: The “8x Gap” Inside and Outside a Rack
The mainstream deployment form for large model inference today packs dozens of accelerators into a single rack, connected through a high-bandwidth intra-rack interconnect (a scale-up network), so that any two cards can communicate in one or two hops with extremely high bandwidth and extremely low latency.
The key fact is: once communication crosses beyond this rack into the inter-rack network (scale-out), the effective bandwidth typically drops by about an order of magnitude. In the scenario discussed here, that gap is roughly 8x.
This seemingly ordinary engineering parameter is actually a hard constraint. It propagates upward to parallelism strategy and model architecture, and ultimately to the cost per token.
3. Expert Parallelism and All-to-All Communication: The Physical Ceiling of Sparse Architectures
Take the widely used sparsification approach (Mixture of Experts, MoE) as an example: a layer contains a large number of “expert” subnetworks, and each token is routed to only a few of them. One configuration commonly discussed publicly is 256 experts per layer with about 32 activated per token.
The most natural deployment is expert parallelism: placing different experts on different accelerators. Because routing results change dynamically, any card may send tokens to any other card, forming all-to-all communication. This communication pattern fits the topology of high-bandwidth intra-rack interconnect very well.
But once experts are distributed across racks, the problem appears immediately: a significant proportion of tokens must travel over links that are an order of magnitude slower, and communication shifts from “almost free” to “the main bottleneck.” This leads to an important conclusion:
How many accelerators fit in one rack essentially limits how large a single expert layer can be.
This also offers a reasonable explanation for a phenomenon that has long puzzled the industry: some labs may have achieved breakthroughs in large-scale pretraining earlier not because of a single algorithmic lead, but because their in-house accelerator systems have a larger scale-up domain, allowing efficient all-to-all communication to be maintained over a wider range. That in turn supports model forms with higher sparsity and higher activation efficiency without sacrificing inference economics.
The takeaway for engineering teams is direct: when evaluating a training or inference approach, look at the interconnect domain boundary first, then the parallelism partitioning scheme; otherwise it is easy to pay hidden costs in cross-domain communication.
4. Training Side: Data Volume and Deviation from the “Theoretical Optimum”
Another counterintuitive conclusion from the blackboard derivation is that the pretraining data volume of frontier models may reach roughly two orders of magnitude beyond the theoretical optimum determined jointly by model capacity and training duration.
This is not waste but a rational engineering choice, for three reasons:
- Inference cost dominates long-term spending: training is a one-time expense, while inference is ongoing. Making the model larger than the “training optimum” and feeding in data far beyond the optimal ratio can significantly reduce per-token inference cost.
- Data reuse and mixture constraints: high-quality corpora are limited, and repetition rounds and mixture strategies change the effective data volume, so the practical optimum naturally deviates from the theoretical value.
- Nonlinear emergence of capabilities: some capabilities appear reliably only after scale crosses a threshold, so planning must leave headroom.
Expressed with a schematic scaling relationship (illustrative only, not a specific formula):
L(N, D) ≈ A / N^α + B / D^β + L0# N: parameter count, D: data volume, L0: irreducible loss# Training optimum requires D to scale at a fixed ratio to N; engineering practice often exceeds that ratio significantly
5. Inference Side: Batch Size Is the Master Switch for Cost
A frequently overlooked fact: without request batching, the cost of a single inference can be about three orders of magnitude (roughly 1000x) higher.
The reason is that an accelerator’s compute can only be kept fed when it processes enough tokens at the same time. Batch size determines the balance among weight reads, memory bandwidth, and compute utilization:
Cost per token ≈ (weight read cost + compute cost) / effective batch size# Batch too small: weights are moved repeatedly, compute idles, unit cost is very high# Batch large enough: weights are amortized, compute approaches saturation, unit cost drops sharply
This also explains a common pricing pattern in the market: some AI coding tools or chat products offer a “fast mode” priced at several times the standard mode (for example, 6x), while the speed improvement is clearly smaller (for example, 2.5x). The reason is that fast mode uses smaller batches and lower queue latency, sacrificing amortization efficiency.
The reverse question also holds: can a “slow mode” be offered at a lower price? The answer is yes—allowing more aggressive batching and scheduling pushes unit cost down. This is essentially an explicit trade-off between cost and latency, not a difference in model capability.
6. Applying the Constraints in Engineering Practice: A Checklist
- Interconnect first: confirm the scale-up domain size and the cross-domain bandwidth ratio, then decide expert layer size and parallelism partitioning.
- Communication modeling: model all-to-all separately, estimate the proportion of cross-domain tokens, and avoid a system that “can compute but cannot move data.”
- Batch scheduling strategy: online low-latency and offline high-throughput workloads should use different batch strategies; for cost optimization, prioritize batching and priority queues.
- Leave headroom in the training data mixture: work backward from the inference cost target to determine model and data scale, rather than focusing only on training loss.
- Observability: bring batch size, queue latency, cross-domain communication volume, and memory bandwidth utilization into monitoring, alerting, and logging services to close the loop on capacity planning.
- Elastic capacity: pair a stateless inference layer with container platforms and message queues to smooth traffic peaks, and tier hot and cold data into object storage.
7. Conclusion
The way large models look today is the result of solving three things together: physical interconnect, communication topology, and batching economics. Mastering this derivation framework helps avoid detours in selection, capacity planning, and cost control. In general engineering practice on platforms such as Baidu AI Cloud, treating interconnect boundaries and batch scheduling as first-class design concerns often delivers more certain returns than chasing single-point parameters.
