FSDP2 Training on Chinese AI Accelerators: Implementation and Memory Estimation

    Adapting large-model training to a new accelerator requires more than running inference. This article covers training-state memory estimates, PyTorch FSDP2 sharding, communication bottlenecks, and numerical stability checks, and explains what a reported 400-step run can—and cannot—demonstrate.

    Training Requires More Than Inference Compatibility

    Chip vendors often use “Day 0 support” to describe running inference on a new chip with a model trained on other hardware. This type of validation primarily checks whether operators execute correctly. Training support has broader requirements: model loading, forward computation, backpropagation, gradient synchronization, and parameter updates must all work on the target chip. The software stack must also support distributed parallelism strategies.

    Training compatibility should therefore be evaluated by the stages it covers, not just the model’s parameter count.

    Estimate Memory Before Configuring Training

    Start with a memory estimate. Under a common mixed-precision training setup, each parameter requires approximately 16 bytes:

    • bf16 weights: 2 bytes
    • bf16 gradients: 2 bytes
    • fp32 master weights: 4 bytes
    • Adam first-moment state: 4 bytes
    • Adam second-moment state: 4 bytes

    Using this estimate, total training-state memory is approximately:

    Parameter count Training-state memory
    100 billion 1.6 TB
    300 billion 4.8 TB
    3 trillion 48 TB

    If each accelerator has 96 GB of device memory, 16 accelerators provide approximately 1.5 TB in total—before accounting for activations. Even with optimizer states offloaded to host memory, the two hosts described would still have far too little memory. Expert parallelism can reduce the computation assigned to each accelerator, but all expert parameters and optimizer states must still reside somewhere. Their total storage requirement does not decrease.

    Under conventional full-parameter training assumptions, the claims of “nearly 3 trillion parameters,” “two servers with 16 accelerators,” and “a stable, complete training pipeline” cannot all hold simultaneously. Some additional qualification would be necessary, such as training only selected modules, or the reported parameter count being incorrect.

    FSDP2 Sharding Example

    FSDP2 refers to PyTorch’s fully_shard interface. It shards parameters by module and represents sharded parameters as DTensors. The older FSDP API uses the FullyShardedDataParallel wrapper. These are different APIs and should not be mixed.

    1. import os
    2. import torch
    3. import torch.distributed as dist
    4. from torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy
    5. def setup_fsdp2(model, backend="nccl"):
    6. # torchrun sets RANK, LOCAL_RANK, WORLD_SIZE, MASTER_ADDR, and MASTER_PORT
    7. rank = int(os.environ["RANK"])
    8. local_rank = int(os.environ["LOCAL_RANK"])
    9. world_size = int(os.environ["WORLD_SIZE"])
    10. # For Chinese AI accelerators, use the vendor's device API and communication backend
    11. torch.cuda.set_device(local_rank)
    12. dist.init_process_group(backend=backend, rank=rank, world_size=world_size)
    13. device = torch.device(f"cuda:{local_rank}")
    14. model = model.to(device)
    15. mp_policy = MixedPrecisionPolicy(
    16. param_dtype=torch.bfloat16,
    17. reduce_dtype=torch.float32,
    18. )
    19. # Shard individual layers first, then shard the outer module
    20. for layer in model.layers:
    21. fully_shard(layer, mp_policy=mp_policy)
    22. fully_shard(model, mp_policy=mp_policy)
    23. return model

    This example assumes the model exposes a module list named layers, as is common in Transformer architectures. Check the exact API against the PyTorch version in use.

    Gradient Synchronization and Communication

    FSDP2 gathers full parameters for each layer through all-gather operations during forward and backward computation. During backpropagation, reduce-scatter produces the gradient shards assigned to each accelerator.

    Communication volume scales roughly with parameter count. In bf16, a complete parameter set for a 10-billion-parameter model occupies approximately 20 GB. Gathering parameters for both the forward and backward passes, plus transferring gradients for reduction, brings per-step communication to the order of tens of gigabytes.

    When investigating communication bottlenecks, check the following:

    1. Communication overlap: Determine whether each layer’s all-gather is hidden by computation. If it is not, the prefetch strategy may need adjustment.
    2. Inter-node bandwidth: Check whether network bandwidth is close to saturation.
    3. Load balance: Compare compute workloads across ranks. An uneven distribution causes faster accelerators to wait for slower ones.

    Monitoring Stability: Diagnosing NaN and Inf

    If NaN or Inf values appear during training, work through this checklist:

    1. Loss scaling: bf16 generally does not require dynamic loss scaling; fp16 generally does.
    2. Operator precision: Key operators such as softmax and LayerNorm should use fp32 accumulation.
    3. Gradient clipping: Record the global gradient norm and set an appropriate clipping threshold.
    4. Input data: Check for missing values, abnormal samples, and excessively long sequences.
    5. Communication consistency: Check whether loss and gradient norms are consistent with the distributed configuration across ranks. Large, unexpected discrepancies warrant checking communication-library versions.

    What the Reported Experiment Shows

    The report states that the model completed 400 consecutive optimization steps while loss and gradient norms remained finite. However, it does not disclose:

    • Batch size
    • Sequence length
    • Parallelism configuration
    • Compute precision
    • Whether offloading was used
    • Actual loss and gradient-norm values
    • Device-memory capacity and interconnect bandwidth

    Without these details, readers cannot reproduce the experiment or determine the scope of its conclusions.

    The 400-step record shows only that no NaN or Inf values appeared under that configuration. It does not establish that the accelerator platform is mature enough for full-parameter training.

    Information to Request When Evaluating a Training Setup

    • An itemized memory breakdown covering parameters, gradients, optimizer states, and activations
    • Whether all parameters or only selected parameters are trained
    • The parallelism layout across the 16 accelerators and the global batch size
    • Loss curves for the 400 steps, plus records demonstrating checkpoint recovery after an interruption

    Scope and Limitations

    These methods apply to most PyTorch-based Transformer training workloads. Communication libraries, operator coverage, and memory management differ across accelerator platforms, so each migration requires fresh validation. Checkpoint recovery after a training interruption must also be tested separately; it should not be assumed to work.