Adapting Trillion-Parameter Multimodal Model Training to Domestic AI Computing Platforms: Key Considerations
This guide is for teams with existing PyTorch training code who plan to migrate training jobs to a domestic Chinese integrated training-and-inference computing platform. It covers hardware verification, operator adaptation and fallbacks, FSDP2-based sharded training, checkpoint resume, acceptance metrics, and troubleshooting. The values and thresholds given are starting recommendations that must be recalibrated for your target model, cluster size, and platform version.
1. Scope
This article is intended for teams that already have PyTorch training code and plan to migrate training jobs to a domestic Chinese AI computing platform that integrates training and inference. All values and thresholds here are starting recommendations and must be recalibrated based on the target model, cluster scale, and platform version.
If the target platform does not yet provide a distributed backend matching your PyTorch version, confirm the version compatibility matrix with the platform vendor before proceeding.
2. Hardware Checks
Verify hardware capabilities before going live. Every check item must have a corresponding validation method.
| Check Item | Validation Method | Starting Recommendation |
|---|---|---|
| Per-GPU memory | Estimate peak memory from sharded parameters, gradients, optimizer states, and activations | Estimated peak should not exceed 85% of usable per-GPU memory, leaving headroom for fragmentation and communication buffers |
| Inter-GPU and inter-node interconnect | Run collective communication benchmarks and record all-reduce and all-to-all bandwidth | Compare measured bandwidth against the vendor’s baseline; any gap must have a clear explanation |
| Mixed precision | Run numerical comparisons of BF16 forward and backward passes on key operators | Relative error against the reference precision stays within an acceptable range, with no NaN or Inf |
| Operator coverage | Run a full forward and backward pass with a small model | Every operator has a native implementation or a registered fallback plan |
Validate operator coverage with a small model first, then scale up gradually. This surfaces hidden incompatibilities early, instead of discovering them only after submitting a full-scale job.
3. Operator Adaptation and Fallbacks
The core operators that multimodal large models depend on include attention, normalization, matrix multiplication, activation functions, and, for MoE models, routing and grouped matrix operations. Handle each operator in three steps:
- Confirm whether the platform provides a native high-performance implementation.
- If not, compose a substitute from operators already available in the framework. For example, combine silu with element-wise multiplication to build an activation function.
- If performance is still insufficient, write a custom kernel and record its numerical error against the reference implementation.
A fused SwiGLU implementation looks like this. The input x already contains the concatenated gate and up projections:
import torch.nn.functional as Fdef swiglu(x):gate, up = x.chunk(2, dim=-1)return F.silu(gate) * up
The output of this function matches the standard SwiGLU definition. After replacing any operator, fix the random seed and compare both output error and per-step latency. If the error exceeds the threshold or performance does not improve, roll back to the previous implementation.
4. Sharded Training Pipeline
Take PyTorch FSDP2 as an example; its API is torch.distributed.fsdp.fully_shard. The PyTorch version on the target platform is determined by the vendor’s officially adapted release—do not assume its behavior matches the community release.
Validate in the following order:
- Sharded loading: Build the model on the meta device, apply
fully_shardlayer by layer, and then load weights. This avoids the memory spike caused by fully loading the model first and sharding it afterward. - Communication primitive mapping: Test all-gather, reduce-scatter, and all-to-all separately with small tensors, and confirm results match single-GPU computation.
- Gradient alignment: Run the same data on two or four GPUs versus a single GPU, and compare the gradient norm of the first step.
from torch.distributed.fsdp import fully_shardfor block in model.blocks: # example attribute name; replace with the actual model structurefully_shard(block)fully_shard(model)
Multimodal training also requires handling the following:
- Data pipeline: Use asynchronous prefetching. Tune the DataLoader’s num_workers and prefetch_factor based on throughput test results.
- Model assembly: Design sharding granularity separately for the vision encoder and the language model. A relatively small vision encoder can be wrapped as a whole.
- Activation recomputation: Enable activation checkpointing on Transformer blocks to trade extra compute for memory.
- Communication-computation overlap: Use a profiler to check whether communication is hidden by computation. If there is no overlap, first inspect sharding granularity and prefetch settings.
5. Checkpoint Resume
Use torch.distributed.checkpoint to save sharded checkpoints, with each rank writing its own shard. Also save metadata, including the version number, world size, and sharding configuration.
When resuming, first compare the world size and sharding configuration. If they do not match, load via resharding if the platform supports it; otherwise, fail immediately with an error rather than loading silently. After each resume, the loss over the first 10 steps should remain continuous with the pre-interruption trend. Retain the most recent N checkpoint versions based on disk capacity, where N is set by the project.
6. Acceptance Metrics
| Metric | Measurement Method | Starting Recommendation |
|---|---|---|
| Numerical alignment error | Relative error of the first N steps of loss against the reference implementation on identical data | Within 1% |
| Gradient norm deviation | Relative deviation of the first-step gradient norm from the reference implementation | Within 1% |
| Peak memory | Maximum value per step from the framework’s memory statistics API | Below 85% of usable per-GPU memory |
| Communication bandwidth utilization | Statistics from the communication library or profiler | A drop of more than 20% versus the benchmark requires investigation |
| Training throughput | Tokens/s measured per step | Any gap versus the reference platform must have a confirmed cause |
| Long-run stability | Continuous runtime and failure count | Target duration is set by the project schedule; no unhandled failures are allowed during the run |
7. Troubleshooting and Rollback
- Startup failure: First check device visibility and backend initialization logs, then progressively reduce the parallelism scale to locate the failing stage.
- Loss divergence: First check BF16 overflow and learning rate warmup settings, then compare gradient norms layer by layer.
- Version rollback: Before every change, save the configuration and checkpoint of the last working version. If a problem occurs, restore that version.
8. Applicability Boundaries
The methods in this article apply to adapting dense and MoE model training within the PyTorch ecosystem. If the target platform lacks critical operators, and neither fusion nor custom kernels can close the performance gap, evaluate model architecture changes or alternative hardware first rather than submitting full-scale training directly.
The team needs to be proficient with distributed training and profiling tools. The migration timeline mainly depends on the number of operator gaps and the maturity of the distributed backend, and the project schedule should reserve buffer accordingly.
