Skip to content

router: measure per-layer expert locality on recent prose and code - #66

Merged
midagedev merged 1 commit into
midagedev:mainfrom
Burntgogi:contribution/router-locality-20261012
Oct 12, 2026
Merged

midagedev merged 1 commit into
midagedev:mainfrom
Burntgogi:contribution/router-locality-20261012

Conversation

@Burntgogi

Copy link
Copy Markdown
Contributor

What and why

Adds per-layer LRU-64/128 and held-out static top-32 replay to the existing router analyzer, with validation of expert ids and agreement between count files and top-k rows. The report records two repeatable 8,192-token CPU traces on recent prose/code, the text sources and model hashes, and a 512-token scalar-vs-batch check. Mean LRU-64 hits are 67.7%/73.3%, above the issue's 60% criterion; these are locality measurements, not GPU speedups. Closes #31.

Code shape

  • No second copy. Existing manifest/top-k readers, count helpers and hot-list selection are reused.
  • Model code holds only architecture facts. No engine or model implementation changed.
  • Dead code is gone. No existing code made unused.
  • No silent failure. Invalid/duplicate ids, inconsistent counts and incomplete traces are rejected.
  • Comments state what is true now. Source comments describe replay contracts.
  • No relaxed gate. No band, tolerance or lint changed.
  • cargo fmt and cargo clippy: no Rust source changed; validation covers the Python analyzer, report and adapter patch.

Existing policy at tools/ref/router-residency.py:568 is a shared cross-layer LRU with copy budgets. This report's fixed-count per-layer replay is a different measurement contract; its start-of-token and context-reset controls are explicit.

What I ran

python3 tools/ref/router-coverage.py --self-test
router-coverage: self-test ok

bash tools/check-recipes.sh
check-recipes: 42 tool self-tests ok
check-recipes: ok
(gate-batch self-test: 542 of 542 ok)

bash tools/contrib-check.sh --tier t0 --only '^(check-(arch|comments|rustflags|levers|unsafe|waits|loads|ptx-names))$'
DONE tier=t0 total=8 red=0 wall=21s

git diff --check
(no errors)

Both full traces were collected twice; every top-k file and count file is byte-identical across the two collections. The mainline API adapter patch was applied to a copy of the original collector and verified to reproduce the compiled source exactly. The first full check had one transient gate-batch fixture failure; a standalone rerun passed 542/542, and the subsequent complete check-recipes run passed without changing the gate code.

Maintainer hardware gates remain for the maintainer. The attached report includes per-layer tables, replay rules, schedule sensitivity, collection commands and provenance. The adapter patch is for reproducing this measurement against the pinned mainline API; it does not replace the existing ik collector or change production execution.

Hardware

Intel i5-12600K, 64 GiB RAM, Linux 7.0.0-38-generic. Routing collection uses CPU only with no KV/operation offload. Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS has 48 routed layers, 512 experts and top-10 routing. Mainline llama.cpp fb4b2737a808a3fb7c2117a498f43815dc9be53e, local Vulkan-only modifications, CPU backend unchanged; report includes the API adapter and exact model hashes. No NVIDIA timing evidence is claimed.

@midagedev

Copy link
Copy Markdown
Owner

Thank you for the measurement and the tool. The 0.3.1 release is being cut now. I will review this with #64 and #65 after the tag.

@midagedev

Copy link
Copy Markdown
Owner

Thanks. I recomputed the all-layer rows from the per-layer rows and they match. The adapter patch applies to tools/ref/router_trace.cpp on main, and the locality self-test passes.

We will finish it on our side and merge it. You do not need to change anything. We add a short "Decision" paragraph:

One thing only you have: the commands behind the cross-genre 17.2 / 14.0 % and the in-sample 39.2 / 46.8 % figures. If you paste them here, we add them to Reproduction.
It is a draft. If you still plan changes, say so; otherwise we take it from here.

@Burntgogi

Copy link
Copy Markdown
Contributor Author

Following up on your request for the commands behind the cross-genre and in-sample figures: I recovered the original trace sets and reran both commands below. Their complete stdout is byte-for-byte identical to the archived static32-transfer.md and static32-in-held.md reports.

From the bloomery checkout (27f2a17, based on main e53cabeb; no analyzer change in that follow-up):

EVIDENCE=/home/jutai05/bloomery-contributions/issue31-evidence
A="$EVIDENCE/data/router/prose-8192"
B="$EVIDENCE/data/router/code-8192"

# A = prose, B = code; learn each hot-32 list on all 8,192 tokens.
python3 tools/ref/router-coverage.py transfer "$A" "$B" --n 32

# Separate in-sample and held-out tables for each corpus.
python3 tools/ref/router-coverage.py coverage "$A" "$B" --n 32

The transfer all-layer row is:

overlap of hot-32 A-list on B (%) B-list on B, in (%) B held-out (%) B-list on A (%) A-list on A, in (%) A held-out (%)
5.8 17.2 46.8 44.1 14.0 39.2 35.8

Thus A-list on B is prose-trained -> code-evaluated, and B-list on A is code-trained -> prose-evaluated. The separate coverage command agrees with the same in-sample and held-out columns. In-sample learns and evaluates on all 8,192 tokens of the same corpus; held-out learns on [0,4096) and evaluates on [4096,8192), aligned to the 2,048-token context chunks. All percentages are routed selections, averaged over 48 layers, each with 512 experts and top-10 routing; they are not engine speedups.

Provenance checked again:

  • All 50 stored SHA-256 fingerprints per *-verified8192 set match result.json (100 files total).
  • Each original *-8192 set has identical counts.tsv and all 48 topk-*.u16 files to its verified repeat (98 raw-file comparisons total). The original manifests were not rewritten; the verified collection adds the recorded input MD5.
  • Input MD5: prose 95ee78d18f59219f3c99682fa079db00; code 33a59998ab0f940fa2acc1a74583303f.

This is a replay of the original CPU-collected traces, not a fresh model collection or GPU measurement. The source/model/schedule remain those in the merged report. EVIDENCE is my retained local archive path; the commands require those trace directories or traces collected using that report's pinned inputs. No new upstream code or measurement claim is needed for this reply.

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

Labels

documentation Improvements or additions to documentation tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

측정: Qwen3.8 expert 라우팅 국소성 (층별 LRU-64/128 적중률)

3 participants