Trillion-Parameter LLM Training on Domestic AI Accelerators: Adaptation Workflow and Engineering Practices

    This article examines the engineering work required to adapt an open-source ultra-large model for training on domestically developed AI accelerator cards. Rather than focusing on a single operator, it treats adaptation as a complete and stable training pipeline covering model loading, sharding, computation, and gradient synchronization. It outlines the main difficulties—memory peaks during initialization, communication overhead after parameter sharding, and hardware-backend differences in operator coverage and communication primitives—and then describes a four-stage pipeline with practical approaches for sharded loading, fully sharded data parallelism with prefetching, gradient synchronization and communication optimization, multimodal training considerations, and a validation and troubleshooting sequence. The goal is to provide reusable engineering ideas and verification checkpoints for teams porting very large models to new accelerator hardware.

    Recently, an open-source ultra-large-scale model completed training adaptation on domestically developed AI computing accelerator cards. The core of this type of work is not a single operator; it is making the model form a complete and stable training chain from loading and sharding to computation and gradient synchronization. Against this background, this article reviews the key stages in the adaptation process and provides reusable engineering ideas.

    1. Where the Difficulties Lie in Ultra-Large Model Adaptation

    When the model parameter scale exceeds the memory capacity of a single card, training is no longer a single-machine problem. Device memory must simultaneously hold parameters, gradients, optimizer states, and activations. If any one of these exceeds the budget, training cannot start. In a common mixed-precision configuration, optimizer states often consume the most memory, so the sharding strategy is more critical than simply adding more cards.

    Adaptation difficulties usually concentrate in three areas:

    • The memory peak during model initialization and weight loading;
    • The communication overhead generated after parameters are split across multiple cards;
    • Differences in operator coverage and communication primitives across hardware backends.

    The third point is the most easily underestimated. When the same training code is migrated to different accelerator cards, missing operators, inconsistent numerical behavior, or communication performance differences may appear, and each item needs to be checked.

    2. Training Pipeline Overview

    A complete training pipeline can be divided into four stages:

    1. Model loading: read weights by layer or by shard and place them directly on the target device;
    2. Shard scheduling: decide which card holds each parameter based on memory capacity and communication topology;
    3. Forward and backward computation: gather parameters on demand, and release them immediately after computation;
    4. Gradient synchronization and optimizer update: reduce gradients and update parameters on each shard.

    These four stages are closely linked. Any failure in one stage will appear in later stages as numerical anomalies or training interruption. Therefore, adaptation should be validated stage by stage rather than waiting until the entire pipeline runs end to end.

    3. Model Loading: Avoid Filling Memory at Once

    Reading the complete weights directly into device memory is the most common cause of failure. A more robust approach is to read layer by layer from host memory or storage, placing each layer only on the device where the corresponding shard resides.

    The following pseudocode illustrates the flow (pseudocode only, to show the process):

    1. def load_sharded_model(model_config, checkpoint_dir, device_mesh):
    2. model = build_model_on_meta_device(model_config) # Do not allocate real device memory
    3. for layer_name, shard_spec in plan_shards(model, device_mesh):
    4. tensor = read_tensor_from_checkpoint(checkpoint_dir, layer_name)
    5. local_shard = slice_tensor(tensor, shard_spec, device_mesh.rank)
    6. assign_local_shard(model, layer_name, local_shard)
    7. return model

    This “build an empty shell first, then fill it layer by layer” approach can reduce the memory peak during initialization to the order of a single layer. It is also necessary to check whether the checkpoint sharding method is consistent with the loading method. If the sharding method used when saving differs from the one used when loading, re-sharding conversion must be performed first; otherwise, shape mismatch or silent data errors may occur.

    4. Parameter Sharding Scheduling: Fully Sharded Data Parallelism

    The basic idea of fully sharded data parallelism is that each card permanently holds only part of the parameters, gradients, and optimizer states. When computing a certain layer, the complete parameters of that layer are temporarily gathered onto each card, and they are released immediately after computation.

    This approach brings two direct benefits. First, static memory usage decreases approximately linearly with the number of cards. Second, parameter gathering can overlap with the computation of the previous layer, thereby hiding part of the communication latency.

    Three issues need to be considered during scheduling:

    • Shard granularity: layer-wise sharding results in fewer communication rounds but a higher peak memory; parameter-block sharding does the opposite;
    • Prefetch strategy: gathering the next layer’s parameters in advance can hide communication time but increases temporary memory usage;
    • Communication topology: intra-node bandwidth between cards is usually higher than cross-node bandwidth, so shard groups should be kept within a node where possible.
    1. def forward_with_prefetch(layers, inputs, mesh):
    2. gathered = all_gather_params(layers[0], mesh)
    3. x = inputs
    4. for i, layer in enumerate(layers):
    5. if i + 1 < len(layers):
    6. next_handle = async_all_gather_params(layers[i + 1], mesh)
    7. x = layer.forward(x, gathered)
    8. release_params(gathered)
    9. if i + 1 < len(layers):
    10. gathered = wait(next_handle)
    11. return x

    Prefetch depth should not be too large. Excessive prefetching can make the temporary memory peak exceed expectations and instead cause out-of-memory errors. During adaptation, start with a depth of 1 and adjust gradually with memory monitoring.

    5. Gradient Synchronization and Communication Optimization

    Gradient synchronization is responsible for reducing gradients across data-parallel replicas. Under a sharding scheme, gradients are usually reduced in the form of reduce-scatter. Each card keeps only the part it is responsible for, and then each card updates its local optimizer state.

    Common issues during adaptation include:

    • Numerical differences caused by different reduction orders; accumulation precision consistent with the reference implementation should be used;
    • Gradient clipping needs to be calculated based on the global norm; otherwise, different shards may obtain inconsistent clipping coefficients;
    • Communication and computation are not overlapped, causing actual throughput to be far below the theoretical value.

    When verifying gradient correctness, it is recommended to compare the gradients obtained from sharded training with a single-card reference implementation parameter by parameter in a small-scale configuration. The error should be within the range allowed by floating-point precision. This step can reveal problems earlier than observing the loss curve.

    6. Engineering Points for Multimodal Training Paths

    The training path of multimodal models is more complex than that of text-only models. The vision encoder, projection layer, and language backbone have quite different computation patterns, and the sharding strategy usually needs to be differentiated by module.

    In practice, the following approaches can be used:

    • Set independent sharding strategies for different modules. Visual inputs often have more irregular shapes, so padding and masking need to be handled separately;
    • Align image and text data at the input stage to avoid sample misalignment in a distributed environment;
    • Configure mixed-precision rules by module, and retain higher precision for numerically sensitive normalization layers.

    Validation of multimodal adaptation should cover each module, not just the end-to-end result. When end-to-end metrics are normal, the gradients of an individual module may already have deviated from expectations. Such deviations often only become apparent after long training.

    7. Adaptation Validation and Common Troubleshooting

    It is recommended to carry out validation in the following order:

    1. Single-card forward and backward results are consistent with the reference implementation;
    2. Forward output under multi-card sharding is consistent with the single-card result;
    3. After gradient synchronization, parameter updates on each shard are consistent with the reference implementation;
    4. Train for several steps at a small scale, and the loss curve trend is normal;
    5. Scale to the target size and monitor memory usage, communication time, and throughput.

    Common issues and troubleshooting directions are as follows:

    • Out-of-memory during initialization: check whether complete weights were loaded at once, and confirm whether lazy initialization is effective;
    • Loss divergence after a few training steps: check the gradient clipping range, learning rate warmup, and precision configuration;
    • Low throughput: use profiling tools to confirm whether communication overlaps with computation and whether shard groups cross nodes;
    • Metrics jump after resuming training: check the random state and shard mapping relationship during checkpoint saving and restoration.

    8. Summary and Practical Recommendations

    Adapting very large models for training on new hardware is essentially about making the four stages of loading, sharding, computation, and synchronization into a verifiable whole. Each stage should have corresponding correctness checks and performance metrics, rather than relying only on the final result to judge success or failure.

    For teams pursuing similar work, it is recommended to establish a single-card reference baseline first, then gradually introduce sharding and communication optimization, and retain validation records for each step. In this way, when problems occur, the specific stage can be located quickly.