Skip to content

common : add --moe-cache-mib auto to size the MoE expert cache from the fit - #251

Open
danielhanchen wants to merge 18 commits into
base/upstream-951d465f5from
moe-cache-auto-mainline
Open

danielhanchen wants to merge 18 commits into
base/upstream-951d465f5from
moe-cache-auto-mainline

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Adds --moe-cache-mib auto on top of the MoE expert cache that is now upstream: ggml-org#29887 (GPU LRU cache for MoE experts kept in host memory, merged 10-07) and ggml-org#30112 (the same cache over multiple GPUs, merged 10-08). With auto, the fitter sizes the cache itself instead of the user guessing a MiB number.

What it does

--moe-cache-mib auto (or -1) only acts when --fit runs on a single GPU, the model has routed experts, and the user did not set -ngl, -ts or -ot:

  1. Model fits: if the whole model fits, nothing changes and the cache stays 0. Resident experts are faster than cached ones (see below).
  2. Experts spill: otherwise the fitter already measures, with a no_alloc dry run, the device memory left with every routed expert in host memory (global_surplus_cpu_moe). With auto, every routed expert goes to host memory and that whole surplus becomes the cache. In other words: free VRAM minus the fit margin minus everything that is not a routed expert (attention, shared experts, dense FFN, output, KV, compute buffers, a draft model).
  3. Verify: a second dry run with the cache allocated checks the result and shrinks it if it overshoots.
  4. Fall back: if the dense part does not fit, or the cache would be below twice the minimum useful size (n_expert_used + 1 slots for every layout group), fit takes its normal path with no cache.

The decision is logged in one line:

common_params_fit_impl: moe cache auto: all routed experts in host RAM, cache 30299 MiB (margin 1024 MiB)

Other details:

  • MTP: a shared MTP context is measured again whenever the fit moves the main model, so its memory follows the placement auto picks.
  • Load mode: use it with --load-mode none. The cache copies misses from host memory, and pinned memory is 2.5x to 8x faster to copy from than pageable mmap. With mmap, the cache was slower than no cache in our runs.

Measurements

All runs used --load-mode none -ub 2048 -c 32768, single GPU, smallest Unsloth dynamic quants. Values are decode tok/s / prompt tok/s at 2048 tokens. Budgets below the card size were emulated with --fit-target. Each auto arm ran twice, and the two runs agree within 0.5%.

GPU, model, expert budget --fit on (no cache) --fit on --moe-cache-mib auto all experts on CPU + hand-sized cache
L4, Qwen3.6-35B-A3B UD-IQ1_M, fits 82.7 / 2593 83.8 / 2583 (cache 0) 79.3 / 2167
L4, Qwen3.6-35B-A3B, 5.8 GiB 49.3 / 2223 77.7 / 2077 77.8 / 2065
L4, Qwen3.6-35B-A3B, 2.0 GiB 28.0 / 1798 59.6 / 1815 59.6 / 1815
L4, gemma-4-26B-A4B UD-IQ2_XXS, fits 76.2 / 2948 77.2 / 2993 (cache 0) 71.2 / 2212
L4, gemma-4-26B-A4B, 5.8 GiB 45.3 / 2044 70.4 / 2144 70.2 / 2128
L4, gemma-4-26B-A4B, 2.0 GiB 24.7 / 1473 45.8 / 1668 45.2 / 1659
A100 40GB, Qwen3.8-Flash-Next UD-IQ1_S, natural 36.2 / 744 50.1 / 674 49.9 / 673
A100 40GB, Qwen3.8-Flash-Next, 18 GiB 18.2 / 576 43.0-46.7 / 565-743 46.2 / 743
A100 80GB, GLM-5.3-Flash UD-IQ1_S, natural 15.3 / 529 37.5 / 544 37.5 / 543
A100 80GB, GLM-5.3-Flash, 40 GiB 6.4 / 284 20.7 / 356 20.6 / 355
RTX PRO 6000, GLM-5.3-Flash, 24 GiB 32.9 / 972 38.6 / 1036 38.5 / 1032

