[PR #325] [CLOSED] GLM batched rows: each routed expert once per group and no empty launches, opt-in (MAYA_GLM_GROUP_EXPERTS, MAYA_GLM_SKIP_EMPTY) #468

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/325
Author: @somnergy
Created: 10/20/2026
Status: ❌ Closed

Base: main ← Head: pr/group-experts-skip-empty


📝 Commits (2)

  • 301c3ae GLM batched rows: leave out empty wait / fetch / CPU-lane launches (STRATA_GLM_SKIP_EMPTY, off by default)
  • 8d56b70 GLM batched rows: each routed expert once for all the rows of a group (STRATA_GLM_GROUP_EXPERTS, off by default)

📊 Changes

12 files changed (+785 additions, -47 deletions)

View changed files

📝 CMakeLists.txt (+8 -0)
📝 docs/SETTINGS.md (+2 -0)
📝 include/strata/core/glm_model.hpp (+11 -1)
📝 include/strata/kernels/glm_fast.hpp (+14 -1)
📝 src/core/glm_fast_path.cu (+113 -36)
📝 src/core/glm_fast_state.hpp (+19 -0)
📝 src/core/glm_memory.hpp (+16 -0)
📝 src/core/glm_multi.cu (+1 -2)
📝 src/core/glm_rows.cu (+168 -3)
📝 src/kernels/cuda/glm_fast.cu (+105 -2)
📝 src/program/generate.cpp (+1 -2)
➕ tests/glm_moe_rows_test.cu (+327 -0)

📄 Description

What

Two opt-in settings for the batched decode step (--parallel on one GPU, or a split with MAYA_GLM_SPLIT_ROWS), both off by default. They change which launches run and how the MoE work of a step's rows is arranged, not the arithmetic of a row.

MAYA_GLM_SKIP_EMPTY=1 (STRATA_GLM_SKIP_EMPTY). The rows path launches moe_wait, moe_fetch and moe_cpu_wait for every row and MoE layer, although the route that decides whether they have work runs on the device. With the setting:

  • check_resident also keeps a per-layer flag (every expert of the layer in VRAM as of the last tier update; between updates VRAM only gains), and the rows of such a layer leave all three out - what MAYA_GLM_RESIDENT_SKIP does for the whole model on the token path;
  • elsewhere the wait and the fetch are one launch (moe_wait_fetch: block 0 waits for the host's answer to a disk miss and hands the fetch sources to the other blocks through device memory, then every block copies its share).
    The single-request token path is unchanged (its launches are part of its graphs' key). The CPU-expert deferral (moe_defer_wait_) keeps its own condition on the CPU-lane wait.

MAYA_GLM_GROUP_EXPERTS=1 (STRATA_GLM_GROUP_EXPERTS). In a batched step only the dense weights were shared: each row ran its whole MoE chain alone, so an expert two rows routed was read twice, and each row's CPU-lane experts were a request of their own. With the setting a step's MoE layer runs the way the verify window's batched MoE runs a window's tokens:

  • every row is routed first (fast_moe_route, factored out of fast_moe_experts) into the window's per-token route state, each row's wait and fetch before the next row's route;
  • each row has its own 8 scratch slots (rows_scr, allocated with the window's buffers before the expert pool is sized), so a scratch clash never needs a redo;
  • the shared expert's down rows of all rows are one mv_nt, then each distinct routed expert runs once for the rows that chose it (moe_win_experts, exl3::win_experts), then the rows' CPU-lane answers in one launch (moe_cpu_wait_rows);
  • the service thread holds a group's routes (MoeRequest::win_rows) and answers their CPU-lane experts as one merged request on the part's own CPU pool.

The grouped path keeps its own error string, fails loudly rather than drop the rows' CPU-lane answers past kMaxMvNt rows, and says once in the log when the setting is on but a group runs its experts row by row (no window buffers). Glm5Model::split_rows_setting() is now the one parse of STRATA_GLM_SPLIT_ROWS (the scheduler, seq_alloc_arenas and the grouped rows' scratch sizing all use it; the same atof + clamp to 0..rows_max() the scheduler had).

Cost: 8 scratch expert slots for each extra row of a group (k - 1 rows on a split, --parallel - 1 on one GPU) and the verify window's buffers, taken from VRAM before the pool is sized.

tests/glm_moe_rows_test.cu (GPU, no model) checks the grouped experts, the fused wait / fetch and the rows' CPU-lane waits against the per-row kernels bit for bit, on random Q8_0 experts. Without a GPU it prints "no GPU, skipped".

How to enable

MAYA_GLM_GROUP_EXPERTS=1 and / or MAYA_GLM_SKIP_EMPTY=1, with --parallel > 1 (and MAYA_GLM_SPLIT_ROWS on a split). Rows in docs/SETTINGS.md.

How it was verified

The setup: 2x RTX PRO 5000 Blackwell 72 GB, GLM-5.3-Flash EXL3 3.1 bpw (every expert in VRAM), split rows 4, --parallel 8 at 512K, KV streaming (window 196608), int8 KV, greedy. main and this branch were built the same way with nvcc 13.4.

  • CI checks: the HIP-name check, the server tests and the installer and tools tests pass.
  • glm_moe_rows_test on the GPU: ok (bit for bit against the per-row kernels).
  • C++ tests on the GPU: the same pass/fail set as main (54/60 vs 53/59; the 6 failures are missing data files and an mlock limit on both).
  • Exactness: a workload where 4 greedy decoders run while a ~90K-token prompt is read gave identical text in three cases: main, this branch with both settings off, and this branch with both on. The workload also has a cancelled read, a client that disconnects mid-read and a queued request. The start logged the grouped buffers on both GPUs, and no group fell back to row by row.
  • Before / after: aggregate decode while N streams of ~126K-token prompts decode at once, both settings on:
streams main this branch, both on
8 131.6 tok/s 149.0 tok/s (+13.2%)
4 73.2 tok/s 79.7 tok/s (+8.9%)
2 64.9 tok/s 66.2 tok/s (+2.0%)

The 8-stream aggregate of builds at main's behaviour varied 131.4-131.8 tok/s across five runs. VRAM before the pool: +0.32 GB on the first GPU and +0.27 GB on the second (the scratch slots and route state).

The run did not cover RAM-tier experts (the CPU lane and PCIe fetches inside a batched step); the kernels of that path are what glm_moe_rows_test checks. I didn't use the greedy texts of the 8 x ~126K workload as an identity check, because two fresh starts of main alone already differ on 3 of 8 streams there (the read order of 8 simultaneous requests varies). Details are in the validation summary that follows in a comment.


🔄 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/325 **Author:** [@somnergy](https://github.com/somnergy) **Created:** 10/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/group-experts-skip-empty` --- ### 📝 Commits (2) - [`301c3ae`](https://github.com/mw00/project-maya/commit/301c3aefea4d4b7055464adb2128255899629a6b) GLM batched rows: leave out empty wait / fetch / CPU-lane launches (STRATA_GLM_SKIP_EMPTY, off by default) - [`8d56b70`](https://github.com/mw00/project-maya/commit/8d56b70871724bb4fdbbe3add8815390a4eae887) GLM batched rows: each routed expert once for all the rows of a group (STRATA_GLM_GROUP_EXPERTS, off by default) ### 📊 Changes **12 files changed** (+785 additions, -47 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+8 -0) 📝 `docs/SETTINGS.md` (+2 -0) 📝 `include/strata/core/glm_model.hpp` (+11 -1) 📝 `include/strata/kernels/glm_fast.hpp` (+14 -1) 📝 `src/core/glm_fast_path.cu` (+113 -36) 📝 `src/core/glm_fast_state.hpp` (+19 -0) 📝 `src/core/glm_memory.hpp` (+16 -0) 📝 `src/core/glm_multi.cu` (+1 -2) 📝 `src/core/glm_rows.cu` (+168 -3) 📝 `src/kernels/cuda/glm_fast.cu` (+105 -2) 📝 `src/program/generate.cpp` (+1 -2) ➕ `tests/glm_moe_rows_test.cu` (+327 -0) </details> ### 📄 Description ## What Two opt-in settings for the batched decode step (`--parallel` on one GPU, or a split with `MAYA_GLM_SPLIT_ROWS`), both off by default. They change which launches run and how the MoE work of a step's rows is arranged, not the arithmetic of a row. **`MAYA_GLM_SKIP_EMPTY=1`** (`STRATA_GLM_SKIP_EMPTY`). The rows path launches `moe_wait`, `moe_fetch` and `moe_cpu_wait` for every row and MoE layer, although the route that decides whether they have work runs on the device. With the setting: - `check_resident` also keeps a per-layer flag (every expert of the layer in VRAM as of the last tier update; between updates VRAM only gains), and the rows of such a layer leave all three out - what `MAYA_GLM_RESIDENT_SKIP` does for the whole model on the token path; - elsewhere the wait and the fetch are one launch (`moe_wait_fetch`: block 0 waits for the host's answer to a disk miss and hands the fetch sources to the other blocks through device memory, then every block copies its share). The single-request token path is unchanged (its launches are part of its graphs' key). The CPU-expert deferral (`moe_defer_wait_`) keeps its own condition on the CPU-lane wait. **`MAYA_GLM_GROUP_EXPERTS=1`** (`STRATA_GLM_GROUP_EXPERTS`). In a batched step only the dense weights were shared: each row ran its whole MoE chain alone, so an expert two rows routed was read twice, and each row's CPU-lane experts were a request of their own. With the setting a step's MoE layer runs the way the verify window's batched MoE runs a window's tokens: - every row is routed first (`fast_moe_route`, factored out of `fast_moe_experts`) into the window's per-token route state, each row's wait and fetch before the next row's route; - each row has its own 8 scratch slots (`rows_scr`, allocated with the window's buffers before the expert pool is sized), so a scratch clash never needs a redo; - the shared expert's down rows of all rows are one `mv_nt`, then each distinct routed expert runs once for the rows that chose it (`moe_win_experts`, `exl3::win_experts`), then the rows' CPU-lane answers in one launch (`moe_cpu_wait_rows`); - the service thread holds a group's routes (`MoeRequest::win_rows`) and answers their CPU-lane experts as one merged request on the part's own CPU pool. The grouped path keeps its own error string, fails loudly rather than drop the rows' CPU-lane answers past `kMaxMvNt` rows, and says once in the log when the setting is on but a group runs its experts row by row (no window buffers). `Glm5Model::split_rows_setting()` is now the one parse of `STRATA_GLM_SPLIT_ROWS` (the scheduler, `seq_alloc_arenas` and the grouped rows' scratch sizing all use it; the same atof + clamp to 0..rows_max() the scheduler had). Cost: 8 scratch expert slots for each extra row of a group (k - 1 rows on a split, `--parallel` - 1 on one GPU) and the verify window's buffers, taken from VRAM before the pool is sized. `tests/glm_moe_rows_test.cu` (GPU, no model) checks the grouped experts, the fused wait / fetch and the rows' CPU-lane waits against the per-row kernels bit for bit, on random Q8_0 experts. Without a GPU it prints "no GPU, skipped". ## How to enable `MAYA_GLM_GROUP_EXPERTS=1` and / or `MAYA_GLM_SKIP_EMPTY=1`, with `--parallel` > 1 (and `MAYA_GLM_SPLIT_ROWS` on a split). Rows in `docs/SETTINGS.md`. ## How it was verified The setup: 2x RTX PRO 5000 Blackwell 72 GB, GLM-5.3-Flash EXL3 3.1 bpw (every expert in VRAM), split rows 4, `--parallel 8` at 512K, KV streaming (window 196608), int8 KV, greedy. `main` and this branch were built the same way with nvcc 13.4. - **CI checks:** the HIP-name check, the server tests and the installer and tools tests pass. - **`glm_moe_rows_test` on the GPU:** ok (bit for bit against the per-row kernels). - **C++ tests on the GPU:** the same pass/fail set as main (54/60 vs 53/59; the 6 failures are missing data files and an mlock limit on both). - **Exactness:** a workload where 4 greedy decoders run while a ~90K-token prompt is read gave identical text in three cases: main, this branch with both settings off, and this branch with both on. The workload also has a cancelled read, a client that disconnects mid-read and a queued request. The start logged the grouped buffers on both GPUs, and no group fell back to row by row. - **Before / after:** aggregate decode while N streams of ~126K-token prompts decode at once, both settings on: | streams | main | this branch, both on | |---|---|---| | 8 | 131.6 tok/s | 149.0 tok/s (+13.2%) | | 4 | 73.2 tok/s | 79.7 tok/s (+8.9%) | | 2 | 64.9 tok/s | 66.2 tok/s (+2.0%) | The 8-stream aggregate of builds at main's behaviour varied 131.4-131.8 tok/s across five runs. VRAM before the pool: +0.32 GB on the first GPU and +0.27 GB on the second (the scratch slots and route state). The run did not cover RAM-tier experts (the CPU lane and PCIe fetches inside a batched step); the kernels of that path are what `glm_moe_rows_test` checks. I didn't use the greedy texts of the 8 x ~126K workload as an identity check, because two fresh starts of main alone already differ on 3 of 8 streams there (the read order of 8 simultaneous requests varies). Details are in the validation summary that follows in a comment. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:46 +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#468
No description provided.