Training a Multimodal MoE Model with FSDP2: A 16-GPU Test Across Two Machines

    This article documents a practical test of training a trimmed multimodal MoE model with FSDP2 across 16 GPUs on two machines. It covers the three main challenges of multimodal MoE training, how FSDP2 shards memory differently from FSDP1, a configuration example using fully_shard, how to inspect cross-node communication, and the observed training results—including loss curves, memory usage, and whether gradients properly flow back to the vision branch.

    1. Conclusions First

    In an environment of two machines with 16 GPUs in total, we used FSDP2 to train a trimmed multimodal MoE model for 400 consecutive optimizer updates without numerical overflow or interruption. Gradients also propagated correctly to the vision tower and the cross-modal projection layers, and those parameters were actually updated.

    These results only demonstrate that the training pipeline can run stably. The test model was a randomly initialized, trimmed version, and the training dataset was small. Therefore, the results cannot be extrapolated to full-scale pretraining of models with hundreds of billions or trillions of parameters.

    2. Three Challenges in Multimodal MoE Training

    Take an open-weight native multimodal model with roughly 2.8 trillion total parameters and support for a 1-million-token context as an example. It uses two attention mechanisms—KDA and Gated DSA—adopts an MoE architecture, and provides visual understanding and tool-calling capabilities. Training this kind of model mainly involves three problems.

    First, routing and sparse attention cause the computation graph to change at runtime, making GPU scheduling difficult to plan in advance.
    Second, once the parameter count reaches the hundreds-of-billions scale, fitting all parameters, gradients, and optimizer states on a single GPU is no longer feasible.
    Third, during joint image-text training, the vision encoder’s output must pass through a projection before entering the language model, and backpropagation through this path is prone to problems.

    3. Sharding Memory with FSDP2

    The main difference between FSDP2 and FSDP1 lies in how sharding is represented. FSDP1 wraps the entire model with FullyShardedDataParallel and shards flattened parameters. FSDP2 uses fully_shard to wrap the model module by module, storing each parameter as a DTensor, with each GPU holding only one shard.

    During the forward pass, GPUs temporarily reconstruct the full parameters needed by the current layer via all-gather. After computation, whether these parameters are released is controlled by reshard_after_forward. During backpropagation, gradients are distributed back to each GPU via reduce-scatter. Optimizer states follow the parameter sharding, so each GPU stores only the momentum for the portion it is responsible for.

    The example below shows the basic configuration. It is based on the fully_shard API in PyTorch 2.x; please refer to the official documentation of your version for exact parameter names.

    1. import torch
    2. from torch.distributed.device_mesh import init_device_mesh
    3. from torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy
    4. # 16 GPUs across two machines form a 1D data parallel mesh
    5. mesh = init_device_mesh("cuda", (16,))
    6. model = build_model() # model construction omitted
    7. mp_policy = MixedPrecisionPolicy(
    8. param_dtype=torch.bfloat16,
    9. reduce_dtype=torch.float32,
    10. )
    11. # Wrap submodules layer by layer first, then wrap the root module
    12. for layer in model.layers:
    13. fully_shard(layer, mesh=mesh, mp_policy=mp_policy, reshard_after_forward=True)
    14. fully_shard(model, mesh=mesh, mp_policy=mp_policy)
    15. # The optimizer must be created after sharding, otherwise it references unsharded parameters
    16. optimizer = torch.optim.AdamW(model.parameters(), lr=1e-4)

    4. How to Check Cross-Node Communication

    In multi-machine training, communication often becomes the bottleneck before computation does. The original experiment records did not specify the communication topology, bucket size, or the exact configuration for compute-communication overlap, so this section only provides directions for inspection.

    • Use the communication library’s logs or profiling tools to confirm which links the all-gather and reduce-scatter operations actually traverse—intra-node interconnects or the cross-node network.
    • Measure the proportion of communication time within each training step. If this proportion remains consistently high, check whether the wrapping granularity is too fine, causing too many communication operations.
    • Compare the measured bandwidth with the machine’s theoretical bandwidth. If the gap is large, further check NIC binding and topology configuration.

    5. Experiment Setup

    • Hardware: two physical servers with 16 AI training/inference compute cards in total. The card model and the intra-machine and cross-machine interconnect bandwidth were not given in the original records.
    • Model: to validate the training pipeline, a randomly initialized trimmed configuration was used. The language backbone retains 13 layers, with 16 routed experts and Top-8 routing. The vision tower retains all 27 layers, and the cross-modal projection module is also fully preserved.
    • Data and hyperparameters: the training data is the MedPix-VQA image-text dataset, with a global batch size of 16 and a sequence length of 1024.

    6. Training Results

    All 16 training processes completed 400 consecutive optimizer updates. The training loss decreased from an average of 8.9365 over steps 21–70 to an average of 2.1802 over the final 50 steps. The validation loss dropped from 6.5297 at step 100 to 4.6873 at step 400.

    The smooth decline of the loss indicates that the data pipeline works correctly. This observation is also consistent with the judgment that expert routing weights are being synchronized and updated correctly in the multi-GPU environment.

    Regarding memory, the reported peak was 44.80 GiB. The original records did not specify whether this is a per-GPU or global figure, nor the sampling period, nor whether activations are included. Before citing this number, its exact definition should be confirmed.

    7. Does the Vision Branch Actually Participate in Training?

    A common pitfall in multimodal training is that the vision module is connected to the computation graph, but gradients never actually flow back, meaning the vision encoder is effectively not being