Open-Source LLM Architecture Selection and System-Level Optimization: Engineering Considerations
This article examines engineering trade-offs in selecting architectures for open-source LLMs and optimizing them at the system level. It compares MHA, GQA, MQA, and MLA in terms of KV cache cost and quality, discusses total versus activated parameters, MoE, and Prefix Caching, reviews optimizer choices such as AdamW and Muon, covers custom kernel work with TileLang, and provides a practical checklist for system-level co-optimization.
Open-source LLMs are iterating quickly. Over the past year, architectures, training methods, and inference deployment have all continued to change. For developers and enterprises, whether a model is useful depends not only on individual benchmark scores in papers but also on inference cost, latency, and engineering implementation difficulty. This article organizes currently verifiable ideas around four areas: attention mechanisms, parameters and cost, optimizers and kernels, and systems engineering.
1. Attention Mechanisms: Trade-Offs Between Memory and Expressiveness
Standard multi-head attention (MHA) stores a separate set of Key and Value tensors for each query head. When the context becomes longer, KV cache memory usage grows with sequence length and head count. The decode phase also repeatedly reads this data, so it is prone to memory-bandwidth limits.
Several common approaches work as follows.
GQA divides query heads into groups, with each group sharing one set of Key and Value. It is a common compromise in current mainstream open-source models.
MQA lets all query heads share the same Key and Value set. KV cache is smallest, and decode bandwidth pressure is lowest, but model expressiveness may decline. The size of the quality loss depends on task type and training method.
MLA projects Key and Value into a low-dimensional latent space for storage, thereby compressing KV cache. The cost is extra projection computation and more complex kernel implementation.
The following table is a qualitative comparison; actual numbers must be measured on the target model and hardware.
| Approach | KV Cache Footprint | Quality | Implementation Complexity | Best-Fit Scenarios |
|---|---|---|---|---|
| MHA | Highest | Baseline | Low | Shorter contexts with sufficient memory |
| GQA | Medium | Close to MHA | Low | General-purpose scenarios balancing quality and speed |
| MQA | Lowest | May degrade | Low | Services sensitive to decode latency and memory |
| MLA | Low | Usually good | High | Long context, with teams capable of kernel optimization |
Some recent models have returned to MQA or its variants in specific scenarios, indicating that there is no universal answer for attention structure. When reading technical reports, focus on the benchmark comparisons and deployment conditions given by the authors, not just the architecture name.
2. Parameter Scale and Inference Cost
As model parameter count increases, capability usually improves, and serving cost also rises. Evaluation needs to distinguish two numbers. Total parameter count determines the memory required for weight storage and loading, while activated parameter count determines the computation per token. Models using a mixture-of-experts (MoE) structure activate only a subset of experts at a time, so a large total parameter count does not necessarily mean high per-inference cost. However, a large total parameter count still increases the number of GPUs required for deployment and communication overhead.
Prefix Caching is a common way to reduce cost. When the same system prompt or long document is reused, the server can save the computed KV cache and reuse it for subsequent requests. Time to first token (TTFT) and computation both decrease. To improve hit rate, place fixed content at the front of the prompt and variable user input later.
The following hypothetical example illustrates the estimation method. Suppose a request has 100,000 input tokens, of which 60,000 hit the cache. The unit price for the hit portion is one-tenth that of the miss portion. Output is 5,000 tokens, with a unit price four times that of missed input. Using relative unit prices:
- Missed input: 40,000 tokens × 1 = 40,000
- Cached input: 60,000 tokens × 0.1 = 6,000
- Output: 5,000 tokens × 4 = 20,000
- Total: 66,000
Without caching, the total would be 100,000 + 20,000 = 120,000, so this example saves about 45%. Actual prices and hit rates need to be recalculated according to the provider’s billing rules and real traffic.
3. Optimizers and Custom Kernels
On the training side, AdamW remains the base optimizer for most models. Muon is a recently discussed class of optimizers; it applies approximate orthogonalization to momentum updates of two-dimensional weight matrices. Some public experiments show that it can improve convergence speed. When adopting it, parameters such as embedding layers and normalization layers usually still use AdamW; specific configurations should follow the documentation of the implementation used.
On the inference side, non-standard structures require custom kernels. The attention-residual-type structures mentioned in technical reports aim to mitigate the gradual dilution of information across layers in deep networks. Such structures are not in standard Transformer implementations, and inference engines need additional support. Before implementation, verify the definitions in the original paper to avoid treating names from different teams as a unified standard.
TileLang is a Python-based domain-specific language for writing GPU kernels. Developers can control thread-block partitioning, shared memory usage, and operator fusion at a higher level of abstraction without writing CUDA code directly. Custom kernels can bring performance gains but also increase maintenance cost. After each upgrade of the inference framework or driver, numerical comparison tests need to be rerun to confirm that outputs match the reference implementation.
4. A Checklist for System-Level Co-Optimization
The performance of LLM serving is determined jointly by algorithms, frameworks, and hardware. Optimizing a single layer alone often yields limited benefits. At implementation time, verify each item:
- Training parallelism strategy: whether the combination of data parallelism, tensor parallelism, pipeline parallelism, and expert parallelism matches the cluster’s network topology.
- Communication bandwidth: whether inter-node bandwidth is sufficient to support the communication volume generated by parallel partitioning.
