Native Multimodal LLM Architecture and Engineering Practices: Sparse MoE, Hybrid Attention, and Visual Coding
This article breaks down the architecture and engineering practices behind native multimodal large language models, using a recently open-sourced sparse multimodal model as a reference case. It explains how sparse MoE activation decouples model capacity from inference compute, how hybrid linear and full attention enables million-token context, and why reducing depth to 45 layers changes the width-depth tradeoff. It also covers the visual coding feedback loop, gateway design, cost control, layered evaluation, and key risks such as hallucination, long-context decay, data compliance, and compute compatibility. Readers will find implementation-oriented guidance for turning frontier multimodal capabilities into stable production output.
1. Introduction: From Bolted-On Multimodality to Native Multimodality
Over the past two years, most multimodal systems have relied on bolt-on designs: a vision encoder converts images into vectors, which are then projected into the language model’s token embedding space. This “stitched-together” approach ships fast, but it has three structural problems. Visual information is compressed into a small number of tokens during projection, so fine-grained text, chart ticks, and UI pixel layouts are easily lost. Training objectives are fragmented, with the vision side and the language side optimized separately, which weakens cross-modal reasoning. And the inference pipeline is long, making end-to-end performance tuning difficult.
The native multimodal approach unifies text, images, video, and documents into a single token sequence and a single objective function during pretraining. A representative example of this route is a recently open-sourced sparse multimodal model with 320B total parameters and 18B activated parameters per inference (internally referred to as an anonymous test model and nicknamed “Niu Lai” by the community). It scores 57 on a public composite intelligence index, on par with leading closed-source flagship models, while its API pricing is one-tenth that of the flagship model in the same series. The official positioning is “frontier intelligence at flash speed and cost.” This article strips away the specific product attributes and abstracts the general technical problems and engineering practices behind it.
2. Architecture: Sparse Activation, Hybrid Attention, and Layer Compression
2.1 Sparse MoE: Decoupling Capacity from Compute
The model uses a Mixture-of-Experts (MoE) architecture with 320B total parameters, activating only about 18B per token, an activation ratio of roughly 5.6%. The essence of this design is decoupling model capacity from per-inference compute: capacity determines the breadth and ceiling of knowledge, while the activation volume determines latency and unit cost. Three engineering points matter:
- Routing balance: skewed expert load causes some experts to overload while others sit idle, so load-balancing loss and capacity-factor constraints are needed.
- Communication overhead: all-to-all communication under expert parallelism can easily become a bottleneck and must be coordinated with pipeline and tensor parallelism.
- Memory and batching: the full parameter set must still be resident or swapped in on demand, and KV Cache management under long context is more complex than in dense small models.
The routing and activation logic can be abstracted as:
# Pseudocode: Top-K expert routing and sparse activationlogits = router(hidden_state) # [batch, seq, num_experts]topk_val, topk_idx = logits.topk(k=2) # pick 2 experts per tokenweights = softmax(topk_val)out = sum(weights[i] * experts[topk_idx[i]](hidden_state)for i in range(k)) # only k experts take part in compute
2.2 Hybrid Sparse and Linear Attention
The core tension in long context is the quadratic complexity of attention. The common approach in hybrid architectures is to use linear attention or gated linear unit structures in most layers, reducing complexity to near-linear in sequence length, while keeping full (or sparse-window) attention in a few layers for precise long-range retrieval and global information integration. This combination of cheap scanning in most layers plus precise look-back in a few layers balances throughput and recall accuracy at the million-token scale. In engineering terms, it must be paired with chunked prefill, prefix caching, and KV Cache quantization; otherwise, time-to-first-token will be dragged down by long prompts.
2.3 Layer Compression: The Width-Depth Tradeoff Behind 45 Layers
Compared with the previous generation’s 92 layers, this model reduces the depth to 45 layers. Halving the layer count means each layer must carry stronger representational capacity, usually compensated by wider hidden dimensions, heavier expert capacity, and stronger hybrid attention modules. The tradeoff brings two direct benefits: pipeline parallelism can be split more flexibly with fewer bubbles, and the serial dependency chain per token is shorter, which helps reduce decoding latency. The cost is higher demands on training stability, requiring finer initialization, normalization, and learning-rate scheduling.
2.4 Million-Level Context and Multimodal Input
The model supports a context window of about 1 million tokens (1,048,576). On the input side, it uniformly supports text, images, video, and files, with text output; pretraining uses about 30T tokens of multimodal corpus. For developers, long context is not about stuffing all material in, but about designing retrieval and compression strategies: first trim candidate segments with rules or vector retrieval, then let the model do global integration, avoiding effective context decay caused by “middle information being drowned out.”
3. The Visual Coding Loop: Letting the Model “See” Its Own Output
One of the most valuable landing directions of native multimodality is using visual capability in the process of programming and document production itself, known as visual coding. The loop can be abstracted into four steps:
- Generate: the model produces frontend code, game logic, or 3D scene descriptions.
- Render: the code is executed in a sandbox and screenshotted to obtain real pixel results.
- Judge: the model reads the screenshot and checks for layout misalignment, control overflow, game bugs, and multi-view consistency.
- Improve: the code is revised based on visual feedback and enters the next round until constraints are met.
Requirement -> Code generation -> Sandbox render/screenshot -> Visual self-check -> Diff localization -> Code revision -> Regression verification
To make this loop reliable, the training side usually needs a data synthesis pipeline: automatically generating four-tuples of “code, render result, defect annotation, fix patch” to train the model’s self visual judgment and test-time improvement ability. In Office and document tasks (presentations, PDFs, documents, spreadsheets), the same mechanism enables the model to check and optimize its own output and to make basic aesthetic judgments, such as whether font hierarchy is clear, whether charts overflow, and whether color schemes clash.
4. Engineering: Integration, Cost Control, and Evaluation
4.1 Integration Layer Design
It is recommended to wrap model calls in a unified gateway that shields underlying differences and makes canary release and rollback easier:
def call_model(messages, images=None, max_tokens=2048):payload = {"messages": messages, # unified message structure"modalities": ["text", "image", "video", "file"],"max_tokens": max_tokens,"temperature": 0.2, # low temperature for code tasks}if images:payload["attachments"] = imagesreturn gateway.post("/v1/chat", json=payload).json()
4.2 Cost Control
The core value of Flash-type models is a significantly lower unit cost than flagship models. Cost-control measures include tiered routing by task (simple intent classification goes to small models, complex reasoning goes to large models), prefix caching to reuse system prompts, batching requests, summarizing long documents before feeding them to the model, and setting thresholds on token consumption and failure rate with monitoring alerts.
4.3 Evaluation System
Do not look at a single leaderboard score. It is recommended to build a three-layer evaluation: a general capability layer (reasoning, knowledge, code); a multimodal layer (chart understanding, UI screenshot understanding, document layout reconstruction); and a business layer (real ticket pass rate, first-pass yield, manual rework time). Also record time-to-first-token, throughput, and unit task cost to form a comparable baseline.
5. Risks and Boundaries
- Hallucination and visual misjudgment: the model can still misjudge screenshots, so critical workflows need human review.
- Long-context decay: middle information utilization drops under very long inputs, so retrieval must come first.
- Data compliance: multimodal inputs involve images and documents, so desensitization and permission isolation are needed in object storage and logging services.
- Compute adaptation: if using a domestic chip cluster, verify operator coverage and mixed-precision support in advance to avoid precision regression.
6. Conclusion
Native multimodality, sparse activation, hybrid attention, and million-level context are turning “high intelligence” and “low cost” from opposites into an engineerable combination. The takeaway for developers is clear: bring visual feedback into an automated loop, build cost governance into the call path, and turn evaluation into a system, so that frontier model capabilities can be converted into stable business output.
