FSDP2 Training Pipeline Validation and Optimization for Ultra-Large Multimodal MoE Models

    This article examines the validation and optimization of an FSDP2-based training pipeline for an ultra-large multimodal Mixture-of-Experts (MoE) model on a domestically developed high-performance AI accelerator. It outlines the main challenges of training trillion-parameter multimodal models, including memory pressure, All-to-All communication bottlenecks, and numerical stability during image-text fusion. The article then describes the FSDP2 training design, communication library support, dual-node 16-card stability test, loss and memory results, visual branch gradient validation, and system-level optimizations such as expert parallelism, parameter prefetching, fused attention operators, and Chunk Loss. Readers gain an engineering reference for validating and optimizing large-scale multimodal MoE training pipelines under constrained hardware resources.

    As AI technology evolves, large language models are moving toward native multimodality, ultra-long context, and sparse architectures. For models with trillions of total parameters, million-token context support, and joint image-text training, the underlying GPU compute, memory management, and multi-card multi-node communication bandwidth face unprecedented challenges. This article provides an in-depth analysis of the FSDP2 training pipeline validation and optimization practices for an ultra-large multimodal MoE (Mixture of Experts) model on a domestically developed high-performance AI computing accelerator.

    1. Background and Technical Challenges

    Current frontier native multimodal models typically have the following characteristics: a very large total parameter count (for example, about 2.8 trillion parameters), an MoE architecture to decouple compute from parameter scale, hybrid attention mechanisms such as dynamic sparse retrieval and Gated DSA, and integrated visual understanding and tool-calling capabilities.

    This architecture faces three core pain points during training:

    1. Memory wall: Trillion-level parameters, together with their gradients and optimizer states, far exceed the memory capacity of a single GPU.
    2. Communication bottleneck: The MoE architecture introduces expert routing, which sharply increases cross-card and cross-node All-to-All communication. If communication and computation cannot overlap effectively, training efficiency is severely degraded.
    3. Numerical stability of multimodal fusion: Joint image-text training requires the vision encoder and the language model to stay synchronized in gradient updates, making them prone to vanishing gradients or numerical overflow.

    2. Training Design: FSDP2 and Native Multimodal Path Construction

    To address these challenges, the technical team designed a multimodal training path based on FSDP2 (Fully Sharded Data Parallel 2). The adaptation work focused on four core modules: attention computation, dynamic routing, visual encoding, and cross-modal projection. These modules were seamlessly integrated into a unified forward pass, backward pass, and parameter update flow.

    1. Memory sharding and state management

    The training design retains the industry-standard native automatic modeling flow. Using FSDP2, model parameters, gradients, and optimizer states are evenly distributed across different GPUs. Similar to traditional ZeRO optimization, FSDP2 further optimizes the sharding strategy and reduces per-card memory pressure, making it possible to train ultra-large models with limited hardware resources.

    2. Communication library support

    Cross-card and cross-node data synchronization is handled by a high-performance collective communication library. The library is deeply optimized for underlying hardware characteristics, ensuring that sharded parameter aggregation and distribution complete with minimal latency in a small-to-medium-scale cluster such as two nodes with 16 cards.

    3. Environment Configuration and Stability Testing

    To verify the functional correctness and stability of the training pipeline, the technical team conducted continuous training tests on a dual-node, 16-card high-performance AI training and inference integrated accelerator.

    1. Test model configuration

    Because this was not full-scale pretraining, the test used a randomly initialized cropped configuration:

    • Language backbone: 13 layers retained.
    • MoE configuration: 16 routed experts with a Top-8 routing strategy.
    • Vision module: the full 27-layer vision tower and the cross-modal projection module were retained.

    2. Data and hyperparameters

    • Dataset: a public image-text multimodal question-answering dataset was used for training.
    • Global batch size: 16
    • Sequence length: 1024

    3. Test result analysis

    Across all 16 training processes, the system completed 400 consecutive optimizer updates with no numerical overflow or abnormal interruption, demonstrating the robustness of the underlying software and hardware stack.

    • Loss convergence: The average training loss from steps 21 to 70 was 8.9365, dropping significantly to 2.1802 over the last 50 steps. Meanwhile, validation loss steadily decreased from 6.5297 at step 100 to 4.6873 at step 400.
    • Memory behavior: The sampled device memory peak remained stable at 44.80 GiB, indicating that the FSDP2 sharding strategy effectively controlled memory growth and left sufficient headroom for future expansion of sequence length or expert count.

    4. Visual Branch Gradient Update Validation

    In multimodal model training, a common concern is that the visual encoding part may act only as a static feature extractor and may not truly participate in end-to-end parameter updates. To address this, the technical team performed a detailed inspection of the gradient flow during training.

    Validation results showed that the image embedding layer, the first and last layers of the vision tower, and the cross-modal projection module all produced non-zero gradients and parameter updates. This confirms that the visual encoding part not only completed the forward data input but also participated in backward error propagation and weight optimization, ensuring true alignment of the multimodal feature space.

    5. Deep Optimization Strategies and Practices

    In addition to basic training adaptation, the technical team completed a series of system-level optimizations to support future training configurations with larger scale and longer context.

    1. FSDP2 and expert parallelism collaboration

    The special characteristic of the MoE architecture is that different samples are routed to different expert networks. The team implemented collaboration between FSDP2 and Expert Parallelism, ensuring that expert parameters are locally computed and sharded-aggregated on the corresponding GPUs, greatly reducing unnecessary data movement.

    2. Parameter prefetching and gradient communication scheduling

    To hide communication latency, the system introduced a parameter prefetching mechanism. While the current layer performs forward/backward computation, the parameter shards required by the next layer are fetched asynchronously. At the same time, after gradients are produced during backpropagation, gradient communication is scheduled immediately so that it overlaps with the remaining backward computation.

    3. High-performance attention operators

    For the Gated DSA hybrid attention mechanism used by the model, high-performance fused operators were developed at the lower layer. These operators use the Tensor Cores of a specific instruction set architecture (such as MUSA) to accelerate matrix operations and reduce memory access overhead.

    4. Chunk Loss computation

    When handling ultra-long context (such as one million tokens), regular loss computation causes intermediate activations to fill memory. This test actually enabled Chunk Loss computation, splitting long sequences into multiple chunks to compute loss separately and accumulate gradients. Without affecting mathematical equivalence, this technique significantly reduces peak memory and makes it possible to process ultra-long sequences under limited memory.

    6. Conclusion

    The dual-node, 16-card, 400-step continuous training validation was not only a rigorous test of a domestic heterogeneous computing software and hardware stack, but also provided an effective set of engineering practices for training ultra-large multimodal MoE models. From FSDP2 memory sharding to confirmation of visual branch gradient updates, and further to deep optimizations such as expert parallelism and Chunk Loss, the entire pipeline demonstrated high functional correctness and stability. These experiences lay a solid technical foundation for subsequent full-parameter-scale pretraining on cloud platforms that provide elastic compute clusters, such as Baidu AI Cloud.