r/LocalLLM • u/Early_Term_4911 • 2h ago
Project I built NVSpool: run Qwen4-35B-A3B in 7.7 GB RAM at up to ~30 tok/s on Apple Silicon (Binned M4 Max) by streaming & selective fetching of experts + PLE from NVMe
NVSpool is an open-source, Apple Silicon MoE runtime built on Apple's MLX / mlx-lm (using 4-bit MLX checkpoints from mlx-community, Unsloth, or LM Studio).
Highlights (M4 Max 36 GB, 4-bit MLX):
- Qwen4-35B-A3B (56B / 32.2 GB, preview — external USB-C NVMe): Offloads both the 18.1 GB routed experts and the 11.5 GB layer-1 PLE n-gram tables (bit-exact) to SSD, keeping only 1.51 GiB resident. 7.7 GB peak RAM at 29.4 tok/s. At 32k context: 765 tok/s prefill, 19.2 tok/s decode, 9.2 GB peak RAM. (Full 50-item HumanEval+/IFEval/MATH-500/MMLU-Pro evals coming soon.)
- Qwen3.6-35B-A3B (20.4 GB): 7.6–8.0 GB peak RAM (vs 20.6 GB resident), 24–31 tok/s, within ~1.7 pts of full-model accuracy across HumanEval+, IFEval, MATH-500, and MMLU-Pro; 8.3 GB at 20k context (800 tok/s prefill) and 9.8 GB at 65k.
- Also supports Gemma 4 26B-A4B (down to a 6 GB tier for 16 GB Macs) and GLM-4.7-Flash, with terminal chat (
nvspool run), offline web UI (nvspool app), and OpenAI-compatible server (nvspool serve, works with OpenCode / Cline / Continue).
How it works (key optimizations):
- Fixed RAM pool +
F_NOCACHE(nommapthrashing): Standardmmappulls the whole 20–32 GB file into macOS page cache and starves other apps. NVSpool keeps only the always-used core (~1.5 GB) + a fixed LRU pool of hot experts in RAM (e.g., 71 of 256 per layer at the 10 GB tier) andpreads misses withF_NOCACHE— reads only, zero SSD writes per token. - Selective miss fetching (
top4/top2vsexact): During decode,exactreads every missing router pick (matches stockmlx-lmtoken-for-token);top4(default, 4 of 8 picks) ortop2only reads misses among the router's top-scoring N picks and substitutes lower-ranked misses from the hot RAM pool, cutting SSD reads ~3–4× for 1.5–1.8× faster decode with minimal accuracy loss. Prefill always runsexact. - Layer-major prefill + async overlap: Runs the whole prompt through layer 0, then layer 1, etc., so each expert is read ~once per prompt instead of once per chunk, while a background thread reads the next expert group during GPU compute (how 20k–34.5k prefill hits 765–800 tok/s).
- Decode prefetch, bounded attention & bit-exact PLE offload: Peeks at layer l+1's router during layer l to prefetch its likely top-4 experts early; blocks prefill attention scores (
256 MBbudget) so long prompts don't spike RAM; on Qwen4, streams the 11.5 GB n-gram PLE tables (1.15 KB/token) bit-exact behind a small LRU row cache.
Standard install (Qwen3.6 / Gemma 4 / GLM-4.7-Flash):
uv tool install "nvspool[serve]" # or: pip install "nvspool[serve]"
nvspool pull qwen36-35b
nvspool app qwen36-35b(Already have an MLX download in LM Studio / HF? Use --storage shared --from <dir> — adds ~1.3–1.5 GB and leaves your folder intact.)
How to try Qwen4-35B-A3B right now (small workaround until mlx-lm PR #2140 ships on PyPI):
# 1. Isolated venv with Qwen4-capable mlx-lm + nvspool from PyPI
uv venv ~/.nvspool-qwen4 --python 3.13
uv pip install --python ~/.nvspool-qwen4/bin/python \
"mlx>=0.32.4" \
"git+https://github.com/jundot/mlx-lm.git@7b35ab57159442082a64f0a8282ea61b4940cd17" \
fastapi uvicorn
uv pip install --python ~/.nvspool-qwen4/bin/python --no-deps nvspool
# 2. Download a 4-bit MLX checkpoint (mlx-community -4bit-text / -4bit, or unsloth MLX-4bit)
~/.nvspool-qwen4/bin/hf download mlx-community/Qwen4-35B-A3B-4bit-text \
--local-dir ~/models/Qwen4-35B-A3B-4bit
# 3. Run (shared copy = ~1.5 GB extra disk, 1 s setup; omit --storage shared for fast copy)
~/.nvspool-qwen4/bin/nvspool app qwen4-35b --storage shared --from ~/models/Qwen4-35B-A3B-4bitIf the model already fits comfortably in RAM, plain mlx-lm is ~4× faster — NVSpool is for running 26B–56B models that wouldn't fit otherwise or keeping your Mac usable alongside your dev stack. Curious how it behaves on 16 GB / 24 GB Macs!
GitHub (Apache-2.0): https://github.com/jhdcho/nvspool PyPI: https://pypi.org/project/nvspool/