With MTP (--spec-type draft-mtp), the shared MTP context is measured too. GLM-5.3-Flash at a 40 GiB cap keeps the same draft acceptance and output text with the cache on.

Why all experts on the CPU instead of keeping some layers resident. At a fixed expert budget we swept the cache share from 0 to 100%, with the rest as whole resident expert layers. That covered 4 models and 8 GPU/host setups (T4, L4, A100 40/80GB, RTX PRO 6000; 4 to 48 vCPUs). Whenever experts spill, a cache covering the whole budget was the best or within about 5% of the best, so there is no knob for the split. Its decode gain over resident layers only:

Host Decode gain
T4, 4 vCPU up to +265%
A100, 12 vCPU up to +193%
RTX PRO 6000, 48 vCPU +17%

When auto keeps the layer split instead

auto now first estimates the share r of the expert weights that the normal layer split would keep in device memory, from the same budget the cache would get: r = (target - non-expert memory) / expert memory. If r >= 0.80, the split is kept and no cache is used:

common_params_fit_impl: moe cache auto: the layer split keeps 85% of the expert weights in device memory, not using a MoE cache

Why 0.80. A sweep on Kaggle T4 (4 vCPU, default 2 threads; nightly b11541, all routed experts in host RAM in every auto run, --load-mode none -ub 2048 -c 8192, 2082-token prompt then 512 decoded tokens, 3 interleaved runs per arm, same-host A/A within 3% decode and 4% prompt):

