LLM Architecture Selection and Inference Optimization: Key Considerations
This article outlines the main factors in choosing and optimizing large language model architectures. It explains how pretraining data, mixture-of-experts (MoE) designs, GRPO, and attention changes such as MLA affect model capability, compute cost, and memory use. It also covers the conditions and limits of each technique and the key points for deployment planning.
Start with Compute Budget, Task Type, and Context Length
Several technical directions for large models are now well established. Pretraining data quality sets the ceiling for base model capability. MoE architectures use sparse activation to reduce the compute required per inference. GRPO removes the critic network from reinforcement learning, which lowers memory requirements. Attention modifications such as MLA mainly ease KV cache pressure in long-context workloads. The sections below explain what each technique solves, what it depends on, and what limits it.
How Does Pretraining Affect Base Model Quality?
A base model’s capability depends largely on its pretraining data. Common practice prioritizes data cleaning, deduplication, data mixing ratios, and training stability, rather than chasing short-term benchmark scores. Training token counts typically reach the trillion scale, and exact figures should be taken from each model’s release notes. Results for models at the same parameter scale depend heavily on the evaluation sets and prompt settings, so reports should not be compared directly.
Practical recommendations:
- Validate the data mixing ratio with small-scale experiments before scaling up training.
- Keep an independent evaluation set, and check whether training data overlaps with test sets (known as data contamination).
- Record the data version and hyperparameters for each training run so results can be reproduced.
How Can MoE Reduce Inference Cost?
Dense models activate all parameters for every inference, so compute grows with parameter count. MoE (mixture of experts) models split the feedforward layers into multiple experts, and each token passes through only the few experts selected by the router. DeepSeekMoE and related work proposed two improvements. Fine-grained expert segmentation splits experts into smaller units, so each expert focuses on a narrower range of knowledge. Shared experts process all tokens and handle general contextual features.
The main differences between the two architectures are summarized below:
| Dimension | Dense model | MoE model |
|---|---|---|
| Activated parameters per token | All parameters | A subset of total parameters |
| Compute per inference | Grows with parameter count | Mainly grows with activated parameters |
| Memory usage | Related to total parameters | Must hold all experts, so memory demand is high |
| Training challenges | Relatively mature | Router load balancing and expert utilization |
| Suitable scenarios | Smaller parameter scale, simple deployment | Large scale, high throughput needs, distributed inference capability |
The benefits of MoE depend on conditions. The model must store the parameters of all experts, so memory pressure at deployment can be higher than the activated parameter count suggests. Unbalanced routing also leaves some experts idle, and the actual speedup may fall below the theoretical value. When selecting a model, review total parameters, activated parameters, hardware memory, and measured throughput together. Do not look only at the activation ratio.
How Should Code Models Be Trained and Evaluated?
Specialized code models are usually pretrained on a mix of code and natural language data. The number of supported programming languages varies by model, so consult the model card or technical report. Trained capability can be assessed with function-level benchmarks such as HumanEval and MBPP. Cross-file completion and repository-level tasks require separately designed evaluations.
In enterprise settings, code models are often used for code completion, unit test generation, and code review assistance. When deploying them, keep the following in mind:
- Generated code must be compiled, tested, and reviewed by a person. Do not merge it directly.
- For requests involving internal code, confirm whether the data will leave the internal network.
- Security-related code requires additional static scanning.
How Does GRPO Enable Reinforcement Learning with Limited Memory?
PPO maintains an actor (the policy model) and a critic (the value model) at the same time. The critic is usually about as large as the actor, so it adds substantial memory and compute overhead. GRPO (Group Relative Policy Optimization) removes the separate critic network. For each prompt, it samples a group of outputs, estimates advantages from the relative reward differences within the group, and then updates the policy. DeepSeekMath and related work reported results for this method on mathematical reasoning tasks.
When using GRPO, decide the following:
- Group size: Larger groups make advantage estimates more stable, but generation cost per step also rises. Common settings range from a few to more than ten, and experiments should determine the right value.
- Reward design: For math problems, answer verification can serve as a rule-based reward. Open-ended tasks usually need a reward model, and the two carry different noise and bias.
- Training stability: Monitor KL divergence, the reward curve, and output length. If the model starts exploiting the reward or output length becomes abnormal, adjust training promptly.
GRPO reduces the memory cost of the critic, but the cost of generating samples remains. Its benefits appear mainly on tasks where rewards can be verified.
How Should Attention Be Changed for Long-Context Workloads?
The KV cache of standard multi-head attention grows linearly with context length, so memory pressure becomes significant during long-text inference. MLA (Multi-head Latent Attention) compresses keys and values into a low-dimensional latent space for caching, then restores them when needed. This reduces KV cache usage. The compression addresses memory, but it does not automatically expand the model’s context capability.
Whether the context window can be extended also depends on the position encoding and training data. RoPE extension methods such as position interpolation can extend the window from the training length to a longer range. Performance usually drops beyond the training length, so long-context continued training and dedicated evaluation are needed. When selecting a model, rely on its published context specifications, such as the 128K class common in public documentation, and do not assume unlimited length.
Key Points for Deploying Multimodal Models
Vision-language models generally consist of a vision encoder, an alignment module, and a language model. Training usually happens in stages: first align image and text representations, then perform instruction tuning. Data quality strongly affects tasks such as chart understanding and text recognition. At deployment, image resolution and the number of visual tokens directly affect memory and latency, so trim them according to task needs.
Which Metrics Matter When Deploying Models?
Regardless of architecture, deployment revolves around three areas:
- Capacity planning: Estimate memory from total parameters, activated parameters, and context length, and reserve headroom for concurrency.
- Inference monitoring: Track time to first token, output tokens per second, peak memory usage, and error rate to locate bottlenecks.
- Training communication: In multi-node training, network bandwidth and the degree of overlap between communication and computation directly affect throughput.
Choose the cloud platform, container scheduling, and storage solution based on your team’s existing infrastructure and compliance requirements.
Summary
Large model technology has no universal best option. Pretraining quality sets the capability ceiling. MoE reduces per-inference compute through sparse activation, but it adds deployment complexity. GRPO lowers the memory barrier for reinforcement learning, but it depends on reliable reward signals. MLA reduces cache pressure for long contexts, but it does not change the context length the model was trained for. Developers should first define the task type, budget, and latency requirements, then verify the benefits and costs of each technique.
