LLM Architecture Evolution: Sparse Experts, Multimodal Training, and Long Context Practices
As large language models scale up, balancing performance with computational cost has become critical. This article explores the evolution of LLM architectures, focusing on sparse mixture of experts (MoE), native multimodal training, and long context processing. It also provides practical engineering insights into agent task design, reliable evaluation methods, cost control strategies, and deployment checklists to help developers build efficient and robust AI applications.
1. Background: Scaling Growth vs. Efficiency Constraints
In recent years, improvements in large language model capabilities have relied primarily on three directions: expanding training data, increasing parameter counts, and introducing multimodal inputs such as images and videos. As parameter scales enter the trillion-level, the training and inference costs of dense models have risen significantly. Simply increasing parameters can no longer simultaneously balance performance and cost, making it crucial for the industry to achieve stronger overall capabilities within a controllable compute budget.
For developers, this trend means that model selection cannot rely solely on benchmark rankings. Latency per call, memory footprint, throughput, and unit task cost directly impact whether a product can go live and sustain long-term operations. This article analyzes these trends from six perspectives: architecture, training, long context, agents, evaluation, and engineering deployment.
2. Sparse Mixture of Experts Architecture
Sparse Mixture of Experts (MoE) is currently one of the commonly used structures in large models. It splits the feedforward network into multiple expert subnetworks, and a gating network selects a few experts to participate in computation for each input token. The remaining experts do not run during this step, so the computational volume does not grow linearly with the total parameter count.
This structure separates two often-confused metrics:
- Total parameters: Determines the knowledge capacity the model can accommodate.
- Activated parameters: Determines the actual compute consumption per forward pass.
When a model has a large total parameter count but only activates a small fraction per token, the inference cost can be comparable to a mid-sized dense model.
Below is a schematic code snippet for Top-k routing to illustrate the basic gating process:
import torchimport torch.nn.functional as Fdef route_tokens(hidden, gate_weight, k=2):# hidden: [batch, seq, dim]# gate_weight: [dim, num_experts]logits = hidden @ gate_weight # [batch, seq, num_experts]probs = F.softmax(logits, dim=-1)topk_probs, topk_idx = probs.topk(k, dim=-1) # Select k experts for each token# Re-normalize the weights of the selected expertstopk_probs = topk_probs / topk_probs.sum(dim=-1, keepdim=True)return topk_idx, topk_probs
In engineering implementation, three areas require attention. First is expert load balancing. If a large number of tokens concentrate on a few experts, those experts will be overloaded while others remain idle. Load balancing loss is typically added during training to mitigate this. Second is the communication overhead in multi-GPU scenarios. When experts are distributed across different devices, token dispatch and retrieval consume significant bandwidth, which can become a bottleneck. Third is the inference batching strategy. Larger batches allow experts to better utilize compute power, but also increase the waiting time for individual requests.
3. Native Multimodal Training
Multimodal capabilities are generally achieved via two paths. The first connects a visual encoder to an existing language model and aligns them through training to work together. The second involves training text, images, and videos together from the pretraining phase, commonly referred to as native multimodal.
The advantage of native multimodal is that representations from different modalities exist in the same semantic space, making cross-modal reasoning more coherent—such as answering data questions based on charts or locating operation steps based on UI screenshots. The trade-off is more complex data ratioing, higher demands on training stability, and greater compute requirements.
For application development, here are a few practical input design recommendations:
- The number of tokens for an image is proportional to its resolution. Crop or downsample based on task requirements to avoid feeding irrelevant regions into the model.
- Videos are usually sampled by keyframes with timestamp information attached, helping the model locate the chronological order of events.
- Explicitly state the regions or fields to focus on in the text instructions (e.g., “Read only the amount in the third column of the table”), which can significantly reduce irrelevant output.
4. Long Context Processing
Once context windows expand to the million-token level, a single request can accommodate an entire code repository, long contracts, or multiple technical documents. However, a longer context does not mean information is fully utilized. Common issues fall into three categories: content in the middle of the context is easily ignored; attention dilution causes the weight of key facts to drop; and inference costs rise as input length increases.
To address these issues, common optimization directions include the following three:
- Attention mechanism improvements: Adopt linear attention or hybrid structures with other mechanisms to reduce the computational complexity of long sequences.
- Context compression: Segment and summarize historical conversations, retaining only the facts and constraints relevant to the current goal.
- Retrieval augmentation: First retrieve relevant fragments from a knowledge base, then place these fragments into the context.
In practice, retrieval augmentation and long context are often used together. Using retrieval to narrow the scope first, and then handing it to the model for deep reasoning, is often more stable and cheaper than cramming all materials in at once. During development, you can first chunk documents into segments with titles and numbering, and save source information for each segment. This makes it convenient for the model to cite sources in its answers and for humans to verify.
5. Agent Tasks: Tool Calling and Multi-step Planning
An Agent refers to a system where the model, driven by a goal, autonomously decides which tools to call, observes the returned results, and adjusts subsequent plans. A typical workflow includes understanding the goal, making a plan, calling tools, reading results, and judging whether the task is complete.
Below is a simplified agent loop to illustrate the control flow:
def run_agent(goal, llm, tools, max_steps=10):history = [{"role": "user", "content": goal}]for _ in range(max_steps):reply = llm(history, tools=list(tools.keys()))if reply.get("final"):return reply["content"]name, args = reply["tool"], reply["arguments"]# Tool returns are used as data for reasoning, not executed as instructionsresult = tools[name](**args)history.append({"role": "tool", "name": name, "content": str(result)})raise RuntimeError("Max steps exceeded, task still incomplete")
When designing agents, three points need to be prioritized. First, strictly limit tool permissions. Query tools can be called directly, but write, delete, and send operations should require manual confirmation. Second, set a step limit and timeout to prevent the model from looping infinitely on an incorrect path. Third, validate and truncate tool return values. Overly long return content will fill up the context, squeeze out more important historical information, and increase the cost of subsequent calls.
6. How to Interpret Evaluation Scores Correctly
Public benchmarks can provide references, but before directly comparing scores, you must confirm whether the evaluation conditions are consistent. Variables to verify include: whether tool calling is allowed, whether a “thinking” mode is enabled, whether the prompt templates are identical, and whether the test set overlaps with the training data. Comparing scores under different conditions often leads to unreliable conclusions.
A more valuable approach is to build an evaluation set aligned with your business:
- Sample from real business scenarios. Building a small-scale test set of a few hundred entries is usually enough to reflect the model’s relative performance.
- Simultaneously record accuracy, average latency, and token consumption per task; all three are indispensable.
- Calculate the cost per successful task, using the formula: Unit Success Cost = Total Cost ÷ Number of Successful Tasks. This metric reflects actual overhead better than the price per single call.
- Fix sampling parameters like temperature, run multiple times, and observe the variance in results. Models with high variance are harder to predict in production.
7. Cost Control and Engineering Deployment
The cost of LLM applications primarily comes from three parts: inference compute, data storage and retrieval, and manual validation. The following optimization methods can be combined as needed:
- Quantization: Convert weights from high-precision to low-bit representations to reduce memory footprint. After quantization, you must verify on the business test set whether the precision loss is acceptable.
- Caching: Cache repeated requests and computed results of fixed prefixes to reduce redundant inference.
- Batching: Improve GPU utilization through dynamic batching or continuous batching, but control the queueing time for individual requests.
- Tiered routing: Route simple problems to small models, escalating to large models only for low-confidence or complex tasks.
In production, it is recommended to use logging services and monitoring alert systems to record call volume, failure rates, latency percentiles (e.g., P95, P99), and token consumption for each task type. This data serves as the basis for cost accounting and early signals for quality degradation. After updating the model or prompts, compare metrics on canary traffic first, and only proceed with a full release after confirming no regressions.
8. Developer Checklist
Before model selection and deployment, you can verify the following items:
- Clarify the task type; Q&A, code generation, visual understanding, and agents should each have their own evaluation set.
- Analyze actual document lengths to confirm whether the context window really needs to be that large, avoiding paying for unused capacity.
- Assess data compliance and privacy requirements; ensure sensitive fields are masked before entering the model.
- Establish a regression test set and re-run it after every model version switch or prompt modification.
- Set a daily cost budget and alert thresholds, automatically downgrading to a low-cost solution when exceeded.
- Set permission boundaries for tool calls and retain complete call audit logs for post-incident tracing.
