Training a Trillion-Parameter Multimodal MoE Model on 16 NPUs: A 400-Step Adaptation Walkthrough
This article walks through a practical adaptation of an open-weight native multimodal MoE model (roughly 2.8 trillion parameters, million-token context) on a domestic training-and-inference accelerator platform with a self-developed software stack, using a trimmed configuration across two nodes and 16 cards. It explains why multimodal sparse models are hard to train (the memory wall, expert routing imbalance, numerical instability, and a vision branch with zero gradients), then details the unified forward/backward design, FSDP2 sharding combined with expert parallelism, fused hybrid attention kernels, and chunked loss computation. The 400-step run completed without overflow or interruption, peaked at 44.80 GiB of sampled device memory, and confirmed real gradient updates in the vision branch. Readers will also find a three-step method for verifying that the vision tower is genuinely training, plus common pitfalls and engineering recommendations.
1. Why Multimodal Sparse Models Are Hard to Train
Over the past year, open-weight native multimodal large models have evolved quickly. Parameter counts have reached the trillion scale, and context windows have expanded to the million-token level. These models typically stack three structural features at once:
- Dynamic sparse computation introduced by Mixture-of-Experts (MoE) routing.
- Sequence modeling that mixes linear attention with dynamic sparse attention.
- Cross-modal projection between the vision encoder and the language backbone.
Combined, these features make training far more than “put the model on multiple cards and run a forward and backward pass.” They simultaneously stress compute density, memory management, cross-card communication efficiency, and numerical stability.
Four obstacles show up most often in engineering practice:
- Memory wall: parameters, gradients, and optimizer states add up to three copies of memory overhead, making it hard for a single card to hold a full model replica.
- Routing imbalance: skewed expert load leaves some devices idle, and overall throughput is dragged down by the slowest one.
- Numerical instability: sparse retrieval and long-sequence accumulation can easily trigger overflow, causing loss spikes or interrupted training.
- Multimodal “fake participation”: the vision branch consumes memory and compute, but its gradients are actually zero, so only the language side gets updated.
One adaptation validation exercise targeted exactly these four points. Built on a flagship domestic training-and-inference accelerator card and a self-developed software stack, it trained a trimmed configuration of an open-weight native multimodal model (about 2.8 trillion parameters, million-level context) in a two-node, 16-card environment. The run completed 400 consecutive steps with no overflow and no interruption, and confirmed that the vision branch produced real gradient updates.
2. Overall Approach: A Unified Forward, Backward, and Parameter Update Flow
The core idea of the adaptation was “unify, don’t stitch together.” Attention computation, dynamic routing, vision encoding, and cross-modal projection were all wired into the same forward, backward, and parameter update flow, avoiding the fragmented state where the language side and the vision side each maintain their own training loop.
The approach kept the native automatic model loading flow of a mainstream training framework and introduced no private model-definition branch. This yields two direct benefits: weight loading and config parsing follow common community conventions, so migration cost stays low; and when the model structure is upgraded later, the surface area of adaptation code changes stays manageable.
For parallelism, the backbone is Fully Sharded Data Parallel (FSDP2): model parameters, gradients, and optimizer states are sharded and spread across different GPUs, so each card holds only a shard and memory pressure drops sharply. Collective communication across cards and nodes is handled by a self-developed collective communication library, scheduled to overlap with the compute stream.
A schematic configuration skeleton looks like this (structure only, not a specific API):
# Pseudocode: FSDP2 + expert parallelism training skeletonfor step in range(total_steps):with no_sync() if step % grad_accum == 0 else nullcontext():text_out = language_main(input_ids, text_mask)vis_feat = vision_tower(images) # full vision towerfused = cross_modal_projector(vis_feat, text_out)loss = chunked_loss(fused, labels) # chunked loss to lower peak memoryloss.backward() # unified backward passrouter_balance_loss().backward() # load-balancing auxiliary lossoptimizer.step(); optimizer.zero_grad()prefetch_next_params() # parameter prefetch
3. Key Techniques and Implementation Details
3.1 Native FSDP2 Sharding and Communication Scheduling
The value of FSDP2 is that it makes sharding a first-class citizen: each card holds a parameter shard, aggregates it on demand during the forward pass, and releases it once done; during the backward pass it aggregates gradient shards again and performs reduction. In engineering terms, prefetch depth needs fine control: too shallow exposes communication latency, too deep raises the memory peak. This validation brought parameter prefetch and gradient communication scheduling into the optimization scope, so communication is hidden behind computation as much as possible.
3.2 Coordinating FSDP2 with Expert Parallelism
MoE layers are not a good fit for plain data parallelism: once experts are split across devices, tokens must be all-to-all exchanged according to routing results. The approach combines expert parallelism with data parallelism: non-expert layers use FSDP2 sharding, expert layers are distributed along the expert dimension, and All-to-All communication is constructed from the routing results. The key is to stagger the two kinds of communication so they do not compete for link bandwidth in the same time window.
3.3 High-Performance Hybrid Attention Kernels
In a hybrid attention structure, the linear branch handles low-cost modeling of long sequences, while the sparse branch handles fine-grained retrieval of key tokens. Assembling these with generic kernels produces many intermediate tensors and kernel launch overhead. The adaptation provided a fused implementation that merges normalization, masking, and accumulation into a few kernels, which both reduces memory usage and lowers the risk of overflow along the numerical accumulation path.
3.4 Chunked Loss Computation
For a trillion-parameter model at million-token context, the logits tensor alone can exhaust memory. Chunked loss splits the sequence dimension into blocks, computes cross-entropy block by block, and accumulates gradients incrementally, reducing peak memory from “proportional to sequence length” to “proportional to block size.” This mechanism was enabled for the 400-step test, where sampled peak device memory measured 44.80 GiB.
4. Test Configuration and Results
The test environment was two servers with 16 accelerator cards in total, and 16 training processes mapped one-to-one to the 16 cards. On the model side, the setup used a 13-layer language backbone with 16 routed experts and Top-8 routing, while keeping the full 27-layer vision tower and the cross-modal projection module. On the data side, it used an image-text question answering dataset with a global batch size of 16 and a sequence length of 1024.
The results can be read along three dimensions:
- Convergence: training loss dropped from an average of 8.9365 over steps 21 to 70 down to 2.1802 over the final 50 steps; validation loss fell from 6.5297 at step 100 to 4.6873 at step 400, with a monotonically decreasing curve and no abnormal plateau.
- Stability: 400 consecutive optimizer updates completed with no numerical overflow and no abnormal interruption, indicating that loss scaling under mixed precision and the numerical path of the sparse kernels are basically reliable.
- Resource usage: the 44.80 GiB sampled peak memory leaves headroom to scale to more layers and longer sequences on the same hardware.
It is worth stressing that this validation used a randomly initialized trimmed configuration. The goal was to check functional correctness and stability of the training pipeline, not full-scale pretraining of a complete model, so the loss values above should not be extrapolated into indicators of final model capability.
5. How to Confirm the Vision Branch Is “Really Training”
The most hidden defect in multimodal training is zero gradients on the vision side. Engineering practice offers a three-step method to confirm it:
- Gradient norm check: compute gradient norms separately for the first and last layers of the vision tower and for the cross-modal projection, confirming they are non-zero and of reasonable magnitude.
- Parameter delta comparison: record weight snapshots before and after the update and compute the differential norm, ruling out the case where gradients exist but are clipped to zero.
- Ablation control: freeze the vision tower, run the same number of steps, and compare the difference in loss descent slope to verify that visual information actually contributes an optimization signal.
In this validation, image embeddings, the first and last layers of the vision tower, and the cross-modal projection all showed non-zero gradients and parameter updates, so vision encoding genuinely participated in training.
6. Common Pitfalls and Engineering Recommendations
- Don’t watch loss alone: monitor routing load distribution, gradient norms, and communication wait ratio at the same time, to avoid a situation that “looks converged but is actually degrading.”
- Tune sharding and prefetch together: peak memory and throughput are often a trade-off, so run a small-scale sweep with a fixed step count before scaling up.
- Prioritize chunked loss for long sequences: it is one of the highest return-on-investment memory optimizations available.
- Keep the native model definition: avoid changing model structure code, and confine adaptation to the parallelism strategy and kernel layer, which makes it easier to track upstream evolution.
- Validate first: start with a smoke test using trimmed layer counts and a small batch, then move on to a long stability run.
7. Conclusion
This adaptation validation, covering two nodes, 16 cards, and 400 consecutive training steps, shows that domestic training-and-inference hardware and a self-developed software stack can already carry the full training pipeline of a trillion-parameter native multimodal model: a unified forward and backward flow, FSDP2 coordinated with expert parallelism, fused attention kernels, and chunked loss computation together form a reusable technical foundation. For development teams, what is more worth borrowing is not any particular set of numbers but the three-stage methodology of “first verify pipeline correctness, then verify numerical stability, and only then scale up.” If an organization plans to build a similar training environment, it can schedule multi-node jobs through a container platform, use object storage to hold datasets and checkpoints, and rely on monitoring, alerting, and logging services to continuously track loss, memory, and communication metrics, turning one successful short run into a sustainable long-stability training capability.
