Flint 40B-A2.5B at 128k on llama.cpp23.4 GB of Q4_K_M on 12 GB
A 23.4 GB MoE GGUF on a 12 GB card at 128k context: every routed expert in RAM, the freed VRAM spent on llama.cpp's adaptive MoE cache. 58.8 tok/s decode, 1,708 tok/s prefill.
- Decode · prose, 128k profile
- 58.8tok/sstock 48.2
- Prefill · cold 11k-token opencode system prompt
- 1,708tok/sstock 329
- Context
- 128k tokens
- VRAM peak
- 11,585MiB
TUNED STOCK FLAGS CEILING FROM MEASURED BANDWIDTH
Run it
./serve.sh
| Model | RecursiveSI/flint on Hugging Face |
|---|---|
| Weights | GGUF Q4_K_M, 23.4 GB from ggml-org/Flint-GGUFFlint-Q4_K_M.gguf |
| Engine | llama.cpp b12242 (3b4d6ab3f), release build · CUDA 12.8 |
| Placement | All routed experts in RAM (about 20 GB, read into RAM, not mmap'd). VRAM holds the dense layers, the f16 KV cache and a 2944 MiB cache of the hottest experts. |
| Hardware | NVIDIA GeForce RTX 3060 12 GB · 62 GB RAM · Intel Core i5-12500 · NVMe SSD PCIe Gen4 x16. RAM read bandwidth measured at 57 GB/s. |
| API | OpenAI-compatible on port 8081 |
| Key flags | -ngl 99 -ncmoe 49 --moe-cache-mib 2944 --moe-cache-cpu-share 0.95 -c 131072 -np 1 -t 6 -b 4096 -ub 4096 --load-mode none -fa on -ctk f16 -ctv f16 --spec-type ngram-map-k --fit off |
- The cache needs --moe-cache-cpu-share 0.95; 1.0 freezes it and loses most of the gain.
- q8_0 KV costs 29% decode at 32k depth on this model; keep f16.
- If your job runner caps memory and counts page cache, allow about 44 GB.
- Smaller expert quants (Q3_K, UD-Q3_K_XL) were slower or too lossy and did not ship.
Measured results
| Metric | Conditions | Measured | Stock | Ceiling | Source line |
|---|---|---|---|---|---|
| Decode | prose, 128k profile | 58.8 tok/s | 48.2 | 76 | RESULTS.md:18 |
| code task (mostly reasoning) | 55.0-55.8 tok/s | 46.7 | RESULTS.md:19 | ||
| at 32k depth | 46.8-47.2 tok/s | 34 | RESULTS.md:20 | ||
| prose, 64k profile (FLINT_PROFILE=64k) | 63.4 tok/s | RESULTS.md:26 | |||
| Prefill | cold 11k-token opencode system prompt | 1,708 tok/s | 329 | 2,600 | RESULTS.md:15 |
| 121k-token prompt | 989 tok/s | RESULTS.md:17 | |||
| Time to first token | cold 11k-token prompt | 6.4 s | 33.4 | RESULTS.md:16 | |
| Needles | 3 codes at 60k and at 120k | 3/3, 3/3 found | RESULTS.md:21 | ||
| VRAM peak | after a 121k request | 11,585 MiB | RESULTS.md:22 | ||
| Quality | KL divergence vs the all-GPU path, wikitext (CPU experts without cache: 0.076) | 0.07 KLD | README.md:19 |
Reproductions
None yet. If you ran this on your own 3060, report your numbers and they appear here with your hardware.
Findings from this recipe
A port-based health check can be answered by someone else's server
A harness that waits for `/health` on a port and then runs its tests will measure whatever answers on that port.
With experts in RAM, a 4096-token micro-batch gives 4.1x prefill and 8192 adds almost nothing
During prefill llama.cpp copies the RAM-resident experts to the GPU once per micro-batch, so a larger micro-batch amortizes the copy.
Smaller expert quants do not speed up CPU-side decode unless their kernel is cheap per byte
With every expert in RAM, fewer bytes per expert did not mean faster decode on this CPU.
An adaptive expert cache matches the oracle hot set and a fixed one does not
Expert routing on code is concentrated, but the hot set moves, which is why a cache that adapts beats pinning experts chosen in advance.
Put every expert in RAM and spend the freed VRAM on the MoE cache
On Flint at 128k, keeping all routed experts in RAM and giving the freed VRAM to llama.cpp's adaptive MoE cache beats placing some layers' experts on the GPU.
The CPU-GPU hand-off is 1.1 ms of an 18.9 ms token, not the bottleneck
With Flint's experts in RAM, each token alternates 42 GPU splits and 42 CPU splits.
Editing a bash script while it runs reorders or breaks the rest of the run
Bash reads a script from disk as it goes, by byte offset.
Greedy-output identity is the wrong quality gate when placement changes
Comparing greedy output hashes before and after a change flags valid configurations as broken whenever the change moves computation between CPU and GPU.
Reading weights into RAM instead of mmap gives 24% faster prefill with experts on the host
With experts kept in RAM, loading the weights with `--load-mode none` instead of the default mmap makes the host-to-GPU copies during prefill faster.
nvidia-smi shows the PCIe link at Gen1 when idle and that is power saving
Reading the PCIe link speed while the GPU is idle gives a misleading answer.
q8_0 KV costs 29% decode at 32k on a model with few full-attention layers
Quantized KV cache is slow on llama.cpp for models with few full-attention layers.
On an i5-12500 RAM read bandwidth peaks at 6 threads and so does decode
On this CPU, RAM read bandwidth stops growing at 6 threads, and expert-in-RAM decode follows it.
A cgroup memory cap counts page cache, so mmap'd weights hit it
On this box every GPU job runs through a flock-based GPU queue that also wraps the job in a cgroup with a memory cap, 20 GB by default.
Thanks
- RecursiveSI The model behind the 128k coding recipe.
- ggml-org Flint-Q4_K_M.gguf and Inkling-2-Mini-IQ4_NL.gguf are the files the two recipes serve; the Q8_0 files are the KLD references.
- llama.cpp (ggml-org and contributors) The engine for Flint, the 3D coder and Inkling-2-Mini, and the base of the Kintsugi fork.
- bartowski The imatrix used when we requantized only the RAM-resident experts.
- Unsloth The Mainline_Support files are the max-speed options of the Inkling recipe (41.4 tok/s whole-on-GPU); UD-Q3_K_XL was the smaller-expert test on Flint.
- 0xSero / Sybil Solutions The tuning method behind the Flint and Inkling recipes; its q8_0 KV gotcha is one we confirmed on Flint.
- Hugging Face Every model, quant and drafter in these recipes is fetched from the Hub at a pinned revision and checked against the API's sha256; the base model's MTP tensors were fetched with HTTP range requests.
- NVIDIA Every recipe runs on CUDA on this card; cuBLAS SGEMV is our VRAM bandwidth probe (342 GB/s), nvidia-smi dmon is the telemetry, and Inkling's experts ship in NVFP4.
Full write-up
Serving Flint (40B-A2.5B MoE: 49 layers, 256 experts top-6 plus shared experts) on the RTX 3060 12 GB with stock llama.cpp, at 128k context, as the local model behind opencode.
The 23.4 GB Q4_K_M GGUF does not fit in 12 GB. This recipe puts every routed expert in RAM and spends the freed VRAM on llama.cpp's adaptive MoE cache, which keeps the hot experts on the GPU. On code, the top quarter of experts takes ~58% of routing picks, so a 2.9 GB cache serves ~45% of expert reads from VRAM.
Numbers are in RESULTS.md. The tuning log is PLAN.md, the ceilings are in THEORY.md, the deeper experiments (context profiles, MoE cache, requant, routing skew, engine prototype) are in experiments/RESULTS.md, and the raw data is in runs/ and experiments/runs/.
Result
| Single user, 128k context | Old serve.sh |
This recipe (default) | Ceiling |
|---|---|---|---|
| Prefill, cold 11k-token opencode system prompt | 329 tok/s (33.4 s) | 1,708 tok/s (6.4 s, 5.2×) | ~2,600 |
| Prefill, 121k-token prompt | 989 tok/s | ||
| Decode, prose | 48.2 tok/s | 58.8 tok/s (+22%) | ~69–76 |
| Decode, code task (mostly reasoning) | 46.7 | 55.0–55.8 | |
| Decode at 32k depth | 34.0 | 46.8–47.2 | |
| Needles, 3 codes at 60k / 120k | 3/3, 3/3 | ||
| KL divergence vs the all-GPU path (wikitext) | 0.076 (CPU experts, no cache) | 0.070 | |
| VRAM, after a 121k request | 11.3 GiB of 12 |
Use it
# weights: ggml-org/Flint-GGUF, Flint-Q4_K_M.gguf (23.4 GB) -> $MODELS/flint/ # engine: llama.cpp b12242 (3b4d6ab3f) release build, CUDA 12.8 -> $SCRATCH/llama.cpp/b12242/ ./serve.sh # 128k profile, OpenAI-compatible on 127.0.0.1:8081, through gpu_run ./opencode.sh # opencode with opencode.json pointed at it FLINT_PROFILE=64k ./serve.sh # faster decode, half the context
Profiles
FLINT_PROFILE |
Context | Placement | Decode, prose / code | Cold 11k prefill | Use it when |
|---|---|---|---|---|---|
128k (default) |
131,072 | all experts in RAM, 2944 MiB cache, ngram-map-k spec | 58.8 / 55–56 | 1,708 | opencode and anything that might grow past 64k. Spec only helps when output repeats the context (file rewrites, edit calls) and never measured below the control. |
64k |
65,536 | all experts in RAM, 5248 MiB cache, spec off | 63.4 / 60.9 | 1,749 | sessions that stay under 64k: +8% decode. Spec is off because it cost 4–8% with this cache size (58.2 / 58.4 with it on). |
nocache |
131,072 | experts of 43 layers in RAM, 4 on the GPU, no cache | 51.9 / 50–51.5 | 1,751 | a reference point without the MoE cache: the first tuned config, and the comparison for any cache change. Prefill is ~2.5% faster; decode is 12% slower. |
All profiles use -b 4096 -ub 4096, f16 KV, --load-mode none (weights read into RAM, not mmap'd), -fa on, 6 threads and one slot. GPU_RUN_MEM=44G is set, because the RAM-resident experts take ~20 GB plus buffers and gpu_run's 20 GB default cap would bind.
Overrides: FLINT_CONTEXT, FLINT_CPU_MOE, FLINT_MOE_CACHE_MIB, FLINT_MOE_CACHE_SHARE, FLINT_SPEC (none to turn off ngram speculation), FLINT_KV, FLINT_UBATCH, FLINT_THREADS, FLINT_MODEL, FLINT_PORT, FLINT_GPU_WAIT (seconds to wait for the shared GPU lock, default 120). Extra llama-server flags go after ./serve.sh.
What was tried and didn't ship
| Idea | Result |
|---|---|
| Bigger 128k cache (3200 / 3328 MiB), cpu-share 0.80 / 0.90 | within noise of 2944 / 0.95; the hit rate stops climbing past 2944 MiB (exp 5, 6) |
| cpu-share 1.0 (freeze the cache once full) | loses most of the gain: 52 vs 58.8 tok/s (exp 5) |
-ub 8192 at 64k / 32k |
+1.7% prefill on 11k prompts, −3 to −6% decode (exp 6) |
| Mixed placement (some expert layers on the GPU plus a smaller cache) | no better than all-in-RAM with a bigger cache at the same VRAM (exp 5) |
| q8_0 KV | −29% decode at 32k depth; f16 KV kept (PLAN #3) |
Threads ≠ 6, --poll, CPU pinning, GGML_CUDA_GRAPH_OPT |
noise or worse; RAM bandwidth saturates at 6 threads (PLAN #5–6, exp 2) |
| ngram-mod speculation | noise (PLAN #10) |
| RAM experts requantized Q4_K_M → Q3_K / IQ4_XS | Q3_K +7% speed, but KLD 0.34 and 78.8% top-1; IQ4_XS no speed gain (exp 3) |
| unsloth UD-Q3_K_XL (18.5 GB, from the original weights) | −6% decode (54.8 vs 58.5), +8% prefill, KLD 0.39, 77.5% top-1, PPL +5.8%: its I-quant experts are slower on the CPU than Q4_K (exp 7) |
Where the remaining time goes
- Decode reaches ~77–85% of the bandwidth ceiling. With experts in RAM, the CPU expert matmuls run at ~80% of the 57 GB/s DRAM peak, and the GPU and CPU halves of each layer run one after the other. The next gains need engine work: an async-copy prototype in
experiments/gives +3%, and overlapping the shared expert with the CPU split is worth up to ~5%. - Prefill of the 11k opencode prompt takes ~6.2 s at ub 4096, and bigger micro-batches don't shorten it (exp 6).
Tools
| Script | What it does |
|---|---|
serve.sh |
the server, with the profiles above |
opencode.sh, opencode.json |
opencode pointed at the local server (128k context, 4k output) |
tools/bench.sh, summarize.py |
one llama-bench run through gpu_run with nvidia-smi dmon telemetry |
tools/servertest.py |
server tests: cold 11k prefill, code rewrite, prose decode, needles; appends to a ledger |
tools/membw.c |
RAM read bandwidth probe (AVX2) |
experiments/tools/srv.sh |
start serve.sh with overrides, wait for health, run tests (TESTS, EXTRA), stop cleanly |
experiments/tools/exp5probe.py |
warm-up windows, greedy hashes, decode at 32k depth |
experiments/tools/phase*.sh |
the sweeps behind each experiment |
experiments/tools/requant.sh, routing_skew.py, static_cache.py |
requant of only the RAM experts; routing-skew analysis |
../scripts/codeeval.py |
8 Python tasks against asserts, temperature 0 |
promo/ holds the Remotion video for this recipe.
Credits
- llama.cpp for the engine and its MoE cache (
--moe-cache-mib); ggml-org for the GGUF. - RecursiveSI for Flint; bartowski for the imatrix used in the requant experiment; unsloth for the UD-Q3_K_XL GGUF tested in exp 7.
- The tuning method comes from 0xSero's inference-optimisation-skill: ceilings first, one change at a time with controls, and output gated as well as speed.
recipe.json · Markdown · Folder with scripts and raw runs · Full results log