Training Trillion-Parameter Multimodal Models on Chinese AI Accelerators: Engineering Steps and Deployment Considerations
Migrating a training framework to Chinese AI accelerators requires more than getting a model to run. This article covers memory estimation, sharded checkpoint loading with PyTorch FSDP2, sharding and recomputation trade-offs, communication tuning, and validation criteria. It also explains why version tracking, numerical checks, and fault-recovery testing should precede large-scale deployment.
1. Define the Scope and Record Versions
This article addresses the engineering work involved in migrating an existing training framework to Chinese AI accelerator hardware. It does not cover model architecture design.
The code examples use the FSDP2 interfaces in PyTorch 2.6 and later as a reference. Chinese accelerator vendors typically provide device backend plugins, but device names, communication backend names, and initialization procedures vary. Replace the placeholders in the examples with the official syntax for your vendor’s software version.
Before starting the migration, record:
- Accelerator model, cards per node, node count, and interconnect type.
- Vendor software stack, driver, and PyTorch versions.
- Versions of the training framework and multimodal data-processing libraries.
- The source of the reference implementation, such as training records for the same model on another platform.
Every subsequent finding should be tied to the versions under which it was established.
2. Estimate Memory Requirements Before Committing Resources
For mixed-precision training with Adam, a common model-state memory estimate per parameter is:
- bf16 weights: 2 bytes.
- bf16 gradients: 2 bytes.
- fp32 master weights: 4 bytes.
- Adam first- and second-moment states: 4 bytes each, or 8 bytes combined.
The total is approximately 16 bytes per parameter. For a trillion-parameter model, model states alone therefore require roughly 16 TB, excluding activations, communication buffers, and memory fragmentation. This is a byte-based estimate, not a measured result.
Across 512 cards, the average model-state allocation is approximately 32 GB per card, with additional memory needed for activations and buffers. If each card has less memory than this, you will need more cards or a more aggressive offloading strategy.
Use the following worksheet, then validate the estimates with a short trial run:
| Item | Estimation method | What to record |
|---|---|---|
| Parameter shards | Total parameters × 2 bytes ÷ shard count | Measured usage |
| Gradient shards | Total parameters × 2 bytes ÷ shard count | Measured usage |
| Optimizer shards | Total parameters × 12 bytes ÷ shard count | Measured usage |
| Peak activation memory | Depends on sequence length, batch size, and recomputation coverage | Measured peak |
| Communication buffers | Determined by framework configuration | Configured allocation |
| Per-card memory headroom | Reserve 10%–15% of total device memory as a practical guideline | Alert threshold |
3. Load the Model Without Materializing All Weights on One Node
Loading a trillion-parameter checkpoint in full on a single CPU host is not practical. Use the following sequence:
- Convert the original checkpoint into a sharded storage format. Each shard file should record its parameter names, shapes, and data types, with an accompanying index file.
- Construct the model skeleton on the
metadevice without allocating real device memory. - Apply FSDP2 sharding layer by layer. Each rank should then load only its assigned shards into local parameters.
The following code is illustrative, not production-ready. Adapt it to the software versions in use:
import torchimport torch.distributed as distfrom torch.distributed.device_mesh import init_device_meshfrom torch.distributed.fsdp import fully_sharddist.init_process_group(backend="...") # Replace with the vendor's communication backendmesh = init_device_mesh("...", (dist.get_world_size(),)) # Replace with the vendor's device typewith torch.device("meta"):model = build_model(config) # Implement build_model for your modelfor layer in model.layers:fully_shard(layer, mesh=mesh)fully_shard(model, mesh=mesh)model.to_empty(device=local_device) # local_device is provided by the vendor pluginload_sharded_weights(model, index_path, rank=dist.get_rank()) # Implement this loader
Define explicit failure handling for checkpoint loading. If parameter names in the index do not match the model, stop with an error rather than silently skipping them.
After loading, compare parameter means and standard deviations layer by layer against records from before conversion to check for numerical changes. Retain the original checkpoint and verify its hashes.
4. Balance Sharding, Recomputation, and Offloading
There is no universally optimal sharding strategy. Evaluate three trade-offs:
- Sharding granularity: Finer-grained sharding lowers per-card memory usage but increases the number of All-Gather operations. Start with Transformer-layer-level sharding, then use the measured communication share to decide whether to adjust it.
- Selective recomputation: Recomputing attention or MLP modules trades additional computation for lower activation memory. Enable it based on measured compute headroom.
- Optimizer-state offloading: Moving optimizer states to host memory introduces PCIe transfer overhead. Use it only when device memory is insufficient, and compare training-step times before and after offloading.
5. Tune Gradient Synchronization and Communication Overlap
Use profiling rather than assumptions to guide communication tuning:
- Check whether communication overlaps with computation. If All-Gather operations sit on the critical path, adjust prefetch depth.
- Gradient accumulation increases the effective batch size and can reduce fixed communication overhead per training step. When changing the accumulation count, adjust the learning-rate schedule accordingly.
- Mixture-of-Experts (MoE) layers can generate many small messages. Grouping or combining communication may help, but the benefit must be measured.
6. Establish Acceptance Criteria and Troubleshooting Checks
Completing a single training step is not sufficient validation. At a minimum, check the following five areas:
- Numerical consistency: With the same data and random seeds, compare the loss curves over the first few hundred steps against the reference implementation. The team should set acceptable relative-error thresholds according to its accuracy requirements; there is no universal threshold provided here.
- Gradient norms: Record the global gradient norm at fixed intervals and check for abrupt changes or NaNs.
- Throughput and utilization: Record tokens processed per second per card and calculate model FLOPs utilization (MFU). State the source of the peak-compute figure used in the calculation.
- Long-run stability: Train continuously for enough steps to determine whether throughput deteriorates over time.
- Fault tolerance: The loss curve after resuming from a checkpoint should agree with an uninterrupted run. Test node removal and rejoining separately through fault injection.
Common issues and initial checks include:
- Loss is unexpectedly high after loading: Parameter-name mapping errors or a mismatch between the shard index and rank are likely causes.
- The first step runs out of memory: Recheck the memory worksheet, then confirm that the loading path has not inadvertently materialized the full model.
- Throughput is far below expectations: Inspect the communication share in the profiler first, then check whether any operators have fallen back to unoptimized implementations.
7. Risks and Limitations
Several limitations need to remain explicit:
- This article presents an engineering methodology, not measured throughput results for a specific accelerator model.
- Operator coverage in vendor software stacks changes across versions. Some operators may silently fall back to slower implementations.
- Weight-format conversion changes file layout. Validate the converted checkpoint against the original, parameter by parameter.
- Incorrect multimodal sequence packing or attention-mask construction can allow attention to leak between samples. Loss may still decrease, so masks require dedicated validation.
8. Conclusion
A successful migration to Chinese AI accelerators depends on verifiable versions, records, and acceptance criteria at every stage—not on a single line of code.
Begin with small-scale validation on a specified software stack. Confirm numerical behavior, throughput, and fault recovery before expanding the deployment incrementally.
