[PR #54] [MERGED] Support pruned expert variants (GSQ-RCO-Coder: 256 of 512 experts) #2432

Closed
opened 2026-11-04 02:00:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/54
Author: @pjgmobile
Created: 9/28/2026
Status: ✅ Merged
Merged: 9/28/2026
Merged by: @Niko1221

Base: main ← Head: pruned-geometry-support


📝 Commits (8)

  • 80a1f13 Merge branch 'pr-7'
  • 30acb0c Merge branch 'pr-8'
  • 9ef55a4 Merge branch 'pr-14'
  • 4a4ec34 Merge remote-tracking branch 'origin/main'
  • e02b848 serve: optional --fit-max-tokens clamps the output cap to remaining context instead of rejecting
  • 597d043 Merge remote-tracking branch 'origin/main'
  • f07c68c Support pruned expert variants (GSQ-RCO Coder: 256 of 512 experts)
  • 9e8a70d Merge remote-tracking branch 'origin/main' into pruned-geometry-support

📊 Changes

8 files changed (+87 additions, -52 deletions)

View changed files

📝 include/strata/artifact/gguf_reader.hpp (+4 -3)
📝 include/strata/prefill/kernels.hpp (+1 -1)
📝 src/core/layer.cpp (+2 -5)
📝 src/kernels/cpu/expert_layout.cpp (+11 -2)
📝 src/prefill/kernels.cu (+16 -9)
📝 src/prefill/prefill.cpp (+20 -20)
📝 src/program/generate.cpp (+23 -6)
📝 tools/iq_pack.py (+10 -6)

📄 Description

Support pruned expert variants (GSQ-RCO-Coder: 256 of 512 experts)

Motivation

ISTA-DASLab recently published Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF — the same
architecture with half the routed experts pruned away per layer (512 → 256,
qwen4exp.expert_count = 256, still 10 active). The engine currently specialises to the
canonical geometry in a number of places, so a pruned model fails at a different spot for
each one: the pack tool divides by a hardcoded 512, the pack loader validates against the
compile-time default, the runtime graph is default-constructed, the prefill kernels and
buffers assume 512, and serve mode additionally demands a canonical profile-filled cache.

This PR threads the model's own declared expert geometry through those paths so pruned
variants boot and run, while canonical behaviour stays byte-identical.

Changes

  • tools/iq_pack.py — N_EXPERT = 512 was hardcoded; the expert count is now derived
    from the router tensor's shape (ffn_gate_inp.weight, dim 1) with a uniformity check
    across layers. Blob sizes, offsets and the native_experts.txt header all follow it.
  • src/kernels/cpu/expert_layout.cpp — expert_layout_load() trusted the caller's
    geometry (a compile-time default) for the contiguity stride. It now parses
    n_expert from the pack header (v3 headers already record it) and uses that for both
    the stride and the stored layout, so ArenaExpertSource's geometry check passes.
  • include/strata/artifact/gguf_reader.hpp — Qwen4ExpGuard validated every GGUF
    against canonical constants. experts/experts_used now default to 0 = presence-only;
    block count, hidden size and head counts are still hard-validated.
  • src/program/generate.cpp — the runtime ModelGeometry was default-constructed;
    it now reads qwen4exp.expert_count / expert_used_count from the --native shard
    (K too). The MTP drafter deliberately keeps the canonical geometry via a
    static const ModelGeometry — the draft layer is the original 512-expert head, and it
    sizes its own arena from it (speculation works unchanged; acceptance 74-85% measured).
    The serve-mode gate also no longer demands the profile-filled graph-hit path: an
    on-demand (--expert-cache auto) cache is a valid serve configuration.
  • src/core/layer.cpp — the native fused router stays canonical-only; non-canonical
    geometry falls back to the generic router_top10 instead of erroring.
  • src/prefill/* — the NE = 512 constant is replaced by the geometry's expert
    count in buffer sizing, host loops and residency indexing; route_kernel is
    templatized on registers-per-lane (512 → 16, 256 → 8, anything else takes the generic
    router_top10); route() gained an n_expert parameter; moe_set_bytes() likewise.

Design notes

  • The model file is the authority on its own MoE shape; the compile-time defaults remain
    as fallbacks and for the canonical fast paths.
  • The draft/target split is intentional: pruning changes the target's routed experts but
    the shipped MTP draft is still the original head, so it must keep 512x10 sizing.
  • Profiles: the shipped data/expert-profile.bin is 48x512. For a pruned model we
    remapped the ranked (layer, expert) pairs onto the survivor indices using the release's
    published tensor-allocation/*.rco-allocation.txt (Section 2 records each survivor's
    original index) — 8000 → 5492 pairs survived remapping, trimmed to fit VRAM. A
    make_profile.py run against pruned-model routing would do this properly; happy to
    follow up with that as a companion tool.

Testing (Ryzen 5 5600X, RTX 3090 24 GB, CUDA 13.1)

  • Pack built from the IQ1_M pruned release (shard 2 is byte-identical to the canonical
    n-gram table; symlinked, no re-download).
  • Pruned lane boots: 11 pool workers, 262144 ctx, KV int8, remapped profile
    (4500 slots), MTP draft over the canonical head.
  • ~3.5-hour real agentic coding session through llama-swap (three.js scene build):
    peak 192k tokens, one omp compaction, zero engine errors, decode 27-42 tok/s
    (post-0.1.14 AVX2 i-quant kernels: 38.7 cold / 42.6 warm on fixed prompts vs 23.1/24.6
    before this upgrade), draft acceptance 65-85%.
  • Canonical lanes unaffected: Q2_0 daily driver answers at its usual speed (53.6 tok/s
    spot check), IQ2_XS and vision configs untouched.

Disclosure

This PR was authored by GLM-5.3-Flash (ZCode agent); Pete (pjgmobile) tested it on real
workloads overnight and submitted it.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/54 **Author:** [@pjgmobile](https://github.com/pjgmobile) **Created:** 9/28/2026 **Status:** ✅ Merged **Merged:** 9/28/2026 **Merged by:** [@Niko1221](https://github.com/Niko1221) **Base:** `main` ← **Head:** `pruned-geometry-support` --- ### 📝 Commits (8) - [`80a1f13`](https://github.com/Niko1221/Strata/commit/80a1f1327b527143a9ccc1d7b97f9353f324841c) Merge branch 'pr-7' - [`30acb0c`](https://github.com/Niko1221/Strata/commit/30acb0c7a89e7a6e2bbbf399b80cda9e88eb2588) Merge branch 'pr-8' - [`9ef55a4`](https://github.com/Niko1221/Strata/commit/9ef55a46992162685b3cff6306a0bf2ad1b0f9bb) Merge branch 'pr-14' - [`4a4ec34`](https://github.com/Niko1221/Strata/commit/4a4ec34db643cc7a197d0b8015ba041c1631166d) Merge remote-tracking branch 'origin/main' - [`e02b848`](https://github.com/Niko1221/Strata/commit/e02b8482222bd265ec29327016b05df78dbdae4c) serve: optional --fit-max-tokens clamps the output cap to remaining context instead of rejecting - [`597d043`](https://github.com/Niko1221/Strata/commit/597d043473bb720abb1168d0f396f92f3974870a) Merge remote-tracking branch 'origin/main' - [`f07c68c`](https://github.com/Niko1221/Strata/commit/f07c68c7c2ffb421cac903623a08a933c1a31831) Support pruned expert variants (GSQ-RCO Coder: 256 of 512 experts) - [`9e8a70d`](https://github.com/Niko1221/Strata/commit/9e8a70d41eb2d538c4a5f17c8ebcb4ace0859346) Merge remote-tracking branch 'origin/main' into pruned-geometry-support ### 📊 Changes **8 files changed** (+87 additions, -52 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/artifact/gguf_reader.hpp` (+4 -3) 📝 `include/strata/prefill/kernels.hpp` (+1 -1) 📝 `src/core/layer.cpp` (+2 -5) 📝 `src/kernels/cpu/expert_layout.cpp` (+11 -2) 📝 `src/prefill/kernels.cu` (+16 -9) 📝 `src/prefill/prefill.cpp` (+20 -20) 📝 `src/program/generate.cpp` (+23 -6) 📝 `tools/iq_pack.py` (+10 -6) </details> ### 📄 Description # Support pruned expert variants (GSQ-RCO-Coder: 256 of 512 experts) ## Motivation ISTA-DASLab recently published `Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF` — the same architecture with **half the routed experts pruned away per layer** (512 → 256, `qwen4exp.expert_count = 256`, still 10 active). The engine currently specialises to the canonical geometry in a number of places, so a pruned model fails at a different spot for each one: the pack tool divides by a hardcoded 512, the pack loader validates against the compile-time default, the runtime graph is default-constructed, the prefill kernels and buffers assume 512, and serve mode additionally demands a canonical profile-filled cache. This PR threads the model's *own declared* expert geometry through those paths so pruned variants boot and run, while canonical behaviour stays byte-identical. ## Changes - **`tools/iq_pack.py`** — `N_EXPERT = 512` was hardcoded; the expert count is now derived from the router tensor's shape (`ffn_gate_inp.weight`, dim 1) with a uniformity check across layers. Blob sizes, offsets and the `native_experts.txt` header all follow it. - **`src/kernels/cpu/expert_layout.cpp`** — `expert_layout_load()` trusted the caller's geometry (a compile-time default) for the contiguity stride. It now parses `n_expert` from the pack header (v3 headers already record it) and uses that for both the stride and the stored layout, so `ArenaExpertSource`'s geometry check passes. - **`include/strata/artifact/gguf_reader.hpp`** — `Qwen4ExpGuard` validated every GGUF against canonical constants. `experts`/`experts_used` now default to 0 = presence-only; block count, hidden size and head counts are still hard-validated. - **`src/program/generate.cpp`** — the runtime `ModelGeometry` was default-constructed; it now reads `qwen4exp.expert_count` / `expert_used_count` from the `--native` shard (K too). The MTP drafter deliberately keeps the **canonical** geometry via a `static const ModelGeometry` — the draft layer is the original 512-expert head, and it sizes its own arena from it (speculation works unchanged; acceptance 74-85% measured). The serve-mode gate also no longer demands the profile-filled graph-hit path: an on-demand (`--expert-cache auto`) cache is a valid serve configuration. - **`src/core/layer.cpp`** — the native fused router stays canonical-only; non-canonical geometry falls back to the generic `router_top10` instead of erroring. - **`src/prefill/*`** — the `NE = 512` constant is replaced by the geometry's expert count in buffer sizing, host loops and residency indexing; `route_kernel` is templatized on registers-per-lane (512 → 16, 256 → 8, anything else takes the generic `router_top10`); `route()` gained an `n_expert` parameter; `moe_set_bytes()` likewise. ## Design notes - The model file is the authority on its own MoE shape; the compile-time defaults remain as fallbacks and for the canonical fast paths. - The draft/target split is intentional: pruning changes the target's routed experts but the shipped MTP draft is still the original head, so it must keep 512x10 sizing. - Profiles: the shipped `data/expert-profile.bin` is 48x512. For a pruned model we remapped the ranked (layer, expert) pairs onto the survivor indices using the release's published `tensor-allocation/*.rco-allocation.txt` (Section 2 records each survivor's original index) — 8000 → 5492 pairs survived remapping, trimmed to fit VRAM. A `make_profile.py` run against pruned-model routing would do this properly; happy to follow up with that as a companion tool. ## Testing (Ryzen 5 5600X, RTX 3090 24 GB, CUDA 13.1) - Pack built from the IQ1_M pruned release (shard 2 is byte-identical to the canonical n-gram table; symlinked, no re-download). - Pruned lane boots: 11 pool workers, 262144 ctx, KV int8, remapped profile (4500 slots), MTP draft over the canonical head. - **~3.5-hour real agentic coding session** through llama-swap (three.js scene build): peak 192k tokens, one omp compaction, zero engine errors, decode 27-42 tok/s (post-0.1.14 AVX2 i-quant kernels: 38.7 cold / 42.6 warm on fixed prompts vs 23.1/24.6 before this upgrade), draft acceptance 65-85%. - Canonical lanes unaffected: Q2_0 daily driver answers at its usual speed (53.6 tok/s spot check), IQ2_XS and vision configs untouched. ## Disclosure This PR was authored by GLM-5.3-Flash (ZCode agent); Pete (pjgmobile) tested it on real workloads overnight and submitted it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:00:04 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2432
No description provided.