r Qwen3.6 UD-IQ1_M prompt / decode, auto vs split gemma-4 UD-IQ2_XXS prompt / decode, auto vs split
0.25 0.95x / 4.07x 1.34x / 4.10x
0.50 0.84x / 3.51x 1.12x / 3.39x
0.65 0.81x / 2.64x 0.97x / 2.40x
0.75 0.79x / 1.94x 0.90x / 1.84x
0.85 0.78x / 1.54x 0.82x / 1.43x
0.95 0.75x / 1.16x 0.74x / 1.06x
  • auto decode and prompt speed are flat in r, while the split keeps improving, so the prompt cost grows with r.
  • End to end: with a 2k prompt and 512 tokens out, the two break even near r 0.95. With an 8k prompt and 128 tokens out, they break even near 0.74 (Qwen3.6) and 0.83 (gemma-4).
  • A 2-thread host is the case most favourable to the cache, since the split runs the spilled experts on the CPU. On a desktop CPU the split does better: an R9700 32 GB (ROCm, Windows) with Qwen3.8-Flash-Next at 128K context and r of about 0.82-0.86 (40 of 49 layers' experts resident, a 20214 MiB cache) decoded about 20% slower with auto.
  • The r estimate matches the fitter: on gemma-4 with a 10240 MiB cap it reports 85%, and the split it then picks keeps 85% of the expert layers.

0.80 keeps the cache wherever it wins decode by 1.5x or more on small hosts, and keeps the split in the range where long prompts and stronger CPUs already favour it.

Tests

  • Decision lines: llama-fit-params --moe-cache-mib auto on all four models with a capped free-memory report. They are sane, the fallbacks trigger when the dense part does not fit, and the measured device total lands within 1 MiB of the target.
  • Real loads: llama-server launches stayed inside their budget and answered requests, with cache hit rates around 69%.
  • Greedy output: with auto, llama-completion --temp 0 -n 64 gives the same tokens as the whole model on the GPU (Qwen3.6, gemma-4).
  • After slimming, on the full nightly build (b11500 plus all pins):
    • greedy output is identical to the whole model on the GPU for gemma-4 (cache 4656 MiB) and Qwen3.6 (cache 3109 MiB);
    • Qwen3.8-Flash-Next with its MTP draft and auto keeps the same text and the same draft acceptance as without auto, 0.80 / 0.71 (cache 10129 MiB);
    • so does GLM-5.3-Flash on both GGUF layouts, 0.62 / 0.57 (cache 30299 MiB).
  • Not exercised: multi-GPU (gated off with a warning) and ROCm.

Branch layout

The head is upstream master at c811cb8f0 (which carries ggml-org#29887 and ggml-org#30112) plus this change, joined by a merge commit so the branch history is not rewritten. The base branch base/ggml-org-30112 is exactly c811cb8f0, so the diff shows only this change.

Kept small on purpose (+165/-17, 9 files):

  • common/fit.cpp:
    • the sizing, about 50 lines;
    • the shared-MTP re-measure, about 20 lines.
  • src/llama-moe-cache.cpp: llama_model_moe_cache_min_size, the floor the fitter needs. It is the only addition to upstream's cache files.
  • --moe-cache-mib accepts auto, and llama-fit-params prints the size it picked.

auto acts on a single GPU only. Multiple GPUs log a warning and fall back to the normal fit; sizing over the per-device split ggml-org#30112 introduced is a follow-up.

Supersedes #250.

am17an and others added 4 commits October 6, 2026 21:19
With --moe-cache-mib auto, --fit sizes the MoE cache when the experts do not
fit in device memory: the memory left after the dense weights, the context
and the compute buffers goes to the cache, or with --moe-cache-static F a
fraction F of it to the experts of whole layers kept in device memory
(first layers first). The result is measured again with the cache allocated
and the cache shrinks by any overshoot. If the cache would be smaller than
n_expert_used + 1 slots per group of cached layers, fit falls back to whole
layers without a cache.

Only for a MoE model on a single GPU, otherwise no cache is used.
llama-fit-params prints the chosen --moe-cache-mib.

(cherry picked from commit 0c0cd60)
- roll back a partially applied MoE cache on errors during the fit
- reduce the static layers and re-measure if they overshoot
- re-measure up to 4 times while shrinking the cache
- require a cache of at least twice the minimum, no cache if no layer is in host memory
- do not cache the NextN/MTP layers in the main context

(cherry picked from commit e5b686c)
… reject a non-numeric --moe-cache-static

A context that shares the main model (MTP) runs on its weights wherever the
fit places them, so its memory was measured once with its own params and went
stale when the fit moved experts to the host. Measure it with the main model
params and again whenever their placement changes.

std::stof accepted NaN and trailing junk for --moe-cache-static.
(cherry picked from commit 82aa472)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T07:26:23.202263Z 79629e9 Manual request
🔒 Security Review ✅ Completed 2026-10-07T15:08:40.793517Z 60d7470 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

ggml-org#29887 and ggml-org#30112 (the MoE cache over multiple GPUs) are now
upstream, so the cache files take upstream's version. --moe-cache-mib auto keeps
its NextN/MTP layer filter and min_size beside it, as an MTP constructor overload
and a separate check, so every upstream line stays as it is.
@danielhanchen
danielhanchen changed the base branch from base/ggml-org-29887 to base/ggml-org-30112 October 8, 2026 12:35
Drop --moe-cache-static: every measurement found the full cache best or within
5% once experts spill, so the static share and its layer bookkeeping go, along
with llama_model_n_bytes_exps. Drop the NextN/MTP layer filter and the MTP
constructor overload, which leaves upstream's cache files untouched apart from
the minimum size the fitter needs. common_fit_params takes a bool instead of a
struct.
EmeraldBitTwizzler pushed a commit to EmeraldBitTwizzler/unsloth-llama.cpp that referenced this pull request Oct 9, 2026
…at merge past b11453, drop unslothai#247, pin unslothai#251

Upstream K2 Horizon (ggml-org#29535), the glm5-next gather removal (ggml-org#30042) and the
GLM5-Next MTP graph (ggml-org#29928) broke the Inkling, unslothai#243 and unslothai#241 pins. Each
branch now carries a merge of upstream master. unslothai#247 is in every tag from
b11452 on. unslothai#251 adds --moe-cache-mib auto on top of ggml-org#29887.
EmeraldBitTwizzler pushed a commit to EmeraldBitTwizzler/unsloth-llama.cpp that referenced this pull request Oct 9, 2026
…29887 and ggml-org#30112 merged

ggml-org#29887 (the MoE expert cache) merged on 10-07 and ggml-org#30112 (the cache over
multiple GPUs) on 10-08. On b11496 and later the old Inkling head refused in six
files and unslothai#251, which carried its own copy of ggml-org#29887, refused in eight.

Both branches now merge upstream master c811cb8. unslothai#251 keeps upstream's cache
lines intact, so the merged tree holds both pins in full.
EmeraldBitTwizzler pushed a commit to EmeraldBitTwizzler/unsloth-llama.cpp that referenced this pull request Oct 9, 2026
unslothai#251 drops --moe-cache-static and the NextN/MTP cache filter, leaving the
auto sizing and the shared-MTP re-measure (+165/-17 against upstream).
EmeraldBitTwizzler pushed a commit to EmeraldBitTwizzler/unsloth-llama.cpp that referenced this pull request Oct 9, 2026
dmds_full can be measured at the native context while the fit has already
reduced the context, so the difference of the totals counted the KV cache
as expert weights and picked the cache where the layer split keeps most
experts resident. Also log the last measured cache size on failure.
…PU device

The fit writes its expert placement into params, but the cache size it
chose stayed in the context params, so a reload from params (the server
waking from sleep) kept the experts in host memory without a cache. The
minimum cache size is 0 unless the device is a GPU the cache can use, and
--moe-cache-mib rejects values with trailing characters.
danielhanchen added a commit that referenced this pull request Oct 15, 2026
Pin #264, #266; repin #243, #251, #149, #240: MoE prompt processing, mmap populate, glm5-next onto b11617
NilayYadav pushed a commit to NilayYadav/llama.cpp that referenced this pull request Nov 9, 2026
NilayYadav pushed a commit to NilayYadav/llama.cpp that referenced this pull request Nov 9, 2026
@danielhanchen
danielhanchen changed the base branch from base/upstream-e95426f16 to base/upstream-5f490d7bf November 9, 2026 21:34
danielhanchen added a commit to NilayYadav/llama.cpp that referenced this pull request Nov 11, 2026
danielhanchen added a commit to NilayYadav/llama.cpp that referenced this pull request Nov 11, 2026
@danielhanchen
danielhanchen changed the base branch from base/upstream-5f490d7bf to base/upstream-951d465f5 November 14, 2026 17:37
@LeoBorcherding

LeoBorcherding commented Nov 17, 2026 •

Copy link
Copy Markdown

-cmoe --moe-cache-mib auto gets no cache at 827478f5a: the fit takes the early no changes needed return before the auto sizing runs. The fix is these commits on top of 827478f5a:

  • f06be43af: any override other than a lone --cpu-moe warns instead of silently sizing nothing.
  • 344fc1817: a lone --cpu-moe gets the cache sized at that early return, with the sizing loop shared with the existing auto path.
  • 3ca685f4b: the log says "cache budget", since the cache caps itself at the host expert size (on a 124 GiB Strix Halo it logged a 100463 MiB request for a 1746 MiB cache).
  • 83c310142: on an integrated GPU, host-resident experts count against the cache target, since both share the same RAM.
  • 040c1bcf4: the cache is also sized when the fit only succeeds by shrinking the context (entire model can be fit by reducing context), which returned before sizing. On granite-3.1-3b-a800m with no -c and a 12000 MiB --fit-target (context 131072 -> 60416), it now logs cache of 2 MiB does not fit ... not using a MoE cache instead of skipping silently; the no changes needed path is unchanged.

Before:

$$\Phi = F - U \ge m ;\Rightarrow; C = 0$$

After, when the only override is --cpu-moe:

$$C = \mathrm{fit}(F - m,\ U,\ s), \qquad C_{j+1} = C_j - \lceil M(C_j) - T \rceil_{\text{MiB}}, \quad \text{accept } M(C_j) \le T,\ C_j \ge 2s$$

Code: before, fit.cpp#L475-L480, after, fit.cpp#L516-L523, sizing loop, #L382-L406.

-cmoe --moe-cache-mib auto, -c 8192 -fa on --fit on, decode tok/s on a 128-token answer (median of 3), head 827478f5a vs fix 3ca685f4b, RX 9060 XT 16 GB (gfx1200), Linux, ROCm 10.1:

model host experts MiB head (no cache) fix full GPU
granite-3.1-1b-a400m Q4_K_M 697 88.2 141.4 223.4
granite-3.1-3b-a800m Q4_K_M 1744 52.8 100.7 145.5
OLMoE-1B-7B-0125 Q4_K_M 3720 52.2 153.4 201.1
LFM2-8B-A1B Q4_K_M 4447 42.8 130.3 181.1
Qwen1.5-MoE-A2.7B Q4_K_M 7920 37.3 86.3 113.8
DeepSeek-V2-Lite-Chat Q4_K_M (MLA) 9086 22.4 46.7 53.5
Moonlight-16B-A3B Q4_K_M (MLA) 9086 27.0 69.3 92.3
gpt-oss-20b MXFP4 9682 21.6 51.4 87.1

#251 -cmoe auto decode on 8 MoE models

On a Radeon 8060S (gfx1151, 128 GB, Linux, HIP 7.16), same flags, head -> fix: gpt-oss-120b 21.0 -> 38.0, Qwen3-30B-A3B 42.3 -> 66.1, gpt-oss-20b 31.3 -> 56.2 tok/s.

Same on CUDA with the models and method from the PR table: L4 24 GB (sm_89), -fa on --load-mode none -ub 2048 -c 32768, 2048-token prompt, budget = VRAM for experts on top of the dense part (--fit-target = free - dense - budget), decode tok/s, median of 3. The PR table's own number is in brackets.

model, expert budget --fit on --fit on --moe-cache-mib auto -cmoe --moe-cache-mib auto, head 827478f5a -cmoe --moe-cache-mib auto, fix 3ca685f4b
Qwen3.6-35B-A3B IQ1_M, 5.8 GiB 50.6 (49.3) 79.5 (77.7) 20.2, no cache 78.1 (hand-sized 77.8)
Qwen3.6-35B-A3B IQ1_M, 2.0 GiB 30.1 (28.0) 60.8 (59.6) 21.6, no cache 60.0 (59.6)
gemma-4-26B-A4B IQ2_XXS, 5.8 GiB 41.9 (45.3) 68.7 (70.4) 20.7, no cache 67.9 (70.2)
gemma-4-26B-A4B IQ2_XXS, 2.0 GiB 25.1 (24.7) 49.5 (45.8) 18.7, no cache 49.5 (45.2)

The first two columns are head; the fix gives the same numbers there (within run-to-run noise). With the fix, -cmoe auto sizes the same cache as plain auto (5992 / 2101 MiB for Qwen3.6, 5987 / 2097 MiB for gemma-4).

Same models and method on a Radeon 8060S (Strix Halo, gfx1151, 128 GB unified memory, Linux, HIP 7.16), no budget emulated (the whole model fits in device-visible memory), decode tok/s, median of 3:

model --fit on --fit on --moe-cache-mib auto -cmoe auto, head 827478f5a -cmoe auto, fix 3ca685f4b
Qwen3.6-35B-A3B UD-IQ1_M 65.6 65.6 32.1, no cache 60.5
gemma-4-26B-A4B UD-IQ2_XXS 62.5 62.7 29.2, no cache 57.4
Qwen3.8-Flash-Next UD-IQ1_S 27.6 27.9 18.1, no cache 26.3
GLM-4.7-Flash UD-IQ1_S 56.8 55.6 22.6, no cache 53.4
Qwen3-Next-80B-A3B UD-IQ1_S 59.1 60.5 27.8, no cache 54.8
GLM-5.3-Flash UD-IQ1_S 14.8 15.1 6.9, no cache fails to load; 12.5 with 83c310142

GLM-5.3-Flash with 3ca685f4b asks for a 79924 MiB cache on top of 80242 MiB of host-resident experts and the allocation fails (failed to allocate buffer for MoE cache). On an integrated GPU the host experts and the cache come out of the same RAM, and the sizing only counted device memory. 83c310142 adds the host buffers to the measured usage when device 0 is GGML_BACKEND_DEVICE_TYPE_IGPU (fit.cpp#L388-L397); discrete GPUs are unchanged. Re-run on the same box: GLM-5.3-Flash now sizes an 11525 MiB cache next to the 79902 MiB of host experts and decodes at 12.5 tok/s (6.9 without a cache, 14.8 with everything on the GPU), with the greedy answer identical to the all-GPU run. Qwen3.8-Flash-Next (31854 MiB cache, 26.2 tok/s) and Qwen3-Next-80B (20597 MiB, 54.7 tok/s) are unchanged by it, and 3ca685f4b fails on GLM-5.3-Flash again.

The greedy 96-token answer of every cache cell is byte-identical to the full-GPU run. A Radeon 8060S (gfx1151, Linux, HIP 7.16) shows the same: granite-3.1-3b-a800m 86.1 -> 138.1 tok/s, output identical in all 8 cells.

Explicit sizes, plain auto, and -cmoe with no cache are unchanged between head and fix. -ot token_embd=CPU with auto now warns. On an R9700 (Windows 11, ROCm 7.1, IQ1_M Qwen3.8-Flash-Next coder GGUF, --load-mode none) the head gets no changes needed with 27833 MiB free and no cache for -cmoe auto, while an explicit --moe-cache-mib 16000 gets a 15995 MiB cache and decodes at 24.8 tok/s against 15.8 without. With the fix, -cmoe --moe-cache-mib auto on the same card sizes a 24.0 GB cache (every host expert) and decodes at 24.8 tok/s against 15.9 for -cmoe alone; with an 8 GiB --fit-target margin it shrinks to 19.6 GB and 23.5 tok/s. Greedy output is identical across all 8 cells. Prompt processing drops from 484 to 313 tok/s with the cache on, the same as with a hand-sized cache, so that cost comes from the cache itself, not from auto.

Same models and method on an R9700 32 GB (gfx1201, Windows 11, ROCm 7.1), fix at 344fc1817 (the later commits only change the log wording and the iGPU path), expert budget emulated the same way as the L4 table, decode tok/s, median of 3:

model, expert budget --fit on --fit on --moe-cache-mib auto -cmoe auto, head 827478f5a -cmoe auto, fix
Qwen3.6-35B-A3B UD-IQ1_M, 5.8 GiB 72.2 60.2 36.4, no cache 60.1
Qwen3.6-35B-A3B UD-IQ1_M, 2.0 GiB 43.3 56.5 36.5, no cache 56.0
gemma-4-26B-A4B UD-IQ2_XXS, 5.8 GiB 57.9 53.9 31.4, no cache 53.8
gemma-4-26B-A4B UD-IQ2_XXS, 2.0 GiB 35.8 43.0 31.2, no cache 42.6

The fix matches plain auto in every row (5938 / 2047 MiB caches). Unlike the L4, at a 5.8 GiB budget plain --fit on beats --fit on --moe-cache-mib auto on this card (72.2 vs 60.2, 57.9 vs 53.9): putting that many experts directly on the GPU is faster here than caching them. That's in auto itself, head and fix alike.

One more thing from these runs, in the auto design itself and present on the head too: auto accepts any cache of at least 2x the one-token minimum, but a cache that holds too little of the experts decodes slower than no cache. Sweeping -cmoe --moe-cache-mib N (fix build, same box, median of 3):

cache, % of host experts 10 20 30 40 50 60 80 100 no cache
OLMoE-1B-7B tok/s 26.5 34.8 43.4 55.5 68.9 86.1 119.8 153.4 51.8
OLMoE hit rate % 22.8 45.3 60.4 71.6 80.3 87.0 95.8 99.2
Qwen1.5-MoE-A2.7B tok/s 21.5 24.0 27.2 30.7 35.1 41.5 57.6 86.5 37.0
Qwen1.5-MoE hit rate % 18.0 30.5 41.2 51.8 61.6 71.5 87.7 98.2

#251 decode vs cache coverage

Break-even is about 37% coverage for OLMoE and 53% for Qwen1.5-MoE, both near a 65% hit rate. I'd have auto skip the cache below about half the host expert size (or below a projected ~65% hit rate) rather than at 2x the one-token minimum.

Multi-GPU: with two R9700s, -cmoe --moe-cache-mib auto declines with needs a MoE model on a single GPU, not using a MoE cache, as intended; that box then hit a ROCm unspecified launch failure during load with an iGPU also visible, so no multi-GPU decode number. Not run: 040c1bcf4 on hardware other than the RX 9060 XT.

@LeoBorcherding

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 827478f5ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@LeoBorcherding LeoBorcherding left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex: clean on 827478f5a here and on the fork mirror, and clean on f06be43af (head plus the override guard) on the mirror. Four findings came up over the mirror rounds:

  • common/fit.cpp:240 (minimum footprint measured without the fitted placement) and tools/ui/src/lib/utils/compaction.ts:56: not from this PR. Both came in verbatim with the ggml-org merge (ggml-org#21231, ggml-org#27401).
  • common/fit.cpp:807, auto never sizes a cache when the placement already fits (--cpu-moe with the dense weights in VRAM): real, and still on the head. On an R9700 with an IQ1_M Qwen3.8-Flash-Next coder GGUF, -cmoe --fit on --moe-cache-mib auto projects 4626 of 32460 MiB, returns no changes needed, and runs with no cache and no message, so about 27.8 GB of VRAM sits unused. With an explicit --moe-cache-mib 16000, the same command gets a 15995 MiB cache and decodes at 24.8 tok/s instead of 15.8.
  • common/fit.cpp:408, scope the guard to expert overrides: not narrowed. With a non-expert -ot (-ot token_embd=CPU), auto either returns early with no cache or aborts the fit at fit.cpp:607, so narrowing the guard brings the silent case back.

f06be43af makes the fit.cpp:807 case say what happened (--moe-cache-mib auto places the tensors itself, drop --cpu-moe/-ot or give a size). It still doesn't size the cache. The useful behaviour for -cmoe + auto is to size the cache from the VRAM the early return leaves free, and that's the bigger win for the people who actually use -cmoe. I'd take f06be43af here as the floor and do the sizing either in this PR or right after it.

Ran: the three cells above on head vs f06be43af (R9700, Windows 11, ROCm 7.1). Explicit sizes are unchanged. Not run: multi-GPU (auto is single-GPU only by its own check), CUDA, Linux ROCm.

LeoBorcherding added a commit to LeoBorcherding/llama.cpp that referenced this pull request Nov 17, 2026
…timings (source line moved off the axes)
LeoBorcherding added a commit to LeoBorcherding/llama.cpp that referenced this pull request Nov 17, 2026
@LeoBorcherding

LeoBorcherding commented Nov 19, 2026 •

Copy link
Copy Markdown

The fix for the -cmoe --moe-cache-mib auto gap is up as #380 against this branch (Codex clean on the mirror; results in the comment above).

@danielhanchen #379 pins this PR at 827478f5a, which is before the fix, so the prebuilt still gets no cache with -cmoe --moe-cache-mib auto. Could you merge #380 here and move the pin in scripts/unsloth/pr-set.json to the new head on the next repin? Unsloth Studio isn't affected, since it never sends -cmoe together with auto, so this can wait for the next repin.

…ache-mib auto minimum

The minimum cache size weighted each group by the bytes of every layer that
reads it, so a looped model (Inkling 2, core layers read 3 times) was sized for
a visit-weighted split. The MoE cache splits its budget by the expert weights,
each counted once, so a core-heavy group could get fewer than n_expert_used
slots at that minimum. Layers that read the same weights (or whole views of
them) now count once here too, unless LLAMA_MOE_CACHE_DEDUPE=0.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 038adc6eab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread common/fit.cpp Outdated
Comment on lines +32 to +33
// --moe-cache-mib auto keeps the layer split instead of a MoE cache when the split would hold at least this share of the
// expert weights in device memory (calibrated in the measurements on the pull request)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep explanatory comment sentences on a single line

The new comment splits a sentence across two lines, contrary to the explicit rule in AGENTS.md against splitting sentences or hard-wrapping comments. Keep this sentence on one line and apply the same correction to the other newly wrapped explanatory comments in this change.

AGENTS.md reference: AGENTS.md:L84-L84

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 79629e9: each of those comments is now one sentence per line (the auto sizing threshold, the shared-context note, the cache vs layer split note, the params reload note and the dedupe note). Comment-only change.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 79629e9c48

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants