---
title: "Running MoE models bigger than your VRAM"
date: 2026-11-28
description: "Why a 150 GiB mixture-of-experts model can run on a 96 GB GPU, how llama.cpp offloads experts, and how to tune --n-cpu-moe without guessing."
tags: ["moe", "llama-cpp", "vram", "offload", "guide", "local"]
---

A 150 GiB Q4 file does not fit on a 96 GB GPU. It can still run there.

Hy4-flash's abliterated `Q4_K_M` is 150.1 GiB. Its author reports running it with about 96 GiB on the GPU and the rest in system RAM. That is not a trick or a compressed cache. It is the difference between a dense model and a mixture-of-experts model: the file is large, but each token only reads a small part of it.

This guide explains where the weights live, which llama.cpp flags move them, and how to size a machine without guessing.

## Total parameters are not the memory you need at once

Every weight still has to be somewhere — VRAM, system RAM, or disk. MoE does not make the file smaller. It makes the *working set per token* smaller.

A model with 512 routed experts and 16 active per token reads 16 experts in each layer, not all 512. The rest stay resident but idle. If the idle experts are in system RAM, the GPU does not need to hold them.

| Model | Total | Active | Q4 file | First realistic fit |
| --- | --- | --- | --- | --- |
| Qwen3.6-35B-A3B | 35B | ~3B | ~21 GB | 24 GB GPU |
| gpt-oss-120b | 117B | 5.1B | ~63 GB | 48 GB GPU + 32 GB RAM |
| Hy4-flash | ~220B | 12B | 150.1 GiB | 96 GB GPU + 64 GB RAM |
| ERNIE 5.5 Flash | 280B | 14B | 170.3 GiB (NVFP4) | 2×96 GB GPUs |

The file sizes are quant-dependent; the fit column is a starting point, not a guarantee. Context length and the runtime's buffers change the answer. To check a specific build against your own machine, use the [hardware fit page](/recommend).

## What has to be on the GPU

Not every tensor is a routed expert. The parts that run for every token should stay on the GPU:

- **Attention weights** and the **KV cache**.
- **Shared experts**, which are active on every token.
- **The router**, which decides which experts to use.
- **Embeddings, norms and `lm_head`**.
- **Dense FFN layers**, if the model has any.

The routed experts are the bulk, and they are the part you can move to the CPU. In llama.cpp, the expert tensors are the `ffn_*_exps` tensors in each block. Everything else in the block is a normal tensor and stays where `-ngl` puts it.

Some models add special tables. Hy4-flash has a 63.5B Engram table, about 59 GiB in the GGUF. It is only row-gathered, so it can live in system RAM without being touched as a matrix. That is why a 150 GiB file can run with 96 GiB of VRAM: the GPU holds the backbone and the experts, and the Engram table stays in RAM.

## The flags that matter

llama.cpp has three ways to move expert weights, plus a cache for the ones you leave on the CPU.

| Flag | What it does | Use it when |
| --- | --- | --- |
| `-ngl 99` | Offload all layers to the GPU | Always, then override |
| `--n-cpu-moe N` | Keep the MoE weights of the first N layers in CPU | VRAM is short |
| `--cpu-moe` | Keep all MoE weights in CPU | VRAM is very short |
| `-ot PATTERN=CPU` | Override specific tensor patterns | Fine control, special tables |
| `--moe-cache-mib N` | GPU cache for CPU-resident experts | Recent builds; repeated experts |
| `-c N` | Context size | Budget the KV cache |
| `-ctk q8_0 -ctv q8_0` | Quantize the KV cache | Long context, short VRAM |
| `-fa on` | Flash attention | Usually faster and smaller |
| `--parallel 1` | One server slot | Single user; avoids KV multiplication |

`--n-cpu-moe N` keeps the **first N layers'** expert tensors on the CPU. It is a prefix, not a budget. If you want the last layers on the CPU instead, use `-ot` with a block range.

`--moe-cache-mib` is newer. It caches recently used CPU-resident experts in VRAM, which helps when routing is stable. Check `llama-server --help` before relying on it.

## A worked example: Hy4-flash on 96 GB

The author's Q4_K_M run kept the Engram table in RAM and the rest on the GPU. In llama.cpp, that is an explicit tensor override:

```bash
llama-server \
  -m Hy4-flash-abliterated-Q4_K_M-00001-of-00002.gguf \
  -ngl 99 \
  -ot "per_layer_token_embd=CPU" \
  -c 16384 \
  -fa on \
  --jinja \
  --host 127.0.0.1 \
  --port 8080
```

The `-00001-of-00002.gguf` file is the entry point; llama.cpp loads the second shard automatically.

On a 48 GB GPU, the same file needs expert offload. Start with a prefix and sweep it:

```bash
llama-server \
  -m Hy4-flash-abliterated-Q4_K_M-00001-of-00002.gguf \
  -ngl 99 \
  -ot "per_layer_token_embd=CPU" \
  --n-cpu-moe 24 \
  -c 8192 \
  -fa on \
  --jinja
```

`24` is a starting point, not a recommendation. The right number depends on your card, the context, and how much RAM you have. Measure it.

