Training a MoE Multimodal Model on 16 GPUs: A Domestic GPU Practice with FSDP2

    This article details a practical validation of a Mixture-of-Experts (MoE) multimodal training pipeline on a two-node, 16-GPU cluster using domestic (China-made) accelerators. It covers the core challenges of MoE routing and multimodal fusion, a scaled-down experimental configuration, the integration of FSDP2 for parameter sharding, and how to interpret convergence and memory metrics. The article also discusses the gap between a small-scale setup and a production-scale cluster, including communication bottlenecks, parallel strategy, and fault tolerance requirements. This is a useful reference for teams planning to reproduce or extend a MoE multimodal training run on limited hardware.

    Training a MoE Multimodal Model on 16 GPUs: A Domestic GPU Practice

    1. Key Difficulties in Training MoE Multimodal Models

    As large models move toward multimodal inputs and trillion-scale parameters, the training pipeline places much higher demands on hardware and communication. The core difficulty lies in combining Mixture-of-Experts (MoE) routing with multimodal branches.

    MoE increases model capacity while keeping computation bounded by introducing multiple expert networks and activating only a subset of them (e.g., Top-K routing) during the forward pass. The downside is that tokens are routed to experts on other GPUs, so every layer triggers an All-to-All communication. A rough estimate of the data volume for a single dispatch is roughly batch × seq_len × top_k × hidden_size × bytes_per_element. The combine phase requires an exchange of the same magnitude. This estimate ignores local hits and load imbalance, but it already shows that network bandwidth and latency become a bottleneck.

    The multimodal part adds another layer of pressure. The vision encoder tower and cross-modal projection modules make input data more heterogeneous, and the tensor shape transformations during feature alignment become more complex. Managing contiguous memory and reusing operator memory becomes more difficult as a result.

    2. Scaled-Down Configuration and Experimental Setup

    Full-scale pretraining is very expensive, so this experiment used a scaled-down configuration. The goal was to verify whether the training pipeline is correct and whether the loss shows a downward trend. The reduced setup is as follows.

    Item Configuration Notes
    Language backbone 13 Transformer blocks Taken from the full model
    Routed experts 16 Full expert count retained
    Activated experts Top-8 Half of the experts activated per token
    Vision tower 27 layers Fully retained
    Dataset Medical image-text VQA dataset Trained from random initialization
    Cluster 2 nodes, 16 GPUs total 8 GPUs per node
    Training steps 400 steps No overflow or interruption

    Two points deserve attention. First, Top-8 with 16 experts activates half of the experts, which gives a much lower sparsity level than a real large-scale MoE model. Therefore this experiment is more about verifying the pipeline than simulating actual computational sparsity. Second, the public material does not give the total parameter count, hidden size, sequence length, batch size, precision, GPU model, interconnect topology, or framework versions. All of these details are required for reproduction, and we recommend that experimenters record them when reporting results.

    3. Integrating FSDP2

    FSDP2, compared with earlier FSDP wrapping methods, shards parameters at the module level and uses DTensor to manage the sharded parameters, gradients, and optimizer states. It can evenly split parameters, gradients, and optimizer states across all GPUs, reducing per-GPU memory usage. Before using it, check the PyTorch version: fully_shard resides in torch.distributed.fsdp for PyTorch 2.6 and later, while earlier versions have it in torch.distributed._composable.fsdp.

    Below is a reference code snippet for integrating FSDP2. The model class and module attribute names are placeholders; replace them with the actual names from your implementation.

    1. import os
    2. import torch
    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. local_rank = int(os.environ["LOCAL_RANK"])
    7. torch.cuda.set_device(local_rank)
    8. dist.init_process_group("nccl")
    9. world_size = dist.get_world_size() # 16 for two nodes with 8 GPUs each
    10. mesh = init_device_mesh("cuda", (world_size,))
    11. model = MultimodalMoEModel(num_layers=13, num_experts=16, top_k=8, vision_layers=27)
    12. model = model.to(torch.bfloat16).cuda()
    13. # First shard each module individually, then shard the root module
    14. for block in model.language_trunk.layers:
    15. fully_shard(block, mesh=mesh)
    16. for block in model.vision_tower.layers:
    17. fully_shard(block, mesh=mesh)
    18. fully_shard(model, mesh=mesh)
    19. optimizer = torch.optim.AdamW(model.parameters(), lr=1e-4)
    20. for step, batch in enumerate(dataloader, start=1):
    21. images = batch["images"].cuda()
    22. texts = batch["texts"]
    23. labels = batch["labels"].cuda()
    24. optimizer.zero_grad(set_to_none=True)
    25. visual_features = model.vision_tower(images)
    26. fused_input = model.cross_modal_proj(visual_features, texts)
    27. logits = model.language_trunk(fused_input) # MoE routing triggers All-to-All internally
    28. loss = compute_loss(logits, labels)
    29. if not torch.isfinite(loss):
    30. raise RuntimeError(f"Non-finite loss at step {step}")
    31. loss.backward() # Triggers backward communication and gradient Reduce-Scatter
    32. torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)
    33. optimizer.step()
    34. if step == 400:
    35. break

    Example launch command:

    1. torchrun --nnodes=2 --nproc_per_node=8 \
    2. --rdzv_backend=c10d --rdzv_endpoint=<MASTER_NODE_IP>:29500 train.py

    The gradient clipping and NaN check in the example are recommended safeguards; whether the original experiment enabled them has not been disclosed.

    4. Interpreting Convergence and Memory Metrics

    The validation report provides three sets of numbers.

    • Training loss: The mean over steps 21 to 70 is taken as the starting point, giving 8.9365; the mean over the last 50 steps is 2.1802. The first 20 steps are excluded to avoid initial instability.
    • Validation loss: It drops from 6.5297 to 4.6873. The step count and frequency of validation are not disclosed.
    • Peak memory: 44.80 GiB. The measurement object (single GPU or the maximum over all GPUs) and whether activations are included are not disclosed.

    The loss decrease indicates that the model is fitting the training data, and the validation loss decrease offers some signs of generalization. However, with random initialization and a limited dataset size, this trend only confirms that the pipeline can train correctly; it does not prove that the model has usable generalization capability.

    The memory numbers also do not prove that the vision branch parameters participate in gradient updates. To verify that, you can perform the following checks:

    1. Record the gradient norms of the vision tower layers and confirm they are non-zero.
    2. Compare the loss curves with and without freezing the vision tower and observe the difference.
    3. Compare the parameter changes in the vision tower before and after training.

    We recommend recording the step ranges, means, standard deviations, learning rate, and gradient clipping threshold for each statistical interval in a table, so other teams can reproduce the same results.

    5. From 16 GPUs to a Thousand GPUs: What Is Missing

    A two-node, 16-GPU setup has a simple communication topology. When scaling to a thousand or ten thousand GPUs, the following issues gradually become critical.

    • Communication congestion: All-to-All traffic grows with the number of experts and nodes, and network routing hash collisions become more likely.
    • Parallel strategies: You need to combine data parallelism, expert parallelism, tensor or pipeline parallelism, and handle the communication dependencies among them.
    • Fault tolerance and recovery: Hardware failures are common in large clusters. The training framework must support checkpoint resumption, slow-node detection, and failure-domain isolation.

    For fault tolerance, at least the following items should be confirmed: checkpoint saving frequency, communication library timeout parameters, slow-node detection thresholds, automatic restart procedures after failures, and whether a single-node failure affects the state restoration of the entire job.

    The two-node, 16-GPU result proves the basic correctness of the training pipeline, but it is still far from a full-scale training run. For teams that want to reproduce or reference this practice, the next steps should be to fill in the complete scaled-down configuration parameters, runtime environment versions, and metric measurement methods, and to validate communication and fault tolerance at a larger scale.