Expert predictor for GLM-5.3-Flash
This is not a language model, and it does nothing on its own. It is a small companion file for zai-org/GLM-5.3-Flash. 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.
| For the model | zai-org/GLM-5.3-Flash (arch glm5-next: 3 dense and 42 MoE layers, 288 routed experts, 8 per token) |
| Trained on the routing of | unsloth/GLM-5.3-Flash-GGUF UD-Q3_K_XL |
| Works with | the Polaris llama.cpp fork (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 other GLM models |
| Size | 30 MB, float32 |
What it does
GLM-5.3-Flash routes each token through 8 of 288 experts in each of its 42 MoE layers. The experts are most of the model: 128 GiB of the 137 GiB of UD-Q3_K_XL. 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. 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 MoE layer how often each expert will be selected over the next 128 and 512 tokens. The cache swaps in the experts the prediction ranks 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 mean of the hyper-connection streams entering layers 15 and 30 (2 Γ 4096 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 (8205 β 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 288 experts gives the prediction. One prediction is about 2 ms on the CPU.
Files
| File | What it is |
|---|---|
glm53-pred-v1.moepred |
The predictor. Pass it with --moe-cache-predictor. |
checks/pred-v1.vec |
Test vectors from the exporter: inputs and the expected outputs of the original PyTorch model. |
The file is a GGUF container (general.architecture = moe-predictor, version 1). It's named .moepred so that
tools that open GGUF models don't offer to run it. The fork reads it by path, whatever the extension. It names the
model layers it stands for (moe_predictor.layers, 3 to 44: the first three layers of GLM-5.3-Flash have no experts),
which needs a build of the fork from 2026-11-17 or later; an older one refuses the file. The format and the contract
are in src/llama-moe-predictor.cpp.
There is no start predictor (--moe-cache-predictor-start) for this model: one was trained and added nothing where it
was measured.
Usage
Build the fork (branch polaris) and add the predictor to a hot spare setup.
This is the setup of the results below, on two AMD Radeon AI PRO R9700 (32 GB each) with a Threadripper 1920X and
125 GiB of RAM. The first card computes layers 0β37 and caches their experts, which stay in RAM; the second holds
layers 38β44 and the model's MTP layer with their experts:
LLAMA_MOE_RESIZE_SPLIT=0 \
llama-server -m GLM-5.3-Flash-UD-Q3_K_XL-00001-of-00004.gguf -c 65536 \
-dev Vulkan0,Vulkan1 -ngl 99 -ts 38,9 -ncmoe 38 -t 12 -np 1 -b 4096 -ub 4096 \
--moe-cache-mode hot-spare --moe-cache-resize --moe-cache-mib 19900,0 \
--moe-cache-predictor glm53-pred-v1.moepred --moe-cache-jit 4 --moe-cache-batch 1024 \
--spec-type draft-mtp --spec-draft-n-max 2 --load-mode mmap+mlock
- The fork's tuning script found these settings for this machine in 99 runs, with one exception, the answer's start.
The script picked a limit (
--moe-cache-predictor-answer-gain 4), which tied on its short answers and cost 2% a verify step on answers of 256β512 tokens, so this setup rebalances in full. --moe-cache-jit 4 --moe-cache-batch 1024withLLAMA_MOE_RESIZE_SPLIT=0is how this setup takes prompts: up to 1,024 tokens keep the cache and upload the experts they use as they go, larger ones release the cache for the prompt and restore it from the prediction.-devnames the two cards in that order (llama-server --list-devices), and-ts 38,9is their share of the layers.- The environment is the one of that machine's other setups: FORK.md.
- It assumes one conversation at a time (
-np 1). - It runs on the CPU with 4 threads by default (
LLAMA_MOE_PREDICTOR_THREADS, or--moe-cache-predictor-device). - GLM-5.3-Flash thinks by default.
--reasoning-effort lowis the switch its template has for answering without. - To check that a file loads and computes what it should:
llama-moe-predictor-check glm53-pred-v1.moepred checks/pred-v1.vec
How the cache uses it: docs/moe-hot-spare.md.
How a predictor is trained: docs/moe-predictor.md.
The training scripts are in 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, 348 answers). The hit rate is the share of the next 128 tokens' expert selections that the experts it ranks highest would serve, at 53 per layer (what the 19900 MiB cache above holds of UD-Q3_K_XL: 18% of a layer's experts):
| tokens into the answer | recent selections (decayed) | this predictor | best possible in hindsight |
|---|---|---|---|
| 0 (the answer's start) | 44.2% | 53.0% | 65.4% |
| 64 | 48.7% | 52.1% | 64.9% |
| 256 | 50.6% | 52.2% | 65.0% |
Replayed as a cache over those conversations, with the same upload budget: 52.5% of the selections served against 48.7% for the cache's own rule, with a third of the swaps (1.6 a token against 5.1).
The rates are far below Flash-Next's (87% there) because the cache is far smaller against the model: 53 of 288 experts a layer, where even hindsight serves 65%.
Live, on the setup above without the two prompt options (which leave a verify step as it is), temperature 0, two alternating passes over 7 requests (about 2,800 generated tokens, the model thinking in two of them). The text differs between the two arms, so the measure is the time of a verify step (one pass of the model over the drafted tokens):
| a verify step | cache hits | generation | |
|---|---|---|---|
| the cache without a predictor | 198.0 ms | 44.1% | 11.1β13.0 tok/s |
| with the predictor | 177.1 ms (β10.6%) | 51.6% | 13.0β13.8 tok/s |
Every request gained, by 1.6% to 17%. In the tuning script's search on the same setup, on other requests, the predictor's stage was worth 8.8% of generation speed. These are one machine's numbers. The gain depends on how much of the model fits in VRAM and how slow the CPU's experts are.
Training data
The predictor was trained on expert-routing traces: which experts GLM-5.3-Flash (UD-Q3_K_XL, in llama.cpp) selected for each token, plus its hidden state at layers 15 and 30 every 16 tokens. The traces cover 190 conversations, 2.9M tokens and 4,882 answers, all recorded on the machine above in 20 hours:
- 114 sessions the model wrote itself: its own answers to the first messages of the datasets below, in synthetic
multi-turn sessions, 75 of them with
reasoning_effortlow and 39 thinking. - 76 conversations read as given (teacher-forced) from the same datasets.
The file holds only the predictor's own weights: no text, no tokens and none of GLM's weights.
| Dataset | License (as its card states) |
|---|---|
| allenai/WildChat-4.8M | ODC-BY |
| allenai/tulu-3-sft-mixture | ODC-BY |
| HuggingFaceTB/smoltalk | Apache-2.0 (its new subsets; the others keep their upstream licenses) |
| teknium/OpenHermes-2.5 | not stated |
| HuggingFaceH4/ultrachat_200k | MIT |
| HuggingFaceH4/no_robots | CC-BY-NC-4.0 (first messages of some of the synthetic sessions) |
| m-a-p/CodeFeedback-Filtered-Instruction | Apache-2.0 |
| ise-uiuc/Magicoder-OSS-Instruct-75K | MIT |
| glaiveai/glaive-code-assistant-v3 | Apache-2.0 |
| bigcode/self-oss-instruct-sc2-exec-filter-50k | ODC-BY |
| nvidia/OpenCodeInstruct | CC-BY-4.0 |
| theblackcat102/evol-codealpaca-v1 | Apache-2.0 |
| nebius/SWE-rebench-openhands-trajectories | CC-BY-4.0 |
| SWE-bench/SWE-smith-trajectories | MIT |
| SWE-Gym/OpenHands-Sampled-Trajectories | not stated |
| NousResearch/hermes-function-calling-v1 | Apache-2.0 |
| meta-math/MetaMathQA | MIT |
| microsoft/orca-math-word-problems-200k | MIT |
| abisee/cnn_dailymail | Apache-2.0 |
| wikimedia/wikipedia (en, de, fr, es) | CC-BY-SA-3.0, GFDL |
| llama.cpp source and docs | MIT |
Training
- Split: every 5th conversation of each source is held out (348 answers); the other 4,534 answers train it.
- Run: PyTorch, 6 epochs, about 4 minutes on one R9700 (ROCm), on the machine that recorded the traces.
- Export: to GGUF, then checked against PyTorch on 24 test vectors (
checks/): the largest difference 6.0e-7, and the top 164 experts of every layer the same. - Scripts: tracing, the corpus, training and export are in
tools/moe-predictor.
Limitations
- A first version on little data. 190 conversations against the 1,181 behind Flash-Next's predictor, where more traces kept adding. The model's thinking is the smaller share of it (39 sessions).
- One model. It's tied to GLM-5.3-Flash's layers, expert count, hidden size and router. A different model, or a retrained or fine-tuned GLM-5.3-Flash, needs a predictor trained on its own traces.
- Quants. It was trained and measured on UD-Q3_K_XL routing. Other quants route a little differently and are untested.
- 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.