In this series / On this page· 9 of 9

When the Experts Don't Fit in RAM Either: Streaming MoE Weights from SSD

When a MoE model outgrows memory, every expert-cache miss is an SSD read: how to estimate the speed, size the cache, and pick the engine.

16 min readUpdated
Blueprint drawing of five layer plates standing on a token's path, each a dense grid of experts with ten lit; on the current layer two of them are misses, traced down by rust dashes to the flash chips of an M.2 SSD lying below.
Each layer uses ten of its experts; the ones not in memory come off the SSD.

Qwen3.8-Flash-Next weighs about 180 GB in FP8, and Hugging Face runs it on a 32 GB Mac at about 14 tok/s by keeping its experts on the SSD and only the ones in use in memory. How fast that goes is set by two numbers you can measure on your own machine: how often the cache hits, and how fast the misses come off the drive. In our runs the second one, through page faults, was a sixth of what the SSD can do.

Bytes per token, and what a miss costs

A mixture-of-experts token reads only the experts its router picks, so the cost of streaming is set by what one token needs, not by the size of the model. Qwen3.8-Flash-Next has 48 MoE layers of 512 experts and routes each token to 10 of them. In the IQ3_S pack Strata uses (a GGUF quantization format at about 3.4 bits per weight), an expert weighs 2.05 MB on average: Strata's log reports 24,576 slots in 46.84 GiB. One token therefore needs 10 × 48 = 480 experts, 0.98 GB, if none of them is already in memory. Qwen3.6-35B-A3B is the smaller cousin: 40 layers of 256 experts, top-8, 3.34 MB per expert in Q8_0 (8-bit weights with one scale per 32, 34 bytes per 32 weights), so 1.07 GB per token with nothing cached, out of 34 GB of experts in all.

Where each of those experts comes from sets the price.

Three stacked tiers an expert can be read from: GPU expert slots at about 273 GB/s, the page cache in the same LPDDR5X memory, and an NVMe SSD at 5.6 GB/s with 16 parallel 1 MiB reads, 2.8 GB/s with one, and 0.65 GB/s for single 128 KiB reads; below, a table showing that Qwen3.8-Flash-Next IQ3_S reads 0.98 GB per token from the SSD when nothing is cached (at most 5.7 tok/s) and 0.13 GB at an 87% hit rate (about 44 tok/s).Three stacked tiers an expert can be read from: GPU expert slots at about 273 GB/s, the page cache in the same LPDDR5X memory, and an NVMe SSD at 5.6 GB/s with 16 parallel 1 MiB reads, 2.8 GB/s with one, and 0.65 GB/s for single 128 KiB reads; below, a table showing that Qwen3.8-Flash-Next IQ3_S reads 0.98 GB per token from the SSD when nothing is cached (at most 5.7 tok/s) and 0.13 GB at an 87% hit rate (about 44 tok/s).

