FSDP2 Adaptation Checklist for Training Large Models on Domestic AI Accelerators
This article presents a vendor-neutral FSDP2 adaptation checklist for training very large models on domestic AI accelerators. It explains memory and communication constraints, how FSDP2 shards model state, sharding granularity tradeoffs, multimodal-specific issues, and a five-step acceptance process covering operator alignment, single-node validation, multi-node scaling, stability, and performance optimization. It also notes that the source material does not provide verifiable vendor, version, throughput, or failure-rate data, so specific adaptation conclusions should be treated as pending verification and re-measured on the target platform.
First, What the Source Material Can Establish
The source material describes one adaptation case for domestic compute training, but it does not give vendor names, model versions, software stack versions, throughput data, or failure rates, nor does it provide public sources. Therefore, this article does not restate specific adaptation conclusions; it covers general methods only. To judge whether a platform fits a given task, readers should request version notes, benchmark results, and reproducible configurations from the vendor.
1. Why Training Very Large Models Is Difficult
How to Estimate Memory Usage
Training memory usage mainly comes from four parts: parameters, gradients, optimizer states, and activations. In a common mixed-precision Adam setup, each parameter takes about 16 bytes: 2 bytes for the bf16 parameter, 2 bytes for the bf16 gradient, 4 bytes for the fp32 master parameter, 4 bytes for the first Adam moment, and 4 bytes for the second Adam moment. Under this accounting, a model with 2.8 trillion parameters needs about 44.8 TB of memory for parameters, gradients, and optimizer states alone (2.8 × 10^12 × 16 bytes). Activations must be counted separately; they depend on batch size, sequence length, and recomputation strategy.
This number shows that a single accelerator or a single machine cannot hold the full model state. State must be sharded across many accelerators.
How to Judge Communication Overhead
The finer the sharding, the more data nodes need to exchange. The main communication during training includes parameter aggregation, gradient reduction, and activation transfer. To judge whether communication is a bottleneck, look at two indicators: the share of step time taken by communication, and whether throughput grows close to linearly as the number of accelerators increases. If doubling the number of accelerators only increases throughput by half, communication or scheduling is usually the bottleneck.
2. What FSDP2 Solves
FSDP2 is a fully sharded data parallel solution provided by PyTorch. It shards parameters, gradients, and optimizer states across processes by dimension. During forward and backward computation, the framework temporarily all-gathers the parameters needed by the current layer and releases them after computation, reducing the memory that remains resident on each accelerator. The newer version uses DTensor to represent sharded parameters, which gives more uniform sharding granularity and makes it easier to combine with techniques such as mixed precision and quantization.
The following code is conceptual and cannot be run directly. Device type, communication backend, and API version must follow the documentation for the platform in use.
# Conceptual illustration; cannot be run directlyimport torchfrom torch.distributed.device_mesh import init_device_meshfrom torch.distributed.fsdp import fully_shard, MixedPrecisionPolicymesh = init_device_mesh(device_type, (world_size,)) # device_type is determined by the vendor backendmp = MixedPrecisionPolicy(param_dtype=torch.bfloat16, reduce_dtype=torch.float32)for block in model.blocks: # Wrap block by block to lower peak memoryfully_shard(block, mesh=mesh, mp_policy=mp)fully_shard(model, mesh=mesh, mp_policy=mp)optimizer = torch.optim.AdamW(model.parameters(), lr=1e-4) # Create the optimizer after wrapping
This code shows three points. First, wrapping should be done layer by layer, with the outer root module wrapped last. Second, the optimizer must be created after wrapping so that optimizer state is sharded along with the parameters. Third, the mixed-precision parameter dtype and reduction dtype must be specified explicitly; otherwise, the numerical precision of gradient reduction may differ from expectation.
For very large clusters, a 2D device mesh can also be used to shard within a node and replicate across nodes, i.e., hybrid sharding. This reduces cross-node communication but adds memory for one replica, so it must be chosen based on actual memory headroom.
3. How to Choose Sharding Granularity
The sharding strategy for different modules depends on parameter count, compute intensity, and communication cost. The table below gives common tradeoffs; exact values must be determined by measurement.
| Module | Recommended sharding | Main cost | Tradeoff |
|---|---|---|---|
| Embedding layer | Full shard; offload to host memory when necessary | Offload adds host-to-device transfer | Large parameter count and low compute make it a priority for saving memory |
| Attention and feed-forward core blocks | Shard by layer; all-gather in forward and release promptly | Per-layer all-gather increases communication | Compute-intensive; check whether communication can overlap with compute |
| Multimodal encoders | Shard independently by encoder | Structures vary widely; wrapping granularity needs separate tuning | For irregular structures, measure the effect of block-by-block wrapping |
| Expert layers (Mixture-of-Experts) | Distribute experts across device groups | Routing imbalance causes load skew | Monitor per-expert load |
4. Additional Issues in Multimodal Training
Multimodal model training has three main difficulty areas.
The first is the data pipeline. Inputs such as images and text have different preprocessing methods and sequence organization. The data loader needs to support mixed sampling and dynamically pack batches by token budget. A common approach is to set a token limit per batch rather than a fixed sample count.
The second is memory peaks. The number of tokens in image inputs varies widely, and the peak may occur on an abnormal sample. To locate it, record peak memory per step and associate the peak with the sample’s token count and modality combination. After finding the source of the peak, decide whether to enable activation recomputation or lower the per-batch token limit.
The third is operator coverage. Multimodal models often contain non-standard operators, such as specific visual encoding structures. Each operator must be numerically validated: feed the same data to a reference device (usually CPU or an fp32 path) and the target device, then compare the maximum absolute error and relative error. If the error exceeds a pre-agreed threshold, investigate.
5. Adaptation Checklist
The following five steps can serve as an acceptance framework. Record results at each step, and when a step fails, go back to the previous step for troubleshooting.
Operator alignment
- Practice: compare forward and backward outputs of the target device and reference device operator by operator.
- Acceptance: errors are within a pre-agreed threshold, which the team determines based on precision requirements.
- Troubleshooting: first check whether data types and random seeds are consistent, then check the accumulation precision of the operator implementation.
Single-node run-through
- Practice: use
torchrun --nproc_per_node=<num_cards> train.pyto launch single-node multi-accelerator training. - Acceptance: complete the specified number of steps stably; after saving a checkpoint and reloading, the loss curve is continuous at the resume point.
- Troubleshooting: if initialization hangs, check the communication backend and environment variables; if loss jumps, check whether the checkpoint contains optimizer state.
- Practice: use
Multi-node scaling
- Practice: gradually add nodes and record throughput (tokens/s) at each scale.
- Acceptance: linear speedup = current-scale throughput ÷ (number of nodes × single-node throughput). The target speedup is set by the team based on network conditions.
- Troubleshooting: when speedup drops significantly, use profiling tools to inspect the communication time share and slow nodes.
Stability validation
- Practice: during long training, manually inject failures such as process exits and network interruptions, and observe the automatic recovery process.
- Acceptance: the job recovers from the latest checkpoint, and the loss after recovery follows the same trend as before the interruption.
- Troubleshooting: if recovery fails, check checkpoint integrity and the logic for rebuilding distributed state.
Performance optimization
- Practice: use profiling tools to inspect compute and communication overlap, then try adjusting bucket size, prefetch strategy, and memory pool configuration.
- Acceptance: effective compute utilization improves over the baseline without accuracy degradation.
- Troubleshooting: change only one parameter at a time to avoid difficulty in attributing results when multiple changes are stacked.
6. Risks to Note
First, the source of the original material cannot be verified, and specific conclusions in it should be treated as information pending verification. Second, one successful adaptation run does not mean production readiness; long-term stability, cost, and operational overhead must be evaluated separately. Third, the code and table in this article are general illustrations and cannot replace vendor documentation. Fourth, performance numbers must be re-measured on your own model, data, and cluster; do not directly apply results from others.
If you need to compare different platforms, use the same model configuration, the same data batch, and the same acceptance metrics, run the five steps above separately, and then compare the results.
