# Flint 40B-A2.5B at 128k on llama.cpp

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.

- Recipe id: `flint`  ·  status: measured  ·  updated 2026-11-22
- Model: [Flint](https://huggingface.co/RecursiveSI/flint) (40B, 2.5B active MoE, 49 layers, 256 experts top-6 plus shared experts)
- Weights: GGUF Q4_K_M, 23.4 GB, from https://huggingface.co/ggml-org/Flint-GGUF, file `Flint-Q4_K_M.gguf`
- Engine: [llama.cpp](https://github.com/ggml-org/llama.cpp) b12242 (3b4d6ab3f), release build; CUDA 12.8
- Hardware: NVIDIA GeForce RTX 3060 12 GB, 62 GB RAM, Intel Core i5-12500, NVMe SSD
- Context: 131,072 tokens
- 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.
- Contributor: [David Hatley](https://github.com/davidghatley)

## Run it

From `flint/` in a clone of https://github.com/davidghatley/3060-recipes:

```sh
./serve.sh
```

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 script itself (`flint/serve.sh`, machine paths shown as `$MODELS`, `$SCRATCH`, `~`; set them to where your weights and builds live):

```sh
#!/usr/bin/env bash
# Flint Q4_K_M on llama-server. Defaults are the tuned config; see PLAN.md and RESULTS.md for the evidence.
set -euo pipefail
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
BIN=${FLINT_BIN:-$SCRATCH/llama.cpp/b12242/bin/llama-b12242}
MODEL=${FLINT_MODEL:-$MODELS/flint/Flint-Q4_K_M.gguf}
CUDA_LIB=${FLINT_CUDA_LIB:-$SCRATCH/llama.cpp/b12242/cudart/cudart-llama-b12242-bin-ubuntu-cuda-12.8-x64}
export LD_LIBRARY_PATH="$BIN:$CUDA_LIB${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export GPU_RUN_MEM=${GPU_RUN_MEM:-44G}
KV=${FLINT_KV:-f16}
UB=${FLINT_UBATCH:-4096}
# Profiles (experiments/RESULTS.md, exp 5): all experts in RAM plus a VRAM cache of the hot ones.
#   128k (default): 2944 MiB cache, ~59 tok/s.  64k: 5248 MiB cache, ~63 tok/s.  nocache: the first tuned profile, -ncmoe 43, ~52 tok/s.
case "${FLINT_PROFILE:-128k}" in
  128k)    d_ctx=131072; d_cpu_moe=49; d_cache=2944; d_spec=ngram-map-k ;;
  64k)     d_ctx=65536;  d_cpu_moe=49; d_cache=5248; d_spec=none ;;
  nocache) d_ctx=131072; d_cpu_moe=43; d_cache=0;    d_spec=ngram-map-k ;;
  *) echo "FLINT_PROFILE must be 128k, 64k or nocache" >&2; exit 2 ;;
esac
CACHE=${FLINT_MOE_CACHE_MIB:-$d_cache}
CACHE_ARGS=()
[ "$CACHE" != 0 ] && CACHE_ARGS=(--moe-cache-mib "$CACHE" --moe-cache-cpu-share "${FLINT_MOE_CACHE_SHARE:-0.95}")
exec "$HOME/anime-pipeline/tools/gpu_run" --need 10500 --wait "${FLINT_GPU_WAIT:-120}" \
  "$BIN/llama-server" -m "$MODEL" --alias flint-local \
  -ngl 99 -ncmoe "${FLINT_CPU_MOE:-$d_cpu_moe}" "${CACHE_ARGS[@]}" --fit off --spec-type "${FLINT_SPEC:-$d_spec}" \
  -c "${FLINT_CONTEXT:-$d_ctx}" -np 1 -t "${FLINT_THREADS:-6}" \
  -b "$UB" -ub "$UB" --load-mode "${FLINT_LOAD_MODE:-none}" \
  -fa on -ctk "$KV" -ctv "$KV" --jinja --reasoning-format deepseek \
  --temp 1.0 --top-p 0.95 --top-k 20 \
  --host 127.0.0.1 --port "${FLINT_PORT:-8081}" "$@"
```

## Measured results

| Metric | Conditions | Value | Stock | Ceiling | Source |
|---|---|---|---|---|---|
| decode | prose, 128k profile | 58.8 tok/s | 48.2 | 76 | [flint/RESULTS.md:18](https://github.com/davidghatley/3060-recipes/blob/main/flint/RESULTS.md#L18) |
| decode | code task (mostly reasoning) | 55.0-55.8 tok/s | 46.7 |  | [flint/RESULTS.md:19](https://github.com/davidghatley/3060-recipes/blob/main/flint/RESULTS.md#L19) |
| decode | at 32k depth | 46.8-47.2 tok/s | 34.0 |  | [flint/RESULTS.md:20](https://github.com/davidghatley/3060-recipes/blob/main/flint/RESULTS.md#L20) |
| decode | prose, 64k profile (FLINT_PROFILE=64k) | 63.4 tok/s |  |  | [flint/RESULTS.md:26](https://github.com/davidghatley/3060-recipes/blob/main/flint/RESULTS.md#L26) |
| prefill | cold 11k-token opencode system prompt | 1708 tok/s | 329 | 2600 | [flint/RESULTS.md:15](https://github.com/davidghatley/3060-recipes/blob/main/flint/RESULTS.md#L15) |
| prefill | 121k-token prompt | 989 tok/s |  |  | [flint/RESULTS.md:17](https://github.com/davidghatley/3060-recipes/blob/main/flint/RESULTS.md#L17) |
| ttft | cold 11k-token prompt | 6.4 s | 33.4 |  | [flint/RESULTS.md:16](https://github.com/davidghatley/3060-recipes/blob/main/flint/RESULTS.md#L16) |
| needles | 3 codes at 60k and at 120k | 3/3, 3/3 found |  |  | [flint/RESULTS.md:21](https://github.com/davidghatley/3060-recipes/blob/main/flint/RESULTS.md#L21) |
| vram_peak | after a 121k request | 11585 MiB |  |  | [flint/RESULTS.md:22](https://github.com/davidghatley/3060-recipes/blob/main/flint/RESULTS.md#L22) |
| quality | KL divergence vs the all-GPU path, wikitext (CPU experts without cache: 0.076) | 0.07 KLD |  |  | [flint/README.md:19](https://github.com/davidghatley/3060-recipes/blob/main/flint/README.md#L19) |

## Caveats

- 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.

## Findings from this recipe

- [A port-based health check can be answered by someone else's server](https://davidghatley.github.io/3060-recipes/findings/health-check-answered-by-another-server.md)
- [With experts in RAM, a 4096-token micro-batch gives 4.1x prefill and 8192 adds almost nothing](https://davidghatley.github.io/3060-recipes/findings/large-ubatch-prefill-with-experts-in-ram.md)
- [Smaller expert quants do not speed up CPU-side decode unless their kernel is cheap per byte](https://davidghatley.github.io/3060-recipes/findings/smaller-expert-quants-dont-speed-cpu-decode.md)
- [An adaptive expert cache matches the oracle hot set and a fixed one does not](https://davidghatley.github.io/3060-recipes/findings/adaptive-cache-beats-static-hot-set.md)
- [Put every expert in RAM and spend the freed VRAM on the MoE cache](https://davidghatley.github.io/3060-recipes/findings/all-experts-in-ram-plus-moe-cache.md)
- [The CPU-GPU hand-off is 1.1 ms of an 18.9 ms token, not the bottleneck](https://davidghatley.github.io/3060-recipes/findings/cpu-gpu-handoff-is-small.md)
- [Editing a bash script while it runs reorders or breaks the rest of the run](https://davidghatley.github.io/3060-recipes/findings/editing-a-running-bash-script.md)
- [Greedy-output identity is the wrong quality gate when placement changes](https://davidghatley.github.io/3060-recipes/findings/greedy-hash-is-the-wrong-gate.md)
- [Reading weights into RAM instead of mmap gives 24% faster prefill with experts on the host](https://davidghatley.github.io/3060-recipes/findings/load-mode-none-speeds-prefill.md)
- [nvidia-smi shows the PCIe link at Gen1 when idle and that is power saving](https://davidghatley.github.io/3060-recipes/findings/pcie-link-reads-gen1-at-idle.md)
- [q8_0 KV costs 29% decode at 32k on a model with few full-attention layers](https://davidghatley.github.io/3060-recipes/findings/q8-kv-slows-decode-with-few-attention-layers.md)
- [On an i5-12500 RAM read bandwidth peaks at 6 threads and so does decode](https://davidghatley.github.io/3060-recipes/findings/ram-bandwidth-saturates-at-six-threads.md)
- [A cgroup memory cap counts page cache, so mmap'd weights hit it](https://davidghatley.github.io/3060-recipes/findings/memory-cap-counts-page-cache.md)

## Credits

- RecursiveSI: The model behind the 128k coding recipe. (https://huggingface.co/RecursiveSI/flint)
- 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. (https://huggingface.co/ggml-org/Flint-GGUF)
- llama.cpp (ggml-org and contributors): The engine for Flint, the 3D coder and Inkling-2-Mini, and the base of the Kintsugi fork. (https://github.com/ggml-org/llama.cpp)
- bartowski: The imatrix used when we requantized only the RAM-resident experts. (https://huggingface.co/bartowski/RecursiveSI_flint-GGUF)
- 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. (https://huggingface.co/unsloth/Inkling-2-Mini-GGUF)
- 0xSero / Sybil Solutions: The tuning method behind the Flint and Inkling recipes; its q8_0 KV gotcha is one we confirmed on Flint. (https://github.com/sybil-solutions/inference-optimisation-skill)
- 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. (https://huggingface.co)
- 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. (https://www.nvidia.com/en-us/geforce/graphics-cards/30-series/rtx-3060-3060ti/)

## Reproductions

None yet. Ran it on your own 3060? Report your numbers: https://github.com/davidghatley/3060-recipes/issues/new?template=reproduction.yml

## Machine-readable

- https://davidghatley.github.io/3060-recipes/recipes/flint/recipe.json
- Folder with scripts and raw runs: https://github.com/davidghatley/3060-recipes/tree/main/flint
- Full results log: https://raw.githubusercontent.com/davidghatley/3060-recipes/main/flint/RESULTS.md

## Full write-up (README)

Serving [Flint](https://huggingface.co/RecursiveSI/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](https://opencode.ai).

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](RESULTS.md). The tuning log is [PLAN.md](PLAN.md), the ceilings are in [THEORY.md](THEORY.md), the deeper experiments (context profiles, MoE cache, requant, routing skew, engine prototype) are in [experiments/RESULTS.md](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

```bash
## 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](https://github.com/sybil-solutions/inference-optimisation-skill): ceilings first, one change at a time with controls, and output gated as well as speed.
