Training Sparse MoE Models on Fully Domestic AI Compute: Architecture, Memory Planning, and Deployment

    This article explains what it takes to pretrain and serve a trillion-scale sparse Mixture-of-Experts (MoE) model on a fully domestic stack of AI accelerators and deep learning frameworks. It breaks down the MoE structure of total versus activated parameters, routing and load balancing, the engineering implications of a domestic operator, compiler, and parallel-training stack, and a practical way to estimate GPU memory for weights and KV Cache at million-token context. It also includes a deployment checklist and a note on why the footprint of an open-weight text-to-image pipeline is larger than its main model.

    1. Background: Why a Fully Domestic Stack, Sparse MoE, and Ultra-Long Context Go Together

    The industry has recently seen ultra-large sparse Mixture-of-Experts (MoE) models trained from scratch on domestic accelerator cards and domestic deep learning frameworks, with total parameters in the hundreds of billions, activated parameters in the tens of billions, and native support for million-token context. What makes these releases noteworthy is not the spec sheet of any single product, but the engineering path they validate: completing pretraining and open-weight release of large-parameter, long-context models on self-controlled compute and frameworks.

    Three dimensions explain the value of this path.

    First, the sustainability of compute supply. Training ultra-large models is no longer just an algorithm problem; it is systems engineering spanning cluster stability, interconnect bandwidth, fault recovery, and framework parallelism strategies. A fully domestic stack matters because it lets the chip, compiler stack, distributed framework, and operator libraries be co-optimized as a whole.

    Second, parameter efficiency. As dense models grow, compute and memory costs rise roughly linearly, while sparse MoE decouples “total capacity” from “per-token compute” through routing, expanding knowledge capacity while keeping inference cost in check.

    Third, context length. Agent and code scenarios inherently require long-range dependencies, and million-token context pushes “stitching retrieved snippets together” toward “whole-repository or whole-codebase input,” which raises new requirements for attention implementations, memory layout, and position-encoding extrapolation.

    2. Sparse MoE Structure: Total Parameters, Activated Parameters, and Routing

    The core of sparse MoE is replacing the feed-forward layer with multiple expert networks, then using a gating network to select a few experts per token. Taking a configuration such as “285 billion total parameters, 17 billion activated” as an example, the structure can be sketched as follows:

    1. # Illustrative pseudocode: forward pass of a single sparse MoE layer
    2. def moe_layer(x, experts, router, top_k=2):
    3. logits = router(x) # [batch, seq, num_experts]
    4. weights, idx = logits.topk(top_k) # sparse routing
    5. weights = softmax(weights, dim=-1)
    6. out = 0
    7. for slot in range(top_k):
    8. e = experts[idx[..., slot]] # gather experts
    9. out = out + weights[..., slot] * e(x)
    10. return out

    Four points require engineering attention:

    1. Load balancing. Routing naturally favors popular experts, so auxiliary losses or noise injection are needed to avoid “expert collapse”; otherwise some experts go untrained for long periods and the effective parameter count shrinks.
    2. Communication overhead. Expert parallelism puts all-to-all communication on the critical path, and insufficient cross-node bandwidth can eat up the compute savings that MoE is supposed to deliver.
    3. Activated parameters drive latency; total parameters drive memory. At inference time all expert weights must still reside in memory, while the multiply-accumulate work per token depends only on activated parameters, so capacity planning has to treat the two separately.
    4. Fine-tuning and alignment cost. Sparse structures are more prone to routing drift during instruction tuning, requiring more conservative learning rates and stronger balancing constraints.

    The direct takeaway for users: open weights + multi-format release + loadability in mainstream inference frameworks is becoming the minimum bar for LLM engineering. Providing weights in both a framework-native format and a generic tensor format essentially decouples the training stack from the inference stack, so downstream users are not locked into the same hardware and software.

    3. What a Fully Domestic Training Stack Means in Practice

    “Trained from scratch on domestic accelerator cards and domestic frameworks” usually means several things are rewritten at once:

    • Operators and compiler layer: Hot operators such as attention, normalization, and MoE routing need to be rewritten or auto-tuned for hardware characteristics, and long-context scenarios additionally require blocked attention and memory reuse.
    • Parallelism strategy: The combination of data, tensor, pipeline, and expert parallelism needs a fresh search for the optimal sharding, and “deep and narrow” configurations such as 45 layers with hidden dimension 4096 significantly affect the pipeline bubble ratio.
    • Fault tolerance and checkpoint resume: Effective training time on a ten-thousand-card cluster is governed by the failure rate, so second-level checkpointing, elastic restart, and slow-node detection matter more to final convergence quality than peak compute.
    • Precision strategy: BF16 mixed precision is a common baseline, but numerically sensitive stages such as normalization, softmax, and routing scores typically need higher-precision accumulation to avoid silent drift late in long training runs.

    The practical implication for users is that open weights + multi-format release + compatibility with mainstream inference frameworks is becoming the entry requirement for LLM engineering. Shipping weights in both a framework-native format and a generic tensor format decouples the training stack from the inference stack, freeing downstream users from a single hardware and software vendor.

    4. Memory Sizing: Don’t Be Misled by Activated Parameters

    A common mistake is assuming that 17 billion activated parameters means memory should be sized for 17 billion parameters. In fact, all expert weights must be loaded at inference time. A rough estimate with BF16 (2 bytes per parameter):

    1. Weight memory ≈ total parameters × 2 bytes
    2. 285B × 2B ≈ 570 GB
    3. Weights alone need 8 80GB GPUs (~640GB) to leave headroom

    Then add the KV Cache. Under long context, the KV Cache often exceeds the weights themselves, and its scale can be approximated as:

    1. KV ≈ 2 × num_layers × num_kv_heads × head_dim × seq_len × bytes_per_element × concurrency

    Million-token context means the KV Cache can reach hundreds of gigabytes, so “native support for million-token context” and “running million-token context on a single machine” are two different things. Practical options include chunked prefill, paged KV management, KV quantization, prefix sharing, and on-demand offloading.

    5. Deployment and Serving Checklist

    1. Do capacity planning first, then pick GPUs. Estimate weights, KV Cache, and framework overhead separately, and reserve more than 20% headroom.
    2. Verify correctness first. Compare output consistency across different parallelism configurations with fixed inputs before discussing throughput.
    3. Serve long context in tiers. Route short requests to high-throughput, high-concurrency pools and long requests to low-concurrency, high-memory pools so they do not crowd each other out.
    4. Factor tokenizer efficiency into evaluation. For Agent and code scenarios, a better tokenizer can cut token consumption by 15%~25%, which translates directly into lower cost and latency, but such figures should be reproduced in your own tests rather than taken from self-reported data.
    5. Build observability. Monitor throughput, time to first token, memory水位, and routing distribution with unified log and metric collection to help locate long-tail latency.
    6. Store data and model assets in tiers. Keep weights, datasets, and evaluation results in different object-storage tiers, and pair them with a container platform for elastic scaling to significantly reduce environment drift.

    6. The Deployment Footprint Trap of Open-Weight Text-to-Image Models

    The same period also saw the release of open-weight text-to-image diffusion models at around six billion parameters, with a default 2048×2048 resolution and a dozen-plus sampling steps. The shared lesson with LLMs is: “main model parameters” do not equal “the deployment footprint of the whole pipeline.” A text-to-image pipeline typically also includes a text encoder in the billions of parameters, a VAE encoder/decoder, and a scheduler; repository size can reach tens of gigabytes, and a single 80GB GPU is only the lower bound for “verifying that it runs.”

    Engineering guidance:

    1. Deployment footprint = main model + text encoder + VAE + scheduler + runtime overhead
    2. Size capacity against peak memory of the whole pipeline, not main model parameters

    At the same time, improvements in complex composition, lighting, and text rendering should be evaluated with a mix of human and automated testing on business sets (e-commerce main images, UI mockups, spatial renderings), since leaderboard scores and business usability require additional calibration.

    7. Conclusion

    Open weights for an ultra-large sparse MoE model supported by fully domestic compute and frameworks mark the point where a self-controlled training pipeline becomes usable; million-token context, dual-format weights, and compatibility with mainstream inference frameworks shift the competition from “can it be trained” to “can it be used cheaply and reliably.” For developers, three things matter most: separately accounting for the memory and compute gap between total and activated parameters, sizing capacity against peak resource usage of the whole pipeline, and replacing self-reported metrics with observability and reproducible evaluation. If an organization needs to host such models elastically, a standardized inference foundation can be built on general cloud product categories such as container platforms, object storage, and monitoring and alerting, balancing cost and stability while staying self-controlled.