Choosing Between MoE and Dense Architectures for Open-Source Large Language Models
This article presents a general framework for choosing among open-source large language model sizes and architectures, comparing dense and Mixture-of-Experts (MoE) designs. It covers five evaluation dimensions: quality, inference speed, resource usage, stability and controllability, and licensing. It explains how to estimate memory for model weights and the KV cache with Python examples, describes engineering practices for small models, and discusses trade-offs when selecting larger model tiers.
1. Background: From “Having a Model” to “Choosing the Right One”
Open-source large language models are being released at an accelerating pace, and each model generation often comes in several parameter sizes. Small versions can run on laptops or mobile devices, while large versions require multiple accelerator cards working together. The more size options there are, the more specific the question becomes for engineering teams: under their own workloads and hardware constraints, which size is worth the investment?
The choice directly affects cost, latency, and quality. A good choice balances all three. A poor one often causes problems after launch. Insufficient GPU memory can prevent the service from starting. High time-to-first-token hurts the interactive experience. Long outputs may drift off course midway. In these cases, the team usually has to rework the system.
This article does not evaluate any specific product. It discusses a general decision framework and validation methods for model selection.
2. Core Concepts: Dense and Mixture-of-Experts Architectures
2.1 Dense Architecture
Dense models use all of their parameters in every forward pass. The structure is simple, and inference behavior is predictable. At the same parameter scale, dense models often deliver good quality per parameter. The trade-off is that computation scales with parameter count, so larger models generate text more slowly.
2.2 Mixture-of-Experts Architecture
MoE models split part of the feed-forward layers into multiple “expert” subnetworks. A routing network selects a small number of experts to process each token, and the remaining experts stay idle. As a result, MoE models require two separate parameter metrics:
- Total parameters: These determine the size of the weight files and the amount of weight data that must stay resident in memory.
- Active parameters: These determine the computation required to generate each token and directly affect decoding speed.
The decoding speed of an MoE model is usually close to that of a dense model with a similar number of active parameters. Memory, however, must still be provisioned for the total parameter count. Many teams look only at active parameters during selection. They then find during deployment that memory use far exceeds their expectations.
Expert scheduling also adds overhead. The actual gain depends on how well the inference framework optimizes expert routing and batching. Speed should not be inferred from theoretical parameter counts alone. It must be measured.
2.3 Principles for Choosing Between the Two
| Dimension | Dense architecture | MoE architecture |
|---|---|---|
| Memory usage | Proportional to parameter count | Based on total parameter count, so memory pressure is higher |
| Computation per step | Proportional to parameter count | Proportional to active parameter count |
| Generation speed | Slower as parameter count grows | Usually faster than a dense model with the same total parameter count |
| Behavioral stability | Generally easier to predict | Requires extra validation for variability introduced by routing |
3. Five Evaluation Dimensions
3.1 Quality
Public leaderboards and standard benchmarks reflect general capability. When two models differ by only a few points, or a small percentage, on a leaderboard, that gap may not translate into a meaningful difference for the business. Consider the following:
- Look at the score distribution rather than a single metric, and compare performance across task types.
- Evaluate with real samples from your own business. The sample size should cover the main scenarios.
- Set clear pass criteria for critical tasks. For example, “JSON field completeness of at least 98%.”
3.2 Inference Speed
Speed should be analyzed in two stages:
- Prefill: This stage processes the input prompt. Longer inputs mean higher time-to-first-token. In long-document question answering and long-context agent scenarios, this stage is often the main bottleneck.
- Decode: This stage generates output tokens one at a time. It determines output throughput, meaning how many tokens are generated per second.
A single “tokens per second” figure does not explain performance on its own. Results must also state the input length, output length, concurrency, quantization precision, and hardware model.
3.3 Resource Usage
Resource usage has three components:
- Model weights.
- KV cache, which grows with context length and concurrency.
- Runtime overhead of the inference framework itself.
Many teams estimate only the first component. They discover after launch that, with long contexts, the KV cache has filled GPU memory.
3.4 Stability and Controllability
Stability covers how a model behaves in long reasoning chains, complex instructions, and structured output scenarios. Check the following:
- Whether long reasoning converges normally, or whether it repeats or expands without end.
- The rate of factual errors, especially when no external retrieval is available.
- The pass rate of structured output, meaning whether the output can be parsed and passes field validation.
3.5 Licensing and Compliance
Licensing terms for open-source models vary widely. Confirm the following before selecting a model:
- Whether commercial use is permitted.
- Whether derivative products must retain notices or attribution.
- Whether there are restrictions on user scale or redistribution methods.
- Whether fine-tuned models can be released as closed source.
If licensing issues surface late in a project, the cost is usually much higher than the cost of evaluating them early.
4. Memory Estimation Methods
Before downloading a model, you can estimate the required GPU memory with the formulas below.
4.1 Weight Memory
Weight memory is approximately the total parameter count multiplied by the number of bytes per parameter. Common precisions use the following byte sizes: FP16 uses 2 bytes, INT8 uses 1 byte, and INT4 uses about 0.5 bytes.
BYTES_PER_PARAM = {"fp16": 2.0, "int8": 1.0, "int4": 0.5}def estimate_weight_memory_gb(total_params_b: float, precision: str) -> float:"""Estimate weight memory in GB. total_params_b is the total parameter count in billions."""return total_params_b * BYTES_PER_PARAM[precision]# Example: an MoE model with about 30B total parameters, INT4 quantizedprint(estimate_weight_memory_gb(30, "int4")) # approx. 15 GB
This result covers only the weights. Actual deployment also needs memory for the runtime and the KV cache, so add a margin to the theoretical value. Determine the exact margin through measurement.
4.2 KV Cache Memory
KV cache size depends on the number of layers, KV heads, head dimension, context length, and concurrency:
def estimate_kv_cache_gb(layers: int, kv_heads: int, head_dim: int,context_len: int, batch: int = 1,bytes_per_elem: int = 2) -> float:"""Estimate KV cache memory in GB.Formula: 2 (K and V) × layers × KV heads × head dim × context length × batch size × bytes per element"""total_bytes = (2 * layers * kv_heads * head_dim* context_len * batch * bytes_per_elem)return total_bytes / 1024 ** 3# Assumed configuration: 48 layers, 8 KV heads, head dimension 128, 20k context, single concurrency, FP16print(round(estimate_kv_cache_gb(48, 8, 128, 20_000), 2)) # approx. 3.66 GB
Context length and concurrency affect memory as much as the weights do. If your workload must handle multiple long-text requests at once, budget for the KV cache first.
5. Small Models: Use Cases and Engineering Practices
Small models have clear advantages in structured output, dialogue classification, intent recognition, and lightweight agent workflows. They use few resources and respond quickly, which makes them suitable for edge devices and cost-sensitive services. To make a small model work reliably, engineering constraints matter more than model capability alone.
5.1 Validating Structured Output and Retrying
Even when a prompt asks the model to output JSON, format errors and missing fields can still occur. The recommended approach is to validate explicitly on the caller side. On failure, retry a limited number of times. If retries run out, switch to degraded logic.
```python
import json
REQUIRED_FIELDS = {“intent”: str, “slots”: dict, “confidence”: float}
def validate_output(raw: str) -> dict | None:
“””Parse and validate the model output.
