Getting Large Model Training Working on Domestic AI Compute Platforms: A Practical Guide

    This article explains how to validate a complete large model training pipeline on domestic AI compute platforms before chasing performance metrics. It covers a five-part definition of a working pipeline, environment setup to reduce variables, parallel strategy choices, memory and throughput tuning, stability and observability, commonly overlooked data issues, and a final acceptance checklist based on a 400-step run across two nodes with 16 cards. Readers will find practical verification steps, two code examples, and a low-cost path to feasibility testing.

    1. Why Getting the Pipeline Working Matters More Than Chasing Metrics

    When adapting large model training to domestic AI compute platforms, the most common mistake teams make is focusing immediately on throughput and loss curves. The first goal should actually be a closed-loop pipeline: data is fed in correctly, the model is partitioned correctly, gradients flow back correctly, parameters are saved correctly, and exceptions are caught in time. When the pipeline is not working, no performance number is meaningful, because it may only reflect the illusion of “it ran a few steps without crashing.”

    A working pipeline usually rests on five verifiable facts:

    • Data side: sample tensor shapes, mask construction, and label alignment are correct, with no misalignment across epochs;
    • Model side: after parallel partitioning, parameter shards and optimizer states on each rank correspond one-to-one;
    • Communication side: collective communication operators complete synchronization without overlap issues or deadlocks;
    • Numerical side: the loss stays within a finite range, and the gradient norm neither explodes persistently nor stays constantly at zero;
    • Engineering side: checkpoints can be saved, loaded, and resumed, and logs and metrics are observable.

    A short validation run of 400 steps across two nodes with 16 cards is essentially a stress test of a “minimum viable closed loop”: the scale is large enough to expose multi-node communication and scheduling problems, while the step count is short enough to complete a regression in hours, making it suitable for continuous integration.

    2. Environment Setup: Reducing Uncertainty to the Minimum

    The first principle of adaptation work is to reduce variables. It is recommended to pin the base software stack versions first, then verify layer by layer upward.

    1. Drivers and runtime: confirm that the accelerator card driver, runtime libraries, and communication libraries match each other in version, avoiding a pseudo-usable state where “devices are recognized but operators misbehave.”
    2. Framework and operator libraries: prefer the framework distribution maintained officially by the platform, which usually already includes operator replacements and performance tuning.
    3. Dependency isolation: use a container platform or a standalone virtual environment to package dependencies, ensuring binary consistency across nodes.
    4. Minimal self-check: run one forward and backward pass with a small model on a single card, then verify collective communication with two cards, and only then scale to multiple nodes.

    A simplified environment self-check example:

    1. import os
    2. import torch
    3. def env_selfcheck():
    4. local_rank = int(os.environ.get("LOCAL_RANK", 0))
    5. torch.cuda.set_device(local_rank)
    6. x = torch.randn(1024, 1024, device="cuda")
    7. y = x @ x.t()
    8. torch.cuda.synchronize()
    9. loss = y.float().pow(2).mean()
    10. loss.backward()
    11. print(f"[rank{local_rank}] selfcheck ok, grad_norm={x.grad.norm().item():.4f}")

    The value of this code lies not in the computation itself, but in verifying three things: the device is visible, operators are usable, and automatic differentiation works.

    3. Parallel Strategy: Correctness First, Then Efficiency

    Most performance problems in multi-node training stem from a mismatch between the parallel strategy and the model structure. Common combinations include:

    • Data parallelism: the first choice when the model fits, with communication concentrated on gradient synchronization;
    • Tensor parallelism: splits matrix operations when a single layer’s parameters are too large; communication is frequent and requires high-bandwidth interconnect;
    • Pipeline parallelism: partitions layers across devices, requiring handling of bubbles and scheduling;
    • Sequence parallelism / context parallelism: splits the sequence dimension in long-context scenarios to reduce activation memory;
    • Expert parallelism: shards by expert under sparse structures, requiring attention to load balancing.

    The practical recommendation is to go “from simple to complex”: first use pure data parallelism to confirm numerical correctness, then gradually introduce tensor parallelism and pipeline parallelism, with loss alignment as the acceptance criterion at each step. After changing the partitioning dimension, the learning rate, gradient accumulation steps, and warmup strategy often need to be adjusted accordingly; otherwise, early-stage oscillation is likely.

    4. Memory and Throughput: Making Every GB Count

    Insufficient memory is the most common hard constraint in large model training. Available techniques include:

    1. Mixed precision: computing at lower precision while maintaining master parameters at higher precision, significantly reducing memory and bandwidth pressure;
    2. Activation recomputation: trading compute for memory, noting that too many recomputed layers will slow throughput;
    3. Optimizer state sharding: partitioning optimizer states within the data parallel group to reduce per-card resident memory;
    4. Gradient accumulation: effectively enlarging the batch under limited memory, with a corresponding learning rate adjustment;
    5. Memory fragmentation management: setting the allocation strategy reasonably to avoid allocation failures after long runs.

    During tuning, it is recommended to maintain a three-dimensional record of “memory - throughput - stability,” changing only one variable at a time to avoid being unable to attribute results when multiple factors are stacked.

    5. Stability and Observability: Getting Conclusions from 400 Steps

    The core output of a short validation run is a conclusion, not curves. Four capabilities need to be built:

    • Metric collection: record throughput, peak memory, communication time, and gradient norm per step, writing uniformly to a logging service;
    • Exception inspection: set threshold alerts for loss spikes, non-finite gradients, and communication timeouts, connected to a monitoring and alerting channel;
    • Checkpoint strategy: save at fixed step intervals, verify the three-step loop of “save - load - resume,” and ensure loss continuity before and after the breakpoint;
    • Fault localization: retain stack traces and key tensor statistics for each rank, making it easy to quickly distinguish data problems, operator problems, or communication problems.

    A gradient anomaly guard example:

    1. def guard_grad(model, step, max_norm=1e4):
    2. total = 0.0
    3. for p in model.parameters():
    4. if p.grad is not None:
    5. total += p.grad.detach().float().norm().item() ** 2
    6. total = total ** 0.5
    7. if not (total == total) or total > max_norm: # NaN or too large
    8. print(f"[step{step}] abnormal grad_norm={total}, skip update")
    9. return False
    10. return True

    6. Easily Overlooked Details on the Data Side

    In multi-node training, data misalignment is often more insidious than operator errors. Recommendations: keep the sharding strategy consistent and non-overlapping across ranks; bucket sample lengths to reduce padding waste; strictly align masks and labels; overlap data loading prefetch with computation to avoid input becoming the bottleneck. Data problems usually manifest as “the loss does not decrease but no error is reported,” so a small-scale overfitting test is needed to verify data pipeline correctness: repeatedly training on a small number of samples should drive the loss extremely low.

    7. Acceptance Checklist

    • Single-card forward and backward pass, dual-card collective communication pass;
    • 400 consecutive steps across two nodes with 16 cards without interruption, with loss decreasing steadily;
    • Checkpoint save, load, and resume are consistent;
    • Throughput and memory data are fully recorded, and anomalies can trigger alerts;
    • Conclusions are reproducible after changing the random seed.

    Following this path, teams can complete a feasibility validation of the training pipeline on domestic AI compute platforms at relatively low cost, and then devote their energy to improving model structure and data quality. If faster resource delivery and environment orchestration are needed, general capabilities such as the container platform, object storage, and monitoring and alerting provided by Baidu AI Cloud can help shorten the cycle from environment setup to pipeline validation.