The 80B Qwen3-Coder-Next on a 16 GB Mac, about 13 tok/s, fully offline. A mixture-of-experts inference engine for Apple silicon.
Rust
Stand-in gap (--stand-ins as shipped), the numbers from three runs, --max-tokens 8000 in the gpt-oss commands
1picassoaiffdd2b292b00
diff --git a/README.md b/README.mdindex 21763b8..4ad8026 100644--- a/README.md+++ b/README.md@@ -15,7 +15,7 @@ gpt-oss-120b on a 16 GB Mac mini M4, writing a TypeScript task (about 4,000 word| Mode | Speed | Score ||---|---|---|-| Fast mode, `--stand-ins` | about 10 tok/s | 4.0 of 5 |+| Fast mode, `--stand-ins` | about 10 tok/s | 4.5 of 5, three runs (5.0, 3.8, 4.8) || The model's own 4 experts | about 4.2 tok/s | 4.8 of 5 |How to set it up is in [gpt-oss-120b](#gpt-oss-120b).@@ -165,13 +165,13 @@ rm ~/Downloads/gpt-oss-120b-MXFP4.gguf```sh# the model's own 4 experts per word, every one read for real-~/coachwhip/coachwhip.sh ~/Downloads/gpt-oss-120b.Q2A.gguf ~/Downloads/tokenizer.json 25 8090 --parallel --flash-reads+~/coachwhip/coachwhip.sh ~/Downloads/gpt-oss-120b.Q2A.gguf ~/Downloads/tokenizer.json 25 8090 --parallel --flash-reads --max-tokens 8000# fast: stand-ins for the light picks that are not in the bank-~/coachwhip/coachwhip.sh ~/Downloads/gpt-oss-120b.Q2A.gguf ~/Downloads/tokenizer.json 25 8090 --parallel --flash-reads --stand-ins+~/coachwhip/coachwhip.sh ~/Downloads/gpt-oss-120b.Q2A.gguf ~/Downloads/tokenizer.json 25 8090 --parallel --flash-reads --stand-ins --max-tokens 8000```-**Fast mode changes the answers.** A word's first expert is always read for real, and so is its second whenever the router gives it at least 0.3 of the weight. A lighter pick that is not already in the bank is replaced by the best expert that is, by the router's own scores, instead of being read from the SSD. Measured on one coding task, it wrote about 2.4 times as fast and scored 4.0 of 5 against 4.8. It is a choice, never the default.+**Fast mode changes the answers.** A word's first expert is always read for real, and so is its second whenever the router gives it at least 0.3 of the weight. A lighter pick that is not already in the bank is replaced by the best expert that is, by the router's own scores, instead of being read from the SSD, and only when that expert's score is close to the real pick's; otherwise the real one is read. Measured on one coding task over three runs, it wrote about 2.4 times as fast and scored 5.0, 3.8 and 4.8 of 5, against the full model's 4.8. It is a choice, never the default. `--max-tokens 8000` gives its thinking room; the default of 4,000 can cut a long answer short.Every setup we measured, what makes it fast and how the scores were taken: [docs/GPT-OSS.md](docs/GPT-OSS.md).diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rsindex 7532d1c..cf55ce4 100644--- a/crates/cli/src/main.rs+++ b/crates/cli/src/main.rs@@ -101,8 +101,9 @@ struct Args {/// Stand-ins (gpt-oss): a light pick that is not in the bank is replaced by the best expert/// that is, by the router's own scores. The first pick is always read for real, and the second- /// whenever the router gives it at least 0.3 of the weight. Fewer reads; the answers change,- /// so check them for your use.+ /// whenever the router gives it at least 0.3 of the weight, and a substitute is used only when its+ /// router score is close to the real pick's. Fewer reads; the answers change, so check them for+ /// your use.#[arg(long)]stand_ins: bool,@@ -134,6 +135,11 @@ fn main() -> Result<()> {if std::env::var("COACHWHIP_STANDIN_W").is_err() {std::env::set_var("COACHWHIP_STANDIN_W", "0.3");}+ // A substitute more than this far below its real pick (router logits) is not used; the+ // real expert is read. Three exam runs at 1.0 scored 5.0, 3.8 and 4.8; without it 4.0, 4.0, 0.8.+ if std::env::var("COACHWHIP_STANDIN_GAP").is_err() {+ std::env::set_var("COACHWHIP_STANDIN_GAP", "1.0");+ }}if args.flash_reads {std::env::set_var("COACHWHIP_NOCACHE", "1");diff --git a/crates/engine/src/experts.rs b/crates/engine/src/experts.rsindex e3cb3be..3455603 100644--- a/crates/engine/src/experts.rs+++ b/crates/engine/src/experts.rs@@ -2175,6 +2175,13 @@ fn stand_in_keep(k: usize) -> usize {std::env::var("COACHWHIP_STANDIN_KEEP").ok().and_then(|v| v.parse().ok()).unwrap_or(k / 2).clamp(1, k.max(1))}+/// Lab (`COACHWHIP_STANDIN_GAP=<g>`): a stand-in only when its router score is within g of the real+/// pick's; a pick that far ahead of every expert in the bank is read for real.+fn stand_in_gap() -> Option<f32> {+ static V: std::sync::OnceLock<Option<f32>> = std::sync::OnceLock::new();+ *V.get_or_init(|| std::env::var("COACHWHIP_STANDIN_GAP").ok().and_then(|v| v.parse().ok()))+}+/// Lab (`COACHWHIP_STANDIN_W=<w>`): with more than two picks, the second stays real when its weight is/// at least w, else only the first does. Off: `COACHWHIP_STANDIN_KEEP` rules.fn stand_in_w() -> Option<f32> {@@ -2304,6 +2311,17 @@ impl StreamedMoe {}None => with_keep(stand_in_keep(k))?,};+ // The gap: a substitute too far below its real pick is not used; the real one is read.+ let ids = match stand_in_gap() {+ Some(gap) => {+ let real_ids = top_ids.contiguous()?;+ let real = logits.gather(&real_ids, D::Minus1)?;+ let sub = logits.gather(&ids, D::Minus1)?;+ let close = (real - sub)?.to_dtype(DType::F32)?.le(gap)?;+ close.where_cond(&ids, &real_ids)?+ }+ None => ids,+ };let w = candle_nn::ops::softmax_last_dim(&logits.gather(&ids, D::Minus1)?)?;return Ok((ids, w));}@@ -2519,7 +2537,7 @@ impl StreamedMoe {for p in keep..row.len() {if !resident.contains(&row[p]) && (row.len() > 2 || w0[p] < stand_in_limit()) {let best = resident.iter().copied().filter(|e| !row.contains(e)).max_by(|a, b| scores[*a as usize].partial_cmp(&scores[*b as usize]).unwrap_or(std::cmp::Ordering::Equal));- if let Some(e) = best {+ if let Some(e) = best.filter(|&e| stand_in_gap().map_or(true, |g| scores[row[p] as usize] - scores[e as usize] <= g)) {row[p] = e;self.store.stats.lock().unwrap().stand_ins += 1;}diff --git a/docs/GPT-OSS.md b/docs/GPT-OSS.mdindex 4cf12de..6edc108 100644--- a/docs/GPT-OSS.md+++ b/docs/GPT-OSS.md@@ -11,11 +11,12 @@ All numbers here: Mac mini M4, 16 GB, macOS 26, the squeezed file (`prepare`, ev| 4 experts, all read for real | 4.2 tok/s | 4.8 | || 3 experts, all read for real | 5.6 tok/s | 4.5 | || 4 experts, the first 2 real, stand-ins for the rest | 7.8 tok/s | 4.5 | 3.5 (7.9 tok/s) |-| **4 experts, stand-ins by weight (`--stand-ins`)** | **9.8 tok/s** | **4.0** | **4.0 (10.0 tok/s)** |+| 4 experts, stand-ins by weight, no gap | 9.8 tok/s | 4.0 | 4.0 (10.0 tok/s) |+| **4 experts, stand-ins by weight with the gap (`--stand-ins` as shipped), three runs** | **9.8, 10.5, 9.6 tok/s** | **5.0, 3.8, 4.8** | not run || 4 experts, only the first real | 9.6 tok/s | 4.5 | 0.8 (10.2 tok/s) || 2 experts | 7.1 tok/s | 0 (the code does not compile) | |-`--stand-ins` is the only setup near 10 tok/s that held its score on both versions of the task. Reading fewer experts (3 or 2) costs more than standing in for the light ones: the model was trained to use 4.+`--stand-ins` as shipped is the only setup near 10 tok/s whose every run compiled and scored above 3.8. Without the gap, one run in three broke its file on a one-character slip (a run scored 0.8 before the gap was added). Reading fewer experts (3 or 2) costs more than standing in for the light ones: the model was trained to use 4.## What makes it fast@@ -25,7 +26,7 @@ Speed on a 16 GB Mac is set by one thing: how many bytes each word reads from th- **The expert bank.** Recently used experts stay on the GPU and are reused; with every expert read for real, about 4 picks in 5 are already there.- **The early guess.** While the GPU works on one layer, Coachwhip runs the router of a later layer on the same input and reads the experts it will want; for gpt-oss, 2 guesses a layer, 2 layers ahead.- **Flash reads (`--flash-reads`).** Experts are read straight from the SSD, past macOS's page cache.-- **Stand-ins (`--stand-ins`).** A word's first pick is always read for real, and so is the second whenever the router gives it at least 0.3 of the weight. A lighter pick that is not in the bank is replaced by the best expert that is, by the router's own scores, and the weights are recomputed over the experts actually used. Bank hits go from about 78% to about 97%, and the bytes read per word fall by about seven-eighths.+- **Stand-ins (`--stand-ins`).** A word's first pick is always read for real, and so is the second whenever the router gives it at least 0.3 of the weight. A lighter pick that is not in the bank is replaced by the best expert that is, by the router's own scores, and the weights are recomputed over the experts actually used. The substitute is used only when its router score is within 1.0 of the real pick's (logits); a pick that far ahead of every expert in the bank is read for real. Bank hits go from about 78% to about 97%, and the bytes read per word fall by about seven-eighths.- **Lean attention.** gpt-oss looks back only 128 words on every other layer; those layers keep only that window, and the shared keys are never copied out per head.## Its chat formatdiff --git a/docs/MODELS.md b/docs/MODELS.mdindex ef27df5..5cca6e3 100644--- a/docs/MODELS.md+++ b/docs/MODELS.md@@ -17,13 +17,13 @@ Mac mini M4, 16 GB, `--parallel --flash-reads`, bank 25 (the Wrangler's pick), t| Mode | Writing | Score of 5 | Second version of the task ||---|---|---|---|-| Fast, `--stand-ins` | 9.8 tok/s | 4.0 | 4.0 at 10.0 tok/s |+| Fast, `--stand-ins` | 9.6 to 10.5 tok/s, three runs | 5.0, 3.8, 4.8 (mean 4.5) | not run with the shipped setting || The model's own 4 experts | 4.2 tok/s | 4.8 | |This model is measured on its own task, not the five-prompt speed set above: its thinking makes 300-token answers mostly thinking. Every setup we measured, and what makes it fast: [GPT-OSS.md](GPT-OSS.md).- **Why the squeeze:** at MXFP4's 13.2 MB per expert the bank holds 15 experts a layer; at Q2_K's 8.7 MB it holds 25. On the task above the squeezed file scores the same as the original download.-- **Why fast mode changes answers:** a light pick that is not in the bank is replaced by the best expert that is. The first pick is always read for real, and the second whenever it carries at least 0.3 of the weight.+- **Why fast mode changes answers:** a light pick that is not in the bank is replaced by the best expert that is. The first pick is always read for real, and the second whenever it carries at least 0.3 of the weight; a substitute is used only when its router score is close to the real pick's.- Tokenizer: [tokenizer.json](https://huggingface.co/openai/gpt-oss-120b) from the model's own page.## Qwen3.5-122B-A10Bdiff --git a/docs/releases/0.5.0.md b/docs/releases/0.5.0.mdindex 17de2d3..5d9bddc 100644--- a/docs/releases/0.5.0.md+++ b/docs/releases/0.5.0.md@@ -6,12 +6,12 @@ Mac mini M4, 16 GB, measured; your Mac and your prompt will move the numbers.- **OpenAI's gpt-oss-120b on a 16 GB Mac** (`gpt-oss`): 117 billion parameters, 4 of its 128 experts per word in each of 36 layers. It thinks before it answers, and the chat page shows the thinking.- **Squeezed once on your own Mac** from the official MXFP4 file: `coachwhip-prepare` takes every expert matrix to Q2_K, rows padded to whole 256-weight blocks; everything else is copied as it is. 63.4 GB in, 42.6 GB out, in about 13 minutes on an M4; about 106 GB free is needed while both exist. Nothing is downloaded from us.-- **Two modes.** The model's own 4 experts per word, every one read for real: about 4.2 tok/s. Fast mode, `--stand-ins`: about 10 tok/s. Both measured on the same coding task (a cancellable async task pool in TypeScript, about 4,000 words of thinking and code, temperature 0): the first scored 4.8 of 5 on our 20 hidden checks, fast mode 4.0 on two versions of the task.+- **Two modes.** The model's own 4 experts per word, every one read for real: about 4.2 tok/s. Fast mode, `--stand-ins`: about 10 tok/s. Both measured on the same coding task (a cancellable async task pool in TypeScript, about 4,000 words of thinking and code, temperature 0): the first scored 4.8 of 5 on our 20 hidden checks, fast mode 5.0, 3.8 and 4.8 over three runs.- **Its own chat format.** gpt-oss speaks OpenAI's harmony format; the chat page and the API speak it to the model, and the API returns only the final answer.## Faster-- **Stand-ins, `--stand-ins`.** When a light pick is not in the bank, Coachwhip uses the best expert that is, by the router's own scores, instead of reading one from the SSD. The first pick is always read for real, and the second whenever the router gives it at least 0.3 of the weight. Fewer reads per word; the answers change, so check them for your use.+- **Stand-ins, `--stand-ins`.** When a light pick is not in the bank, Coachwhip uses the best expert that is, by the router's own scores, instead of reading one from the SSD. The first pick is always read for real, and the second whenever the router gives it at least 0.3 of the weight, and a substitute is used only when its router score is close to the real pick's. Fewer reads per word; the answers change, so check them for your use.- **Flash reads, `--flash-reads`.** Experts are read straight from the SSD, past macOS's page cache, which has nothing to give back on a 16 GB Mac. The answers do not change.## Structure