Adapting Trillion-Parameter Model Training to Domestic Compute Hardware with FSDP2

    This article explores the technical challenges of adapting trillion-parameter model training to domestic compute hardware using FSDP2. Using a 2.8-trillion-parameter multimodal model as an example, it details how to address memory and communication bottlenecks, configure sharding granularity, load model weights efficiently, hide communication latency, and ensure long-term training stability, providing a practical guide for large-scale AI deployments.

    Training trillion-parameter models is no longer just an algorithmic challenge; memory, communication, and data pipelines can all become major bottlenecks. This article uses an open-source 2.8-trillion-parameter multimodal model as an example to explain the common issues that must be resolved in an FSDP2-based training pipeline on domestic compute hardware. Both the chip vendor and model source are anonymized, and specific performance data should be referenced against public benchmarks and testing conditions.

    How Significant are the Memory and Communication Pressures in Trillion-Parameter Training?

    When estimating memory, the first step is to account for model states. In mixed-precision training using bf16 for computation and fp32 for optimizer states, each parameter consumes approximately 16 bytes. The table below uses a 2.8-trillion-parameter model as an example (where 1TB equals 10^12 bytes), showing the total overhead without including activation values.

    Item Bytes per Parameter Total for 2.8T Parameters
    bf16 Weights 2 5.6 TB
    bf16 Gradients 2 5.6 TB
    fp32 Master Weights 4 11.2 TB
    Adam First-Order Momentum (fp32) 4 11.2 TB
    Adam Second-Order Momentum (fp32) 4 11.2 TB
    Total 16 44.8 TB

    If these model states are evenly distributed across 4,096 cards, each card handles about 10.9 GB. This figure does not include activation values, communication buffers, and memory fragmentation, meaning the actual footprint will be higher. Activation values can be reduced through activation recomputation, at the cost of increased computation.

    Communication volume can also be estimated. When using FSDP2, each forward step requires one parameter gather, the backward pass typically requires another, and gradient reduction requires one more. If parameters are transmitted in bf16, the send and receive volume per card is approximately 3 * 2P bytes, or 6P bytes, where P is the parameter count. When P is 2.8 trillion, each card transmits about 16.8 TB per step. This number is largely independent of the number of cards because traffic per card stabilizes under ring communication algorithms. Therefore, simply increasing the number of cards will not reduce the per-step communication volume; you must rely on overlapping communication with computation, increasing per-card computation, and gradient accumulation to amortize the overhead. Note that this is a theoretical estimate and does not account for the actual effects of gradient accumulation and overlapping.

    What Determines the Sharding Granularity in FSDP2?

    FSDP2 is implemented based on DTensor, splitting each parameter along the 0th dimension across different cards. The sharding granularity is not a single scalar but is determined by the module where fully_shard is called. Each wrapped module constitutes a communication unit, gathering parameters before execution and releasing them after use. Unlike FSDP1, which flattens parameters within the same module into a shared buffer, FSDP2 keeps parameters independent. This allows sub-networks with different structures, such as vision encoders and language models, to select their own sharding strategies.

    CPU Offload stores parameters in host memory and transfers them to GPU memory before computation. Because the PCIe bandwidth between CPU and GPU is significantly lower than inter-card interconnect bandwidth, offload is only suitable for scenarios where memory is extremely tight and the computation time of a single layer is sufficient to cover the data transfer. If throughput drops noticeably after enabling offload, you should prioritize adding more cards or enabling activation recomputation.

    How to Avoid Single-Process Memory Overflow During Model Loading?

    A common practice is to first construct the model structure on a meta device, where no actual memory is allocated. After calling fully_shard to complete sharding, use to_empty to move the empty shells to the cards, and finally read the weights by shard through the distributed checkpoint interface. Each process only reads the parameters it is responsible for, so the memory pressure on a single node decreases as the number of nodes increases.

    Concurrent reads from object storage require rate limiting and retries. Excessive concurrency can trigger server-side throttling, causing individual shards to time out. After loading is complete, you must verify the shape, data type, and global offset of each shard to ensure they correspond one-to-one with the cards in the topology. Common errors include shard order mismatching the rank, and weight data types mismatching the training configuration.

    How Does Shard Scheduling Hide Communication Latency?

    The core of shard scheduling is prefetching parameters for the next layer. While the current layer is computing, the next layer’s all-gather executes asynchronously on the communication stream, allowing the two to overlap. The following structural code snippet illustrates the main interfaces for sharding, precision, and prefetching in FSDP2.

    1. import torch
    2. import torch.distributed as dist
    3. from torch.distributed.device_mesh import init_device_mesh
    4. from torch.distributed.fsdp import (
    5. fully_shard, MixedPrecisionPolicy, CPUOffloadPolicy,
    6. )
    7. # Example environment: PyTorch 2.x, launcher has set RANK and WORLD_SIZE
    8. dist.init_process_group(backend="nccl") # For domestic accelerators, replace with the vendor-provided communication backend
    9. mesh = init_device_mesh("cuda", (dist.get_world_size(),))
    10. mp_policy = MixedPrecisionPolicy(
    11. param_dtype=torch.bfloat16, # Computation precision for forward and backward passes
    12. reduce_dtype=torch.float32, # Gradient reduction precision, numerically more stable but higher communication volume
    13. )
    14. offload_policy = CPUOffloadPolicy(pin_memory=True) if use_offload else None
    15. # Build the model on the meta device, consuming no actual memory
    16. with torch.device("meta"):
    17. model = build_model(cfg) # build_model and cfg are placeholders; replace with actual implementations
    18. layers = list(model.layers)
    19. for layer in layers:
    20. fully_shard(layer, mesh=mesh, mp_policy=mp_policy, offload_policy=offload_policy)
    21. fully_shard(model, mesh=mesh, mp_policy=mp_policy, offload_policy=offload_policy)
    22. # Prefetch depth is 1: forward prefetches the next layer, backward prefetches the previous layer
    23. for i in range(len(layers) - 1):
    24. layers[i].set_modules_to_forward_prefetch([layers[i + 1]])
    25. for i in range(1, len(layers)):
    26. layers[i].set_modules_to_backward_prefetch([layers[i - 1]])
    27. model.to_empty(device="cuda")
    28. # Then read weights by shard, method shown in the previous section

    Several parameters in the code need to be adjusted based on actual conditions. The prefetch depth determines the number of simultaneous in-flight parameter gathers. A larger depth makes communication easier to hide, but it also increases memory usage. reshard_after_forward controls whether parameters are released after the forward pass. The default setting saves more memory but requires gathering again during the backward pass. Setting reduce_dtype to fp32 reduces numerical errors at the cost of doubling gradient communication volume. When troubleshooting, if you encounter OOM (Out of Memory), first lower the prefetch depth to 0 or keep the default reshard settings. If throughput is significantly lower than expected, check whether the communication and computation streams are truly overlapping, and use profiling tools to view the communication wait time for each layer. Interface names may vary by version, so refer to the official documentation for your specific PyTorch version.

    Why Use ReduceScatter Instead of AllReduce for Gradient Synchronization?

    In FSDP2, parameters are already sharded across cards, so each card only needs to retain the gradients for the portion it is responsible for. After backward computation is complete, gradients are summed and split using ReduceScatter, with each card only receiving its local shard. AllReduce would allow every card to obtain the full gradient, consuming more memory and communication volume. AllReduce is only necessary when parameters are replicated across cards, such as in DDP or during the cross-replica group step in HSDP.

    Scenario Gradient Reduction Method Does Each Card Retain Full Gradient?
    FSDP2 Full Sharding ReduceScatter No, only local shard retained
    DDP Replicated Parameters AllReduce Yes
    HSDP ReduceScatter intra-node, then AllReduce cross-replica No, only local shard retained

    FSDP2 does not have fixed byte-size communication buckets like DDP; the communication granularity is determined by the module where fully_shard is applied. Once a module’s backward pass is complete, its gradient immediately initiates a ReduceScatter, overlapping with the backward computation of subsequent modules. If a single module is too large, the peak memory for a single communication also increases; in such cases, you can split it into smaller sub-modules.

    When using gradient accumulation, intermediate micro-steps can skip reduction by using set_requires_gradient_sync(False), synchronizing only on the last micro-step to reduce communication frequency.

    How Does the Training System Ensure Long-Term Stability?

    Ultra-large-scale training typically lasts for weeks, during which hardware failures are inevitable. Container orchestration platforms like Kubernetes can quickly rebuild containers after a node failure and recover from the latest checkpoint. The checkpoint interval can be estimated using an empirical formula: the optimal interval is approximately equal to sqrt(2 single_save_duration mean_time_between_failures). For example, if a single save takes 5 minutes and the mean time between failures (MTBF) is 6 hours, the optimal interval is about 60 minutes. The actual value should also account for storage bandwidth fluctuations and recovery time.

    On the data side, frequently accessed samples can be cached on the local NVMe disks of compute nodes to reduce network read pressure. Cache hit rates should be monitored continuously as a routine metric. For monitoring, it is necessary to collect GPU temperature, memory utilization, network throughput, and communication wait times. The threshold for slow nodes should be set based on the cluster’s baseline data, rather than copying values from other clusters. When an alert is triggered, operators must first determine whether the issue is related to hardware, network, or data reading before deciding whether to isolate the node.

    What Should Be Checked Before Deployment?

    1. Memory Budget: Estimate model states, activation values, communication buffers, and fragmentation separately, leaving sufficient margin.
    2. Communication Budget: Estimate the single-step communication time based on the per-step per-card communication volume and link bandwidth, and verify that it can overlap with computation.
    3. Precision Configuration: Confirm the data types for parameters, computation, and gradient reduction, and verify that the loss curve aligns with the baseline.
    4. Load Verification: Check the shape, dtype, and offset of each shard to confirm the correspondence between shards and ranks.
    5. Checkpoint Strategy: Determine the save interval, storage location, and frequency of recovery drills.
    6. Monitoring Thresholds: Set alert thresholds based on baseline data, and record the cause and recovery time of each failure.

    Conclusion

    Under specific cluster scales, software versions, and model configurations, the native FSDP2 path successfully adapted the training of this model, proving its feasibility. However, to determine if it can support long-term production training, data from extended multi-task stable runs, fault recovery records, and throughput and MFU metrics with testing conditions are required. Since these data points are not provided in the original materials, this article does not offer performance conclusions.