Repository navigation
Per-expert imatrix stats reveal domain-dependent MoE routing — used them to prune 25% of OLMoE's experts (tool + measurements) #25622
Replies: 2 comments
|
Thanks for writing up the OLMoE per-expert routing measurements. I ran into the same domain-specialization behavior at a much larger scale while trying to fit Instead of keeping coding, I inverted the calibration set to keep Creative Writing (35%) / Roleplay (30%) / World Knowledge (20%) / Logic (15%) on two separate monolingual tracks (English and Chinese), intentionally dropping coding and unused language experts (
If the masks, GGUF slicer, or
|
|
Thanks a lot for this — a 512-expert replication is exactly what this thread needed, and it's great to see the approach hold up at 125B scale (and in the opposite direction: dropping code instead of specializing on it). A few notes: 1. Re-collecting imatrix after pruning — this matches what moe-scalpel does (slice → regenerate imatrix → quantize), so it's good to have independent confirmation that slicing the original imatrix is the worse option. 2. Protecting dense tensors — I hadn't tested this at all. Keeping ~4% of dense weights ( 3. KL cliff at 128 — this fits what I saw on OLMoE: the cost grew roughly geometrically (mean KLD 0.0270 → 0.0550 → 0.1259 for keep=56/48/40), so there seems to be a model-dependent knee rather than a smooth trade-off. A couple of questions:
Happy to coordinate if you want to compare masks or run the same eval harness on both models. |
Uh oh!
There was an error while loading. Please reload this page.
The imatrix files that
llama-imatrixproduces already contain per-expert activationstatistics (
.counts+.in_sum2are[n_expert, ...]-shaped for the_expstensors) — they're just never exposed at expert granularity. I parsed them, measured
whether expert routing depends on the input domain (it does: cold-tail overlap between
code and prose is only 24.6% on OLMoE), and built a small tool that prunes the
coldest experts for a target domain directly at the GGUF level.
Repo (MIT, two Python scripts on top of stock llama.cpp): https://github.com/lucafulgenzi/moe-scalpel
What I measured
Model: OLMoE-1B-7B (16 layers, 64 experts, top-8). Two calibration profiles: JS/TS
source code vs wikitext.
Routing concentration is domain-dependent. On prose, routing is near-uniform
(entropy 0.972 — the load-balancing loss doing its job); on code it concentrates
(0.835), with the coldest 25% of experts carrying only 2.95% of tokens (vs 11.5% on
prose). And the cold tails of the two domains barely overlap (24.6%), so a
domain-specific profile finds a genuinely different cut than a generic one would.
Pruning curve (prune F16 → fresh imatrix → Q4_K_M →
llama-perplexity --kl-divergencevs F16, held-out code):Each 8 experts removed ≈ 2× mean KLD — smooth geometric growth, no cliff. Damage is
tail-concentrated (median stays tiny; the pain lives in rare tokens). keep=56 adds
less damage than Q4 quantization itself.
The price is real specialization: off-domain (wikitext) the keep=48 model has
PPL +79% and agrees with the F16 on the top token only 61.3% of the time (vs 90.5%
for the unpruned quant). A pruned model is a domain model, by design.
Full logbook with protocol, go/no-go thresholds fixed before measuring, and raw
numbers: docs/LOGBOOK.md
How the pruning works
Plain GGUF surgery on the unquantized model with
gguf-py: slice theffn_*_expstensors and the router (
ffn_gate_inp) along the expert dimension with per-layerkeep-lists, patch
{arch}.expert_count, regenerate the imatrix (indices shift),quantize as usual.
expert_countbeing a global hparam means every layer must keepthe same number of experts (which experts can differ per layer).
Per-expert mixed precision would have been the gentler alternative, but it's not
representable in GGUF: all experts of a layer share one 3D tensor and a tensor has a
single quantization type. (The imatrix already does per-expert weighting within the
fixed budget, which is the conservative version of the same idea.)
Questions for people who know this codebase better than I do
llama-imatrix --show-statisticsexposing per-expertbreakdowns (counts/energy per expert), instead of aggregating them away? The data
is already collected; it's a display-level change.
considered for the GGUF format, or is one-type-per-tensor a hard design constraint?
n_expert_groups): pruning currently breaksthe group structure unless cuts are uniform per group — is there prior art /
interest in supporting this?
Limits so far: one model, one domain pair. Replications on other MoEs very welcome —
the pipeline is fully scripted.
All reactions