Local LLM Deployment: How to Choose Models and Offload MoE Weights to CPU
Running open-source large language models on consumer GPUs and memory-rich mini PCs is now a common practice for developers, researchers, and small teams. This guide explains how to choose models under real hardware constraints, the difference between total and active parameters in MoE architectures, and why the decode phase is limited by memory bandwidth. It focuses on MoE weight CPU offloading as a practical way to free up VRAM at a small speed cost, and provides starting points by VRAM tier, a method for finding the optimal offload layer count, quantization guidance, troubleshooting tips, and notes on moving from local to cloud deployment.
1. What Are You Really Choosing When You Deploy an LLM Locally?
Running open-source LLMs on consumer GPUs with 16GB or 24GB of VRAM, or on mini PCs with plenty of system memory, is already common among developers, researchers, and small teams. The three main motivations for local deployment are: data never leaves your machine, on-demand access, and low long-term cost. But when people actually get started, their first instinct is often “which model is the best?” A more precise question is: Under my hardware constraints, which model has enough capability while still running and staying stable?
A good approach is to evaluate selection across four dimensions:
- Task and capability: Everyday chat, document summarization, retrieval-augmented Q&A, and coding assistance each demand different levels of reasoning depth and context length. Prioritize models that perform reliably on your own business samples, rather than judging only by parameter count.
- Resource boundaries: VRAM capacity and bandwidth, system memory capacity and channel count, bus bandwidth between the GPU and system memory, and CPU core count. Together these determine both “whether the model fits” and “how fast it runs once it fits.”
- Architecture type: A dense model routes every token through all of its parameters. A MoE (Mixture of Experts) model activates only a small subset of parameters at a time, so it often uses less compute for the same total parameter count.
- Engineering support: The availability of quantized versions, how well the inference runtime supports the model, and whether the open-source license permits your use case. These directly affect deployment cost.
One easily overlooked principle: Don’t sacrifice basic, usable interaction speed for a model that only “looks stronger.” Local inference lacks the near-unlimited VRAM elasticity of the cloud. A configuration that emits a single token every 30 seconds may feel worse than a slightly smaller model that responds smoothly.
2. Two Concepts First: Total Parameters vs. Active Parameters
2.1 How MoE Works
You can think of an MoE model as a company with several domain experts. A dense model is like calling an all-hands meeting for every question; an MoE model has a “dispatcher” that decides, based on each token’s features, whom to consult, usually waking only a few experts. Implementation details vary, but common structures include:
- Routing mechanism: Computing a match score between each token and each expert, then selecting the top-scoring few experts (often called top-k routing).
- Shared experts: General-purpose computation that applies to all tokens, handling common knowledge.
- Fine-grained experts: A larger number of smaller experts that handle differences in specialized areas.
Under this naming convention, “35B A3B” means the model has about 35 billion total parameters and activates only about 3 billion per token on average; “26B A4B” means about 26 billion total parameters and about 4 billion activated per token.
2.2 What This Means for Local Deployment
This MoE structure neatly separates a model’s two types of resource cost:
- Total parameters decide “how much you must load”: All expert weights must stay resident in VRAM or memory, ready to be called at any time. This sets the VRAM threshold.
- Active parameters decide “how much you read per step”: Only a small number of parameters actually participate in computing each generated token. This determines generation speed.
So MoE is well worth prioritizing for local deployment. It’s like a team that’s fairly large but only sends a few people out for everyday tasks: the bigger the team, the tighter the “workstations” (VRAM); but each time you actually “pull a file” (move data from VRAM), only a small fraction of the team is involved.
3. Why VRAM Is the Bottleneck: Heavy Reading, Light Compute in Decode
To understand the optimization techniques that follow, you first need to understand the two phases of LLM inference:
- Prefill: Processing all of the user’s input tokens at once. This is highly parallel, mainly limited by compute, and is compute-intensive.
- Decode: Generating new tokens one at a time, handling only one position per step. The weights must be read repeatedly, so this phase is mainly limited by VRAM bandwidth and is memory-access-intensive.
A common rough estimate for decode throughput is:
Tokens per second ≈ effective VRAM bandwidth ÷ bytes that must be read per generated token
For example, with a VRAM bandwidth of 1000 GB/s and about 70% utilization:
- Reading 3GB of weights per step, you can theoretically generate about 233 tokens per second;
- Reading 15GB of weights per step, you can theoretically generate only about 47 tokens per second.
(These numbers are illustrative for order-of-magnitude only; actual results depend on framework scheduling, batching, and other factors.) This means: Generation speed depends mainly on how much data must be moved at each step, not on everything the model “knows.” Models with small active-parameter counts have a clear advantage here.
4. MoE Weight CPU Offloading: Moving “Low-Usage” Weights Out of VRAM
Many inference runtimes offer an experimental option to set the number of MoE layers whose weights are forced to run on the CPU (memory), often described as something like “number of MoE layers to force onto the CPU.” Put simply, on some of those layers:
- General components like attention stay in VRAM;
- The routed expert weights live in memory, and as each token is routed to a given expert, the corresponding weights are fetched to the GPU to take part in the computation.
4.1 Why This Technique Works Especially Well for MoE
Every layer of a dense model fully participates in each forward pass. If you move a few of those layers’ weights to memory, you must move data from those layers for every generated token, and the speed penalty is noticeable.
MoE is different: once a layer is moved to memory, most of its expert weights won’t be read at all during the computation of a given token. Depending on the routing implementation, the read probability is roughly proportional to k/n (where k is the number of activated experts and n is the total number of experts). As a rough illustration:
- When the activation ratio is about 1/8, on average only about one-eighth of the offloaded expert weights are moved;
- When the activation ratio is about 1/16, on average only about one-sixteenth are moved.
So keeping some layers’ expert weights in memory can still preserve decent generation speed when VRAM is tight. VRAM savings and speed loss are not proportional—that’s exactly where the value of this technique lies. The prerequisite is that your model is genuinely an MoE architecture.
4.2 Why It’s Best Understood as “Trading Memory for VRAM”
In MoE models, expert weights typically make up the bulk of all weights, while general components like attention are relatively small. Keeping some layers’ expert weights in memory trades a very small speed cost for a significant freeing-up of VRAM.
5. Choosing Your Starting Point by VRAM Tier
Keep in mind: There is no universal offload-layer value that works everywhere. The suggestions below are only starting points and should be validated through repeated testing on your specific model.
| VRAM tier | Suggested starting point | Notes |
|---|---|---|
| 8GB | Consider a lower-bit quantization first | If only reducing quantization, start trying offload layers around 10 |
| 12GB–16GB | Start offloading at 10 layers, then try 10 → 15 → 20 → 25 | Pick the fastest setting that still fits |
| 24GB and above | Start at 0 for regular chat; start at 5 for long context | The KV cache consumes a lot of VRAM in long-context scenarios |
Strategies for each VRAM tier:
- 8GB GPU: Prioritize trying lower-precision quantization (around 3 bits). Quantization usually hurts speed less than offloading: quantized weights are computed in VRAM with only a lightweight dequantization step, whereas offloaded layers may trigger cross-bus transfers for every token.
- 12GB / 16GB GPU: If the full model already fits entirely in VRAM, keep offloading off. If, after loading, the remaining VRAM isn’t enough for your target context, start at 10 layers and increase the offload count step by step.
- 24GB and above GPU: For regular chat, most models fit entirely in VRAM with no offloading needed. When handling long documents or long conversations, the KV cache grows linearly with context length, so you can start around 5 layers and gradually find a balance between quality and speed.
6. How to Find the Optimal Offload Layer Count
Different models and runtimes can react very differently to the same layer count, so a rigorous approach is to let data decide:
- Establish a baseline: First load the model with offloading disabled, and record VRAM usage and generation speed as a reference.
- Test step by step: Starting from the points in the table above, increase the offload layer count one step at a time, provided the model still loads. For each step, record generation speed, VRAM usage, and memory usage.
- Find the tipping point: As the offload count rises, speed usually declines slowly at first, then drops sharply past a certain point. The step just before this tipping point—where you still have enough VRAM headroom—is usually the better choice.
- Validate with real workloads: Many workloads have long inputs, so evaluate the prefill phase’s time-to-first-token alongside decode speed. Some runtimes also support quantizing the KV cache itself, which can further reduce VRAM usage in long-context scenarios.
- Leave headroom: Don’t push VRAM to its limit; reserve space for runtime fluctuations and future adjustments.
The following pseudocode illustrates the tuning idea and is independent of how any specific runtime is configured:
GPU_LIMIT = 16 * 1024 # VRAM limit in MiB; adjust to your actual setupbest = Nonefor moe_offload in [0, 10, 15, 20, 25]: # Candidate offload layer countsmem = load_model(moe_offload=moe_offload) # Load the model with the given settingif mem > GPU_LIMIT: # Over the VRAM limit; try the next stepcontinuespeed = benchmark(tokens=128) # Measure speed and time-to-first-tokenif best is None or speed > best.speed: # Keep the fastest configurationbest = Config(moe_offload=moe_offload, speed=speed)print(best)
7. Don’t Overlook Quantization: The More Fundamental Layer of Optimization
Offloading addresses “how the same model is distributed across different devices,” while quantization addresses “how many bits represent each parameter.” It’s the most direct way to lower the VRAM threshold. Take 4-bit quantization as an example: a 35B-parameter model’s weights come to roughly 18–20GB, far smaller than a 16-bit version. In practice, weigh three points:
- Lower bits, less VRAM: Going from 8 bits to about 4 bits roughly halves the size; going further down to about 3 bits saves even more.
- Verify precision loss: Low-bit quantization may degrade quality on tasks like coding, math, and long-chain reasoning. It’s best to compare and test on the task samples you care about.
- Match the quantization format to the runtime: Some low-bit formats lack well-optimized compute kernels in certain runtimes and may trigger a “dequantize-then-compute” path that actually slows things down.
A sensible order is: First use appropriate quantization to fit the model into VRAM, then use offloading to handle the remaining gap, rather than dumping a large number of layers onto the CPU right away.
8. Common Issues and Troubleshooting
- Out-of-VRAM error: Usually the weights plus the KV cache exceed VRAM. First try increasing the offload layer count; if that’s still not enough, consider a lower quantization level or limiting context length.
- Out-of-memory error: With too many offloaded layers, memory usage approaches the total model weight size. Reduce the offload layer count, or load fewer models at once.
- Slower after offloading: The bus bandwidth may be low, or system memory may have few channels or not be fully populated, or the quantization format may be taking a dequantization path. In this case, reduce the offload layer count or switch to a lower-bit quantization.
- Sharp slowdown with long text: The KV cache grows with context length and gradually fills up VRAM. Limit the maximum context length, or quantize the KV cache when the runtime supports it.
- Unstable option behavior: Some options are still marked experimental and may behave differently across versions. When issues arise, pin a version, roll back an update, or review the parameters against the official documentation.
9. From “Runnable” to “Usable”: Service-Oriented and Cloud Deployment
Once local validation passes, if you need to share the capability within a team or integrate it into business systems, you can use containerized deployment to package the model, inference runtime, and dependencies together, ensuring a consistent environment and easy migration. If your local hardware can’t support the target model, or you need to handle concurrent access, you can also consider cloud compute such as general-purpose GPU cloud servers. When deploying in the cloud, supporting capabilities are equally worth attention:
- Model distribution: Model weights can be centrally managed through object storage and downloaded on demand;
- Operations and monitoring: Use general cloud offerings such as logging and monitoring/alerting to track service availability and resource usage;
- Elastic scaling: Some cloud providers offer general-purpose inference services like Serverless GPU that scale on demand, suited to scenarios with fluctuating request volume. For example, in China’s cloud ecosystem, Baidu AI Cloud’s Function Compute supports this form.
When moving from local to cloud, you need to reassess concurrency, time-to-first-token, and throughput. A configuration that’s smooth for a single local user may no longer be appropriate under multi-user concurrency.
10. Summary
Deploying LLMs locally is fundamentally about balancing VRAM, memory, bandwidth, context length, and response speed.
- From a selection standpoint, MoE models—with their “large total parameters, small active parameters”—are well suited to local deployment.
- From an optimization standpoint, MoE weight CPU offloading is a simple and effective way to extend VRAM: only the less-frequently-used portion is moved to memory, trading a small speed cost for VRAM space.
- From a workflow standpoint, the recommended order is: first clarify the task and resource constraints, then use appropriate quantization to fit the model into VRAM, then choose a starting offload layer count by VRAM tier and test step by step, and finally validate speed and quality with real workloads.
For developers who want to try LLM capabilities at low cost, and for teams exploring AI applications in resource-constrained environments, mastering this approach can significantly improve the feasibility and stability of local inference.
