LLM Engineering Guide: Model Selection, Evaluation, and Deployment

    This practical guide covers the main stages of putting large language models into production: sparse Mixture-of-Experts (MoE) architecture, model selection and internal evaluation, long-context processing, lightweight deployment and cost control, and agent engineering. Each section includes an actionable checklist.

    Introduction

    Around 2025, the competition among large language models shifted from single leaderboard scores to overall capability. Developers care about complex reasoning, very long inputs, multimodal understanding, agent execution, and the unit cost and response speed of each request. To deploy a model, three questions need answers: which capabilities can be used directly in a business, which metrics reflect performance after launch, and how to balance quality, cost, and latency.

    This article covers five areas: sparse Mixture-of-Experts (MoE) architecture, model selection and evaluation, long-context processing, lightweight deployment and cost, and agent engineering. Each section provides an actionable checklist. The formulas and numbers in this article show how to calculate values. Actual values depend on the model configuration and your own load test results.

    1. Sparse Mixture-of-Experts Architecture: Using Less Compute for Greater Capacity

    1.1 Core Idea

    In a dense model, every parameter takes part in computing each generated token. A sparse Mixture-of-Experts (MoE) model splits the feed-forward layer into several expert sub-networks. A router selects a few experts for each token. The total parameter count can be very large, but a single forward pass activates only part of the parameters. At a similar compute budget, MoE models usually have higher capacity.

    1.2 Routing and Load Balancing

    The router outputs a score for each expert, selects the top k experts with the highest scores, and merges their outputs using normalized weights. In practice, two problems come up often.

    • Uneven expert load: A few experts receive most of the traffic, while the others get little training. A common fix is to add a load-balancing term to the training loss so that traffic spreads across experts.
    • Unstable routing: Routing fluctuates a lot early in training, which slows convergence. A common fix is to set a capacity factor that limits how many tokens each expert processes in one batch.

    The capacity factor is calculated as follows.

    Expert capacity = ceil(capacity factor × tokens in batch × k / number of experts)

    The framework determines how tokens above capacity are handled. There are three common approaches. The first drops the token’s expert output for that layer and keeps only the residual connection. The second queues the token for the next round. The third reassigns the token to the next-best expert. When you read or choose a framework, confirm which approach it uses, because each one affects output quality and latency differently.

    The following pseudocode illustrates the routing steps only. It cannot be run directly.

    1. # Pseudocode: illustrates the routing steps only
    2. # token_vec: [d_model], hidden vector of a single token
    3. # router_w: [num_experts, d_model], router weights
    4. # experts[i]: function, input [d_model], output [d_model]
    5. # k is usually 1 or 2, depending on the model configuration
    6. import numpy as np
    7. def softmax(x):
    8. e = np.exp(x - np.max(x))
    9. return e / e.sum()
    10. def moe_forward(token_vec, router_w, experts, k=2):
    11. logits = router_w @ token_vec # [num_experts]
    12. top_idx = np.argsort(logits)[-k:] # [k], the k experts with the highest scores
    13. weights = softmax(logits[top_idx]) # [k], normalized weights
    14. out = np.zeros_like(token_vec) # [d_model]
    15. for w, i in zip(weights, top_idx):
    16. out += w * experts[i](token_vec) # only compute the selected experts
    17. return out

    1.3 Engineering Implications and Deployment Trade-offs

    Sparse architectures reduce the compute required per inference request, but they do not reduce memory requirements. All expert parameters must stay in GPU memory, because the router decides which expert to use only at runtime. Check the following items during deployment.

    Check item Question to answer
    GPU memory capacity Can all expert parameters plus the KV cache fit on the target device?
    Cross-device communication When experts are spread across multiple GPUs, how much data moves for token dispatch and merging?
    Batching efficiency With small batches, is expert load sparse enough to leave compute idle?
    Throughput and latency At the target concurrency, does P95 latency meet business requirements?

    Do not select a model based only on its total parameter count. Also check the active parameter count, actual throughput, and memory footprint. Two models labeled at the 100B scale can have very different inference costs if their active parameter counts differ.

    2. Model Selection and Evaluation: How to Read Evaluation Results

    2.1 Why Leaderboard Rankings Do Not Directly Reflect Business Results

    Public leaderboards show a model’s relative performance on specific question types. They have the