FSDP2 Training Adaptation for Large Models: Pipeline and Validation Checklist
This article explains the difference between training adaptation and base model pretraining. It then covers memory estimation, an FSDP2-based distributed training pipeline from sharded loading to gradient synchronization, and a code skeleton. It also covers what a 400-step run can and cannot show, which metrics to record, and how checkpoint frequency affects recovery point and recovery time objectives.
1. Separate Training Adaptation from Base Pretraining
Showing that training works does not mean a model was pretrained from scratch on that hardware. Training adaptation and base model pretraining differ in goals, scale, and acceptance criteria.
| Dimension | Training adaptation | Base model pretraining |
|---|---|---|
| Goal | Verify that operators, communication libraries, and parallelism strategies work on the target hardware | Learn general capabilities from scratch |
| Starting point | Existing architecture and pretrained weights | Random initialization |
| Typical number of cards | One machine to dozens of cards | Thousands to tens of thousands of cards |
| Typical duration | Hours to days | Weeks to months |
| Main acceptance metrics | Whether the run completes, throughput, step time, and whether loss behaves normally | Convergence curves, long-term failure rate, and effective cluster utilization |
| Main risks | Missing operators, precision anomalies, communication misconfiguration | Card failures, network jitter, invalid checkpoints |
Take the technical report of an open-source large model as an example. The report validated two chip platforms side by side and presented a fine-grained expert parallelism scheme. The general reading is that this side-by-side validation mainly targeted inference operators and some fine-tuning capabilities. The report does not clearly disclose the compute source for base pretraining. When reading such reports, first check the original wording of each validation item, then judge the scope of the conclusions.
2. Estimate Memory Before Deciding Whether a Run Is Feasible
Memory is the first constraint in training very large models. Any estimate should state the precision, the optimizer configuration, and whether the states are sharded.
- Storing only FP16 or BF16 weights: 3 trillion parameters × 2 bytes ≈ 6 TB. This is the theoretical lower bound and excludes all other overhead.
- Typical mixed-precision AdamW training: about 16 bytes per parameter. This covers BF16 weights and gradients, FP32 master weights, the first moment, and the second moment (variance). For 3 trillion parameters, this is about 48 TB.
- Activations, communication buffers, memory fragmentation, and temporary tensors use additional memory, so actual requirements are higher.
Sharding spreads these states across cards but does not reduce the total. Consider a 64 GB card. Sixteen cards across two machines provide about 1 TB in total, which is far less than 48 TB. If the full training state is counted, the combined memory of 16 cards is not enough. Runs like this usually rely on other conditions, such as training only part of the parameters, using parameter-efficient fine-tuning, activating only some experts in an MoE model, or offloading optimizer states to host memory or disk. The report must state the actual configuration. Otherwise, readers cannot judge what the run demonstrates.
3. The FSDP2 Training Pipeline: From Loading to Gradient Synchronization
FSDP2 is a parameter sharding strategy. It splits parameters, gradients, and optimizer states across cards. It does not depend on whether a model is multimodal. This article therefore refers to this pipeline as an FSDP2-based distributed training pipeline.
The pipeline has three stages.
1. Sharded Loading
Weight files are large, so each card reads only the shard it owns. In practice:
- Use a sharded checkpoint format that stores metadata for each shard, including its shape, start offset, and owning card ID.
- Limit the number of threads used for concurrent reads to avoid saturating object storage or the distributed file system.
- Verify a hash for each shard. If verification fails, retry only that shard instead of reloading the entire model.
- Record completed shards so that loading can resume from a breakpoint.
2. On-Demand Gathering and Release
FSDP2 wraps parameters by module, typically one Transformer layer at a time. During the forward pass of a layer, an all-gather temporarily collects that layer’s full parameters. After the computation, the parts that do not belong to the card are freed immediately. The backward pass works the same way. As a result, only a few layers’ full parameters are held in memory at any moment.
3. Gradient Synchronization and Communication Overlap
During backpropagation, gradients are synchronized with reduce-scatter. Each card keeps only the gradients for its own shard. To hide communication time, the framework computes the backward pass of the previous layer while the current layer’s communication runs. If communication takes longer than computation, the overlap shrinks. In that case, use a profiler to find the bottleneck.
Code Skeleton
The original pseudocode used the FSDP1 API and lacked import statements. The skeleton below is the FSDP2 version, which applies to recent PyTorch releases (2.6 and later).
import osimport torchimport torch.distributed as distfrom torch.distributed.device_mesh import init_device_meshfrom torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy# Bind each process to one card. Environment variables are set by the launcher (e.g., torchrun).dist.init_process_group(backend="nccl")local_rank = int(os.environ["LOCAL_RANK"])world_size = dist.get_world_size()torch.cuda.set_device(local_rank)# 1D device mesh: all cards participate in parameter shardingmesh = init_device_mesh("cuda", (world_size,))# Build the model on the meta device to avoid materializing the full model on a single cardwith torch.device("meta"):model = build_model() # User-definedmp_policy = MixedPrecisionPolicy(param_dtype=torch.bfloat16,reduce_dtype=torch.float32,)# Wrap each layer first, then the outer module, so each layer's parameters are gathered on demand and freed after usefor block in model.blocks:fully_shard(block, mesh=mesh, mp_policy=mp_policy)fully_shard(model, mesh=mesh, mp_policy=mp_policy)# Materialize the sharded parameters, then load weights from the sharded checkpoint (loading logic omitted)model.to_empty(device="cuda")load_sharded_checkpoint(model) # User-defined; torch.distributed.checkpoint is recommended as the basis# Create the optimizer after sharding so that optimizer states are sharded with the parametersoptimizer = torch.optim.AdamW(model.parameters(), lr=1e-5)for step, (data, target) in enumerate(dataloader):optimizer.zero_grad(set_to_none=True)output = model(data) # Parameters are all-gathered layer by layer during the forward passloss = loss_fn(output, target)loss.backward() # Gradients are reduce-scattered during the backward passoptimizer.step()if step % 50 == 0:save_sharded_checkpoint(model, optimizer, step) # User-defineddist.destroy_process_group()
On Ascend and other accelerator cards made in China, switch to the corresponding communication backend (such as HCCL) and the vendor-provided PyTorch adaptation plugin. The code structure stays the same.
4. What 400 Steps Can Prove
A 400-step run shows that the system runs continuously under a given configuration and does not crash early. It does not show that the model has converged or that the system is stable over the long term. For acceptance, record at least the following items.
| Metric | How to record | Notes |
|---|---|---|
| Task type | Full pretraining, continued pretraining, SFT, or LoRA | Determines what the result means |
| Parameter count and trainable parameter count | Total parameters and the parameters actually updated | Avoids confusing total size with the number of updated parameters |
| Throughput | Average tokens/s per card | Used to compare scalability |
| Step time | Mean and variance after excluding warm-up steps | High variance indicates communication or I/O jitter |
| Loss | Whether NaN values or spikes appear, and whether the trend declines | Shows only whether values are numerically healthy, not convergence |
| Failures and recovery | Number of card failures and recovery time | Corresponds to the recovery time objective (RTO) |
| Checkpoints | Save time, and whether loss stays continuous after loading | Verifies that the recovery pipeline is reliable |
5. Stability and Monitoring
Card failures and network jitter are routine in long training runs. Monitoring should cover step time, the number of NCCL collective communication timeouts, link packet loss and jitter, ECC error counts, memory fragmentation rate, checkpoint save time, and recovery success rate.
Checkpoint frequency determines recovery cost. If a checkpoint is saved every N steps and each step takes T, the worst-case lost training time is about N × T. This is the recovery point objective (RPO). The recovery time objective (RTO) covers fault detection, node isolation, rescheduling, checkpoint loading, and rebuilding communication groups. Measure both metrics in failure drills rather than relying only on estimates.
On cloud-native platforms, container scheduling, object storage, log services, and alerting are typically provided by the platform. When choosing a platform, verify its actual capabilities. Do not assume that one platform’s capabilities are the industry default.
6. Conclusion
A 16-card run across two machines that ran continuously for 400 steps shows that the adaptation pipeline works under this configuration. This is a starting point for further validation. To determine whether the system can support long-running, end-to-end training, larger and longer runs are needed. These should report convergence curves, throughput, failure rates, and recovery times.