Figure 1: a token that misses every cached expert reads about 1 GB from the SSD and is capped near 6 tok/s; the best possible cache raises that ceiling to 44 to 52 tok/s.

  • GPU expert slots. A hit costs nothing extra: the kernel reads the expert where it is. Our expert-paging piece covers how a discrete GPU fills these slots from host RAM over PCIe.
  • RAM or page cache. The experts are mapped from the model file, and the OS keeps the pages it has read. A hit is a memory read; a miss is a page fault: the process stops until the OS has read that part of the file from the disk.
  • SSD. A miss is a disk read, and how fast the drive delivers misses is the ceiling. Measure it first, with the read pattern your engine uses. Our test machine, a GB10 box with 128 GB of unified LPDDR5X and a 1 TB NVMe, reads 5.6 GB/s with 16 parallel 1 MiB reads, 2.8 GB/s with one, and 0.65 GB/s with one 128 KiB read at a time (nvme.py, direct I/O, so the page cache doesn't help). Same drive, a factor of nine.

What a cache can buy

A cache can't push the miss rate to zero, and Hugging Face's Space measured how close it gets. They replayed Qwen3.8-Flash-Next's real routing for four 200-token answers through a 12 GiB cache (5,991 expert slots):

  • Belady's policy, which evicts the expert needed furthest in the future and so is the best any cache can do, hits 86.8 to 89.3%.
  • LRU, which evicts the expert used least recently, hits 81.3 to 86.2%.
  • Pinning half the cache to the most-used experts loses 4 to 6 points against plain LRU.
  • First uses are 10 to 13% of lookups: one answer touches 10,700 to 12,600 distinct experts, twice what the cache holds, and no policy avoids a first use.

The post sums it up: no cache policy beat LRU by much.

The ceiling follows from the miss rate: tok/s ≤ miss delivery rate / (miss rate × bytes per token). For Qwen3.8-Flash-Next IQ3_S at 0.98 GB per token:

Hit rate SSD bytes per token Ceiling at 5.6 GB/s Ceiling at 0.6 GB/s
0% (nothing cached) 0.98 GB 5.7 tok/s 0.6 tok/s
81% (LRU, low end) 0.19 GB 30 tok/s 3.2 tok/s
87% (Belady, low end) 0.13 GB 44 tok/s 4.7 tok/s
89% (Belady, high end) 0.11 GB 52 tok/s 5.6 tok/s

These ceilings count only the reads; compute and host overheads come on top. The last column is about the rate we measured (0.5 to 0.9 GB/s) when the page cache does the streaming, in the runs below.

Quantization moves the whole table: the same model's experts in FP8 weigh 4.92 MB, so 2.36 GB per token, and every ceiling falls by a factor of 2.4.

On unified memory, "offload to CPU" frees nothing

On a discrete GPU, --n-cpu-moe (llama.cpp) or --cpu-offload-gb with --cpu-offload-params experts (vLLM) move experts out of VRAM into host RAM, a separate and larger pool. On a DGX Spark-class machine or a Mac there is one pool: the "CPU" experts sit in the same LPDDR5X as the "GPU" ones. Moving them frees no capacity. It only changes which processor computes them.

We measured the cost on the same machine with llama.cpp b12588 and Qwen3.6-35B-A3B Q8_0 (unsloth GGUF, 36.9 GB). Workload for every llama.cpp number here: one request at a time, a fresh short prompt (about 25 tokens), 256 generated tokens, greedy; median of three requests after one discarded cold request.

Where the experts are Decode tok/s
All on the GPU (-ngl 99) 58.6
Computed on the CPU, all in RAM (--n-cpu-moe 99) 20.5

Same memory, same model, a third of the speed. On unified memory, only the SSD adds room.

Measured: decode speed against memory

Neither test model is too big for a 128 GB machine, so we made the machine smaller instead. A cgroup memory cap counts the process's RAM and the page cache it fills; once the mapped experts don't fit under it, the kernel evicts pages, and the next use of an evicted expert faults it back in from the SSD:

$ systemd-run --user --scope -p MemoryMax=16G -p MemorySwapMax=0 \
    llama-server -m Qwen3.6-35B-A3B-Q8_0.gguf \
      -c 8192 -np 1 -ngl 99 -t 10 \
      --n-cpu-moe 99 --no-repack \
      -lm mmap --no-host

--n-cpu-moe 99 keeps every layer's experts on the CPU side, mapped from the file; -lm mmap --no-host keeps them mapped rather than copied into resident buffers (see the gotchas); --no-repack stops the ARM CPU backend from repacking Q8_0 weights into a resident copy. Attention, the router and the KV cache stay on the GPU.

A bar chart of llama.cpp decode speed for Qwen3.6-35B-A3B Q8_0 under shrinking cgroup memory caps: 20.5 tok/s with no cap, then 16.1, 10.5, 5.1, 3.7 and 2.4 tok/s at 32, 24, 16, 12 and 8 GB, against a dashed 58.6 tok/s reference for all experts on the GPU. Under each bar is the SSD read rate, which climbs from 0 to only 0.85 to 0.90 GB/s, far below the drive's 5.6 GB/s direct-read ceiling.A bar chart of llama.cpp decode speed for Qwen3.6-35B-A3B Q8_0 under shrinking cgroup memory caps: 20.5 tok/s with no cap, then 16.1, 10.5, 5.1, 3.7 and 2.4 tok/s at 32, 24, 16, 12 and 8 GB, against a dashed 58.6 tok/s reference for all experts on the GPU. Under each bar is the SSD read rate, which climbs from 0 to only 0.85 to 0.90 GB/s, far below the drive's 5.6 GB/s direct-read ceiling.

Figure 2: once the cap drops below the experts' 34 GB, decode falls from 20.5 to 2.4 tok/s, yet the SSD never reads faster than 0.9 GB/s, a sixth of what it can do.

Memory cap Decode tok/s Read from the SSD per answer Implied hit rate SSD rate over the request
none 20.5 0 GB 100% —
32 GB 16.1 0.7 to 2.0 GB over 99% up to 0.12 GB/s
24 GB 10.5 5.7 to 8.1 GB 97 to 98% 0.24 to 0.30 GB/s
16 GB 5.1 25 to 35 GB 87 to 91% 0.51 to 0.58 GB/s
12 GB 3.7 45 to 66 GB 76 to 84% 0.65 to 0.74 GB/s
8 GB 2.4 99 to 115 GB 58 to 64% 0.85 to 0.90 GB/s

The implied hit rate is 1 − (bytes read / 256 tokens) / 1.07 GB. It is a lower bound: readahead brings in pages nobody asked for, and the count includes the short prompt. The rate is the bytes read over the whole request; ranges cover the three measured requests.

At 16 GB, under half the experts' 34 GB, the page cache still hits about 89% of the time, close to what Belady reaches on the other model. Decode is 5.1 tok/s anyway, because the misses arrive at 0.55 GB/s, not 5.6. The formula with that measured rate gives 0.55 / 0.12 GB = 4.6 tok/s, close to what we got; at 8 GB it gives 0.87 / 0.42 = 2.1 against 2.4 measured. So the formula works, as long as you feed it the rate the misses actually arrive at.

Why so slow? This kernel's readahead window (how much the OS reads around a fault) is 128 KiB, so a fault brings in at most 128 KiB, and the drive sat near its 128 KiB rate even with ten threads faulting. Strata, which reads whole experts on 8 I/O threads, averaged about 1 GB/s over its capped requests too (below), and in both engines the CPU computes the experts that come from the file rather than from GPU slots (Strata's log: "page-cached experts computed from the mapping"). We did not take the remaining time apart. What the numbers do show: a faster SSD behind the same fault path would buy little.

