Large Model Training on Domestic GPUs: How to Get FSDP2 Running

    As large models scale from hundreds of billions to trillions of parameters, training demands on compute, parallelism, and numerical stability rise sharply. This article explains why training adaptation is the core challenge for large model deployment, how it differs from inference access, and how to build a native Fully Sharded Data Parallel (FSDP2) training path on domestic all-in-one GPUs. It includes a runnable FSDP2 code skeleton, the key layers to tune (operator coverage, sharding, gradient synchronization), a reproducible multi-node stability verification methodology, an engineering checklist, and a troubleshooting table for common failures such as communication timeouts, loss NaN, deadlocks, and memory overflow.

    1. Why Training Adaptation Is the Core Challenge for Large Model Deployment

    As large models scale from hundreds of billions to trillions of parameters, the demands on compute, parallel strategy, and numerical stability grow exponentially. Many teams can “get inference running” on a domestic accelerator, yet frequently hit loss divergence, communication timeouts, and out-of-memory errors during actual training. The reason is straightforward: inference only requires a single forward pass, while training involves the complete chain of forward computation, backward propagation, gradient accumulation, and optimizer updates. That chain places far stricter requirements on memory management, communication efficiency, and numerical precision.

    As a result, “being able to adapt a training workload to a piece of hardware” and “the model was pretrained on that hardware” are two different levels of claim. The former is about the engineering feasibility of whether training can run at all; the latter concerns where the base-model compute actually came from and should be verified against official technical reports.

    2. Training Adaptation vs. Inference Access: Don’t Conflate the Two

    • Inference access: The model is loaded, performs a forward pass, and produces logits or generated output. It is a one-way validation with no gradient backpropagation, and its engineering difficulty is relatively manageable.
    • Training adaptation: It requires connecting every stage, from model loading and parameter sharding to forward computation, loss backpropagation, gradient synchronization, and optimizer updates. It must also sustain hundreds of consecutive, numerically stable optimizer updates across multiple nodes and GPUs.

    Common industry reports of “multi-route parallel validation” usually mean that the same model has passed inference operator validation on several hardware backends. What such validation proves is operator compatibility, not which hardware the base model was pretrained on. Keeping these two strictly separate is essential to avoid misjudging the maturity of domestic compute.

    3. The FSDP2 Training Path: From Loading to Gradient Synchronization

    To train large models stably on a domestic all-in-one GPU, the core is to build a native Fully Sharded Data Parallel (FSDP) training path. This shards parameters, gradients, and optimizer states along the data-parallel dimension across processes, breaking through the memory limit of a single card, and hides communication overhead by overlapping communication with computation.

    Below is a skeleton of FSDP2. It is important to emphasize: FSDP1 (torch.distributed.fsdp.FullyShardedDataParallel, a class-based interface) and FSDP2 (fully_shard, a functional interface) have completely different APIs, and the two cannot be mixed. The example below is based on FSDP2’s functional fully_shard interface (imported from torch.distributed.fsdp in PyTorch 2.6+, or from torch.distributed._composable.fsdp in 2.4–2.5). This is illustrative code; actual execution depends on the domestic backend’s support for the corresponding operators, and the exact interfaces should be confirmed against the framework version in use:

    1. import torch
    2. import torch.nn as nn
    3. from torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy # FSDP2, PyTorch 2.6+
    4. # Dependency definitions (example; replace build_transformer / dataloader per the domestic backend)
    5. def build_transformer(num_layers=80, hidden_size=8192):
    6. # Return an nn.Module built by stacking Transformer Blocks
    7. ...
    8. mp_policy = MixedPrecisionPolicy(
    9. param_dtype=torch.bfloat16, # Compute parameters in bf16; typically no loss scaling needed
    10. reduce_dtype=torch.float32, # Reduce gradients in fp32 for better numerical stability
    11. )
    12. model = build_transformer()
    13. # FSDP2 sharding by layer: shard each Transformer Block first, then shard the whole model
    14. for block in model.layers:
    15. fully_shard(block, mp_policy=mp_policy)
    16. fully_shard(model, mp_policy=mp_policy)
    17. optimizer = torch.optim.AdamW(model.parameters(), lr=1e-4, betas=(0.9, 0.95))
    18. # The dataloader must be constructed by the caller with distributed sampling
    19. for step, batch in enumerate(dataloader):
    20. with torch.autocast("cuda", dtype=torch.bfloat16):
    21. loss = model(batch).loss
    22. loss.backward() # Triggers sharded gradient sync (reduce-scatter)
    23. # Gradient clipping compatibility under sharded parameters must be verified: you can clip
    24. # directly on model.parameters(), or use the framework's dedicated FSDP interface; always
    25. # include it in long-duration stability tests
    26. torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)
    27. optimizer.step()
    28. optimizer.zero_grad(set_to_none=True)

    Getting this chain to truly run end to end requires coordinated tuning across several layers:

    1. Operator coverage and precision alignment: Ensure operators such as attention, normalization, and positional encoding have equivalent, numerically consistent implementations on the domestic backend, to avoid precision drift that leads to loss divergence.
    2. Sharding and scheduling: Set a reasonable sharding granularity so that memory usage and communication volume are balanced across nodes.
    3. Gradient synchronization and communication library: Rely on collective communication primitives such as all-reduce / reduce-scatter to complete gradient reduction. The stability of the communication library directly determines whether multi-GPU training can run reliably over long periods. To reproduce results, you also need to specify the domestic GPU backend model, the collective communication library, and framework dependency versions; otherwise the results are not reproducible.

    4. Stability Verification for Multi-Node, Multi-GPU Training

    The most convincing evidence that a training adaptation is mature is not “it can run a few steps,” but whether it can sustain a large number of consecutive optimizer updates across nodes without interruption.

    A reproducible verification pattern (stated as a precondition, not a universal guarantee): two physical machines totaling 16 accelerators form a cluster, running 16 data-parallel processes; the model has about 7B parameters with a sequence length of 2048 and a global batch of about 256; storage and network bandwidth must meet the throughput required for per-step checkpoints and gradient reduction; a checkpoint is saved every 50 steps; and 400 consecutive optimizer updates are completed while continuously monitoring:

    • Loss curve: Smoothly decreasing or fluctuating reasonably, with no sudden jumps or NaN.
    • Gradient norm (grad norm): Always finite, with gradient clipping to prevent gradient explosion.
    • Numerical overflow: fp16 requires loss scaling to prevent underflow; bf16 typically does not need loss scaling but still needs NaN/Inf and numerical-overflow monitoring.
    • Process survival rate: No abnormal exits among the 16 processes, and no communication timeouts or deadlocks.

    The model size, sequence length, batch, bandwidth, checkpoint frequency, and “stability thresholds” above (e.g., no NaN/Inf for N consecutive steps and throughput no lower than 90% of baseline) together form the preconditions. Cross-node training introduces issues that single-card testing cannot expose, such as network jitter, topology differences, and collective-communication-library timeouts. Only sustained stability over hundreds of steps shows that an adaptation has moved from “demo-grade” to “production-grade.”

    5. From Quick Deployment to a Full-Chain Engineering System

    A single successful run is only the starting point; real capability shows up in a reusable engineering system:

    • Automated fault tolerance and checkpoint resume: Save checkpoints periodically, and on node failure automatically reschedule and recover from the most recent state.
    • Observability: Use logs, metrics monitoring, and alerts to collect loss, memory, communication bandwidth, and GPU utilization in real time, quickly locating bottlenecks and abnormal nodes.
    • Data and storage pipeline: Supply data through high-throughput object storage or a distributed file system, and orchestrate training jobs with a container platform.
    • Environment consistency: Package drivers, communication libraries, and framework dependencies into images to ensure consistent behavior across development, testing, and production.

    As an example of a cloud provider’s general-purpose capabilities, container platforms, object storage, logging services, and monitoring/alerting can provide the underlying support for large model training, letting teams focus on the model and algorithms themselves. This is a description of general capabilities and does not point to any specific vendor.

    6. Training Large Models on Domestic All-in-One GPUs: A Reproducible Checklist

    Distill the points above into an actionable checklist:

    Item Key Action
    Environment dependencies Pin the framework version, domestic GPU driver, and communication library versions; package as images
    Operator coverage Verify numerical consistency of operators such as attention / normalization / positional encoding one by one
    Communication library Confirm all-reduce / reduce-scatter are available with no timeouts
    Memory monitoring Monitor fragmentation and peak usage; adjust sharding granularity or enable activation recomputation if needed
    Checkpoint resume Checkpoint periodically; automatically recover after node failure
    Metric baselines Establish baselines for loss, grad norm, and throughput so deviations can be quickly attributed

    A practical path can follow: inference first, then training (validate operator coverage and precision with inference before moving to training); small, fast iterations (achieve stable runs of hundreds of steps on a small multi-node, multi-GPU setup first, then scale up the cluster and parameters); prefer native frameworks (favor native options like FSDP that are compatible with the ecosystem, though this depends on the framework version, the domestic backend’s operator coverage, and ecosystem maturity, and is not absolute); establish metric baselines; and accumulate a toolchain.

    7. Common Errors and Diagnosis

    Symptom Likely Cause Metric / Command to Check
    Communication timeout / hang Network jitter, topology differences, communication library timeout Check communication library logs; verify bandwidth and timeout-threshold settings
    Loss NaN bf16/fp16 overflow, learning rate too high, operator precision drift Monitor grad norm and loss; bisect to locate suspect operators
    Deadlock Inconsistent sharding/reduction calls across processes Check each rank’s call order and collective-operation pairing
    Memory overflow / fragmentation Improper sharding granularity, activations not released Monitor memory peaks; adjust sharding and activation recomputation
    Low throughput Communication not overlapping with computation, insufficient bandwidth Monitor communication bandwidth and GPU utilization; tune the sharding strategy

    8. Outlook: From “Able to Train” to “Train Out of the Box”

    The hallmark of maturing domestic compute is a shift from “able to complete training adaptation” to “train out of the box” — where users can launch large-scale training on domestic hardware directly, without deep code changes or per-operator debugging. This depends on the continued refinement and ecosystem collaboration of three things: operator adaptation, multi-GPU coordination, and automated tooling. For developers, understanding the underlying logic of training adaptation and mastering stability verification methods for FSDP2 in multi-node, multi-GPU settings is the key capability for grasping this trend.