Training Multimodal Large Models on Chinese AI Accelerators: An Engineering Guide
A practical guide to training trillion-parameter-scale open-source multimodal models on Chinese AI accelerators. It covers hardware and software validation, sharded weight loading, FSDP2 parameter sharding, token-based data pipelines, communication tuning, troubleshooting, and a production-readiness checklist, without relying on a specific accelerator vendor or software stack.
1. Scope and Prerequisites
This guide addresses open-source multimodal models at the trillion-parameter scale. It does not identify a particular model or cite specific parameter counts, release dates, or sources. Before using any model-specific figures, verify them on the model’s official release page.
Confirm the following before starting:
- Cluster configuration: Accelerator count, accelerators per node, and inter-node network topology.
- Software stack: The version combination of drivers, compilers, communication libraries, and the deep learning framework.
- Training precision: BF16, FP16, or mixed precision, including the storage precision of gradients and optimizer states.
- Data characteristics: Visual and text token length distributions, and the maximum sequence length per sample.
- Model architecture: Layer counts and hidden dimensions for the vision encoder and language model, and whether cross-modal attention modules are present.
The methods in this guide do not apply to single-node training of small models, text-only training, or platforms that lack critical operator implementations when custom kernels cannot be developed.
The approach is vendor-neutral and does not depend on a particular accelerator or software stack. All code is illustrative pseudocode, not executable code. Replace the interfaces according to the target platform’s official documentation.
Training models at this scale presents three main engineering challenges:
- Device memory pressure: Parameters, optimizer states, and activations cannot all fit on one accelerator, making sharding and offloading necessary.
- Communication pressure: Sharding introduces frequent collective communication during forward and backward passes, placing substantial demands on interconnect bandwidth and scheduling.
- Load imbalance: Joint training of vision encoders and language models involves widely varying sequence lengths, which can leave ranks with uneven workloads.
2. Validate Hardware and Software Before Training
Advertised specifications are reference points, not substitutes for measurements on the target machines. Establish a baseline before running training.
| Metric | Measurement method | Acceptance criteria | Troubleshooting |
|---|---|---|---|
| Device memory bandwidth | Platform-provided memory-copy benchmark | Record the ratio of measured to advertised bandwidth | Check driver versions and device frequency policies |
| Intra-device and inter-device interconnect bandwidth | All-reduce and all-gather benchmarks; plot bandwidth against message size | Confirm that bandwidth approaches a plateau as message size increases; record small-message performance separately | Check drivers, topology connections, and process CPU affinity |
| Matrix multiplication throughput | Benchmark representative matrix sizes at the target precision; record achieved TFLOPS | Establish a baseline for comparison with training throughput | Check power limits, temperature, and whether operators use reference implementations |
| Operator coverage | Enumerate model operators and inspect backend implementations | Maintain a complete fallback list with an assessment for every entry | Develop custom kernels or select alternative implementations |
| Device visibility and communication library versions | Environment-check script that prints devices and versions for each rank | Verify consistent device visibility and library versions across ranks | Standardize environment variables and reinstall inconsistent components |
If measured collective communication bandwidth is substantially below the advertised figure—for example, less than half—check drivers, topology connections, and process CPU affinity before attributing the problem to hardware. This threshold is only a rule of thumb and must be assessed in the context of the actual cluster.
An operator coverage check can follow this pattern:
# Illustrative pseudocode; replace interfaces for the target platform.for op in collect_model_ops(model):if not target_backend.has_impl(op):record_fallback(op) # Record the fallback operator.fallback_to_reference_impl(op) # Use a reference implementation or develop a kernel.
For each fallback operator, record:
- Operator name
- Call frequency
- Share of execution time
- Alternative implementation
- Responsible owner
Evaluate fallback operators separately during performance analysis. Operator coverage often accounts for a substantial share of platform adaptation work, so plan for it early.
3. Model Loading and Sharded Initialization
A trillion-parameter-scale model cannot be loaded in full onto a single accelerator. Weight loading must therefore be designed together with the sharding strategy.
3.1 Build the Model on the Meta Device
Construct the model on the meta device first. This records tensor shapes and data types without allocating actual device memory.
At this stage, validate the model structure, including total parameter count, layer dimensions, and shared-parameter bindings.
3.2 Map Parameter Shards to Ranks
Use the sharding plan to determine which rank owns each parameter shard. The mapping should contain:
- Parameter name
- Tensor shape
- Target rank
- Sharding dimension
Save the mapping to disk so that loading failures can be reproduced and investigated.
3.3 Stream and Materialize Weights by Rank
Each rank should read and materialize only the shards it owns, avoiding excessive peak host memory usage.
Read shards in chunks. After transferring each chunk to the device, release its host buffer immediately.
3.4 Measure Peak Memory Usage
Record both:
- Peak device memory usage per accelerator
- Peak host memory usage
If either approaches its limit, reduce concurrent reads or increase the number of shards, then repeat the loading process.
3.5 Recover from Loading Failures
Handle loading failures in the following order:
- Preserve the original weight files. Do not modify or delete them.
- Remove temporary shards created by the failed load.
- Use the saved mapping to identify missing or corrupted shards, and reread only those shards.
- If failures persist, fall back to the last usable checkpoint and record the failed shard IDs and error messages.
4. Per-Parameter Sharding with FSDP2
The core principle of per-parameter sharding is to gather full parameters only when they are needed and release the gathered copies afterward.
4.1 Define the Sharding Plan
Use Transformer blocks as the basic grouping unit.
Group the vision encoder and language model separately. Avoid mixing parameters from both modalities in one group so that each module’s sharding strategy can be adjusted independently.
4.2 Group Parameters
Place parameters from the same computation block in the same group to reduce the number of communication operations.
Groups that are too small generate many small messages and reduce communication efficiency. Groups that are too large increase the memory required by each all-gather.
4.3 Schedule Communication
- Forward pass: Run all-gather before computing a group to assemble its full parameters. Release nonlocal shards after leaving the group.
- Backward pass: After computing a group’s gradients, run reduce-scatter to distribute gradient shards to their owning ranks.
- Prefetching: Start the next group’s all-gather while computing the current group to overlap communication with computation.
# Illustrative pseudocode; not directly executable.for group in shard_plan.groups:shard_group(model, group, mesh=device_mesh)# The framework automatically performs all-gather during the forward pass# and reduce-scatter during the backward pass.
Replace these interfaces with those supported by the target platform.
4.4 Balance Memory and Communication
Finer-grained sharding reduces per-device memory usage but increases communication frequency.
Tune based on measurements. Start with relatively coarse groups, inspect memory headroom and the fraction of step time spent communicating, then subdivide groups gradually.
4.5 Validate Correctness
After changing the sharding strategy:
- Compare single-device and multi-device loss curves on a small model. Use the same random seed and compare the first several steps.
- Save a sharded checkpoint, reload it fully, and compare every parameter against its value before saving.
- Monitor the global gradient norm. If one group’s gradient norm differs substantially from others, inspect its sharding and communication order.
5. Build a Multimodal Data Pipeline
Visual and text token lengths can differ substantially. Assigning batches by sample count alone can produce uneven workloads across ranks.
5.1 Form Batches by Token Count
Organize batches by total token count rather than sample count, with a token budget for each batch.
Place long-sequence samples in separate buckets. Pack short sequences where appropriate to reduce padding waste.
5.2 Balance Work Across Ranks
Each rank should perform a similar amount of work at every step. Track:
- Variance in token counts across ranks per step
- The gap between the slowest rank’s step time and the average
If the gap remains large, adjust bucket boundaries or use dynamic batching.
5.3 Overlap Data Loading with Computation
Data reading and preprocessing should overlap with model computation. Monitor:
- The fraction of time accelerators spend waiting for data
- Whether the data-loading queue remains empty for extended periods
If data wait time is high, increase the number of loading workers or prefetch depth, and check storage bandwidth.
5.4 Tune the Pipeline
- Measure visual and text token length distributions in the training dataset.
- Set the per-batch token budget and define bucket boundaries using quantiles.
- Run several steps and record workload variance across ranks and data wait time.
- Adjust bucket boundaries if workloads are uneven. Adjust loading workers and prefetch depth if data wait time is high.
- Change only one setting at a time and record the effects on throughput and loss.
6. Optimize Gradient Synchronization and Communication
6.1 Overlap Communication with Computation
Overlap gradient synchronization with backward computation wherever possible.
Inspect the profiler timeline to determine whether communication and computation kernels overlap. If they execute serially, check when communication is launched and which dependencies delay it.
6.2 Use Gradient Accumulation
Increasing gradient accumulation steps can reduce synchronization frequency, but may increase per-step memory usage and lengthen the interval between parameter updates.
Evaluate the trade-off between throughput and convergence speed.
6.3 Tune Communication Buckets
Gradient communication bucket size affects bandwidth utilization.
Start with the default size, then use the bandwidth curves measured in Section 2 to guide tuning. Small buckets increase scheduling overhead; large buckets can delay the start of communication.
6.4 Validate Low-Precision Communication
Low-precision communication reduces transferred data volume but may affect numerical stability.
Before enabling it at scale, compare loss curves in small-scale experiments and monitor gradient overflow and NaN occurrences.
6.5 Measure and Tune
Track the fraction of step time spent communicating and whether loss remains stable. The goal is to reduce communication overhead without causing loss divergence.
Follow this process:
- Record baseline step time and communication time share.
- Adjust bucket size, changing one setting at a time, and measure the communication share.
- If communication overhead decreases, validate the loss curve. Revert the setting if loss behaves abnormally.
- Freeze the best validated configuration and save it in the training configuration.
7. Troubleshoot Common Failures
| Symptom | Possible cause | Investigation and corrective action |
|---|---|---|
| Host out-of-memory failure during loading | Too many concurrent reads or too few shards | Reduce concurrent reads, increase shard count, and reload |
| Device out-of-memory failure during training | Groups are too large or activations are not recomputed | Split groups further, enable activation recomputation, and inspect peak memory records |
| Collective communication timeout | Topology problems, inconsistent drivers, or a stalled rank | Inspect logs from every rank; verify driver versions and CPU affinity settings |
| Throughput substantially below baseline | Operators are using reference implementations or data wait time is excessive | Review the fallback operator list and measure data wait time |
| NaN loss | Low-precision overflow or an excessive learning rate | Inspect gradient norms and reproduce with low-precision communication disabled |
| Multi-device loss differs from single-device loss | Misaligned random seeds or incorrect gradient reduction order | Repeat correctness checks on a small model and compare outputs layer by layer |
Start troubleshooting by comparing against the baselines established in Section 2. Without a baseline, it is difficult to determine whether current behavior is abnormal.
8. Production-Readiness Checklist
Before launching the training run, confirm that:
- Hardware measurements are recorded and compared with advertised specifications, and anomalies have been investigated.
- Operator coverage checks are complete, with all required fields recorded for fallback operators.
- Device visibility and communication library versions are consistent across nodes.
- Peak memory usage during weight loading remains within safe limits, and the recovery procedure has been tested.
- The sharding plan and rank-to-shard mapping are saved, and small-model correctness checks have passed.
- Data pipeline load balance and data wait time meet predefined targets.
- Communication overhead has a recorded baseline, and loss remains stable after tuning.
- The training configuration is frozen and version-controlled, and a usable rollback checkpoint is available.
After launch, continue monitoring throughput, communication time share, and loss. If any metric deviates from its baseline, follow the troubleshooting guidance in Section 7.
