How to Choose and Deploy Open-Source LLMs Across Model Sizes

    A practical guide to selecting and deploying open-source large language models of different sizes. It explains how depth, width, and attention heads differ across model families, how to estimate VRAM and throughput, where sparse mixture-of-experts and dense models each fit, why dense architectures are easier to fine-tune, and what to include in a deployment and observability checklist.

    1. Background: Why a Full Size Range Is Only the Starting Point

    When an open-source LLM family spans everything from very large models down to sizes that run on a single consumer GPU, the first reaction is usually relief that there is finally a choice to make. The real engineering difficulty shows up right after: models in the same series share an architecture and a tokenizer and differ only in parameter count and layer configuration, yet their behavior on a specific business task can vary considerably. Treating “more parameters” as automatically meaning “better results” is the most common misjudgment at the deployment stage.

    A more realistic picture is that the business usually has two conflicting sets of requirements at the same time. One is online scenarios with high concurrency and low latency, such as retrieval-augmented question answering, conversation summarization, and intent classification and routing. The other is offline scenarios with low concurrency but extremely high quality requirements for each individual result, such as complex mathematical derivation, long-chain logical reasoning, and code generation. Forcing one model to handle both workloads usually leaves both sides unsatisfied. The value of a multi-size model family therefore lies not in having more options, but in being able to configure capacity and latency in tiers per scenario.

    2. Key Architectural Differences: Depth, Width, and Attention Heads

    Models in the same series typically share the same macro design, for example a hybrid attention structure in which linear attention layers and regular attention layers are stacked alternately at a fixed ratio, combined with gating mechanisms to stabilize training. Three dimensions are what actually separate them.

    The first is network depth. As the number of layers grows, the number of nonlinear transformations in the forward pass increases, and features are repeatedly rewritten and abstracted at every layer, which in theory favors stability on long-chain reasoning and code tasks. Fewer layers mean a shorter information path and lower compute per token.

    The second is hidden width. Width determines how many feature dimensions a single layer can carry; a wider representation space means a single computation can capture denser semantic features. For sparse models, the total parameter count comes mainly from a large pool of routed experts, so their “largeness” shows up in the capacity pool rather than in per-layer width.

    The third is the number of attention heads. The head counts of the linear attention and regular attention parts each determine the number of subspaces used for context modeling, and more heads generally mean finer-grained relationships in long text are captured more thoroughly. The number of key-value heads is directly tied to cache overhead during inference.

    An illustrative structural comparison (numbers are for explanation only):

    1. Config A (sparse mixture of experts)
    2. Layers: 40 Hidden size: 2048
    3. Linear attention V heads: 32
    4. Regular attention: 16 Q heads / 2 KV heads
    5. FFN: routed expert pool (only a few experts activated)
    6. Config B (dense)
    7. Layers: 64 Hidden size: 5120
    8. Linear attention V heads: 48
    9. Regular attention: 24 Q heads / 4 KV heads
    10. FFN: conventional full feed-forward

    3. VRAM and Throughput: Turning Intuition into Calculable Rules of Thumb

    Model selection has to come down to a resource budget you can actually account for. Inference VRAM can be roughly split into weights, cache, and runtime overhead:

    1. Total VRAM ≈ weight bytes + KV cache + activations and framework overhead
    2. Weight bytes ≈ parameters × bytes per parameter (FP16 ≈ 2, INT8 ≈ 1, INT4 ≈ 0.5)
    3. KV cache ≈ 2 × layers × KV heads × head dim × sequence length × batch × bytes per element

    Three practical conclusions follow. First, sparse models take up a lot of VRAM for weights but require little compute per activated token, which suits online serving where VRAM is adequate and high concurrency is the goal. Second, both the weights and the compute of a dense model grow linearly with width, but they are more manageable in offline tasks with small batches and long outputs. Third, in long-context scenarios the cache often exceeds the weights themselves, so reducing KV heads, adopting more aggressive quantization, or using paged cache management is more effective than switching to a larger model.

    4. Dividing Work by Scenario: A Reasonable Boundary Between the Two Types

    The online high-throughput tier is a good fit for sparse expert models: passage retrieval and reranking in retrieval-augmented generation, everyday multi-turn conversation, content summarization, and the nodes in an agent system responsible for fast decisions and tool dispatch. These tasks are sensitive to time to first token and output tokens per second, and they tolerate a higher variance in the peak quality of a single inference.

    The offline high-quality tier is a good fit for dense models: competition-level math problems, logical reasoning that requires multiple verification steps, and cross-file code generation and refactoring suggestions. These tasks usually run in small batches, accept longer response times, and set a strict floor on output quality; at the same activation scale, a dense structure is more consistent.

    The engineering recommendation is to combine the two rather than choose one, using a single classification router to dispatch requests to models of different sizes:

    1. def route(prompt: str, expected_tokens: int) -> str:
    2. # Simple heuristic: long outputs, code, or reasoning go to the large dense model
    3. if expected_tokens > 1024 or looks_like_code(prompt):
    4. return "dense-large"
    5. # Short Q&A, summarization, and dispatch go to the sparse low-activation model
    6. return "moe-small"

    5. Domain Fine-Tuning: Why Dense Structures Are Less Trouble

    During domain fine-tuning, gradients in a sparse model only reach the activated experts, so updates are sparse and stochastic. This tends to produce uneven expert load and under-trained experts, and it requires an additional load-balancing loss plus more careful learning rate and batch size settings. The behavioral gap between expert routing in training and in inference further amplifies instability. In a dense structure, every parameter participates in every forward pass, so gradient signals are dense and consistent, hyperparameters transfer better, and convergence on small datasets is more predictable. If the dataset is limited, labeling is expensive, and domain performance still has to be guaranteed, prefer a dense configuration with more layers and greater width, and use parameter-efficient fine-tuning such as low-rank adaptation to control VRAM use and overfitting risk.

    6. Deployment and Observability Checklist

    • Quantization strategy: weights can be compressed with low-bit quantization, while the cache is better kept at higher precision to control degradation on long text; run a before-and-after consistency comparison on the business dataset before release.
    • Batch scheduling: continuous batching and paged cache substantially improve concurrency, but long-output requests need a separate queue so they do not block short requests.
    • Structured output: constrain the output format when tool calls are involved, and validate arguments against a schema with retries on failure.
    • Monitoring metrics: time to first token, output tokens per second, cache hit rate, VRAM level, the share of traffic routed to each model size, and quality spot-check results.
    • Elasticity and cost: run inference services on a container platform, use logging and monitoring with alerting to locate long-tail latency, store fine-tuning data and model versions in object storage, and use a message queue to smooth out traffic peaks and troughs.
    • Evaluation loop: maintain a fixed business evaluation set covering short Q&A, long reasoning, and code, and require regression runs for any model or quantization change.

    7. Common Pitfalls

    The first is looking only at total parameter count while ignoring activated parameters and the combined effect of depth and width. The second is equating long-context capability with effective use of information, which in practice needs to be verified with tests for recalling information from the middle of the context. The third is choosing the model before planning resources, so the cache is only discovered to be exhausting VRAM right before launch. The fourth is running full-parameter training without enough fine-tuning data, ending up worse than a smaller dense model with low-rank adaptation. General capabilities in model serving and inference acceleration from Baidu AI Cloud can serve as a foundation for the workflow above, but selection decisions should still come from measured results on your own business dataset.

    8. Conclusion

    The right way to use a multi-size open-source model family is in tiers: let sparse low-activation models carry high-concurrency online traffic, let deep and wide dense models carry difficult offline reasoning and domain fine-tuning, and connect the two into one operable pipeline with a unified routing layer, quantization scheme, and evaluation loop. The deciding criteria are not parameter-count leaderboards, but the combined performance of time to first token, output stability, and cost per request on your specific business distribution.