[PR #88] [MERGED] The expert profile as Strata has it, for GLM packs (9 GPUs, a fresh start: decode 35.4 -> 40.7 tok/s); learning across starts is opt-in #326

Closed
opened 2026-10-29 21:24:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/88
Author: @needmorevram
Created: 10/10/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @mw00

Base: main ← Head: glm-expert-profile


📝 Commits (2)

  • 5070eba The expert profile as Strata has it, for GLM packs: --expert-profile decides each layer's VRAM slots and what a start loads first, --expert-profile-save learns across starts when asked; the usage file is opt-in (9 GPUs, a fresh start: decode 35.4 -> 40.7 tok/s)
  • 342fc04 The draft layer keeps at least the per-layer equal share of its card's slots, whatever the expert profile ranks it

📊 Changes

20 files changed (+959 additions, -103 deletions)

View changed files

📝 CMakeLists.txt (+11 -0)
➕ data/expert-profile-glm.bin (+0 -0)
📝 docs/SETTINGS.md (+28 -7)
📝 include/strata/core/expert_cache.hpp (+19 -0)
📝 include/strata/core/glm_model.hpp (+18 -1)
📝 maya.py (+41 -1)
📝 src/core/expert_cache.cpp (+87 -2)
📝 src/core/glm_fast_path.cu (+113 -19)
📝 src/core/glm_fast_state.hpp (+10 -0)
📝 src/core/glm_model.cu (+6 -6)
📝 src/core/glm_prefill.cu (+8 -0)
📝 src/program/generate.cpp (+38 -1)
➕ tests/core/expert_profile_save_test.cpp (+80 -0)
➕ tests/core/expert_profile_version_test.cpp (+73 -0)
📝 tools/calibrate_glm.py (+29 -14)
📝 tools/glm_expert_prior.py (+5 -4)
📝 tools/make_profile.py (+120 -36)
📝 tools/test_calibrate_glm.py (+17 -12)
➕ tools/test_make_profile.py (+145 -0)
➕ tools/test_maya_profile.py (+111 -0)

📄 Description

Summary

GLM packs get Strata's expert profile, the way Strata's own setup uses it:

  1. --expert-profile FILE decides which experts a start puts in VRAM and how many VRAM slots each layer gets. Setup passes the shipped data/expert-profile-glm.bin to every config.
  2. Learning across starts is opt-in. --expert-profile-save FILE saves what the expert tiers learned. STRATA_GLM_USAGE (the usage file read at start and written after every request) no longer has a default.
  3. A new shipped profile, built from a Maya-L routing trace with the MTP draft block running, so the draft layer is ranked by its real use.

On 9 GPUs a fresh start decodes 35.4 -> 40.7 tok/s (no profile -> this one). On one RTX 3090 the new profile ties the earlier one.

What changes

Engine (--glm-pack)

Argument What it does
--expert-profile FILE Strata's STRP profile (46 layers x 288 experts). Its ranking of every (layer, expert) pair gives each layer its VRAM slots (a floor each, then the next slot to the layer whose next expert ranks highest) and the warm-up its order. It replaces the pack's expert_counts.txt / expert_prior.txt; without a profile the engine reads those as before.
--expert-profile-save FILE Writes the experts in VRAM, then the routes counted this run, then the starting profile. Saved every --expert-profile-save-every MIN minutes (default 10) between requests and at QUIT, through a .tmp and a rename.
--dump-routing FILE Every route, from prompts and answers, as a routing trace (int32 layer, int32 k, k ids, k weights).
  • STRATA_GLM_USAGE is opt-in: unset (or 0), no usage file is read or written. The split search reads the same setting. STRATA_GLM_USAGE=<pack>/expert_usage.txt gives the old behaviour back.
  • Reader and writer: read_expert_profile now refuses a profile version other than 1 by its number. rank_learned_profile and write_expert_profile are added for the save.
  • Splits: every part reads the same profile. The saved profile takes each part's resident experts and route counts.

Setup (maya.py)

  • Every GLM config gets --expert-profile data/expert-profile-glm.bin.
  • A profile wired in by hand is kept by a later setup, but only if it is a different file that still exists. Otherwise the shipped one comes back. --expert-profile-save and --expert-profile-save-every are kept too.
  • Existing installs: an update restarts the installed config without a setup. A GLM config with no --expert-profile therefore gets the shipped one at its next start and is saved back once (starts from the shipped expert profile now). An update needs nothing else.

Calibration (tools/calibrate_glm.py)

  • Its engine runs without --expert-profile-save / --dump-routing, so tuning prompts never reach a learned profile or a trace.
  • It copies a usage file only when the config sets STRATA_GLM_USAGE.

Tools

  • tools/make_profile.py --glm: 46 x 288 layout. It reads --dump-routing traces and the engine's text records (usage files, expert_counts.txt, STRATA_GLM_TRACE lines).
    • --reorder: traces before the base.
    • --equal: each input scaled to one total.
    • A trace record cut short at the end of the file is skipped.

The shipped profile

tools/make_profile.py --glm --no-base over one --dump-routing trace:

  • Model and hardware: Maya-L on 9 GPUs with MTP drafting on. Routing is the router's, so the trace serves every quant of GLM-5.3-Flash and every GPU count.
  • Requests: 66 of them, with thinking on and off:
    • code in several languages, math with thinking, explanations and chat;
    • French, Spanish, Chinese, German, Japanese, Russian, Portuguese and Arabic;
    • JSON and tool calls;
    • 8 long documents (1-4K tokens each).
  • Size: 25.7K prompt tokens and 25.6K generated tokens, 2.28 M routes. Every one of the 12,384 routed (layer, expert) pairs was seen.
  • Draft layer: it routes only while drafting, so it has about half a decoder layer's routes.
    • In the earlier profile (built on a quant without a draft block) it ranked last. On a split it got only the floor of VRAM slots (60, against 206 for the other layers on the last 5060 Ti here), filled in expert order.
    • Now it is ranked by use. In the held-out estimate below, its experts in VRAM on a 9-GPU split cover 84% of its routes, against 3% with the earlier profile.
  • Single GPU: the draft block is loaded only on a split, so on one GPU those entries are ignored.
  • No overlap: none of the benchmark's prompts or topics are in the trace.

Benchmarks

Setup: Maya-L (156 GB), 2x Xeon Gold 6152 (88 vCPUs), 177 GB RAM.

Method:

  • A fresh start each row, the usage file off (unless the row says otherwise). The 9-GPU rows ran this branch on v1.0.29, the 3090 rows the rebased branch on v1.0.31; within each table the build is the same.
  • Five requests: a warm-up, code (256 tokens), French (256), a 9.9K-token document question (128), and math right after it (166).
  • Temperature 0, thinking off.
  • One run per row. Identical runs here differ by about +/-5%, so read the speeds with that in mind; the VRAM and CPU columns move far more than that.

9 GPUs (RTX 3090 + 8x RTX 5060 Ti, 64K context, MTP on)

Start Decode, mean of 5 Routes served from VRAM Experts a token on the CPU 9.9K prompt Drafts accepted
No profile (expert order) 35.4 tok/s 83-90% 36-65 561 tok/s 90.9%
Earlier profile 37.5 tok/s 91.5-94.6% 18-28 731 tok/s 91.1%
This machine's own expert_usage.txt (today's default, through STRATA_GLM_USAGE) 39.1 tok/s 85-94% 21-51 639 tok/s 92.1%
This profile 40.7 tok/s 91.9-96.8% 11-29 700 tok/s 90.1%

