Getting Large Model Training Running on Domestic Compute: A Practical Guide

    This article walks through the practical steps for validating an end-to-end large model training pipeline on domestic accelerator hardware before scaling up. It covers why closing the training loop matters more than raw compute size, how to make the environment reproducible, choosing a parallel strategy at small scale, spotting communication and data pipeline bottlenecks, building checkpointing and fault tolerance for long runs, and a concrete acceptance checklist to confirm the pipeline is truly working. The content is based on a two-node, multi-card setup running a few hundred steps.

    1. Why Getting the Pipeline Working Matters More Than Scaling Up First

    A common mistake in large model training engineering is focusing all attention on compute scale, assuming that more cards and a bigger cluster automatically mean better training results. In practice, what slows teams down is usually not the total amount of compute but whether the training pipeline is closed end to end. A closed pipeline means the entire path — data loading, forward computation, backward propagation, gradient synchronization, parameter updates, and checkpoint saving and restoration — runs stably and repeatably on the target hardware.

    When the pipeline is not connected, teams face several fundamentally different problems at the same time: errors from unsupported operators, numerical overflow under mixed precision, distributed communication timeouts, insufficient data pipeline throughput, and random failures caused by memory fragmentation. Mixed together, these problems are extremely expensive to diagnose. The common industry practice is therefore to complete end-to-end validation on a smaller two-node, multi-card environment first, decoupling “can it run” from “does it run fast,” and then scale up gradually.

    The other value of small scale is iteration speed. Single-node multi-card or two-node multi-card experiments typically take minutes per cycle, making it quick to verify whether the parallel strategy, batch size, and learning rate schedule are self-consistent. If loss stops decreasing or gradients behave abnormally at small scale, environmental factors can almost be ruled out, letting the team focus on configuration and implementation.

    2. Environment Setup: Moving Uncertainty Ahead of Launch

    Whether the pipeline starts smoothly depends largely on whether the environment is properly configured. It is advisable to fix the environment build process into a reproducible image or configuration script, avoiding version drift from manual installation on each machine.

    The elements that need to be aligned include: accelerator driver and runtime versions, communication library version, deep learning framework version, dependent operator library versions, and container runtime configuration. Any mismatch can show up as a hard-to-reproduce failure such as “works on a single node but hangs across nodes.”

    Illustrative environment validation logic:

    1. import os, subprocess, json
    2. def check_env():
    3. report = {
    4. "rank": os.environ.get("RANK"),
    5. "world_size": os.environ.get("WORLD_SIZE"),
    6. "local_rank": os.environ.get("LOCAL_RANK"),
    7. "master_addr": os.environ.get("MASTER_ADDR"),
    8. "master_port": os.environ.get("MASTER_PORT"),
    9. }
    10. # Print driver and runtime info to make cross-node comparison easier
    11. report["runtime"] = subprocess.getoutput("device-query --summary")
    12. print(json.dumps(report, ensure_ascii=False))
    13. assert report["world_size"] is not None, "Distributed environment variables missing"
    14. if __name__ == "__main__":
    15. check_env()

    The most critical factors are inter-node network connectivity and port availability. Before launch, run bidirectional connectivity probes between all nodes and confirm the chosen port is not occupied. Many cases of “training that just hangs” ultimately trace back to a firewall policy or port conflict on one machine.

    3. Parallel Strategy: Trade-offs at the Small-Scale Validation Stage

    At two-node multi-card scale, complex 3D parallelism is usually unnecessary; pure data parallelism with gradient accumulation is enough to validate the pipeline. Data parallelism is simple to implement and has a regular communication pattern. Its cost is that memory usage does not decrease as the number of cards grows, so techniques like gradient accumulation and activation recomputation are needed to trade for a larger effective batch size.

    The effective batch size relationship can be written as:

    1. effective_batch = micro_batch_size × grad_accum_steps × world_size

    This formula looks simple, but it is the first ruler for diagnosing convergence anomalies. When the number of cards changes and the learning rate is not adjusted accordingly, the change in effective batch size shows up directly in the loss curve as oscillation or slow convergence. In practice, teams generally keep the effective batch size stable and then apply a mild scaling to the learning rate based on experience.

    Activation recomputation is a typical way of trading compute for memory. It increases per-step time but significantly reduces peak memory, allowing a larger micro batch. Whether to enable it should be decided by small-scale measurement rather than assumed from experience.

    4. Communication and Data Pipeline: The Two Most Overlooked Bottlenecks

    The efficiency ceiling of distributed training is often determined by communication. The volume of gradient synchronization data is proportional to the number of parameters, and insufficient communication bandwidth causes scaling efficiency to decay quickly. Common optimization directions include gradient bucketing with computation-communication overlap, compressing communication data by precision, and confining communication to topologically better links. To judge whether a communication bottleneck exists, compare single-card throughput with multi-card throughput; if doubling the number of cards yields far less than the expected throughput gain, prioritize investigating communication rather than computation.

    Data pipeline problems are more subtle. When data preprocessing runs synchronously inside the training process, the accelerator idles while waiting for data, showing up as periodic dips in utilization. A workable approach is to move operations like decoding and augmentation into separate worker processes or a thread pool, combined with prefetching and caching, so data preparation overlaps with computation. For extremely large sample sets, offline preprocessing in advance can reduce runtime overhead to a minimum.

    1. # Pseudocode: minimal skeleton of prefetch + gradient accumulation
    2. for step, batch in enumerate(loader): # loader has multi-process prefetch enabled
    3. with auto_cast():
    4. loss = model(batch) / accum_steps
    5. loss.backward()
    6. if (step + 1) % accum_steps == 0:
    7. clip_grad_norm_(model.parameters(), 1.0)
    8. optimizer.step()
    9. optimizer.zero_grad(set_to_none=True)

    5. Stability and Recoverability: The Real Threshold for Long Jobs

    As training goes from dozens of steps to tens of thousands, the importance of stability design exceeds any single-point performance optimization. Three things must be prepared in advance.

    First, checkpoints. Saved content should include not only weights but also optimizer state, learning rate scheduler state, random number state, and the current step; otherwise loss will jump after restoration. Save frequency needs to balance storage pressure against recomputation cost, usually derived backward from the “tolerable recomputation time.”

    Second, exception handling. The outer layer of the training loop should wrap exception handling so that when a runtime error, communication timeout, or numerical anomaly is caught, the current state is written to disk before exiting, avoiding hours of wasted compute.

    Third, numerical monitoring. Mixed precision training needs to watch loss scale and overflow counts. Once continuous overflow occurs, the system should automatically reduce the scale or fall back to higher-precision computation, rather than letting training silently diverge.

    6. Acceptance Criteria: How to Tell It Is “Really Working”

    A working pipeline cannot be judged only by whether the process failed to exit. It is advisable to establish a quantifiable acceptance checklist: within a few hundred steps, loss shows a stable downward trend with no NaN; gradient norms across ranks are of the same order of magnitude; multi-card throughput improves reasonably over single card; peak memory leaves a safe margin; and after actively killing one training process, the job automatically resumes from the latest checkpoint and continues to decrease.

    Only after verifying these five items one by one does the pipeline have a foundation for scaling. After that, whether adding nodes, switching parallel dimensions, or adjusting the model structure, incremental changes can be made on a known-good baseline, greatly reducing the cost of problem localization.

    7. Additional Notes for Cloud Environments

    If the training job runs in a cloud environment, general cloud product capabilities can further reduce operational burden: use a container platform for unified environment delivery and elastic scheduling, use object storage to hold training data and checkpoints, use a log service to centrally collect multi-node output, and use monitoring and alerting to set threshold notifications for utilization, memory, and job liveness. These are general industry categories, and specific choices should be evaluated against your own scale and compliance requirements. The capabilities Baidu AI Cloud offers in heterogeneous compute scheduling and training operations can serve as one reference direction for teams during evaluation.

    Overall, the value of completing a few hundred steps of training on a two-node multi-card setup lies not in speed, but in converging the uncertainty of the entire pipeline at the lowest cost, laying a reproducible, observable, and recoverable engineering foundation for subsequent scaling.