llama.cpp's GPU expert cache (--moe-cache-mib, merged on 7 October) adds an LRU pool of experts in GPU memory in front of the mapped ones:

$ systemd-run --user --scope -p MemoryMax=12G -p MemorySwapMax=0 \
    llama-server -m Qwen3.6-35B-A3B-Q8_0.gguf \
      -c 8192 -np 1 -ngl 99 -t 10 \
      --n-cpu-moe 99 --no-repack -lm mmap --no-host \
      --moe-cache-mib 4096

With 4 GiB of it on top of a 12 GB cap (16 GB in all), decode climbed over four requests as the cache filled: 2.8, 5.3, 7.0, then 12.0 tok/s, against 5.1 for a plain 16 GB cap. With an 8 GB cap (12 GB in all), the fourth request reached 12.8, against 3.7 for a plain 12 GB cap. These are single requests that had not settled: a trend, not a steady state. And part of the gain is not caching at all. The experts the GPU cache holds are computed on the GPU, the rest on the CPU, and on this model that difference alone is 58.6 against 20.5 tok/s.

Strata on Qwen3.8-Flash-Next

Strata v0.2.13 runs Qwen3.8-Flash-Next from the ISTA-DASLab IQ3_S pack: 54.8 GB of weights plus a 28.8 GB n-gram table, a large lookup table of embeddings the model indexes by recent tokens, read one row at a time. Strata is built for this case: experts mapped from the GGUF, a GPU slot pool sized by --expert-cache, misses read with whole-expert preads on 8 I/O threads, and the n-gram table read from the SSD (--ple-io direct). The flags we changed in the config its setup writes:

--expert-cache 4096    # GPU expert slots (default: auto, as many as fit)
--mmap-experts         # experts read in place from the GGUF
--ple-io direct        # n-gram table rows read from the SSD, never cached in RAM
--max-context 16384

Its native pack requires MTP speculation (--spec 4: a small draft head proposes tokens that the model checks in one pass), so these numbers include speculative decoding, unlike Hugging Face's. Workload: Strata's own dgx_bench.py, fresh 4K-token prompts, 256 generated tokens, greedy, median of three.

GPU expert slots Memory cap Budget in all Decode tok/s Prefill tok/s Read from the SSD per request
all 24,576 (46.8 GiB) none — 49.4 1,540 under 0.2 GB after the first
4,096 (7.8 GiB) 32 GB about 40 GB 21.3 336 about 25 GB
4,096 (7.8 GiB) 24 GB about 32 GB 13.5 281 about 30 GB

The slots sit in GPU memory, outside the cap (see the gotchas), so the budget is the cap plus the slots. Prefill pays more than decode: a 4K-token prompt routes to nearly every expert in every layer, so most of each request's 25 to 30 GB is likely read during the prompt, and prefill falls from 1,540 to about 300 tok/s.

Hugging Face's 14.8 tok/s for Strata on a 32 GB Mac is not directly comparable: it ran without speculation, with Strata 0.1.60, IQ3_XXS experts and a true 32 GB budget.

The gap that isn't the SSD

No run came near the drive's limit, so the time goes elsewhere: waiting on reads, CPU compute on missed experts, and the host's own overheads. Hugging Face's account of closing the gap between Transformers and Strata points the same way. Their first version ran at 10.0 tok/s against Strata's 14.8 on the same Mac. Committing GPU work early, Metal kernels for the layers without a fast path, reading one guessed expert per layer while the SSD would otherwise sit idle, and switching to Strata's smaller IQ3_XXS weights brought it to 13.9 (about 11.6 with their own 3-bit experts). What remains is about 10 ms per token of host round trips: Python queues each layer only after the previous one, so the GPU runs dry in between, while Strata queues the whole token's work up front and has the GPU wait at each layer only for the experts still being read.

