Dense vs Sparse (MoE) LLMs for Local Inference: Balancing Generation Speed and VRAM

    When running large language models on a single workstation or a single-GPU server, availability is usually not dictated by parameter count alone but by three constraints at once: model quality, inference speed, and VRAM capacity. Using a ~27B dense model and a sparse Mixture-of-Experts (MoE) model (~35B total parameters, ~3B active per token) as examples, this article explains why two models can occupy similar VRAM yet generate at very different speeds. It covers how to estimate VRAM for both weights and KV cache (including GQA and context length) with a runnable Python example, compares quality against speed, and offers selection guidance, common mistakes, and an FAQ for local single-GPU deployment.

    1. The Core Tension of Local Deployment: Parameter Count Is Not Enough

    When you run a large language model on a personal workstation or a single-GPU server, three variables constrain usability at the same time: model quality, inference speed, and VRAM capacity. Many developers first ask “which model is smarter,” but once you move to local deployment, the more practical questions tend to be: is there enough VRAM, will long context blow up memory, and does generation speed hurt interactivity.

    For discussion, this article uses two example sizes: a dense model with roughly 27 billion parameters, and a sparse MoE model with roughly 35 billion total parameters that activates only about 3 billion per token. Note that these are illustrative examples for comparison, not an absolute reference to any specific product; actual selection should still rely on the specific model card, license, quantization format, and framework support.

    Under this premise, a common phenomenon appears: two models may show similar weight VRAM—even total usage close to the 20GB level—yet their generation speeds can differ by several times. To understand this, you need to look separately at weights, the KV cache, and the prefill and decode stages.

    2. Dense vs Sparse Architecture: Full-Parameter Activation vs Partial Expert Activation

    A dense model activates all of its parameters when generating each token. With 27 billion parameters, every forward pass step theoretically uses all 27 billion. Its advantage is that capability is fully engaged and behavior is stable; the cost is that generating every single token requires the full compute and memory-bandwidth expense.

    A sparse model—the Mixture-of-Experts (MoE) architecture—has a large total parameter pool but uses a routing or gating mechanism so that only a small subset of experts participates in each token’s computation. For example, with roughly 35 billion total parameters, only about 3 billion are activated per step. This gives the model both large knowledge capacity and a lower per-token compute load. The speed advantage comes from exactly this: not “fewer parameters,” but “fewer parameters activated each time.”

    However, it must be stressed: fewer activated parameters in an MoE does not mean lower VRAM usage. The weights still have to be fully loaded into VRAM, because the router needs to select from all experts. What really determines weight VRAM is the total parameter count, not the per-step active parameter count.

    3. VRAM Estimation: Weights Follow Total Parameters, KV Cache Follows GQA and Context

    VRAM is mainly composed of three parts:

    1. Model weights: positively correlated with the total parameter count.
    2. KV cache: positively correlated with context length, layer count, number of key/value heads, and precision.
    3. Runtime overhead: including the framework, temporary buffers, CUDA graphs, scheduling caches, and so on.

    Many estimates only look at weights and ignore the KV cache. This is especially problematic in long-context scenarios, where the KV cache can become the main factor that exhausts VRAM.

    Here is an easily overlooked parameter: GQA (Grouped Query Attention). Standard multi-head attention maintains a separate KV for each query head, while GQA lets multiple query heads share KV, thereby reducing the KV cache size. So when estimating the KV cache, you should not only account for layer count, hidden dimension, and context length, but also include kv_heads and head_dim.

    A recommended VRAM estimation formula:

    1. Weight VRAM = total parameters × bytes per parameter
    2. KV cache ≈ 2 × layers × context_len × (kv_heads × head_dim) × bytes per KV element

    Below is an illustrative snippet you can modify directly. To stay close to the common “VRAM” phrasing, it uses decimal GB throughout, i.e., 1GB = 10^9 bytes. If your inference framework reports GiB, the numbers will differ slightly, so leave some headroom when buying a GPU.

    1. def estimate_vram(params_billion, bits=4, context_len=32768,
    2. layers=64, kv_heads=8, head_dim=128, kv_bytes=1):
    3. # Use decimal GB throughout: 1GB = 1e9 bytes
    4. weight_gb = params_billion * 1e9 * (bits / 8) / 1e9
    5. kv_gb = 2 * layers * context_len * (kv_heads * head_dim) * kv_bytes / 1e9
    6. return round(weight_gb, 1), round(kv_gb, 1), round(weight_gb + kv_gb, 1)
    7. # Example: 27B dense model, 4-bit weights, 32k context, GQA=8, head_dim=128, KV 8-bit
    8. print(estimate_vram(27))
    9. # Example: 35B total-param MoE model, 4-bit weights, 32k context, GQA=8, head_dim=128, KV 8-bit
    10. print(estimate_vram(35))

    With the default parameters above, the 27B dense model is roughly: 13.5GB weights, ~4.3GB KV, about 17.8GB total; the 35B total-param MoE is roughly: 17.5GB weights, ~4.3GB KV, about 21.8GB total. In other words, the two have similar weight and KV structure, but the 35B total-param model runs a bit higher, and a 20GB-class GPU will be very tight—you typically need a shorter context, more aggressive KV quantization, or more VRAM.

    If you raise the context to 70000, the KV cache swells noticeably. Using the same layer count of 64, GQA=8, head_dim=128, and 8-bit KV, the KV cache is about 9.2GB. At this point the 27B dense model totals roughly 22.7GB, and the 35B MoE about 26.7GB—not including runtime overhead. So you cannot simply claim that “a 20GB GPU can definitely handle a 70k context.” Whether it fits depends on layer count, kv_heads, head_dim, KV precision, weight precision, and runtime overhead.

    A more practical rule of thumb:

    • Short context, e.g., 8k to 32k: a 20GB-class GPU may run a 27B-class 4-bit model.
    • Long context, e.g., above 64k: check the KV cache carefully; favor GQA, lower KV precision, or wider VRAM.
    • Larger total parameters: the baseline weight cost is higher, leaving less room for the KV cache.

    4. Why Similar VRAM Yet Several Times the Generation Speed?

    Inference speed is usually split into two stages: prefill and decode.

    The prefill stage—processing the input prompt—has the model read the entire input in parallel. It is compute-intensive and typically achieves high throughput. This stage is mainly affected by GPU compute capability, framework optimization, batch size, and context length.

    The decode stage—generating tokens one by one—requires the model to read the weights and KV cache needed for the current token at every step. Because each step depends on the previous result, when the batch is usually 1, it is hard to fully saturate the compute units, so this stage is more likely to be limited by memory bandwidth.

    A dense model reads all activated weights at every step; an MoE model reads only the weights of the selected experts at each step. So in terms of weight-reading volume, MoE has a clear advantage.

    But this also calls for avoiding a misunderstanding: if a dense model activates 27 billion parameters and an MoE activates 3 billion, looking only at weight-reading volume, the theoretical gap is close to 9×. The actual end-to-end generation speed, however, does not necessarily reach 9×, for reasons including:

    • MoE routing itself requires extra computation and scheduling;
    • the layout of different experts’ weights in VRAM can add reading complexity;
    • expert switching and kernel efficiency affect actual throughput;
    • KV cache, attention computation, and framework implementation also consume time;
    • different layer counts, hidden dimensions, and context lengths change the share of fixed overhead.

    So a more rigorous statement is: with similar VRAM usage, a dense model’s decode speed may be only a fraction of a sparse MoE’s—commonly a several-fold gap; the exact multiple depends on the active ratio, framework, quantization, KV precision, and implementation quality.

    To make numbers verifiable, any speed figure should come with its test conditions. For example, a sample test condition could be: a single 24GB GPU, batch=1, 4-bit weights, 8-bit KV, 32k context, a framework such as llama.cpp or a similar local inference engine, averaged over multiple runs after warmup. Under this condition, a dense 27B model might show a prefill of roughly a few hundred tokens/s and a decode of about 15 to 20 tokens/s; a sparse MoE might show a similar or slightly lower prefill but a decode above 50 tokens/s. Switch to FP16 weights, long context, a different framework, or a larger batch, and the results change markedly.

    So rather than looking only at parameter count, it is better to fix your real input length and output length and measure prefill and decode throughput separately.

    5. The Quality-versus-Speed Trade-off

    Dimension Dense model example Sparse MoE example Impact on local deployment
    Active parameters Full activation, ~27B Only ~3B active MoE usually decodes faster
    Weight VRAM ~13.5GB, 4-bit ~17.5GB, 4-bit MoE has more total params, higher weight VRAM
    KV cache Depends on context and GQA Also depends on context and GQA Both can get tight with long context
    Prefill speed Usually compute-bound May be affected by routing and expert scheduling MoE is not guaranteed to be faster
    Decode speed Limited by all weights’ bandwidth Reads only active experts MoE is usually smoother
    Quality ceiling Full-param engagement, stable Large knowledge capacity, but few active Complex tasks need real-world testing
    Use cases High-precision analysis, complex reasoning High-frequency interaction, writing, Q&A Interactive scenarios favor speed

    From an experience standpoint, the importance of speed is often underestimated. A generation speed of 20 tokens/s may look usable, but in scenarios like long answers, continuous conversation, code completion, and document Q&A, the sense of waiting accumulates. Conversely, multiplying decode speed several times noticeably improves interaction fluidity.

    That said, MoE is not unconditionally better. If a task demands very high complexity of reasoning, long chains of logic, or precise instruction following, a dense model is sometimes more stable at the same VRAM. In the end, you still need to evaluate with real tasks.

    6. Selection Advice and Common Mistakes

    1. First decide whether the scenario is sensitive to interaction speed
      If it is used for everyday Q&A, writing assistance, fast responses after voice transcription, or conversational operation, prioritize models with faster decoding. If it is used for offline batch analysis, complex code generation, or rigorous reports, you can trade some speed for quality.

    2. VRAM estimation must include the KV cache
      Do not look only at weights. Start by estimating with the formula: with 4-bit weights, a 32k context, GQA, and 8-bit KV, a 27B-class model is usually closer to the 20GB level; if the context reaches 70k, watch out for insufficient VRAM.

    3. 4-bit quantization is an important balancing tool
      4-bit significantly reduces weight VRAM, but it is not free of quality loss. The way to verify is to compare the same set of tasks before and after quantization using perplexity, accuracy, code pass rate, instruction-following success rate, or human ratings. Do not only check that “it runs after quantization”—check whether “it is good enough after quantization.”

    4. Do not look only at parameter count, nor only at active parameters
      Total parameters affect knowledge capacity and weight VRAM, active parameters affect decode speed, and the KV cache affects long-context availability. All three must be considered together.

    5. Run a small-scale real-world test
      Fix the input length and measure prefill; fix the number of generation steps and measure decode; and record the peak VRAM at the same time. Pseudocode can be written as:

    1. import time
    2. # Note: this is illustrative pseudocode; replace the actual API with your framework's interface
    3. def benchmark(model, prompt, gen_steps=64):
    4. # Warm up first to avoid skewing results with first-run compilation or cache allocation
    5. model.warmup()
    6. model.reset_peak_memory()
    7. t0 = time.perf_counter()
    8. model.prefill(prompt)
    9. prefill_time = time.perf_counter() - t0
    10. t1 = time.perf_counter()
    11. for _ in range(gen_steps):
    12. model.generate_one_token()
    13. decode_time = time.perf_counter() - t1
    14. print(f"Prefill: {len(prompt) / prefill_time:.1f} tok/s")
    15. print(f"Decode: {gen_steps / decode_time:.1f} tok/s")
    16. print(f"Peak VRAM: {model.peak_memory_gb():.1f} GB")

    7. FAQ

    Q: Why does generation speed differ by several times when VRAM is similar?
    A: Because a dense model reads all activated weights at every step, while an MoE reads only a small set of experts. Different weight-reading volumes create different decode bandwidth pressure, so the speed gap is significant.

    Q: How much does 4-bit quantization affect quality?
    A: It depends on the model, task, and quantization method. Lightweight tasks may see little impact, while complex reasoning or code tasks may degrade noticeably. Compare task metrics before and after quantization.

    Q: What is the most common mistake in local deployment?
    A: Looking only at parameter count, ignoring the KV cache, inferring long-context experience from short-context test results, and failing to record the specific framework and quantization conditions.

    8. Summary

    There is no absolute winner between dense and sparse MoE models. A dense model trades full-parameter activation for stable quality, at the cost of slower decoding; an MoE trades total parameters for knowledge capacity and low active parameters for decode speed, but its weights still have to be fully loaded. For local single-GPU deployment, when VRAM is similar but generation speed differs by several times, faster speed usually means higher availability for most interactive scenarios. The final decision should return to the specific task, real prompt length, hardware VRAM, and quantization scheme, and be validated through conditional, real-world testing—not judged by parameter count alone.