Training Very Large Models on Domestic AI Accelerators: A Practical Adaptation Guide

    A step-by-step guide to adapting very large model training for domestic AI accelerator cards. This article covers hardware evaluation (memory, bandwidth, interconnect), software stack version management, FSDP2 sharding and scheduling, multimodal data pipeline consistency, load balancing, numerical and performance validation, checkpointing, and a pre-flight checklist for full-scale training runs.

    Adapting Very Large Model Training to Domestic AI Accelerators: A Practical Guide

    1. What the Adaptation Needs to Solve

    Recent public reports describe an open-source multimodal model with roughly 2.8 trillion parameters. At that scale, training infrastructure faces three kinds of pressure: insufficient memory capacity, excessive inter-card communication, and a software stack that struggles to organize model sharding, scheduling, and communication. For the domestic AI compute ecosystem, the ability to stably complete a full training pipeline on its own accelerator cards is a direct test of hardware–software co-design.

    Adaptation is not done when “the model runs.” A usable training pipeline must cover: model loading, parameter sharding, forward and backward computation, gradient synchronization, optimizer updates, checkpoint save and resume, and multimodal data ingestion. Any weak link is amplified at very large parameter scales, showing up as sudden throughput collapse, out-of-memory errors, or loss divergence.

    This article does not discuss a specific model; the parameter scale in the background comes from public reporting. Verify all figures against official releases before using them.

    2. Hardware Selection: Memory First, Then Bandwidth

    Adaptation usually starts with hardware evaluation. Accelerator spec sheets are easy to read, but what really needs checking are a few metrics that directly determine training feasibility.

    First, per-card memory capacity. Take standard mixed-precision training with an Adam-family optimizer: each parameter occupies roughly 16 bytes — 2 bytes for the half-precision parameter, 2 bytes for the half-precision gradient, 4 bytes for the single-precision master weight, and 4 bytes each for the optimizer’s first and second moments. By this estimate, a 2.8-trillion-parameter model needs about 44.8 TB of memory just for parameters, gradients, and optimizer states. With 1,024 cards sharing the load, that’s about 44 GB per card. This excludes activations, communication buffers, and memory fragmentation, so real requirements are higher. Per-card memory therefore determines the minimum number of cards and how fine the sharding granularity can be.

    Second, memory bandwidth. Most of the training time for large models is spent on memory access. If HBM bandwidth falls short of expectations, compute utilization drops noticeably. Record the vendor’s stated bandwidth values and measurement methodology, and verify with operator-level benchmarks in your own environment.

    Third, interconnect bandwidth, latency, and topology. Evaluate intra-server card-to-card interconnect separately from cross-server network bandwidth. Partition communication groups so that high-frequency traffic lands on high-bandwidth links — for example, keep tensor parallelism within a single node.

    Fourth, precision support. Confirm the hardware supports the required half-precision or low-precision formats, that numerics are stable, and that the relevant operators have mature implementations.

    Fifth, unified training and inference. If the same platform handles both training and inference and shares operator libraries and drivers, the cost of moving from training to deployment drops significantly. Verify this with a real model, not marketing claims.

    Write up the selection results as a table noting the measurement conditions, tools, and dates for each metric, so results can be reproduced and compared later.

    3. The Software Stack: The Version Matrix Matters More Than the Feature List

    Hardware capability is unlocked through the software stack. A complete stack typically includes:

    • Compiler and runtime layer: compiles the framework’s computation graph to the accelerator’s instruction set and provides optimized implementations of common operators.
    • Communication library: provides collective primitives such as AllReduce, AllGather, and ReduceScatter, supporting combinations of data, tensor, and pipeline parallelism.
    • Framework adaptation layer: lets mainstream training frameworks’ parallelism APIs call the underlying hardware with minimal changes to model code.

    The most commonly overlooked issue is version dependency. Build a version matrix that records at least:

    1. Operating system and kernel version;
    2. Accelerator driver and firmware versions;
    3. Compiler/runtime version;
    4. Collective communication library version;
    5. Training framework version and its adaptation patches;
    6. The maximum verified model size, card count, and sequence length.

    The “verified scale” column must be filled in based on actual runs. Any combination without test records should be marked as unverified. Most adaptation failures come from version mismatches — for example, a sharding API whose semantics changed after a framework upgrade, or a communication library that hangs because it doesn’t match the driver version.

    4. The Core Path: FSDP2 Sharding and Scheduling

    Fully Sharded Data Parallel (FSDP2) is the core training path in this guide. The idea: parameters, gradients, and optimizer states are all sharded across cards. During computation, the full parameters a layer needs are gathered on demand and released immediately afterward, leaving only each card’s own shard.

    The pipeline has three stages.

    4.1 Model Loading

    A trillion-parameter model cannot be loaded whole onto a single card or node; it must be split by layer and read in as shards. Two things are required during loading.

    First, build a metadata index recording which layer and parameter each shard belongs to, and its offset within the full tensor. Metadata errors misplace parameters and are hard to detect early, so run a full verification after loading: reassemble the shards and compare element-wise against the original weights, or compare hashes.

    Second, load according to the precision plan. Parameters can be stored in low-precision formats while master weights and optimizer states stay in single precision, balancing memory usage and numerical stability. Put the precision policy in a config file under version control — don’t hard-code it in scripts.

    4.2 Sharding and Scheduling

    The pseudocode below illustrates scheduling order only; it is not production-ready code.

    1. # Pseudocode: illustrates scheduling order only, not runnable
    2. # In real frameworks, all_gather and reduce_scatter are usually
    3. # triggered automatically by pre/post hooks
    4. def train_step(model, batch, optimizer):
    5. # 1. Forward: gather parameters layer by layer, release right after use
    6. x = batch["inputs"]
    7. for layer in model.layers:
    8. full = all_gather(layer.shards) # gather full parameters for this layer
    9. x = layer.forward(x, full)
    10. free(full) # release after forward; keep only this card's shard
    11. loss = model.loss_fn(x, batch["labels"])
    12. # 2. Backward: re-gather before each layer's backward, then reduce
    13. # gradients to this card's shard. The framework triggers all_gather
    14. # before each layer's backward and reduce_scatter after it.
    15. loss.backward()
    16. # 3. Each card updates only its own shards' parameters and optimizer states
    17. optimizer.step()
    18. optimizer.zero_grad()
    19. return loss.detach()

    Three points in this pseudocode deserve attention.

    First, parameters are freed after the forward pass, so they must be re-gathered during backward. Skipping this causes the backward pass to fail with missing full parameters.

    Second, loss is computed once after the entire forward pass, followed by a single backward call. Layer-by-layer gather and reduce operations are handled automatically by the framework during backward; user code does not loop over them manually.

    Third, the optimizer updates only the shards this card owns. Gradients have already been reduced to the corresponding shards via reduce_scatter at the end of backward, so each card’s optimizer states map one-to-one with its parameter shards.

    With PyTorch’s FSDP2, the entry point is torch.distributed.fsdp.fully_shard, typically applied layer by layer to Transformer blocks. The all_gather and reduce_scatter in the pseudocode correspond to the parameter gathering and gradient reduction inside that API. On domestic accelerators, the exact API names and behavior follow the adaptation layer’s documentation — do not assume they match upstream.

    4.3 Gradient Synchronization and Communication Overlap

    Gradients from backward are reduced across cards via reduce_scatter and re-sharded. To cut waiting time, frameworks typically overlap one layer’s gradient communication with the next layer’s backward computation.

    Overlap effectiveness must be measured. Track two numbers: total step time and communication wait time. The ratio of communication wait to total step time shows whether the overlap strategy is working. If this ratio stays high, check the communication group partitioning, communication bucket sizes, and prefetch layer counts.

    5. The Multimodal Part: Sharding, Data, and Load

    Multimodal models are more complex than text-only models in three main ways.

    5.1 Co-sharding the Vision Encoder and Language Model

    The vision encoder and language model have different compute profiles. The vision encoder consumes image patch sequences; the language model consumes text token sequences — their memory peaks occur at different stages. Consider these practices:

    • Give each component its own sharding granularity instead of forcing a single level;
    • Handle the connector layers between them separately, ensuring the vision feature output shape exactly matches the language model’s input shape;
    • Enable activation recomputation on the vision encoder to trade compute for memory, and record the resulting compute overhead increase.

    5.2 Data Pipeline Consistency

    In distributed training, the image and text of each image-text sample must stay paired. Common problems include: distributed samplers splitting differently across cards so images and texts get misaligned; augmentation random seeds not differentiated per card, causing duplicate samples; and inconsistent preprocessing versions producing different token sequences for the same dataset on different cards.

    Suggested checks:

    1. Assign each sample a unique ID at the data-loading end, and log which card reads which sample ID at each step;
    2. Periodically sample to verify image-text pairing — roughly one in a thousand, adjusted as training progresses;
    3. Pin the preprocessing version and record the data version in checkpoints.

    5.3 Load Balancing

    Multimodal sample lengths vary widely. One high-resolution image can produce thousands of visual tokens, while a short text may have only a few dozen. Without balancing, some cards carry far more compute in the same step, and overall throughput is bounded by the slowest card.

    A common approach is bucketing samples by sequence length or visual token count so each card’s per-step compute is similar. The key metric is the ratio of the maximum per-step time to the average — the closer to 1, the better balanced. Log this metric in every training run.

    6. Validation and Troubleshooting

    Adaptation should use layered validation: verify numerical correctness on a reduced model configuration first, then scale to full parameters and full card counts.

    6.1 Numerical Validation

    Compare the adapted training against a reference implementation on three metrics:

    • Loss curve: loss over the first few hundred steps should closely match the reference; agree on the acceptable deviation in advance, e.g., a relative deviation threshold;
    • Gradient norms: record per-layer gradient norms and check for abnormally large values or layers that are all zero;
    • Single-step forward outputs: fix the random seed and compare forward output numerical errors for the same input.

    Deviation thresholds should match the precision format in use. Low-precision training inherently tolerates larger error — don’t judge it by single-precision standards.

    6.2 Performance Validation

    Standardize on these metrics:

    • Throughput: tokens per second, noting sequence length and batch size;
    • Compute utilization: actual throughput divided by theoretical peak; document how the theoretical peak is calculated;
    • Communication share: communication time as a percentage of step time.

    Every performance number should include measurement conditions: card count, node count, sequence length, precision format, and software versions. Numbers without conditions can’t be reproduced or compared.

    6.3 Checkpoint Save and Resume

    Checkpoints for very large models are huge, and saving and resuming both take significant time. Save sharded and in parallel — each card writes only its own shards — plus a global metadata record.

    After resuming, check:

    • Whether the first few steps’ loss continues smoothly from before the interruption;
    • Whether optimizer states loaded correctly, e.g., momentum statistics match pre-interruption values;
    • Whether random number states are restored and the data reading position is aligned.

    Treat resume verification as a routine test, not something to run for the first time during an actual failure.

    6.4 Common Issues

    • Memory peak higher than expected: usually too many layers gathered simultaneously during forward. Reduce prefetch layer counts or use finer sharding.
    • Communication bottleneck: first check whether communication groups cross low-bandwidth links, then check whether bucket sizes are reasonable.
    • Training hangs mid-run: usually related to drivers, communication library versions, or a node’s network state. Check the version matrix first, then inspect node by node.
    • Unstable multimodal throughput: usually uneven sample length distributions. Check the bucketing strategy and the distribution of per-step times.

    7. Adaptation Checklist

    Before declaring adaptation complete, confirm each of the following:

    1. Memory estimation is done and compared against measured peak;
    2. The version matrix is filled in, and unverified