Key Pipelines for Adapting Multimodal Large Models on Alternative AI Accelerators

    Training trillion-parameter multimodal models requires immense computational and memory resources, demanding high standards for compute, memory, interconnect bandwidth, and software stack maturity. Adapting these training pipelines to alternative, non-CUDA AI accelerators presents unique challenges across the entire software stack. This article explores the critical steps for achieving successful adaptation, including model loading and weight initialization, FSDP2 parameter sharding engineering, multimodal data pipelines and sequence packing, gradient synchronization, fault tolerance, and a general methodology for heterogeneous software stack adaptation. It provides actionable checkpoints and verification methods to ensure numerical stability and system performance before launching large-scale training.

    I. Scope and Prerequisites

    Open-source multimodal models with 2.8 trillion parameters have scales that exceed the capacity of a single machine or even a single cluster. The weights alone reach the terabyte level, imposing high demands on compute power, memory, interconnect bandwidth, and software stack maturity during training. This article uses models of this scale as a reference to discuss the key areas of focus when adapting training pipelines for alternative AI accelerators.

    First, we must define the boundaries. This article describes methodologies and checkpoints rather than a directly reproducible benchmark report. Public materials do not provide specific accelerator models, driver and software stack versions, communication library versions, memory usage, or throughput data; therefore, no specific performance figures are cited here. Additionally, this article does not cover the details of pipeline parallelism or expert parallelism. Readers should treat these concepts as a starting point for adaptation, not as conclusions that can be universally reproduced on any alternative accelerator.

    Whether a CUDA-like software stack can support the complete training pipeline is the core question of this practice. It requires at least three things to hold true: the programming interfaces must cover the operators required by the model, the collective communication library must correctly execute multi-card communication, and the compatibility layer of mainstream training frameworks must work properly. If any of these is missing, training will either stall at a certain stage or produce silent errors.

    II. Model Loading and Weight Initialization

    The weight volume of a trillion-parameter model is massive, requiring three main issues to be addressed during the loading phase.

    Sharded Loading. Checkpoints should utilize lazy loading and metadata indexing mechanisms to avoid reading the entire weights into memory at once. A checkpoint typically records the shard location of each parameter, and each training process only reads its assigned portion. Before loading, you should confirm that the number of shards matches the number of training processes; otherwise, errors will only surface mid-run.

    Precision Planning. A common practice is to perform calculations using BF16 or FP8 while maintaining master weights in FP32 to ensure numerical stability during optimization. During loading, the correspondence between storage precision and compute precision for each tensor type must be explicitly defined and saved as a configuration file. The numerical stability of FP8 varies significantly across different hardware and requires separate validation; conclusions from other platforms cannot be applied by default.

    Structural Validation. Perform consistency checks on the shapes and configurations of attention layers, MoE layers, and multimodal encoders. If a shape mismatch occurs, the program should throw an error and exit immediately. Allowing silent continuation might result in anomalous losses only after hours of training, making debugging extremely costly.

    III. Engineering FSDP2 Parameter Sharding

    Fully Sharded Data Parallel (FSDP) splits model parameters, gradients, and optimizer states across all devices. During forward and backward passes, the required parameters are temporarily gathered and released after use. The next-generation implementation (commonly known as FSDP2) introduces two major changes: first, parameter-by-parameter sharding based on DTensor, refining the granularity from module-level to parameter-level; second, a prefetch mechanism that initiates the all-gather for the next layer’s parameters while computing the current layer, reducing communication wait times.

    The following code is structural and cannot be run directly. You need to replace the communication backend name and device type, and adjust it according to your actual environment.

    1. # Schematic code, cannot be run directly. Assumed environment: PyTorch 2.6+,
    2. # vendor-provided PyTorch adaptation package installed, communication backend per vendor docs.
    3. import torch.distributed as dist
    4. from torch.distributed.device_mesh import init_device_mesh
    5. from torch.distributed.fsdp import fully_shard
    6. dist.init_process_group(backend="<vendor_comm_backend_name>")
    7. world_size = dist.get_world_size()
    8. device_mesh = init_device_mesh("<device_type>", (world_size,))
    9. model = build_model() # User-defined model building function
    10. for layer in model.layers:
    11. fully_shard(layer, mesh=device_mesh) # Layer-wise sharding
    12. fully_shard(model, mesh=device_mesh) # Fallback sharding for the root module

    The launch command also needs to be modified according to the cluster topology. Below is an example using 4 nodes with 8 cards per node:

    1. torchrun --nnodes=4 --nproc_per_node=8 \
    2. --rdzv_backend=c10d --rdzv_endpoint=${MASTER_ADDR}:29500 \
    3. train.py

    Three types of issues are commonly encountered during adaptation, each requiring specific validation methods.

    Collective Communication Compatibility. For operators like all-gather, reduce-scatter, and all-reduce, perform unit tests using different data types and tensor sizes, comparing the results against a reference platform. Tests should cover the actual sizes used by FSDP, not just a small example tensor.

    Pinned Memory Behavior Differences. Under different drivers, the allocation success rate and copy bandwidth of pinned memory may vary. You should log allocation failures and compare throughput results with pinned memory enabled versus disabled. You can search the logs for keywords related to allocation failures, which depend on the vendor’s driver output.

    Mixed Precision and Loss Scaling Matching. BF16 generally does not require loss scaling, whereas FP16 does. If loss scaling is used, track the number of skipped updates. A consistently high skip count indicates frequent gradient overflow, requiring a check of the numerical range or an adjustment to the scaling strategy.

    IV. Multimodal Data Pipeline and Sequence Packing

    Multimodal samples contain images, videos, and text, whose preprocessing computational loads vary significantly. A common practice is to execute visual preprocessing asynchronously on the CPU side, decoupling it from GPU computation via prefetch queues. The queue depth needs to be adjusted based on data reading speed and single-step computation time. If the GPU is waiting for data, prioritize checking the queue depth and CPU thread count.

    When sample lengths vary significantly, sequence packing can be used to improve token utilization. After packing, multiple samples are concatenated into a single sequence, but they should not attend to each other. This requires isolating samples using attention masks. In practice, there are two common types of errors.

    The first is cross-sample attention leakage. The validation method involves computing two samples separately, then computing them after packing, and comparing the outputs at their respective positions. If the packed results do not match the separately computed results within tolerance, the mask is incorrect.

    The second is positional encoding misalignment. The position ID for each sample should restart from zero, rather than using the global position within the packed sequence. You can print the position IDs of several samples in a data checking script to confirm that each segment starts from zero.

    A staged training strategy is also commonly adopted during the training phase. First, freeze the language model and only train the projection layer and visual encoder. Once convergence stabilizes, proceed to full-parameter joint training. The number of steps and learning rates for each stage need to be adjusted according to the data distribution, and convergence should be confirmed on the validation set rather than copying values from other projects.

    V. Gradient Synchronization and Communication Optimization

    The core objective of gradient synchronization is to overlap communication with computation as much as possible. Common techniques include the following.

    Gradient Bucketing and Reduce Split. Divide gradients into buckets and initiate reduce-scatter as soon as a portion of the backward pass completes, executing it concurrently with the computation of the remaining layers. The bucket size affects the overlap effect: if buckets are too small, launch overhead increases; if too large, the overlap window shrinks. This needs to be determined through empirical testing.

    Compressed Communication. Provided convergence is guaranteed, gradients can be transmitted in BF16. Before applying this, compare the loss curves with compression enabled and disabled to ensure the difference is within an acceptable range.

    Topology Awareness. Intra-node card-to-card connections usually have high-bandwidth direct links, while inter-node connections rely on the network. Communication should be maximized within nodes to reduce cross-node traffic.

    To verify whether these optimizations take effect, two types of baselines must be established. The first is a bandwidth baseline: run all-reduce benchmarks intra-node and inter-node respectively, recording the effective bandwidth. The second is an overlap baseline: use a profiler to inspect the timeline and confirm whether communication operators overlap temporally with compute operators. If communication and computation always appear serially, the overlap is not working, and you need to check the bucketing and prefetch configurations. The proportion of reduce-scatter time relative to the single-step time is also a direct metric for evaluating optimization effectiveness.

    VI. Fault Tolerance and Checkpoint Resumption

    In ultra-long training cycles, hardware failures are almost inevitable, so fault tolerance mechanisms must be designed in advance.

    Checkpoints should be saved asynchronously so that the saving process does not block the main training flow. Each save should include not only model parameters but also the data loading position, optimizer states, and random number states. Missing any of these will cause the resumed training trajectory to deviate from the original one.

    Checkpoint integrity must also be guaranteed. During writing, first write to a temporary file; after writing and verification are complete, rename it to the official file to prevent leaving a corrupted checkpoint due to a mid-save failure. You can record checksums for each file, verify them before recovery, and retain the last few checkpoints to ensure you have a fallback if the latest one is corrupted.

    The equivalence of resumed training needs practical verification. One method is to save a checkpoint at step N, train from scratch to step N+M, and record the loss; then resume from the checkpoint and train for M steps, comparing the two loss curve segments. Only when they are consistent within numerical tolerance can the recovery mechanism be considered reliable.

    Additionally, you can establish automated detection and replacement scheduling for faulty nodes. This mechanism reduces the frequency of manual intervention, but it relies on the accuracy of monitoring metrics and requires manual review of alerts during the initial phase.

    VII. General Methodology for Heterogeneous Software Stack Adaptation

    Training adaptation on accelerators outside the mainstream CUDA ecosystem can be advanced in the following four steps.

    Step 1: Operator Coverage Audit. List all operators from the model’s computation graph and verify the support status of the target software stack one by one. It is recommended to organize this into a table to track progress:

    Operator Name Supported Alternative Implementation Test Case Blocking Level
    Attention (FlashAttention-like impl.) Per vendor docs Standard attention impl. Single-layer fwd & bwd comparison High
    Layer Normalization Per vendor docs Decomposed into basic operators Random input comparison Medium
    Rotary Positional Encoding Per vendor docs Custom implementation Fixed input comparison Medium

    Operators with a high blocking level should be prioritized; otherwise, subsequent steps cannot proceed.

    Step 2: Equivalence Verification. On both the reference platform and the target platform, train a small-scale model for several steps using the same random seed, and compare activations and gradients layer by layer. Record the maximum absolute error and relative error during comparison. Tolerances should be set according to the data type; the reasonable range for FP32 and BF16 is significantly different, so the same threshold cannot be used for all cases.

    Step 3: Scale-Up Expansion. First verify correctness on a single card, then verify parallel correctness on a single machine with multiple cards, and finally scale out to multiple machines. A performance baseline should be established at each step; if performance drops at a later step, it can be localized to the specific scaling stage.

    Step 4: Performance Profiling-Driven Optimization. Use a general profiler to locate communication bottlenecks and operator hotspots, and let the data dictate the optimization direction. Blindly tweaking parameters often consumes significant time with uncertain results.

    VIII. Risk Warnings and Conclusion

    There are three types of risks that require special attention.

    First, conclusions cannot be directly extrapolated. Different accelerator models, driver versions, and software stack combinations may differ in operator support, communication performance, and numerical behavior. The methods in this article are transferable, but every number and conclusion must be re-measured on your own platform.

    Second, numerical issues can appear silently. A training loss without obvious anomalies does not mean the numerical path is flawless. Equivalence verification and regular small-scale comparisons are the primary means of detecting such problems.

    Third, the larger the scale, the higher the debugging cost. Locating a numerical error on thousands of cards takes far more time and resources than locating it on a single card. Therefore, before formal large-scale training, operator coverage testing and numerical equivalence verification must be completed.

    For teams planning to build their own controllable training infrastructure, it is recommended to prioritize establishing automated workflows for operator coverage testing and numerical equivalence verification. While these tasks do not directly improve model performance, they can expose most underlying issues before large-scale training, making them highly cost-effective foundational engineering practices for heterogeneous adaptation.