Training Multimodal Large Models with FSDP2 on Domestic AI Accelerator Cards: Key Steps
This article presents a practical workflow for training large multimodal models with native FSDP2 on domestic AI accelerator cards. It covers memory usage analysis, multimodal data pipeline bottlenecks, software stack and version validation, sharded checkpoint loading, layer-wise and hybrid sharding layouts, MoE considerations, gradient synchronization and communication overlap, common troubleshooting, validation records, training risk control, and platform selection criteria.
Start With the Conclusion
Training very large multimodal models on domestic AI accelerator cards usually hinges on whether the software stack can support the full distributed training workflow. Peak compute alone cannot determine whether training will run stably. A workable approach is to organize parameter sharding with the framework-native FSDP2 interface, configure sharding strategies separately according to the characteristics of each submodule, and then validate peak memory, communication overlap, and checkpoint recovery item by item.
The code and configurations in this article are generic. Device type names, communication backend names, and version numbers must follow the official documentation of the vendor being used. The memory estimates and performance numbers here are only order-of-magnitude references. Final conclusions should be based on actual measurements with your own model, data, and configuration.
Why Memory Is Insufficient
During training, memory is mainly occupied by two categories of content. The first is model state, including parameters, gradients, and optimizer states. The second is activations and temporary buffers, which depend on sequence length, batch size, and model structure.
In common mixed-precision training, each parameter usually corresponds to a low-precision compute copy, an FP32 master weight, a gradient, and the first and second moments of the Adam optimizer. Under this configuration, the model state for each parameter is roughly on the order of 10+ bytes. When the parameter count reaches hundreds of billions or more, a single machine cannot hold a complete copy in memory.
FSDP2 shards parameters, gradients, and optimizer states along the data-parallel dimension. Each card keeps only a portion long term. During forward and backward computation, the framework temporarily aggregates the parameters needed by the current layer and releases them immediately after computation. Therefore, the per-card footprint of model state is roughly inversely proportional to the size of the sharding group.
Activations do not automatically decrease because of sharding. Reducing activation memory requires other methods, such as activation recomputation, sequence parallelism, and reducing micro-batch size. When troubleshooting memory issues, measure model state and activation usage separately, then decide which item to adjust first.
Will the Multimodal Data Pipeline Become a Bottleneck
Decoding, resizing, alignment, and batching of image and video inputs usually take much longer than text-only processing. If data loading cannot keep up with computation, accelerator cards will frequently sit idle, and throughput will drop.
Troubleshooting can be done in three steps. First, measure data loading time separately and compare it with single-step compute time. Second, observe whether the prefetch queue is often empty and measure idle accelerator time as a share of single-step time. Third, compare thread settings for different modalities and the effective token ratio before and after variable-length sequence packing. The effective token ratio equals the number of non-padding tokens divided by the total number of tokens.
You can set your own threshold when deciding whether optimization is needed. For example, if data loading time consistently exceeds 30% of single-step compute time, the data pipeline should be prioritized. The threshold needs to be adjusted according to task characteristics.
Step 1: Confirm the Software Stack and Versions
Before loading a large model, record the following information and save it as a checklist file so issues can be reproduced later:
- Accelerator card driver version and firmware version;
- Vendor-provided PyTorch adaptation version and the corresponding base PyTorch version;
- Collective communication library version and network driver version;
- Operator library version.
The import path and available versions of FSDP2-related interfaces depend on the PyTorch version and vendor adaptation version being used. Check official release notes before installation. You can use a small script to verify whether fully_shard can be imported from the target path and whether its behavior matches the documentation.
Before formally loading the model, run a small-scale communication test. Execute all-reduce and all-gather on all processes, check whether the results are correct, and record bandwidth. If this step fails, the problem is likely in the communication layer rather than the model code.
Step 2: Model Loading
Large model weights are usually stored as sharded checkpoints. During loading, each process should read only the portion it is responsible for. If the model is loaded in full and then sharded, the memory peak during loading will be much higher than during stable training.
A common approach has two steps. First, build the model structure on the meta device. At this point no actual storage is allocated; only parameter names, shapes, and sharding positions are determined. Second, shard the model, materialize the shards onto the corresponding devices, and then load weights through a distributed checkpoint interface such as torch.distributed.checkpoint.
After loading, perform three checks:
- The parameter names, shapes, and sharding layout on each process match the sharding plan;
- Using the same set of inputs, compare the forward output after distributed loading with a single-machine reference result; the error should fall within the allowable numerical precision range;
- Run a smaller model through the entire workflow first to confirm that the loading script has no issues, then switch to the target model.
Step 3: Sharding Scheduling
A multimodal model consists of submodules such as a vision encoder, a projection layer, and a language backbone. The parameter counts and compute density of these parts differ significantly, so a single sharding strategy is usually not suitable.
Below is a common organization pattern. The code is illustrative, and device type names need to be replaced with actual values:
import torch.distributed as distfrom torch.distributed.device_mesh import init_device_meshfrom torch.distributed.fsdp import fully_sharddist.init_process_group(backend="<vendor-provided communication backend name>")world_size = dist.get_world_size()# One-dimensional mesh: all cards participate in full shardingmesh = init_device_mesh("<device type>", (world_size,))# The language backbone has the largest parameter count; fully shard layer by layerfor layer in model.language_model.layers:fully_shard(layer, mesh=mesh)# The vision encoder and projection layer are smaller; choose sharding or replication based on measured resultsfully_shard(model.vision_encoder, mesh=mesh)fully_shard(model, mesh=mesh)
The point of layer-wise sharding is that forward computation only needs to aggregate the parameters of the current layer, so peak memory can be controlled at the scale of a single layer. If the entire model is treated as one sharding unit, the peak will rise noticeably.
For cross-node training, hybrid sharding (HSDP) can be considered. Its semantics are sharding within a node and replication across nodes. Cards within a node form a sharding group. Parameter aggregation and gradient reduce-scatter are completed among this group of cards using higher-bandwidth intra-node links. Nodes are replicas of each other, and gradients only need to be synchronized among replica groups. Cross-node communication volume is lower, but it is more sensitive to network latency and stability.
HSDP uses a two-dimensional device mesh. The first dimension is the replication dimension, corresponding to the number of nodes; the second dimension is the sharding dimension, corresponding to the number of cards per node. The names of the two dimensions must match the requirements of the version being used.
# First dimension: cross-node replication; second dimension: intra-node shardingmesh_2d = init_device_mesh("<device type>",(num_nodes, gpus_per_node),mesh_dim_names=("replicate", "shard"),)fully_shard(model, mesh=mesh_2d)
Whether to use HSDP should be based on communication profiling results. If cross-node bandwidth is sufficient, a pure sharding approach may be simpler.
If the model contains MoE layers, expert parameters usually also need an additional expert parallel dimension, forming a two-dimensional or multidimensional mesh of data parallelism and expert parallelism. In this case, all-to-all communication among experts may become the main overhead, and the performance and correctness of this operator on the target hardware need to be tested separately.
Step 4: Gradient Synchronization and Communication Overlap
Training throughput often depends on the efficiency of gradient synchronization. In FSDP2, backward propagation proceeds layer by layer. After each layer’s gradient is computed, reduce-scatter can be launched immediately. If communication overlaps in time with backward computation of subsequent layers, waiting time can be hidden.
Whether overlap actually occurs must be confirmed with profiling tools; it should not be assumed. If profiling shows that communication and computation execute serially, check the following in order: whether communication calls are non-blocking, whether communication and computation are on different streams, and whether topology-aware routing is enabled for the cross-node network.
Mixed-precision training has two other error-prone areas. First, when using BF16 computation with FP32 master weights, gradient accumulation and parameter updates should be completed at the correct precision. Second, gradient clipping requires computing the global norm across shards. Confirm that the clipping function in the version being used correctly handles sharded tensors, and compare the norm before and after clipping with a single-machine result.
Common Issues and Troubleshooting Directions
| Symptom | Possible Cause | Troubleshooting Direction |
|---|---|---|
| Out of memory on the first forward pass | Full materialization during loading, or sharding granularity too coarse | Check whether meta initialization takes effect, reduce the sharding unit, and verify activation recomputation settings |
| NaN in loss | Low-precision underflow, ineffective gradient clipping, or learning rate too high | Check gradient norm, locate the first abnormal value layer by layer, and verify how the clipping function handles sharding |
| Collective communication timeout | Network issue on a node, or incorrect communication group partitioning | Run a small-scale communication test first, and verify the device mesh and rank mapping of each process |
| Loss jump after checkpoint resume | Optimizer state not restored correctly, or random number state inconsistent | Compare parameters and optimizer state before and after resume, and confirm the data read position |
| Throughput far below expectation | Data loading bottleneck, no communication overlap, or operator falling back to a slow path | Profile data, compute, and communication time separately and rule out issues one by one |
Validation Checklist
After adaptation is complete, keep the following records as the basis for conclusions:
- Number of nodes, cards per node, and total world size;
- Global batch size, sequence length, and parallel partitioning method, including whether HSDP is used;
- Per-card peak memory, recorded separately for loading, forward, backward, and optimizer update stages. Peak memory can be read through the framework’s memory statistics interface; on domestic platforms, use the interface provided by the vendor;
- Tokens processed per second. When reporting, specify the number of warm-up steps and measurement steps, and divide the total number of tokens in the measurement window by wall-clock time;
- Comparison of loss curves for the first few hundred steps with a reference implementation under the same data, same random seed, and same data order;
- Measured cross-node communication bandwidth, obtained using the communication test tool provided by the vendor.
These metrics are valid only for the recorded configuration. Changing the number of nodes, sequence length, or sharding method can change the conclusion. Therefore, externally published conclusions should state the configuration conditions.
Risk Control During Training
Failures in large-scale training are costly. Save checkpoints regularly, and rehearse the checkpoint recovery workflow once before formal training. Set monitoring alerts for memory and communication for long-running jobs. Set thresholds for key metrics such as loss, gradient norm, and throughput, and pause automatically when anomalies occur, so that incorrect results are not continuously written into checkpoints.
What to Look for During Selection
If a team is evaluating domestic compute platforms, the following questions can be used for initial screening:
- Does the platform support native FSDP2 interfaces without requiring custom modifications for each model?
- Can the full pipeline run at the target scale, including checkpoint saving, interruption recovery, and gradient clipping?
- Do the bandwidth and latency of multi-node communication under the actual network topology meet expectations?
- Does the vendor documentation provide a version matrix, known issues, and troubleshooting guides?
A single performance metric is not enough to represent platform capability. Judgments should be based on small-scale tests using your own model, data, and scale before deciding whether to expand investment.