What to look for in your own runs:

  • SSD read rate during decode (iostat -x 1, or /sys/block/<dev>/stat): if it sits far below your direct-read ceiling, the misses wait on small reads, not on the drive.
  • Bytes read per token, divided by the bytes of the experts a token needs, gives an upper bound on the miss rate. Compare it with LRU's 14 to 19% on Qwen3.8-Flash-Next; first uses, 10 to 13%, are the floor no policy beats.
  • GPU idle time between layers: host round trips show up there, and no cache fixes them.

What to run, and how big a cache

Pick the budget, read off the hit rate, apply the formula with the rate your misses really arrive at.

  • Which rate. Through page faults (llama.cpp with -lm mmap), use the rate you measure during a capped run, not the drive's spec: here 0.5 to 0.9 GB/s against 5.6. If your engine reads whole experts in parallel, measure that path the same way before you trust the direct-read number.
  • How big a cache. The experts that keep coming back are a fraction of the model: a budget of about half the experts' size (16 GB for Qwen3.6-35B-A3B's 34 GB) still hit about 89%, and about a third (12 GB) fell to 76 to 84%. Start at half the experts' size; give as much of it as you can to the GPU-side cache (--moe-cache-mib, Strata's --expert-cache), since its hits are also computed on the GPU, and leave the rest to the page cache.
  • Which engine. For Qwen3.8-Flash-Next on a Mac or a Spark-class box, Strata, which is built for it. For another MoE GGUF, llama.cpp with --n-cpu-moe 99 --moe-cache-mib N -lm mmap --no-host. vLLM and SGLang only if the model fits in memory, except SGLang's experimental expert pack for DeepSeek-V4-Flash and Kimi-K3 (below).

Gotchas

A memory cap doesn't cover GPU allocations on unified memory. cudaMalloc memory is not charged to the cgroup: a process capped at 4 GB allocated 8 GiB on the GPU while the cgroup counted 0.65 GiB. Strata's slot pool is GPU memory, so a 32 GB cap with the --expert-cache auto its setup writes (all 24,576 slots) ran at 49.9 tok/s, the uncapped speed (49.4). To emulate a smaller machine, cap the GPU-side cache yourself and add it to the budget you state.

The default load mode can make the experts resident. With llama.cpp b12588's default --load-mode auto, the CPU-side experts did not stay mapped on our unified-memory machine: under a 32 GB cap the server was killed at load, at 33.6 GB. With -lm mmap --no-host it loads under a 16 GB cap and streams. Check what your build does before you trust a capped run.

Leftover page cache makes the first run look fast. Pages read by a previous run stay cached after it exits, and they are no longer counted against the new cgroup. Evict the model file's pages before each run: posix_fadvise(POSIX_FADV_DONTNEED) on the file works without root (dropcache.py), and so does vmtouch -e. Then discard the first request anyway: it warms the cache.

The cap is a hard wall. It counts the server's own buffers and the page cache together, and at the cap the kernel kills the process without warning; a system-wide guard such as earlyoom may act before it. The llama.cpp server ran at 8 GB, but give yourself room above that on a real machine, where the browser and the OS share the same memory.

What the big engines offer

vLLM and SGLang serve batches, and a batch touches most experts every step, so neither streams from an SSD by default. vLLM's --cpu-offload-gb N --cpu-offload-params experts keeps experts in host RAM and reads the routed ones each step, with no cache and no disk tier; on unified memory, as measured above, that frees nothing. SGLang v0.5.23 has an experimental SSD tier, --load-format expert_pack, for DeepSeek-V4-Flash and Kimi-K3 only: LMSYS measured about 2 tok/s for DeepSeek-V4-Flash on an RTX 5090 with 32 GB of RAM, at a 46 to 54% hit rate (counted over distinct experts, not per lookup). For one user on a machine too small for the model, the single-user engines (Strata, llama.cpp, and Transformers with the draft PR #50717, built on MPS with a CUDA preview) are where expert streaming lives today.

For the tier above, GPU slots fed from host RAM over PCIe, read the expert-paging piece; for where Strata came from, agent-built inference engines.

Sources

  1. Model LibraryQwen3.8-Flash-Next Architecture
  2. Quantization in PracticeHumming, Measured: One Quantized-Kernel Library Against Marlin and FlashInfer
  3. Quantization in PracticeQuantizing Mixture-of-Experts Models

Inference Notes

Once a week: what changed in serving AI models, and what it means if you build, run or pay for them, in about five minutes.

Read past issues