One RTX 3090 (32K context, rebased build)

Start Decode, mean of 5 Routes served from VRAM Experts a token on the CPU 11K prompt
Earlier profile 15.3 tok/s 19.9-29.4% 235-251 407 tok/s
This profile 15.0 tok/s 25.0-29.3% (first request 25.9% vs 19.9%) 231-246 407 tok/s

On one GPU the two profiles tie: a 3090 holds 1,340 of Maya-L's 12,096 routed experts, and both profiles rank those first about equally well.

Without a GPU: the share of routes a start's VRAM serves

Held-out estimate: a profile built from one half of the trace, scored on the other half's routes, at the VRAM budget of each card. This is static: it ignores the live tier's promotions. The range covers both directions.

Ranking 16 GB card (~600 experts) One 24 GB card (~1,000) 24 + 16 GB (~2,200) 9 GPUs (11,144)
No profile 4.9-5.0% 7.9-8.0% 17.6% 89.9-90.1%
A usage file from one machine's own use 4.6-5.1% 7.7-8.2% 18.7-19.1% 94.3-94.5%
Earlier profile 11.4-12.9% 16.9-18.6% 30.8-32.9% 96.6-96.7%
This profile (half the data) 12.3-12.7% 18.1-18.6% 32.4-33.1% 96.8-96.9%
Best possible (the test half's own counts, one direction) 13.7% 20.1% 35.4% 97.8%
  • Small cards: a profile matters most here. A fresh 16-24 GB card serves about twice the routes from VRAM with one as without.
  • Learned usage: one machine's learned usage barely beats expert order for other workloads, so the shipped default is a profile rather than anyone's usage.

Tests

  • tests/core/expert_profile_save_test: rank_learned_profile's order and write_expert_profile's file, read back.
  • tests/core/expert_profile_version_test: a version other than 1 is refused.
  • tools/test_make_profile.py, including --glm and the text records.
  • tools/test_maya_profile.py: the shipped profile in a new config, a hand-wired profile and --expert-profile-save kept by a later setup, an older config gaining the profile at its next start.
  • tools/test_calibrate_glm.py: the usage copy only when opted in; the calibration's engine without the arguments that write files.
  • All of tools/ (201 tests) and serve/ (130) pass; CUDA build for sm_86 + sm_120.

🔄 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/mw00/project-maya/pull/88 **Author:** [@needmorevram](https://github.com/needmorevram) **Created:** 10/10/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `glm-expert-profile` --- ### 📝 Commits (2) - [`5070eba`](https://github.com/mw00/project-maya/commit/5070ebad995a7a56671a0c1c31267f0fe8602f5e) The expert profile as Strata has it, for GLM packs: --expert-profile decides each layer's VRAM slots and what a start loads first, --expert-profile-save learns across starts when asked; the usage file is opt-in (9 GPUs, a fresh start: decode 35.4 -> 40.7 tok/s) - [`342fc04`](https://github.com/mw00/project-maya/commit/342fc045d4cfa567591cd68b3a1c9ea86f5bcefd) The draft layer keeps at least the per-layer equal share of its card's slots, whatever the expert profile ranks it ### 📊 Changes **20 files changed** (+959 additions, -103 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+11 -0) ➕ `data/expert-profile-glm.bin` (+0 -0) 📝 `docs/SETTINGS.md` (+28 -7) 📝 `include/strata/core/expert_cache.hpp` (+19 -0) 📝 `include/strata/core/glm_model.hpp` (+18 -1) 📝 `maya.py` (+41 -1) 📝 `src/core/expert_cache.cpp` (+87 -2) 📝 `src/core/glm_fast_path.cu` (+113 -19) 📝 `src/core/glm_fast_state.hpp` (+10 -0) 📝 `src/core/glm_model.cu` (+6 -6) 📝 `src/core/glm_prefill.cu` (+8 -0) 📝 `src/program/generate.cpp` (+38 -1) ➕ `tests/core/expert_profile_save_test.cpp` (+80 -0) ➕ `tests/core/expert_profile_version_test.cpp` (+73 -0) 📝 `tools/calibrate_glm.py` (+29 -14) 📝 `tools/glm_expert_prior.py` (+5 -4) 📝 `tools/make_profile.py` (+120 -36) 📝 `tools/test_calibrate_glm.py` (+17 -12) ➕ `tools/test_make_profile.py` (+145 -0) ➕ `tools/test_maya_profile.py` (+111 -0) </details> ### 📄 Description ## Summary GLM packs get Strata's expert profile, the way Strata's own setup uses it: 1. **`--expert-profile FILE`** decides which experts a start puts in VRAM and how many VRAM slots each layer gets. Setup passes the shipped `data/expert-profile-glm.bin` to every config. 2. **Learning across starts is opt-in.** `--expert-profile-save FILE` saves what the expert tiers learned. `STRATA_GLM_USAGE` (the usage file read at start and written after every request) no longer has a default. 3. **A new shipped profile**, built from a Maya-L routing trace with the MTP draft block running, so the draft layer is ranked by its real use. On 9 GPUs a fresh start decodes **35.4 -> 40.7 tok/s** (no profile -> this one). On one RTX 3090 the new profile ties the earlier one. ## What changes **Engine (`--glm-pack`)** | Argument | What it does | |---|---| | `--expert-profile FILE` | Strata's STRP profile (46 layers x 288 experts). Its ranking of every (layer, expert) pair gives each layer its VRAM slots (a floor each, then the next slot to the layer whose next expert ranks highest) and the warm-up its order. It replaces the pack's `expert_counts.txt` / `expert_prior.txt`; without a profile the engine reads those as before. | | `--expert-profile-save FILE` | Writes the experts in VRAM, then the routes counted this run, then the starting profile. Saved every `--expert-profile-save-every MIN` minutes (default 10) between requests and at QUIT, through a `.tmp` and a rename. | | `--dump-routing FILE` | Every route, from prompts and answers, as a routing trace (int32 layer, int32 k, k ids, k weights). | - **`STRATA_GLM_USAGE`** is opt-in: unset (or `0`), no usage file is read or written. The split search reads the same setting. `STRATA_GLM_USAGE=<pack>/expert_usage.txt` gives the old behaviour back. - **Reader and writer:** `read_expert_profile` now refuses a profile version other than 1 by its number. `rank_learned_profile` and `write_expert_profile` are added for the save. - **Splits:** every part reads the same profile. The saved profile takes each part's resident experts and route counts. **Setup (`maya.py`)** - Every GLM config gets `--expert-profile data/expert-profile-glm.bin`. - A profile wired in by hand is kept by a later setup, but only if it is a different file that still exists. Otherwise the shipped one comes back. `--expert-profile-save` and `--expert-profile-save-every` are kept too. - **Existing installs:** an update restarts the installed config without a setup. A GLM config with no `--expert-profile` therefore gets the shipped one at its next start and is saved back once (`starts from the shipped expert profile now`). An update needs nothing else. **Calibration (`tools/calibrate_glm.py`)** - Its engine runs without `--expert-profile-save` / `--dump-routing`, so tuning prompts never reach a learned profile or a trace. - It copies a usage file only when the config sets `STRATA_GLM_USAGE`. **Tools** - `tools/make_profile.py --glm`: 46 x 288 layout. It reads `--dump-routing` traces and the engine's text records (usage files, `expert_counts.txt`, `STRATA_GLM_TRACE` lines). - `--reorder`: traces before the base. - `--equal`: each input scaled to one total. - A trace record cut short at the end of the file is skipped. ## The shipped profile `tools/make_profile.py --glm --no-base` over one `--dump-routing` trace: - **Model and hardware:** Maya-L on 9 GPUs with MTP drafting on. Routing is the router's, so the trace serves every quant of GLM-5.3-Flash and every GPU count. - **Requests:** 66 of them, with thinking on and off: - code in several languages, math with thinking, explanations and chat; - French, Spanish, Chinese, German, Japanese, Russian, Portuguese and Arabic; - JSON and tool calls; - 8 long documents (1-4K tokens each). - **Size:** 25.7K prompt tokens and 25.6K generated tokens, 2.28 M routes. Every one of the 12,384 routed (layer, expert) pairs was seen. - **Draft layer:** it routes only while drafting, so it has about half a decoder layer's routes. - In the earlier profile (built on a quant without a draft block) it ranked last. On a split it got only the floor of VRAM slots (60, against 206 for the other layers on the last 5060 Ti here), filled in expert order. - Now it is ranked by use. In the held-out estimate below, its experts in VRAM on a 9-GPU split cover 84% of its routes, against 3% with the earlier profile. - **Single GPU:** the draft block is loaded only on a split, so on one GPU those entries are ignored. - **No overlap:** none of the benchmark's prompts or topics are in the trace. ## Benchmarks **Setup:** Maya-L (156 GB), 2x Xeon Gold 6152 (88 vCPUs), 177 GB RAM. **Method:** - A fresh start each row, the usage file off (unless the row says otherwise). The 9-GPU rows ran this branch on v1.0.29, the 3090 rows the rebased branch on v1.0.31; within each table the build is the same. - Five requests: a warm-up, code (256 tokens), French (256), a 9.9K-token document question (128), and math right after it (166). - Temperature 0, thinking off. - One run per row. Identical runs here differ by about +/-5%, so read the speeds with that in mind; the VRAM and CPU columns move far more than that. ### 9 GPUs (RTX 3090 + 8x RTX 5060 Ti, 64K context, MTP on) | Start | Decode, mean of 5 | Routes served from VRAM | Experts a token on the CPU | 9.9K prompt | Drafts accepted | |---|---|---|---|---|---| | No profile (expert order) | 35.4 tok/s | 83-90% | 36-65 | 561 tok/s | 90.9% | | Earlier profile | 37.5 tok/s | 91.5-94.6% | 18-28 | 731 tok/s | 91.1% | | This machine's own `expert_usage.txt` (today's default, through `STRATA_GLM_USAGE`) | 39.1 tok/s | 85-94% | 21-51 | 639 tok/s | 92.1% | | **This profile** | **40.7 tok/s** | **91.9-96.8%** | **11-29** | 700 tok/s | 90.1% | ### One RTX 3090 (32K context, rebased build) | Start | Decode, mean of 5 | Routes served from VRAM | Experts a token on the CPU | 11K prompt | |---|---|---|---|---| | Earlier profile | 15.3 tok/s | 19.9-29.4% | 235-251 | 407 tok/s | | **This profile** | 15.0 tok/s | **25.0-29.3%** (first request 25.9% vs 19.9%) | 231-246 | 407 tok/s | On one GPU the two profiles tie: a 3090 holds 1,340 of Maya-L's 12,096 routed experts, and both profiles rank those first about equally well. ### Without a GPU: the share of routes a start's VRAM serves Held-out estimate: a profile built from one half of the trace, scored on the other half's routes, at the VRAM budget of each card. This is static: it ignores the live tier's promotions. The range covers both directions. | Ranking | 16 GB card (~600 experts) | One 24 GB card (~1,000) | 24 + 16 GB (~2,200) | 9 GPUs (11,144) | |---|---|---|---|---| | No profile | 4.9-5.0% | 7.9-8.0% | 17.6% | 89.9-90.1% | | A usage file from one machine's own use | 4.6-5.1% | 7.7-8.2% | 18.7-19.1% | 94.3-94.5% | | Earlier profile | 11.4-12.9% | 16.9-18.6% | 30.8-32.9% | 96.6-96.7% | | This profile (half the data) | 12.3-12.7% | 18.1-18.6% | 32.4-33.1% | 96.8-96.9% | | Best possible (the test half's own counts, one direction) | 13.7% | 20.1% | 35.4% | 97.8% | - **Small cards:** a profile matters most here. A fresh 16-24 GB card serves about twice the routes from VRAM with one as without. - **Learned usage:** one machine's learned usage barely beats expert order for other workloads, so the shipped default is a profile rather than anyone's usage. ## Tests - `tests/core/expert_profile_save_test`: `rank_learned_profile`'s order and `write_expert_profile`'s file, read back. - `tests/core/expert_profile_version_test`: a version other than 1 is refused. - `tools/test_make_profile.py`, including `--glm` and the text records. - `tools/test_maya_profile.py`: the shipped profile in a new config, a hand-wired profile and `--expert-profile-save` kept by a later setup, an older config gaining the profile at its next start. - `tools/test_calibrate_glm.py`: the usage copy only when opted in; the calibration's engine without the arguments that write files. - All of `tools/` (201 tests) and `serve/` (130) pass; CUDA build for sm_86 + sm_120. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:24:13 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#326
No description provided.