Trillion-Parameter LLM Training on Domestic AI Accelerators: A Full-Pipeline Adaptation Guide
This article walks through the engineering behind adapting a trillion-scale (2.8T-parameter) sparse multimodal MoE model for training on domestic AI accelerators. It explains why such models must be sharded before training, how to design a memory-friendly weight-loading path, how to orchestrate FSDP together with tensor and expert parallelism across a multi-dimensional device mesh, how gradient synchronization and communication-computation overlap work under sharding, and the extra complexity introduced by multimodal workloads. It closes with a three-layer acceptance checklist (single-step numerical alignment, convergence-curve alignment, and performance/memory baselines) and a reusable adaptation workflow that teams can turn into a repeatable pipeline.
1. Introduction: The engineering scale behind a “training adaptation”
Recently, an open-source community released a flagship large model with 2.8 trillion parameters. Around the same time, a domestic hardware vendor announced that its flagship training-and-inference integrated AI accelerator, together with its software stack, had completed training adaptation for the model and built a native full-sharded data parallel (FSDP) multimodal training path — connecting the full chain from model loading and shard scheduling to gradient synchronization.
Put together, these two events send a signal worth paying attention to: support from domestic compute platforms for ultra-large models is moving from “can run a few operators” to “can run the complete training pipeline end to end.”
The announcement is only a couple of sentences, but behind the phrase “training adaptation” sits an entire systems-engineering effort. It has to answer four questions:
- Can the model be loaded correctly: Is the weight layout complete, and is the metadata accurate?
- Can parameters be partitioned sensibly: How can limited memory hold trillion-scale parameters?
- Can gradients be synchronized correctly: Are numerics stable under mixed precision, and can communication overlap with computation?
- Can training run steadily over time: Is the loss healthy, and is long-running stability guaranteed?
Using a trillion-parameter sparse multimodal model as an example, the rest of this article breaks down the approach, methods, and validation for full-pipeline adaptation.
2. Why a trillion-parameter model must be “sharded first, trained second”
1. Four structural shifts
Compared with a ten-billion-parameter model, the challenge of a 2.8-trillion-parameter model is not simply “more parameters.” There are four structural shifts, and each one changes the design of the adaptation.
- A jump in scale: Crossing the trillion-parameter mark completely overturns the premise that “the model fits on a single card.”
- Sparse structures become common: Flagship models generally use a mixture-of-experts (MoE) architecture that activates only a small fraction of the total parameters on each forward pass. This introduces new bottlenecks around expert routing, All-to-All communication, and load imbalance.
- Multimodality becomes standard: Encoders for text, images, and other modalities must be trained together, which sharply increases the heterogeneity of the computation graph.
- Higher fault-tolerance requirements: Training runs often last weeks, and any unexpected interruption can cause costly compute loss.
2. A quick calculation that makes the memory constraint clear
Memory is the first hard constraint in adaptation. Take mixed-precision training with “data parallelism + the classic Adam optimizer” as an example, and we can roughly compute the memory taken by model states. Let the total number of parameters be Ψ. The per-parameter byte breakdown is:
- BF16 parameters: 2 bytes
- BF16 gradients: 2 bytes
- FP32 master copy of parameters: 4 bytes
- First-order and second-order momentum: 4 bytes each, 8 bytes total
That is 16 bytes/parameter in total. Plugging in Ψ = 2.8×10¹², the model states need roughly 44.8 TB of memory — and that excludes activations, temporary buffers, and communication buffers. Under a common “8 cards per node” deployment, you would need 5,600 accelerators just to barely fit the model states.
Step back for a moment: even if we assume a card is a memory-rich flagship training-and-inference accelerator with 160 GB per card, you would still need at least 280 cards. And a card holding a model of that scale must simultaneously cover parameters, gradients, optimizer states, activations, and various temporary buffers — plus the kernel stack and fragmentation, which already push a single card near its limit. At that point, the attention activations from long sequences have likely already consumed all the available memory.
There is also a key assumption here: in data parallelism, every card keeps a complete copy of the model. So even if the total number of GPUs exceeds 280, memory usage does not drop as a result. The extra burden from optimizer states makes this clear:
- One Adam update step on the FP32 master weights itself requires multiple memory accesses: “read weights + read two momenta + write back weights.”
- Compared with SGD without optimizer states (about 2 bytes/parameter), memory is amplified 8× directly.
The table below gives a qualitative comparison of different parallelism strategies.
| Dimension | Traditional data parallelism (with classic optimizer) | Full-sharded data parallel (FSDP) | Tensor/expert parallelism (“splitting the compute”) |
|---|---|---|---|
| What gets split | Only the input data; each card holds the full model | Parameters, gradients, and optimizer states split along the data-parallel dimension | Parameters and compute of a single operator or layer |
| Per-card model states | ≈16Ψ bytes, independent of card count | ≈16Ψ/N bytes (N = shard count) | Decreases linearly with the split |
| Main communication | Gradient All-Reduce | Weight All-Gather and gradient Reduce-Scatter | All-to-All, All-Reduce (varies by split dimension) |
| Added complexity | Low | Parameter sharding and gathering scheduling | High; usually combined with FSDP |
The conclusion is clear: a trillion-parameter model must be “sharded first, trained second.” FSDP answers “how to split,” while hybrid parallelism answers “at what granularity to split.”
3. The starting point of the pipeline: model loading and a memory-friendly weight layout
1. Three typical pitfalls at the loading stage
Loading is the first step of the whole pipeline, and it is also the most easily underestimated. In practice, this step is where you most often hit three pitfalls.
- Building the graph all at once: If you instantiate the entire model on real devices at once, peak memory is roughly equal to one full set of model states — tens of TB, which is clearly impossible.
- Initialization cost: Even if you do not build on real devices, constructing random weights layer by layer on the CPU still means traversing all parameters and consuming random-number generation, and the time cost is not negligible either.
- Mismatch between metadata and the actual layout: For example, the shard list recorded in an index file does not match the actual files, tensor names do not match, or the length of a non-persistent parameter (such as positional encoding) does not match the current context length.
2. A stepwise loading strategy
To address these problems, the mainstream approach cleanly separates “structure definition” from “weight loading”:
- Empty-shell graph construction: Use a “meta device” to build the model structure from config. At this point only metadata such as tensor shapes and dtypes exists; no actual storage is allocated.
- On-demand assembly: Read weight files shard by shard, and bind the real tensors to the corresponding modules via
assign. - In-place sharding: Once the sharder finishes splitting, it immediately frees the original weights, keeping resident memory down to the size of a single-card shard.
Key code (illustrative, not tied to any specific framework’s API) is as follows:
import torchfrom torch.distributed.device_mesh import init_device_mesh# Illustrative interface: naming differs across frameworks, use per your version's docsfrom torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy# 1) Empty-shell graph construction: build structure on the meta device only, no real memorywith torch.device("meta"):model = build_model(config)# 2) Shard-by-shard loading: replace weights in place, free the original tensors after loadingload_checkpoint_shard(model, shard_id=rank_id, assign=True)# 3) Mixed-precision policy: resident shards use BF16# compute runs in BF16, gradient reduction runs in BF16, master weights stay FP32mp = MixedPrecisionPolicy(param_dtype=torch.bfloat16,reduce_dtype=torch.bfloat16)# 4) Wrap each layer as a shard unit, then wrap the outer model as a wholefor block in model.blocks:fully_shard(block, mp_policy=mp, reshard_after_forward=True)fully_shard(model, mp_policy=mp, reshard_after_forward=True)
Two things about this code are worth noting:
- Per-layer wrapping: Wrap each Transformer block as an independent shard unit, rather than treating the whole model as one unit. Only when the granularity is fine enough can the forward All-Gather and the backward Reduce-Scatter be “hidden” behind compute, forming a pipeline where communication and computation overlap. If it is one whole unit, you can only start computing after all weights are gathered, and communication is fully exposed on the critical path.
- Mixed-precision policy: Both resident shards and computation uniformly use BF16. BF16’s exponent bits are the same as FP32, so its dynamic range is on par with single precision, which usually means no gradient scaling (loss scaling) is needed. But high-precision state such as momentum and the master weights should still be maintained in FP32, which directly affects the gradient-synchronization design later on.
Two engineering notes:
- When loading a massive number of shards via object-storage mounts or a distributed file system, watch out for metadata access amplification (latency amplification from too many small files) and I/O bandwidth.
- Lifecycle management for the training set and checkpoints (periodic archiving, keeping multiple versions, storing by training task in separate directories) should be designed alongside, otherwise a single failed rerun of a trillion-parameter model can cost days.
4. Shard scheduling: from “data parallelism” to “compute is also parallel”
Loading only solves “it fits.” Shard scheduling is about “splitting correctly, splitting evenly, and splitting economically.”
1. A 3D device mesh and parallelism-dimension orchestration
On top of FSDP, ultra-large models usually add two more “split-the-compute” parallelism dimensions to form a multi-dimensional device mesh:
- Tensor parallelism (TP): Split a single operator (such as the linear projection of attention heads, or the two matrix multiplications of the MLP) along one dimension; each card computes part of it and stitches the result back with All-Reduce or All-Gather. It solves “a single layer does not even fit” and “single-card compute is insufficient.” The cost is frequent in-layer synchronization, so it must be confined to a node’s high-speed interconnect domain.
- Expert parallelism (EP): An MoE model assigns different experts to different cards, and tokens are sent via All-to-All to the card holding their target expert based on routing results. It solves “there are too many expert parameters” and “a single card cannot hold all experts,” while naturally spreading sparse parameters across more cards.
Here is typical mesh setup code:
# Device mesh sketch: dp is the data-parallel dim, tp is the tensor-parallel dim, ep is the expert-parallel dimmesh = init_device_mesh(device_type="cuda", mesh_shape=(dp, tp, ep),mesh_dim_names=("dp", "tp", "ep"))# Dense layers: split operators along the tensor-parallel dim# Sparse layers: split experts along the expert-parallel dimplan = ParallelPlan(dense=RowColParallel(tp_mesh=mesh["tp"]),moe=ExpertParallel(ep_mesh=mesh["ep"], capacity_factor=1.25),)# FSDP adds another split on top of the dense-layer TP combination dim (illustrative, 2D combination)shard_mesh = mesh[("tp", "dp")].reshape(mesh["tp"].size() * mesh["dp"].size())model = shard_model(model, shard_mesh, mp_policy=mp)
A note: the table above is only a qualitative comparison. Which combination to choose depends on the cluster topology and model structure; there is no universal answer. In practice, the decision generally follows this order:
- First, decide whether TP is needed, and to how many ways to split it, based on “the parameters and activation scale of the largest single-layer operator.”
- Then, decide the scale of EP based on “how many experts a single card can hold.”
- Allocate the remaining cards to the FSDP/data-parallel dimension.
2. Two easily overlooked details
On the FSDP shard group: The FSDP shard group often covers the TP dimension (i.e., a 2D combination of TP × FSDP), and there is an easily overlooked implication.
- A fragment of a single parameter on the “parameter sharding” dimension does not necessarily all land on the same TP card.
- But TP weight loading usually requires that “cards in the same TP group” each hold a complete copy of the same parameter and then each take their own slice.
- So you need a “shard → TP split” weight rearrangement.
Also, FSDP’s HSDP mode (two-level reduction inside and outside the shard group) only holds when “single-card memory is abundant.” Trillion-scale models must be truly sharded, so this shortcut is not available.
On MoE load imbalance: Expert routing is data-dependent. If some experts are selected by a large number of tokens, they become “long-tail experts” and slow down the whole step. Common countermeasures include:
- Capacity factor: limit the number of tokens each expert receives; the excess is dropped or overflowed to shared experts.
- Load-balancing loss: explicitly penalize routing skew in the training objective.
- Grouping experts and combining with tensor parallelism: spread hot experts across more cards.
5. Gradient synchronization: the correctness and performance core of trillion-parameter training
Gradient synchronization is the “heart” of the whole pipeline. Whether the adaptation is truly complete ultimately comes down to whether this step is correct and fast enough.
1. Gradient semantics under sharding
In traditional data parallelism, each card holds the full gradient; All-Reduce sums the gradients and divides by the data-parallel degree, and each card ends up with the same averaged gradient.
In FSDP, the semantics become Reduce-Scatter:
- Each card only reduces the parameter segment it is responsible for and ultimately holds only its own shard’s gradient.
- The communication volume is roughly half that of a traditional All-Reduce (down from 2(N-1)/N times the parameter size to (N-1)/N times).
But when the semantics change, the bar for correctness validation rises accordingly:
- Is the gradient mean mathematically equivalent to single-card?
- Is the reduction dtype BF16 or FP32?
- How is an operation needing global statistics, such as gradient clipping, correctly implemented when “each card holds only part of the gradient”?
In practice, there are three common approaches:
- Sync first, then clip: After Reduce-Scatter completes, aggregate the global gradient norm with one All-Reduce, then clip uniformly. Simple to implement, but adds one more communication.
- Deferred clipping: Cache the Reduce-Scatter output and do a global clip once after the backward finishes. Requires extra memory.
- Shard-local clipping with a global correction: Each card clips its local shard first, then applies a consistency correction to the scaling coefficient. Mathematically more complex, requiring rigorous derivation and validation.
A common mistake is “clip directly on the local shard, then update normally.” This ignores that the gradient norms differ across shards, introduces a systematic bias, and causes the loss to descend more slowly or even oscillate.
2. Communication-computation overlap
FSDP’s performance ceiling largely depends on “how much of the communication can be hidden behind compute.” There are three tunable items in practice:
- Shard granularity: The finer the shards, the more pipeline stages, and the better communication and computation overlap — but the scheduling overhead also grows.
- Whether to reshard immediately after forward (
reshard_after_forward): Resharding saves memory but requires another All-Gather of weights during backward, adding one communication. - Prefetching: Launch the next layer’s All-Gather ahead of time, hiding the communication inside the current layer’s compute.
For MoE models there is an additional consideration: All-to-All and FSDP’s All-Gather/Reduce-Scatter compete for interconnect bandwidth at the same time. If the two are not staggered across levels, bandwidth contention easily arises. The usual practice is to place EP within a node and FSDP across nodes, so the two kinds of communication use different levels of the interconnect as much as possible.
3. Guarantees for long-running stability
Trillion-parameter training is measured in weeks, so fault tolerance must be as important as training capability. Common measures include:
- Periodically writing parameters, optimizer states, RNG states, and the data-loader position together to disk, ensuring the loss curve connects strictly after resuming from a checkpoint.
- Having the monitoring layer automatically detect and isolate hardware errors and slow cards (stragglers), avoiding “one slow card dragging down the whole cluster.”
- Storing checkpoints in a sharded format to avoid single-point writes becoming a bottleneck.
6. Multimodal adaptation: the added complexity of heterogeneous computation graphs
Adapting a pure-text model already has a mature paradigm. The difficulty with multimodal models is that the computation graph is heterogeneous: the same card may run convolution, attention, pooling, and other operators simultaneously, and the memory usage and compute intensity differ greatly across stages.
First, the parameters and compute intensity of modality encoders differ significantly. A vision encoder is usually a dense model with moderate parameters and high compute intensity; a text decoder is a huge sparse model. If you apply the same parallelism strategy to both, one side will necessarily be “split too finely” or “not split enough.” The common approach is divide and conquer: use TP on the vision side, FSDP + EP on the text side, and connect the two with All-Gather or All-to-All.
Second, variable image resolution and text length cause per-step compute and memory usage to fluctuate. Adaptation needs to reserve a memory headroom and use gradient accumulation to keep the global batch size stable at the target value.
Third, contrastive-learning objectives need cross-card aggregation. For example, in image-text contrastive training, negative-sample pairs need features gathered across all data-parallel cards before computing the similarity matrix. This introduces extra All-Gather whose scale grows with the global batch size. During adaptation, it must be considered within the same communication budget as gradient synchronization, otherwise it easily becomes a hidden bottleneck.
Fourth, how multimodal inputs are organized. Image/text interleaving and variable-length sequences need unified sample organization (packing) and attention-mask strategies. The generation and propagation of attention masks must be consistent with the parallelism strategy, otherwise you get “silent errors” that compute but compute wrong — the loss looks like it is decreasing, but nothing is actually being learned.
7. Correctness validation and performance tuning: the acceptance criteria for “adaptation complete”
“Adaptation complete” is not the same as “adaptation successful.” The following three layers of validation should be run in order.
1. Single-step numerical alignment
- Fix the random seed, fix the input batch, and disable gradient clipping and any non-deterministic operators.
- Run one step at single-card or minimal parallelism, and compare the loss, gradient norm, and parameter-update magnitude between the “domestic platform” and the “reference platform.”
- Differences should be within floating-point error (typically within 1e-3 relative error, depending on the dtype).
This step catches 90% of “silent errors.”
2. Convergence-curve alignment
Run a few hundred to a few thousand steps on a small dataset and compare the trend and final convergence level of the two loss curves. If the domestic platform converges more slowly or shows abnormal jitter, prioritize checking:
- Gradient-clipping implementation;
- Mixed-precision policy;
- Whether optimizer states are correctly sharded.
3. Performance-baseline comparison
Measure with model FLOPs utilization (MFU):
MFU = actual training throughput (tokens/s) × per-token compute / (card count × single-card peak compute)
For sparse models, per-token compute should be estimated from the number of activated parameters (not the total parameter count).
For memory headroom, watch peak usage and the communication buffer.
8. A reusable adaptation checklist
Consolidating the above practice into an executable checklist:
- Do the math first: Use the 16Ψ-byte formula to estimate model states and determine the minimum card count and split dimensions.
- Then set the mesh: Orchestrate in the order “a single layer fits → experts fit → remaining cards to FSDP.”
- Load with an empty shell: Meta-device graph construction, shard-by-shard loading, in-place sharding — three steps to keep the peak during loading low.
- Three-piece sync set: Reduce-Scatter, global clipping, checkpoint persistence — validate the semantics of each.
- Overlap through granularity: Trade fine-grained shard units, prefetching, and staggered communication for throughput.
- Three-floor acceptance: Single-step numerical alignment → convergence-curve alignment → MFU and memory baselines.
9. The cloud environment: turning adaptation from “one-off” to “reusable”
Finally, from a platform perspective, training adaptation for trillion-parameter models is often not one-off work. It is more like an engineering pipeline that needs continuous maintenance. On cloud platforms such as Baidu AI Cloud, this kind of work can typically be realized with the following general capabilities:
- Container platform: Package training images and distributed launch configuration in a containerized way, ensuring consistent environments across experiments of different scales and avoiding “voodoo problems caused by inconsistent environments.”
- Object storage: Host checkpoints and training datasets, naturally fitting the small-file, write-heavy nature of sharded weights.
- Logging and monitoring/alerting: Centrally collect training metrics and hardware metrics from each rank, and set threshold alerts for loss anomalies, slow cards, and communication timeouts.
- Message queue: Asynchronously decouple data preprocessing from training to ease data-supply jitter.
For teams that need to repeatedly validate adaptation correctness, the value of this combination is that it turns one-off adaptation experience into a repeatable pipeline, rather than starting from scratch every time.
10. Conclusion: adaptation capability is fundamentally systems-engineering capability
From “model loading” to “gradient synchronization,” training adaptation for trillion-parameter models is not a victory of any single technique but a concentrated expression of systems-engineering capability.
- It requires a precise ledger for memory;
- A clear understanding of communication topology;
- Rigorous validation standards for numerics;
- Sufficient fault-tolerance design for long-running stability.
When a domestic compute platform completes training adaptation for such a flagship model, it means its software stack has moved from “usable” to “good to use.” For developers and enterprise users, what is more worth paying attention to is the method itself: shard first, then train; validate first, then scale; checklist first, then automate. This method does not depend on any specific hardware and can be reused across different platforms and model scales — that is the true long-term value of adaptation capability.
