Trillion-Parameter Multimodal MoE Training on Domestic Accelerators: Adaptation and Troubleshooting Guide

    This guide explains how to adapt and troubleshoot trillion-parameter multimodal MoE training on domestic accelerators. It covers the baseline conditions to record, memory accounting, FSDP2 loading and weight mapping, gradient synchronization and numerical validation, multimodal pipeline checks, a practical checklist, and a common-error troubleshooting table. The goal is to help readers establish reproducible conditions, verify loading and numerical correctness, and diagnose memory, throughput, and expert-load issues.

    1. Conditions to Record Before Adaptation

    Adaptation results are only useful when the conditions are clear. Before reproducing or citing adaptation results, record the following information. The parameter scales in this article are hypothetical examples and do not correspond to any specific released model. Readers should recalculate based on their own model configuration.

    Condition What to record Why it matters
    Hardware Accelerator card model, per-card memory, intra-node interconnect, number of cards, inter-node network bandwidth Determines memory limits and communication topology
    Software stack Versions of driver, training framework, communication library, and operator library Interfaces and operator behavior change across versions
    Model Model architecture, total parameter count, number of experts, number of experts activated per token Determines compute volume and memory baseline
    Weights Weight format, shard layout, data type, parameter naming rules Determines loading logic and parameter name mapping
    Training stage Pretraining, continued training, or fine-tuning Determines optimizer state and data pipeline configuration
    Validation metrics Throughput (tokens/s), MFU, peak memory, loss curve Without metrics, it is impossible to judge whether the target is met

    The MFU calculation method, the throughput measurement scope (global or per-card), and the peak memory sampling tool and interval should all be recorded together with the results. Numbers with different scopes cannot be compared directly.

    2. Memory Accounting: Order-of-Magnitude Judgment

    This article uses 1 TB = 10^12 bytes and 1 GB = 10^9 bytes. Assume the model has 2.8 trillion total parameters.

    BF16 weights alone require about 5.6 TB (2.8 trillion × 2 bytes). With common mixed-precision Adam training, the model state per parameter is as follows.

    State Precision Bytes per parameter Total
    Working weights BF16 2 5.6 TB
    Gradients BF16 2 5.6 TB
    Master weights FP32 4 11.2 TB
    First-order momentum FP32 4 11.2 TB
    Second-order variance FP32 4 11.2 TB
    Total 16 44.8 TB

    Forward and backward computation use BF16 working weights, while optimizer updates use FP32 master weights. If another configuration is used, for example, no FP32 master weights or low-precision optimizer states, the total bytes will change and must be recalculated based on the actual configuration.

    Model states are sharded across cards by FSDP. If the cluster has 4096 cards and each card receives an equal shard, the per-card model state is about 44.8 TB ÷ 4096 ≈ 10.9 GB. If only 1024 cards are used, it is about 43.75 GB. As the number of cards decreases, the per-card model state increases approximately proportionally.

    The numbers above are lower bounds. Fully aggregated parameters for a single layer, activations, communication buffers, and memory fragmentation all consume remaining space. Expert parameters are usually sharded by expert parallel group rather than entirely by data parallel group, so the per-card numbers for the expert portion will differ. The table below can serve as a template for actual estimation.

    Item Estimation method Measurement method
    Model states Parameter count × bytes per parameter ÷ number of shards Read allocated memory on each card after training starts
    Single-layer aggregated parameters Maximum single-layer parameter count × 2 bytes (BF16) Record memory difference before and after forward pass
    Activations Related to sequence length, batch size, and number of layers; no general formula Gradually increase batch size and record peak memory
    Communication buffers Determined by chunk size and concurrency Compare peak memory after adjusting chunk parameters
    Memory fragmentation Cannot be estimated directly Compare the difference between allocated and reserved memory

    3. FSDP2 Loading and Weight Mapping

    If an error occurs during loading, subsequent training numerical results are untrustworthy. Follow the order below.

    1. Build the model on the meta device; no actual memory is allocated at this point.
    2. Call fully_shard on submodules layer by layer, sharding the innermost modules first and the root module last.
    3. Read weights using a distributed checkpoint interface consistent with the shard layout; each rank reads only its own shard.
    4. Build a mapping table from source parameter names to target parameter names, handling residual prefixes (such as module. and _orig_mod.) and expert IDs.
    5. After loading, verify parameter count, shape, data type, and shard offset item by item.

    The example code is below. Specific API names and parameters vary by framework version; refer to the documentation for the version in use.

    1. import torch
    2. from torch.distributed.fsdp import fully_shard
    3. with torch.device("meta"):
    4. model = build_model(cfg)
    5. for block in model.blocks:
    6. fully_shard(block, mesh=mesh)
    7. fully_shard(model, mesh=mesh)

    The mapping table should be generated and saved to a file before loading for later review. Do not silently drop unmatched keys during weight conversion. Any unmatched key should raise an error.

    4. Gradient Synchronization and Numerical Validation

    Gradient reduction is usually performed in FP32 to reduce errors from BF16 accumulation. If the framework defaults to BF16 reduction, first confirm its impact on results.

    Global gradient norm is used for gradient clipping. Each shard first computes the local sum of squares, then obtains the global sum of squares through communication reduction, and finally takes the square root. Dense parameters and expert parameters use different reduction groups; compute them separately and then combine. Counting only the local shard will cause inconsistent clipping coefficients across cards.

    Numerical validation is recommended in the following steps.

    • Fix the random seed, disable dropout, and use a small-scale configuration with few layers and few experts.
    • Run the same batch of data on a single card and on multiple cards, and compare forward outputs and first-step gradients.
    • Tolerance should be determined by local measurements. Under BF16, start by observing relative error on the order of 1e-2.
    • Check at each step whether loss and gradient norm contain NaN or Inf.

    5. Multimodal Pipeline

    Multimodal input requires additional checks.

    • The number of tokens output by the visual encoder must match the number of placeholders reserved in the text. This error usually does not raise an error; it only silently misaligns the image-text correspondence.
    • Changes in image resolution cause sequence length changes. Bucketing by length can reduce wasted compute from padding.
    • Expert load of MoE routing should be recorded periodically. If some experts receive far more tokens than others, cards holding those experts become bottlenecks.
    • The all-to-all communication overhead of expert parallelism grows with sequence length and number of experts. Record the proportion of communication time in per-step time to determine whether the bottleneck is communication.

    6. Checklist

    • Hardware, driver, framework, communication library, and operator library versions have been recorded
    • Memory estimation covers model states, single-layer aggregated parameters, activations, and communication buffers
    • A parameter mapping table has been generated before loading, with no unmatched keys
    • Parameter count, shape, data type, and shard offset have been verified after loading
    • First-step outputs and gradients have been compared between single-card and multi-card runs
    • Global gradient norm for clipping has been reduced across shards
    • The number of multimodal placeholders matches the number of visual tokens
    • Expert load and communication share are included in monitoring
    • After checkpoint resume, the loss curve is continuous with the pre-resume curve

    7. Common Error Troubleshooting Table

    Symptom Possible cause Troubleshooting method
    Missing or unexpected keys during loading Incomplete parameter name mapping or residual prefixes Print the key difference sets on both sides; check prefixes such as module. and _orig_mod.
    Shape mismatch Inconsistent sharding dimension or expert count Check the sharding axes and expert IDs for tensor parallelism and expert parallelism
    Dtype mismatch Loaded FP32 weights were not converted to the target precision Print the dtype of each parameter after loading
    First-step loss is NaN Weights were not loaded, or routing and softmax overflow under BF16 Check whether meta tensors remain, and perform a separate numerical check on routing outputs
    Single-card and multi-card first-step loss differ greatly Random seeds differ, initialization is not synchronized, or dropout is not disabled Fix the seed and rerun, comparing forward outputs layer by layer
    Gradient clipping coefficients differ across cards Gradient norm is computed only locally Confirm that the global norm undergoes cross-shard reduction
    Out of memory at the first step High activation memory, oversized communication buffers, or severe fragmentation Enable recomputation, reduce chunk size, and compare allocated and reserved memory
    Expert load is highly imbalanced Routing auxiliary loss is missing or its coefficient is too small Record the token count per expert and adjust the auxiliary loss coefficient
    Low throughput and high communication share Chunk size is too small, concurrency is insufficient, or topology does not match Adjust chunk parameters and check intra-node and inter-node bandwidth utilization
    Image-text correspondence is wrong Visual token count and placeholder count are inconsistent Assert that both are equal for each sample
    Loss jumps after checkpoint resume Optimizer state was not restored, or step count is incorrect Compare optimizer state and step value before and after resume

    8. Scope of Use

    The conclusions in this article apply only to the hardware, software versions, and configurations listed in Section 1. After changing the driver, framework, or communication library version, re-validate loading, gradient synchronization, and numerical validation results. The memory numbers in this article are for order-of-magnitude judgment only and are not capacity commitments. Actual usable scale depends on measured activations, communication buffers, and fragmentation.