## Sizing by machine

| Setup | What fits | Reality check |
| --- | --- | --- |
| 16 GB VRAM, 32 GB RAM | 35B-A3B Q4 with most experts on CPU | Slow; keep context at 4K–8K |
| 24 GB VRAM, 64 GB RAM | 35B-A3B Q4 fully on GPU; 120B Q4 with heavy offload | 120B is a stretch |
| 32 GB VRAM, 96 GB RAM | 120B Q4 with offload; Hy4 IQ4_XS with most experts on CPU | Hy4 will be slow |
| 48 GB VRAM, 128 GB RAM | Hy4 IQ4_XS with partial offload; Hy4 Q4 with heavy offload | Measure before committing |
| 96 GB VRAM, 64 GB RAM | Hy4 Q4 with the Engram table in RAM | The author's setup |
| 2×96 GB VRAM | ERNIE 5.5 Flash NVFP4 at TP=2 | vLLM, not llama.cpp |

Two rules keep the table honest:

1. **The file must fit in VRAM plus RAM.** If it does not, the OS pages from disk and throughput collapses.
2. **Leave headroom.** Compute buffers, the KV cache and fragmentation need 1–2 GB. A machine that is 100% full at load will fail at 16K context.

## Why it can still be slow

Moving experts to the CPU is not free. Three costs show up:

- **CPU matmuls.** The experts that are not on the GPU are computed on the CPU. That is bandwidth-bound and much slower than a GPU matmul.
- **PCIe traffic.** If the runtime copies experts to the GPU instead of computing on the CPU, each token pays a transfer. `--moe-cache-mib` reduces repeat transfers but cannot remove the first one.
- **Prefill.** Prompt processing touches many tokens and many experts. With experts on the CPU, prefill can be far slower than decode. A model that feels fine at 20 tokens/s can take a long time to read a 32K prompt.

Measure both numbers: prompt-processing speed and generation speed. A single tokens/s figure hides the cost that matters for long documents.

## Multi-GPU

llama.cpp splits across GPUs with `--split-mode`:

- **`layer`** (default) pipelines layers across GPUs. It is the simplest and works over PCIe.
- **`row`** splits tensors by rows. It can use more bandwidth and benefits from NVLink.
- **`tensor`** splits weights and KV across GPUs and is marked experimental.

`--tensor-split 3,1` gives the first GPU three times the share. Use it when the GPUs have different memory.

For NVFP4 checkpoints, the runtime is usually vLLM rather than llama.cpp. There, the equivalent knob is `--tensor-parallel-size`, often with `--enable-expert-parallel`. The ERNIE release uses TP=2 or TP=4; check the model card for the exact command.

## Measure, don't guess

`llama-bench` accepts the same offload flags:

```bash
llama-bench \
  -m Hy4-flash-abliterated-Q4_K_M-00001-of-00002.gguf \
  -ngl 99 \
  -ncmoe 24 \
  -p 512 \
  -n 128
```

Sweep `-ncmoe` in steps and record both `pp512` and `tg128`. The best value is the smallest prefix that keeps you under the VRAM limit with the context you actually use. Larger values load too, but they move work to the CPU for no reason.

Watch memory while it runs:

- **NVIDIA:** `nvidia-smi` or `nvtop`.
- **Apple Silicon:** Activity Monitor's Memory Pressure graph, not the raw used-memory number.
- **AMD:** `rocm-smi`.

If the process starts swapping, reduce context, drop to a smaller quant, or move experts back to the GPU if VRAM allows. If it is merely slow, move fewer experts to the CPU and try again.

## Caveats

- **Not all MoEs are the same.** Shared experts, dense layers and special tables change the ratio of “must be on GPU” to “can be on CPU.”
- **Quant quality still matters.** A Q4 file that fits is better than a Q2 file that fits easily. Do not use offload as an excuse to drop two quant levels.
- **Context is part of the budget.** A 32K context can cost several GB of KV cache. Quantized KV helps, but it is not free.
- **Vendor fit claims are optimistic.** “Runs on 24 GB” often means a short context, a small quant, and no other GPU work. Measure your own workload.
- **The model card is the source of truth for flags.** Architectures like Hy4-flash need a recent llama.cpp build; older binaries can load a file and produce nonsense.

## Next steps

- Read the [Hy4-flash abliterated release](/news/hy4-flash-abliterated) for a worked example of a 150 GiB model and its llama.cpp build requirements.
- Read [GGUF quantization, explained](/guides/gguf-quantization-guide) before choosing between Q4_K_M, Q5_K_M and IQ4_XS.
- Read [Running abliterated models on Apple Silicon with MLX](/guides/running-abliterated-models-on-apple-silicon-with-mlx) if your “VRAM” is unified memory.
- Browse the [catalog](/models) and filter by size and method.

---

Canonical: https://www.wahloon.net/guides/running-moe-models-bigger-than-your-vram

- Newer: [GGUF quantization, explained: how to pick the right quant](https://www.wahloon.net/guides/gguf-quantization-guide)
- Older: [What is Abliteration? (and why it matters in 2026)](https://www.wahloon.net/guides/what-is-abliteration)
