Trillion-Scale Multimodal LLM Training on Domestic GPUs: A Full Adaptation Workflow
Training trillion-parameter multimodal models on domestically developed GPUs raises challenges that go well beyond the operator coverage and multi-card communication of the dense Transformer era. Using an open-weight native multimodal model as a case study — roughly 2.8 trillion parameters, up to 1M-token context, gated linear attention, retrieval-based dynamic sparse attention, and MoE — this article walks through a complete adaptation workflow organized into four layers: model structure, precision and memory, parallelism (FSDP), and verification. It explains how to complete operators and close the image-text gradient link, how to configure mixed precision and shard state with FSDP, how to budget memory, and how to surface problems early with a reduced configuration before judging whether adaptation is truly complete. Readers get a reusable engineering path covering operator implementation, memory management, numerical alignment, long-context handling, and long-run stability testing.
1. Introduction: Where the Difficulty Lies
Parameter counts for multimodal large models have reached the trillion scale. Models in this class generally share three traits:
- They use a Mixture-of-Experts (MoE) sparse architecture;
- Their context window can reach a million tokens;
- They support joint image-text understanding and tool use.
These models represent the main direction of large-scale training and pose a systemic challenge to domestic full-function GPUs. Adapting for the dense Transformer era mostly came down to two questions: are the operators complete, and does multi-card communication work? Facing trillion-scale multimodal models, three more questions must be answered at the same time:
- Complex structure: linear recurrent state, dynamic sparse retrieval, and expert routing are layered within the same network, multiplying the difficulty of operator coverage.
- End-to-end link: the vision encoder and the language backbone must close the loop within a single forward pass, backward pass, and parameter update.
- Massive scale: a single card cannot hold the model parameters, so sharding, recomputation, and similar techniques are needed to compress memory usage while keeping many cards running stably over the long term.
This article uses an open-weight, trillion-parameter native multimodal model (referred to below as “the model”) as an example. It has roughly 2.8 trillion parameters in total, supports a context of up to 1 million tokens, and adopts gated linear attention, retrieval-based dynamic sparse attention, and an MoE structure. The aim is to reconstruct the complete adaptation approach for training on domestic GPUs, with emphasis on two points: how to surface problems early with a smaller validation scale, and how to judge when “adaptation is complete.”
2. Breaking Down the Difficulties: Three Barriers in the Adaptation Chain
2.1 Barrier 1: Three Kinds of Sparse/Stateful Structures Layered Together Sharply Increase Operator Work
Gated linear attention carries a state that recurs across time steps, and its computation takes the form of a “state update” rather than a standard attention matrix. Dynamic sparse attention decides, based on input content, which context to retrieve and which parts to activate, so the computation path differs from sample to sample within the same batch. MoE routing sends different tokens to different experts, and the load on each card shifts dynamically with the input. With all three layered together, the complexity of adapting operators, memory, and communication is far higher than for a conventional dense model.
2.2 Barrier 2: Joint Image-Text Training Requires an End-to-End Closed Link
Native multimodal training treats the vision encoder and the language backbone as a single network. After an image is encoded and cross-modally projected, it enters the representation space of the language backbone; the supervision signal on the language side must also flow back through the computation graph to the vision part. A broken gradient link or an inconsistency in numerical semantics anywhere along the way will show up as “loss keeps dropping, but the vision tower learns nothing.”
2.3 Barrier 3: A Single Card Cannot Hold It, and Multiple Cards Cannot Run It Stably
As a rough estimate with BF16 (2 bytes), the parameters, gradients, and first- and second-order optimizer states for 1 trillion parameters add up to about 20TB — several orders of magnitude beyond a single card’s memory. Even with parameter sharding and optimizer-state offloading enabled, balancing cross-card communication, activation memory, and operator efficiency remains a hard constraint.
Therefore, the adaptation plan needs a “native path” that covers the entire process of model loading, sharding/scheduling, forward/backward/update, and gradient synchronization. The verification criteria should also be split into three levels:
- Computes correctly: numerics match the reference implementation;
- Fits: memory leaves a reasonable margin;
- Runs stably: many cards run stably over the long term with loss dropping smoothly.
3. Overall Approach: Four-Layer Adaptation Built on the Native Training Flow
The adaptation targets a certain class of trillion-scale multimodal model and follows the native training flow of a mainstream training framework rather than rewriting from scratch. The reason: the native path is usually aligned with the weight format, data pipeline, and distributed strategy, and a rewrite tends to introduce hidden deviations in the details. The work is organized around four layers: the model structure layer, the precision and memory layer, the parallelism strategy layer, and the verification and observability layer.
┌─────────────────────────────────────────────────────────────┐│ Verification & Observability: reduced-config check → numeric ││ alignment → multi-card gradient consistency → long-run test│├─────────────────────────────────────────────────────────────┤│ Parallelism: FSDP sharding (params/grads/optimizer states) + ││ activation recomputation + communication overlap │├─────────────────────────────────────────────────────────────┤│ Precision & Memory: BF16 compute + FP32 persistent state + ││ gradient clipping + memory-pool tuning │├─────────────────────────────────────────────────────────────┤│ Model Structure: gated linear attention | dynamic sparse ││ attention | vision tower + cross-modal projection | MoE │└─────────────────────────────────────────────────────────────┘
4. Model Structure Layer: Completing Operators and Closing the Image-Text Link
For the hybrid attention and expert structures, adaptation work concentrates on four areas:
- Operator implementations for gated linear attention and dynamic sparse attention;
- Expert dispatch and combine;
- Vision encoding and cross-modal projection;
- Connecting all three into a unified training flow.
In practice, this falls on three fronts.
4.1 Attention and Routing
- Complete forward and backward: define the forward computation and backward gradient for each new structure, and ensure custom operators produce consistent results in both forward and recompute execution modes.
- Unified computation graph: connect expert dispatch and combine into the computation graph so that the expert path also participates in the same backward pass and auxiliary losses can flow back.
- Handle special mechanisms: the numerical stability of gating coefficients and recurrent state, the index correctness of sparse retrieval, expert capacity and drop policy, and routing auxiliary loss must all be verified one by one.
4.2 Vision and Cross-Modal
- Keep trainable parameters: fully preserve the trainable parameters of the vision tower, avoiding treating it as a frozen feature extractor.
- Feature alignment: image features are mapped through cross-modal projection into the representation space of the language backbone, and concatenated with text tokens in the input sequence.
- Supervision closure: image-text input and language supervision are closed within a single forward, backward, and parameter update.
In engineering terms, the modalities can be arranged flexibly. Taking the mainstream interleaved image-text format as an example:
<image> image placeholder → vision tower encoding → cross-modal projection → language backbone<interleaved> interleaved image-text input → multimodal data pipeline splitting/packing → language backboneplain text → language backbone
All three forms share a single training loop, but the vision tower only participates in the forward and backward passes for batches that contain images. A few points deserve particular attention:
- The gradient semantics of batches with images and plain-text batches should stay consistent;
- The sharding strategy must remain correct for parameters that did not participate;
- Gradient accumulation can be used so that the vision-tower parameters are updated at an appropriate granularity.
4.3 Precision and Memory
The precision and memory design follows a layered scheme:
| Data type | Compute precision | Persistent/accumulation precision | Role |
|---|---|---|---|
| Main compute such as matmul and convolution | BF16 | — | Balances throughput and dynamic range |
| Parameters | Implementation-dependent | FP32 (master weights) | Provides a high-precision baseline for parameter updates |
| Gradients | Follows the compute path | FP32 accumulation | Reduces rounding error from accumulating large numbers of gradients |
| AdamW first- and second-order moments | — | FP32 | Avoids small-magnitude states being truncated under BF16 |
Activation recomputation trades a small recomputation overhead for lower activation memory. It applies to compute-intensive modules with relatively controllable recomputation cost, such as Transformer layers and vision-tower encoding blocks, and works together with FSDP sharding. In addition, pay attention to numerical boundaries:
- Sensitive tensors such as routing scores and gating coefficients can easily overflow or underflow during summation and normalization, and can be promoted to FP32 computation when necessary.
- Gradient clipping should be based on the global norm computed from FP32 gradient statistics.
- If the framework uses loss scaling, the scaling factor should be adjusted dynamically in combination with gradient-norm monitoring.
5. Parallelism Strategy Layer: Fully Sharded Data Parallel (FSDP)
5.1 What to Shard and How
FSDP evenly shards parameters, gradients, and optimizer states across ranks:
- When entering a sharded unit in the forward and backward passes, it gathers the full parameters on demand and releases them immediately after computation;
- Gradients stay on each card per-shard after reduction;
- The optimizer updates only the local shard.
As a result, the parameters and optimizer states carried by a single card are about 1/N of the unsharded case (N being the number of ranks in the sharding group), leaving room for activations, communication buffers, and the vision tower. The sharding granularity requires a trade-off:
- Blocks too coarse: high peak memory;
- Blocks too fine: many communication calls, with computation interrupted by communication;
- Recommendation: use Transformer layers and vision-tower encoding blocks as sharding units, combined with compute-communication overlap and prefetching.
5.2 Main Training Loop
The illustrative pseudocode below omits framework-specific interfaces:
# Illustrative pseudocode: one step of joint image-text training under FSDPfor batch in dataloader: # batch contains text and images, split/packed by the multimodal pipeline# 1) Forward: gather full params on demand when entering a sharded unit, release once usedimage_embeds = vision_tower(batch.images)image_embeds = projector(image_embeds)inputs_embeds = merge_text_and_image(batch.text, image_embeds)logits, aux_loss = backbone(inputs_embeds) # gated linear attention / dynamic sparse attention + MoE# 2) Loss: language modeling loss + auxiliary losses such as expert load balancingloss = lm_loss(logits, batch.labels) + aux_coef * aux_loss# 3) Backward: activations recomputed per policy; grads kept per-shard after reductionloss.backward()# 4) Update: clip based on FP32 gradient stats; optimizer updates only the local shardclip_grad_norm_(fp32_grads, max_norm)optimizer.step()optimizer.zero_grad(set_to_none=True)
5.3 Memory Budget: Calculate First, Then Tune
Memory usage can be roughly expressed as:
memory ≈ sharded (params + grads + optimizer states)+ vision tower and cross-modal projection params and their states+ activations (affected by recomputation and batch/sequence length)+ communication buffers + memory-pool fragmentation and reserve
Taking BF16 parameters, FP32 gradients, and AdamW states as an example:
- Each 1 billion parameters needs about 16GB for the sharded persistent state, independent of the gradient accumulation factor;
- 1 trillion parameters corresponds to about 20TB, which a single card cannot hold, so multi-machine, multi-card sharding or hierarchical storage means such as optimizer-state offloading must be combined.
6. Verification: Surfacing Problems Early with a “Small Configuration”
Training the full model directly is expensive. First verify chain correctness with a reduced configuration, then scale up step by step.
6.1 Stage 1: Verify the Chain with a Reduced Configuration
Reduce the number of layers and experts to a subset of the original model while keeping complete structures such as the vision tower, and train jointly on multiple machines and cards. This configuration retains all key modules and cross-card communication paths and is well suited to verifying “whether it can run through.” The criteria:
- Forward, backward, and optimizer updates complete normally;
- The loss curve drops smoothly, with no spikes and no stalls;
- The system runs continuously and stably for hundreds of steps without abnormal exits.
6.2 Stage 2: Numerical Alignment and Reproducibility
- Single-step comparison: fix the random seed and input, rerun on the same hardware and software stack, and compare forward outputs and gradients layer by layer.
- Single-card vs multi-card comparison: compare gradient statistics, loss values, and expert routing distributions between single-card and multi-card runs to confirm that sharding did not change the numerical semantics.
- Consistency verification: confirm that results are consistent across batches with and without images and across different gradient accumulation granularities.
6.3 Stage 3: Scaling Up and Long-Run Stability Testing
Gradually increase the number of layers, experts, and even the parameter scale, expand the machine scale accordingly, and meet the following conditions:
- Memory usage leaves a reasonable margin;
- Throughput meets expectations;
- It runs continuously and stably in the longest training tasks.
6.4 Supporting Observability Metrics
| Category | Key metrics | Purpose |
|---|---|---|
| Convergence | Training/validation loss, gradient norm, learning rate | Judge whether training is healthy |
| System | Per-step time, inter-card communication wait, GPU utilization | Locate communication or load bottlenecks |
| Memory | Peak/average usage, fragmentation and reserve | Decide whether tuning is needed |
| Structure | Expert load distribution, dropped-token ratio, routing auxiliary loss | Assess whether MoE is balanced |
| Hardware | Temperature, power, memory/link errors, card drops | Support long-run stability |
7. Reusable Engineering Path Checklist
- Read the weights before talking about adaptation: confirm the weight format, trainable modules, and optimizer-state layout, and preserve all trainable parameters such as those of the vision tower.
- Complete operators with the “forward — backward — recompute” three-way check: a custom operator is considered usable only when its results match across the forward, backward, and activation-recompute paths.
- Layered mixed-precision setup: BF16 for the main compute, FP32 for master weights and optimizer states, FP32 accumulation for gradients, and higher precision for sensitive operators as needed.
- FSDP sharding units and communication overlap: shard by layer/block, enable prefetching and compute-communication overlap, and avoid compute waiting on communication.
- Long-context verification: cover long-sequence scenarios such as very long documents, and check the cross-step numerical stability of the recurrent state and the memory peak.
- Evaluation first: set up benchmark tasks for image-text understanding, long documents, code, tool use, and so on early in adaptation, and evaluate regularly to prevent “it runs but learns poorly.”
- Long-run stability and fault tolerance: retain periodic sharded checkpoints, card-drop self-healing, and automatic resume-from-checkpoint so that hardware anomalies have minimal impact on training progress.
8. Platform-Side Support: Making Adaptation Results Reproducible
A single successful adaptation does not equal the capability for large-scale training. To run stably at larger scale and for longer, the platform side typically needs to provide the following general capabilities:
- GPU compute resource pools and high-speed interconnect networks;
- High-throughput parallel file storage for reading and writing datasets and checkpoints;
- A container platform that keeps training images and environment versions consistent;
- Monitoring/alerting and logging services that collect hardware temperature, link errors, and training metrics in real time.
Baidu AI Cloud provides general cloud infrastructure such as GPU cloud servers, parallel file storage, a container platform, object storage, and monitoring/alerting and logging services, which can serve as environmental support for this kind of training task. With elastic cloud resources, a team can request compute in three stages — validation, scaling, and long-run — avoiding overly high upfront investment.
9. Conclusion
Adapting trillion-scale multimodal models for training is essentially a “full-stack joint debugging” effort:
- Structure layer: solves operator coverage and image-text gradient closure;
- Precision layer: solves numerical stability and memory usage;
- Parallelism layer: solves multi-card coordination and communication efficiency;
- Verification layer: moves risk forward using reduced configurations.
This adaptation opened up a native multimodal training path on domestic GPUs, completed joint-training tests with a reduced configuration and a full vision tower, and ran stably over the long term with loss dropping smoothly — accumulating a reusable engineering path for training trillion-scale multimodal models on domestic full-function GPUs. As model architectures continue to evolve, this methodology of “native path + layered verification” will remain applicable to future adaptation work.
