|
Download README.md from Lanilen/Inkling-2-Mini-Expert-Predictor: direct link, hf CLI and curl.
- Browser
- Download file 16.7 kB
-
https://huggingface.co/Lanilen/Inkling-2-Mini-Expert-Predictor/resolve/main/README.md
- Command line
-
hf download hf://Lanilen/Inkling-2-Mini-Expert-Predictor/README.md
-
curl -L -o README.md https://huggingface.co/Lanilen/Inkling-2-Mini-Expert-Predictor/resolve/main/README.md
16.7 kB
| license: mit | |
| tags: | |
| - inkling-2-mini | |
| - mixture-of-experts | |
| - moe | |
| - expert-offloading | |
| - expert-caching | |
| - llama.cpp | |
| # Expert predictor for Inkling 2 Mini | |
| **This is not a language model, and it does nothing on its own.** It is a small companion file for | |
| [thinkingmachines/Inkling-2-Mini](https://huggingface.co/thinkingmachines/Inkling-2-Mini). An inference engine that | |
| keeps that model's experts in system RAM and caches some of them in VRAM loads it to decide which experts to keep on | |
| the GPU. It doesn't generate text and can't be run, chatted with, merged or fine-tuned. | |
| **Made for chat, not raw completion.** The predictor is made for requests that go through the model's chat template: | |
| llama-server's chat endpoint (`/v1/chat/completions`) or `llama-cli` in conversation mode. There it serves 7β10 points | |
| more of the expert selections and generates 2.6β3.2% faster. On raw completion, a text continued without the template | |
| (`llama-completion -no-cnv`, or llama-server's `/completion` endpoint), it does the opposite: the cache serves fewer | |
| of the selections and generates about 3% slower than without it, so leave `--moe-cache-predictor` out for that | |
| ([Raw completion](#raw-completion)). | |
| | | | | |
| |---|---| | |
| | **For the model** | [thinkingmachines/Inkling-2-Mini](https://huggingface.co/thinkingmachines/Inkling-2-Mini) (arch `inkling2_loop`: 24 MoE layers, 128 routed experts, 8 per token; layers 6β17 run three passes a token) | | |
| | **Trained on the routing of** | [ggml-org/Inkling-2-Mini-GGUF](https://huggingface.co/ggml-org/Inkling-2-Mini-GGUF) `Q8_0` | | |
| | **Measured with** | that Q8_0, [unsloth/Inkling-2-Mini-GGUF](https://huggingface.co/unsloth/Inkling-2-Mini-GGUF) `Mainline_Support/UD-Q4_K_XL`, and a Q4_K_M made from the Q8_0 | | |
| | **Works with** | the [Polaris llama.cpp fork](https://github.com/Lanilen/llama.cpp) (branch `polaris`): `--moe-cache-predictor` in the hot spare cache mode | | |
| | **Won't work with** | upstream llama.cpp, Ollama, LM Studio or any other engine; any other model, including Inkling 2 | | |
| | **Version** | 5 (2026-11-23), trained on 718 traces; version 3 is in this repository's history | | |
| | **Size** | 12.4 MiB and 7.8 MiB (the start file), float32 | | |
| ## What it does | |
| Inkling 2 Mini routes each token through 8 of 128 experts in each of its 24 MoE layers, and runs layers 6β17 three | |
| times a token with the same experts. The experts are most of the model: about 24.5 of the 26.4B parameters. On GPUs that can't | |
| hold them all, the fork's *hot spare* cache keeps as many as fit in VRAM and computes the rest on the CPU, keeping one | |
| set per layer for all three passes. Every expert the cache misses costs CPU time. So the question the cache keeps | |
| asking is which experts the next tokens will use. | |
| The predictor answers that question. It runs every 16 generated tokens and at the start of each answer, and predicts | |
| for each of the 24 layers how often each expert will be selected over the next 128 and 512 tokens. The cache counts a | |
| looped layer's prediction once per pass, ranks every layer's experts together, and swaps in the ones ranked highest, | |
| within its upload budget. Without a predictor, the cache can only rank experts by how often they were selected | |
| recently. | |
| It reads: | |
| - the model's own hidden state at the newest token: the inputs of layers 8 and 16 in their first pass | |
| (2 Γ 2304 floats); | |
| - nine count maps of the selections so far: decayed over all tokens (half-lives 64 and 512), the conversation, the | |
| current turn's prompt, the previous answer, the answer so far (whole, and decayed with half-lives 32 and 8), and a | |
| fixed prior; | |
| - how far into the answer it is (13 position buckets, 0 to 1024 tokens). | |
| The model is a 2-layer MLP (4621 β 512 β 128, GELU) and one low-rank head per horizon. A head's logits for layer *l*, | |
| expert *e* are a bias, plus a per-bucket weighting of the log count maps, plus a rank-128 projection of the MLP's | |
| output. A softmax over each layer's 128 experts gives the prediction. One prediction is 0.4β0.6 ms on the CPU. | |
| The **start file** predicts from a turn's text before its prompt runs (the counts and the mean of the turn's token | |
| embeddings), so the experts upload while the prompt computes. | |
| ## Files | |
| | File | What it is | | |
| |---|---| | |
| | `inkling2-pred-v5.moepred` | **The predictor.** Pass it with `--moe-cache-predictor`. | | |
| | `inkling2-start-v5.moepred` | The start file. Pass it with `--moe-cache-predictor-start`. | | |
| | `checks/pred-v5.vec`, `checks/start-v5.vec` | Test vectors from the exporter: inputs and the expected outputs of the original PyTorch model. | | |
| The files are GGUF containers (`general.architecture` = `moe-predictor`, version 1). They're named `.moepred` so that | |
| tools that open GGUF models don't offer to run them. The fork reads them by path, whatever the extension. They name the | |
| model's 24 physical layers (`moe_predictor.layers`, 0 to 23), not the 48 cache slots of the three passes; the cache | |
| ignores a file made for the slots. The format and the contract are in | |
| [`src/llama-moe-predictor.cpp`](https://github.com/Lanilen/llama.cpp/blob/polaris/src/llama-moe-predictor.cpp). | |
| ## Usage | |
| Build the [fork](https://github.com/Lanilen/llama.cpp) (branch `polaris`) and add the predictor to a hot spare setup. | |
| This is the setup of the results below on a 12 GB NVIDIA GPU, a 14600KF with an RTX 4070 Ti and 32 GB of RAM, with | |
| Unsloth's UD-Q4_K_XL (the file under `Mainline_Support/`, renamed from `.gguf_file` to `.gguf`): | |
| ```bash | |
| GOMP_SPINCOUNT=30000000 GGML_CPU_MMID_FLAT=128 LLAMA_GRAPH_CACHE=8 \ | |
| llama-server -m Inkling-2-Mini-UD-Q4_K_XL.gguf \ | |
| -ngl 99 -ot _exps=CPU --no-op-offload -t 6 -c 16384 -b 512 -ub 512 \ | |
| --moe-cache-mode hot-spare --moe-cache-mib 3500 --moe-cache-resize --moe-cache-batch 16384 \ | |
| --moe-cache-predictor inkling2-pred-v5.moepred --moe-cache-predictor-start inkling2-start-v5.moepred \ | |
| --moe-cache-predictor-device Vulkan0 --moe-cache-refill 0 --moe-cache-predictor-answer-gain 8 | |
| ``` | |
| - With version 3 it generated at 27β28.5 tokens a second and read a 1.3k-token prompt at 65β70, in 8.3 GB of VRAM. | |
| Version 5 has the same size and cost; on that machine it hasn't been measured yet. | |
| - `--no-op-offload` is needed on NVIDIA GPUs: without it a prompt reserves 8.5β10 GB of VRAM for copies of the looped | |
| layers' experts, and the driver refuses it. | |
| - `-t 6` is that CPU's performance cores; use your CPU's count of them. | |
| - `--moe-cache-mib` follows the free VRAM: about the free memory less 4.5 GB with this file. | |
| - [docs/inkling2-mini.md](https://github.com/Lanilen/llama.cpp/blob/polaris/docs/inkling2-mini.md) has why each | |
| setting, the sizes for 6 and 8 GB cards, the quants, and an RX 480 setup. | |
| - It assumes one conversation at a time (`-np 1`), through the chat template. | |
| - To check that a file loads and computes what it should: | |
| ```bash | |
| llama-moe-predictor-check inkling2-pred-v5.moepred checks/pred-v5.vec | |
| llama-moe-predictor-check inkling2-start-v5.moepred checks/start-v5.vec | |
| ``` | |
| How the cache uses it: [docs/moe-hot-spare.md](https://github.com/Lanilen/llama.cpp/blob/polaris/docs/moe-hot-spare.md#a-learned-predictor---moe-cache-predictor). | |
| How a predictor is trained: [docs/moe-predictor.md](https://github.com/Lanilen/llama.cpp/blob/polaris/docs/moe-predictor.md). | |
| The training scripts are in [`tools/moe-predictor`](https://github.com/Lanilen/llama.cpp/tree/polaris/tools/moe-predictor), | |
| so you can train one for another model or quant. | |
| ## Results | |
| **Offline, on held-out conversations** (every 5th conversation of each source, 306 answers). The hit rate is the share | |
| of the next 128 tokens' expert selections that the experts it ranks highest would serve, at 25 per layer (what a | |
| 5000 MiB cache holds of the Q8_0: 20% of a layer's experts). *Pooled* gives the layers their 600 slots between them, | |
| as the cache does, so the looped layers hold more: | |
| | tokens into the answer | recent selections (decayed) | this predictor | best possible in hindsight | pooled: decayed | pooled: this predictor | pooled: hindsight | | |
| |---|---|---|---|---|---|---| | |
| | 0 (the answer's start) | 54.1% | **62.8%** | 70.2% | 59.8% | **67.7%** | 74.7% | | |
| | 64 | 60.2% | **62.1%** | 69.9% | 65.5% | **67.4%** | 74.5% | | |
| | 256 | 59.7% | **61.4%** | 69.5% | 65.3% | **66.9%** | 74.2% | | |
| At 43 experts a layer (a 4-bit quant in the same 5000 MiB), pooled: 75.5% β 82.2% at the answer's start, against | |
| 88.6% in hindsight. Version 3 scores 66.2% pooled at the start on the same answers. | |
| **Live** on one AMD Radeon RX 480 (8 GB) with a Threadripper 1920X, a 5000 MiB hot spare, llama-server with the chat | |
| template, temperature 0, 256 tokens a request. The share of the selections the cache served, and the generation speed: | |
| | request | the cache without a predictor | with the predictor | generation | | |
| |---|---|---|---| | |
| | Q8_0, cold | 55.8% | **63.5%** | 11.96 β 12.47 tok/s | | |
| | Q8_0, a conversation's second turn | 53.3% | **63.0%** | 11.99 β 12.38 tok/s | | |
| | Q4_K_M, cold | 66.3% | **73.4%** | 14.05 β 14.41 tok/s | | |
| | Q4_K_M, a conversation's second turn | 66.6% | **75.9%** | 14.31 β 14.54 tok/s | | |
| Over nine chat answers, generation is 3.2% faster with the Q8_0 and 2.6% with the Q4_K_M. The speed gains less than the | |
| hits: there a token waits more on the GPU's many small ops than on the CPU's experts. With UD-Q4_K_XL on the RTX | |
| 4070 Ti setup above, version 3 served 66.0% of the selections against 62.7% without a predictor. These are two | |
| machines' numbers; the gain depends on how much of the model fits in VRAM and on how slow the CPU's experts are against | |
| the rest of a token. | |
| ### Raw completion | |
| On the same RX 480, a document continued without the chat template (`llama-completion -no-cnv`, 255 tokens), the | |
| predictor costs: | |
| | | the cache without a predictor | with the predictor | | |
| |---|---|---| | |
| | Q8_0, selections served | **66.7%** | 61.8% | | |
| | Q8_0, time a token | **77.5 ms** | 80.1 ms | | |
| | Q4_K_M, selections served | **80.3%** | 76.7% | | |
| Every version measured does this (versions 3, 4 and 5: 79.3, 79.8 and 80.1 ms a token at Q8_0), and 400 more raw-text | |
| traces in version 5's training didn't change it. The reasons: | |
| - **There is no turn to predict across.** The predictor's gain comes at the start of an answer, where the next experts | |
| differ from the last ones: a new question, after a prompt, after another answer. A continued document keeps its | |
| prompt's topic, so the experts the cache already ranks by recent use are the ones the continuation needs. | |
| - **It starts from a full predicted set.** Without a predictor, a cold cache fills its free slots with what the text | |
| uses as it goes. With one, it loads the set it predicts and then changes it only within its upload budget, so its | |
| misses at the start stay longer. | |
| So the predictor is made for the chat template: that is how its training sessions were run and where it pays. For raw | |
| completion, run the hot spare without `--moe-cache-predictor` and `--moe-cache-predictor-start`. | |
| ## Training data | |
| The predictor was trained on expert-routing traces: which experts Inkling 2 Mini (ggml-org's Q8_0, in llama.cpp) | |
| selected for each token and pass, plus the inputs of layers 8 and 16 every 16 tokens. The traces cover 718 | |
| conversations, 2.03M tokens and 2,879 answers, recorded with the model whole on AMD Radeon AI PRO R9700s: | |
| - **213 sessions the model wrote itself:** its own answers to the first messages of the datasets below, in synthetic | |
| multi-turn sessions through the chat template, 149 of them with `reasoning_effort` 0.1 and 64 at its default. | |
| - **25 conversations read as given** (teacher-forced) from the same datasets. | |
| - **480 sessions of raw text,** without the chat template, as `llama-completion` runs it: 240 starts of documents from | |
| the datasets below for the model to continue and 240 bare requests, 512 tokens each. | |
| The file holds only the predictor's own weights: no text, no tokens and none of Inkling's weights. | |
| | Dataset | License (as its card states) | | |
| |---|---| | |
| | [allenai/WildChat-4.8M](https://huggingface.co/datasets/allenai/WildChat-4.8M) | ODC-BY | | |
| | [allenai/tulu-3-sft-mixture](https://huggingface.co/datasets/allenai/tulu-3-sft-mixture) | ODC-BY | | |
| | [HuggingFaceTB/smoltalk](https://huggingface.co/datasets/HuggingFaceTB/smoltalk) | Apache-2.0 (its new subsets; the others keep their upstream licenses) | | |
| | [teknium/OpenHermes-2.5](https://huggingface.co/datasets/teknium/OpenHermes-2.5) | not stated | | |
| | [HuggingFaceH4/ultrachat_200k](https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k) | MIT | | |
| | [HuggingFaceH4/no_robots](https://huggingface.co/datasets/HuggingFaceH4/no_robots) | CC-BY-NC-4.0 (first messages of some of the synthetic sessions) | | |
| | [m-a-p/CodeFeedback-Filtered-Instruction](https://huggingface.co/datasets/m-a-p/CodeFeedback-Filtered-Instruction) | Apache-2.0 | | |
| | [ise-uiuc/Magicoder-OSS-Instruct-75K](https://huggingface.co/datasets/ise-uiuc/Magicoder-OSS-Instruct-75K) | MIT | | |
| | [glaiveai/glaive-code-assistant-v3](https://huggingface.co/datasets/glaiveai/glaive-code-assistant-v3) | Apache-2.0 | | |
| | [bigcode/self-oss-instruct-sc2-exec-filter-50k](https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k) | ODC-BY | | |
| | [nvidia/OpenCodeInstruct](https://huggingface.co/datasets/nvidia/OpenCodeInstruct) | CC-BY-4.0 | | |
| | [theblackcat102/evol-codealpaca-v1](https://huggingface.co/datasets/theblackcat102/evol-codealpaca-v1) | Apache-2.0 | | |
| | [nebius/SWE-rebench-openhands-trajectories](https://huggingface.co/datasets/nebius/SWE-rebench-openhands-trajectories) | CC-BY-4.0 | | |
| | [SWE-bench/SWE-smith-trajectories](https://huggingface.co/datasets/SWE-bench/SWE-smith-trajectories) | MIT | | |
| | [SWE-Gym/OpenHands-Sampled-Trajectories](https://huggingface.co/datasets/SWE-Gym/OpenHands-Sampled-Trajectories) | not stated | | |
| | [NousResearch/hermes-function-calling-v1](https://huggingface.co/datasets/NousResearch/hermes-function-calling-v1) | Apache-2.0 | | |
| | [meta-math/MetaMathQA](https://huggingface.co/datasets/meta-math/MetaMathQA) | MIT | | |
| | [microsoft/orca-math-word-problems-200k](https://huggingface.co/datasets/microsoft/orca-math-word-problems-200k) | MIT | | |
| | [abisee/cnn_dailymail](https://huggingface.co/datasets/abisee/cnn_dailymail) | Apache-2.0 | | |
| | [wikimedia/wikipedia](https://huggingface.co/datasets/wikimedia/wikipedia) (en, de, fr, es) | CC-BY-SA-3.0, GFDL | | |
| | [llama.cpp](https://github.com/ggml-org/llama.cpp) source and docs | MIT | | |
| ## Training | |
| - **Split:** every 5th conversation of each source is held out (306 answers); the other 2,573 answers train it. | |
| - **Run:** PyTorch, 6 epochs, 157 seconds on one R9700 (ROCm), and the start file 12 epochs in 19 more. | |
| - **The loop:** each layer's target is the selections of all its passes, and its loss is weighed by its passes. | |
| - **Export:** to GGUF, then checked against PyTorch on 24 test vectors each (`checks/`): the largest difference | |
| 3.0e-7 for the predictor and 2.2e-7 for the start file. | |
| - **Scripts:** tracing, the corpus, training and export are in | |
| [`tools/moe-predictor`](https://github.com/Lanilen/llama.cpp/tree/polaris/tools/moe-predictor). | |
| ## Limitations | |
| - **Few long conversations.** 718 traces against the 1,181 behind | |
| [Flash-Next's predictor](https://huggingface.co/Lanilen/Qwen3.8-Flash-Next-Expert-Predictor). From version 3's 161 | |
| traces to version 5's, chat gained 1β2.5 points of hits and under 1% of speed. Few conversations are long: the | |
| recording lost the GPU on conversations past 37k tokens. | |
| - **One model.** It's tied to Inkling 2 Mini's layers, loop, expert count, hidden size and router. Inkling 2, or a | |
| retrained or fine-tuned Mini, needs a predictor trained on its own traces. | |
| - **Quants.** It was trained on the Q8_0's routing and measured on the Q8_0 and a Q4_K_M (and UD-Q4_K_XL with version 3). | |
| Other quants route a little differently. | |
| - **A current build.** Build the fork's `polaris` as of this file's release or later. Older builds either ignore a | |
| predictor for a looped model, or count a looped layer's prediction like a layer that runs once and serve fewer of | |
| the selections. Unsloth's mainline files also need upstream llama.cpp's #32704, which the fork has from the same | |
| release. | |
| - **The chat template.** It is made for requests through the chat template. On raw completion it makes the cache | |
| slower ([Raw completion](#raw-completion)): leave it out there. | |
| - **One conversation at a time:** the counts follow a single conversation (`-np 1`). | |
| - **It doesn't change outputs.** It only decides where experts are computed. The GPU and the CPU round differently, so | |
| text at temperature 0 can still differ slightly from a run with another cache state, as with any cache setting. | |