Back to News
ProductAI Understanding briefing

Llama.cpp introduces CPU-offloading for Mixture-of-Experts cache misses

The latest llama.cpp release adds functionality to process Mixture-of-Experts (MoE) cache misses on the CPU, alongside a new tuning script to optimize cache performance.

4 min readRead the primary source
Source-page capture accompanying Llama.cpp introduces CPU-offloading for Mixture-of-Experts cache misses
Primary-source documentSource recorded
Publisher
github.com
Source type
Primary document — an official announcement, paper, filing, or first-party page we read directly.
ContextUnderstand this in 60 seconds

Key terms

Mixture of Experts (MoE)
An architecture with specialized subnetworks where only selected experts run per input.
Memory (Agent Memory)
Stored context an AI agent uses across steps or sessions to improve continuity.
Inference
The runtime phase where a trained model generates predictions or outputs.

What happened

The llama.cpp project has released version b12191, which introduces a mechanism to offload a portion of Mixture-of-Experts (MoE) cache misses to the CPU. By utilizing the new `--moe-cache-cpu-share` parameter, users can designate a specific fraction of cache misses to be computed on the host CPU rather than uploading them to the primary device (such as a GPU). The update includes a new tuning script, `moe-cache-tune.py`, designed to help users determine optimal cache sizes and CPU share settings based on their specific hardware's upload and processing speeds.

The b12191 update modifies how llama.cpp handles MoE cache misses. Previously, cache misses were typically uploaded to the device for computation. The new implementation allows for a hybrid approach where a share of these misses is computed on the CPU using host experts.

The system now builds the expert Feed-Forward Network (FFN) twice: once on the device using cache slots and once on the CPU for the designated share of misses. The results are then combined before the final down-bias operation.

A new utility, `moe-cache-tune.py`, has been added to automate the configuration process. It runs the llama-server at varying cache sizes and CPU shares to profile the machine's performance, ultimately recommending values for `--moe-cache-mib` and `--moe-cache-cpu-share`.

The update also includes architectural changes to the scheduler and graph construction, such as enabling asynchronous result copying and removing backend-specific logic from the graph to allow for more flexible execution of CPU-bound parts.

Source details: github.com

Why it matters

This update is significant for users running large MoE models on hardware with limited VRAM or constrained interconnect bandwidth. By allowing the CPU to handle a portion of the expert computations, the system can mitigate bottlenecks associated with transferring cache misses to the GPU. The inclusion of an automated tuning script provides a practical, data-driven approach to balancing the workload between the CPU and GPU, which is essential for maintaining throughput in memory-constrained environments. This development reflects a broader trend in local AI deployment: optimizing the orchestration of heterogeneous compute resources to run increasingly complex model architectures on consumer-grade or edge hardware.

MoE models are notoriously memory-intensive because they require loading multiple 'experts' into memory. When the cache is full, 'misses' occur, requiring data to be fetched or computed, which can create significant latency.

By offloading these misses to the CPU, the system can bypass the overhead of moving data across the PCIe bus or other interconnects, which is often the primary bottleneck for local AI .

The tuning script addresses the difficulty of manual optimization, providing a standardized way for users to find the 'sweet spot' for their specific hardware configuration, which is critical for users who may not have deep expertise in system-level AI optimization.

This release demonstrates a continued focus on making high-parameter models accessible on diverse hardware, a core mission of the llama.cpp project.

Interactive Mechanism

Interactive Mechanism: How It Actually Works

Explore the underlying technology behind this development interactively.

Document Size:128K tokens
Needle Placement Depth (Location in document):50% into text
Attention Context Buffer Map:
Target Fact (50%)
Equivalent Pages~320Standard book pages
Retrieval Accuracy99.9%Needle recall score
RAM / KV Cache5.1 GBMemory overhead
Prompt CachingActive~80% discount on reuse
Core takeaway: Million-token context windows allow querying whole codebases or legal archives in one prompt. However, KV cache memory scales with context length, making prompt caching crucial for real-time production.
Interactive Concept Check+10 Points
AI Models Explained Quiz

Which component of an AI application is the machine-learning model itself?

What to watch next

Users should monitor how this CPU-offloading strategy impacts latency in real-world scenarios, as the performance benefit will depend heavily on the specific CPU-to-GPU bandwidth and the relative compute power of the host system. It remains unknown how this implementation scales across different MoE architectures beyond those tested by the developers. Future updates may refine the scheduling logic or introduce more sophisticated cache eviction policies, such as the ClassLRU policy mentioned in the release notes, to further improve hit rates and reduce the frequency of cache misses that necessitate CPU intervention.

Watch for community benchmarks comparing speeds with and without the CPU-offloading feature enabled on various hardware configurations, particularly on systems with high-speed CPUs but limited GPU memory.

The documentation provided in `docs/moe-cache.md` should be monitored for further clarifications on how the `moe-cache-cpu-share` parameter interacts with different model architectures.

Future iterations may see improvements to the `moe-cache-tune.py` script, potentially adding support for more complex profiling scenarios or different cache eviction strategies.

Related guides & quizzes

Found this useful?