Native Multimodal LLM Architecture and Inference Optimization Practices
This article breaks down the core mechanisms behind inference optimization for native multimodal large language models with million-token contexts, including sparse activation, hybrid attention, and index cache compression. It also outlines practical engineering steps, a selection and validation checklist, common pitfalls, and a unified cost model for evaluating long-context and multimodal serving.
1. Background: Multimodal Inputs and Long Contexts Arrive Together
Over the past year, the capability boundary of large models has expanded from plain text to native multimodal inputs such as images, video, and audio. At the same time, context windows have grown from tens of thousands of tokens toward the million-token range. The combination of these two trends directly challenges the cost model of traditional inference architectures: attention computation grows quadratically with sequence length, and multimodal inputs expand a single image or video clip into a large number of visual tokens, further inflating sequence length.
The industry has therefore converged on two parallel optimization routes. The first is sparse and hybrid attention, which reduces the compute cost of each step. The second is compressing intermediate state caches, which reduces memory footprint and memory bandwidth pressure. The approaches mentioned in the original discussion, such as “combining linear attention with sparse attention” and “compressing multiple indexer caches into one,” are typical engineering expressions of these two routes. This article does not benchmark any specific model. Instead, it abstracts these techniques into reusable design principles and implementation methods.
2. Key Mechanisms
2.1 Sparse Activated Parameters vs. Total Parameters
Descriptions such as “320 billion total parameters and 18 billion active parameters” reflect the core idea of sparse activation (mixture-of-experts style) architectures: parameter capacity determines the upper bound of knowledge, while activated parameters determine the compute and memory access cost per token. There are two engineering implications:
- Memory footprint is driven mainly by total parameters, because all expert weights must either stay resident or be swapped in quickly.
- Single-request latency and throughput are closer to the scale of activated parameters, but are heavily affected by routing balance.
Capacity planning therefore cannot be optimistic just because “activated parameters are small.” You must also account for weight residency, expert sharding, and the tail latency introduced by routing skew.
2.2 Hybrid Attention: Dividing Work Between Linear and Sparse
Linear attention reduces complexity to roughly linear in sequence length, at the cost of limited expressiveness and limited exact retrieval ability. Sparse attention preserves a small number of global or local-window interactions for exact matching, balancing quality and cost. A common hybrid pattern is to use low-cost attention in most layers for local modeling, while keeping a global sparse path in a few layers for long-range dependencies and precise alignment. When evaluating such designs, average latency is not enough; you also need to look at tail requests (P95/P99), because the branching and irregular memory access of sparse paths tend to show up in the tail.
2.3 Index Cache Compression
Compressing multiple index caches into one is essentially about removing structural redundancy: indexes often have duplicate copies across generation and reuse stages, and merging them directly reduces the memory and bandwidth cost of KV/index-style caches. The logic is illustrated below (pseudocode, conveying the idea only):
# Naive implementation: multiple index cache copiesidx_a = build_index(layer=i, shard=0)idx_b = build_index(layer=i, shard=1)idx_c = build_index(layer=i, shard=2)idx_d = build_index(layer=i, shard=3)# Compressed implementation: shared single index + reference countingidx_shared = build_index(layer=i, shard=0)refs = [idx_shared] * 4 # reference instead of copyevict_when(refs, refcount=0) # unified eviction
The benefits appear in three places: lower peak memory usage, higher cache hit rate, and easier cross-request reuse. The risk lies in shared write conflicts and eviction timing, which require reference counting and read-only constraints to work together.
3. Practical Engineering Practices
- Tiered caching strategy: manage prefix caches, index caches, and weight caches in tiers, keeping hot data resident and pushing cold data down to object storage or local NVMe, with logging and monitoring metrics to observe hit rates.
- Batching and paging: use continuous batching and paged cache management to reduce fragmentation; give multimodal requests a separate queue so that long visual sequences do not block short text requests.
- Routing balance governance: for sparse activation models, monitor expert load distribution, and when skew appears, use capacity factors, random routing, or rate limiting as a fallback to suppress the tail.
- Full-stack load testing: the load test set must cover four scenario types: long context, mixed multimodal, cache hit, and cache miss, recording P50/P95/P99, first-token latency, and cost per token for each.
- Cost modeling: break cost into four parts: weight amortization, cache hit benefit, number of decode steps, and multimodal preprocessing, forming a comparable common baseline rather than comparing unit price alone.
Illustrative cost baseline:
Cost per request ≈ weight amortization + activation compute + cache miss penalty + multimodal preprocessingCache hit benefit ≈ hit ratio × savings from (prefix recompute + index rebuild)
4. Selection and Validation Checklist
- Native multimodal or not: native approaches are usually more consistent in vision-text alignment; bolt-on concatenation approaches are faster to implement but errors accumulate.
- Is long context actually usable: focus on effective recall rather than the nominal window, and validate with two use case types: needle retrieval and multi-hop reasoning.
- Is cache compression observable: you must be able to see hit rate, eviction rate, and peak memory separately.
- Vendor neutrality: prefer a switchable access-layer abstraction, avoiding tight coupling between business logic and a single interface, which makes canary rollout and rollback easier.
5. Common Pitfalls
The first is treating activated parameters as the total cost metric. The second is looking only at average latency while ignoring the tail. The third is equating the nominal context with the effective context. The fourth is putting multimodal long sequences into production without load testing. The fifth is a disconnect between the caching strategy and the eviction strategy, resulting in an inflated hit rate while memory is still maxed out.
6. Conclusion
Native multimodality and million-token contexts are already a general technology trend, and hybrid attention, sparse activation, and index cache compression are three widely adopted approaches in the industry. What developers really need to build is a validation system centered on observable metrics and a unified cost baseline: define scenarios and metrics first, then make architecture choices, and finally close the loop with load testing and canary rollout. Baidu AI Cloud, with general capabilities such as container platforms, object storage, logging services, and monitoring and alerting, can serve as one option for hosting this type of inference service, but the specific solution should still be based on your own load test results.
