[PR #391] [MERGED] GLM batched decode: the rows' DSA attention, selections, scores and KV resolves in one launch, opt-in (MAYA_GLM_ROWS_ATTN, MAYA_GLM_ROWS_SMALL) #510

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/391
Author: @somnergy
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @mw00

Base: main ← Head: pr/glm-rows-attn


📝 Commits (9)

  • 6e56c54 GLM batched rows: the rows' mHC and KDA recurrence in one launch each, opt-in (MAYA_GLM_ROWS_BATCH)
  • 0d7e87f GLM batched rows: mv_nt past 8 activations in groups of 8; a gather kernel for a window's KDA inputs
  • 61b7264 GLM several conversations: MTP drafting in the batched steps, opt-in (MAYA_GLM_MULTI_MTP)
  • 2973a1a GLM batched decode: the rows' DSA attention in one launch, opt-in (MAYA_GLM_ROWS_ATTN)
  • 2d2d6dd GLM batched decode: the rows' indexer selections in one launch with MAYA_GLM_ROWS_ATTN
  • b017368 GLM batched decode: a verify window's rows on a streamed layer in the rows' attention
  • 966a67b GLM batched decode: the rows' indexer scores, KV resolves and expert grouping in fewer launches, opt-in (MAYA_GLM_ROWS_SMALL)
  • 561ddec glm_rows_attn_test: check the rows' KV resolves by what the attention reads
  • df0f599 Merge main into pr/glm-rows-attn (the PRs merged before it, side by side: test lists, settings rows, includes, the prompt read's loop)

📊 Changes

20 files changed (+3279 additions, -192 deletions)

View changed files

📝 CMakeLists.txt (+16 -2)
📝 docs/SETTINGS.md (+7 -0)
📝 include/strata/core/glm_model.hpp (+59 -3)
➕ include/strata/core/mtp_rows.hpp (+73 -0)
📝 include/strata/kernels/glm_fast.hpp (+59 -7)
📝 include/strata/kernels/glm_kv_stream.hpp (+14 -0)
📝 src/core/glm_fast_path.cu (+27 -5)
📝 src/core/glm_fast_state.hpp (+7 -2)
📝 src/core/glm_model.cu (+3 -1)
📝 src/core/glm_mtp.cu (+7 -5)
➕ src/core/glm_mtp_rows.cu (+889 -0)
📝 src/core/glm_multi.cu (+2 -0)
📝 src/core/glm_rows.cu (+370 -141)
➕ src/core/glm_rows_state.hpp (+76 -0)
📝 src/kernels/cuda/glm_fast.cu (+271 -18)
📝 src/kernels/cuda/glm_kv_stream.cu (+33 -1)
📝 src/program/generate.cpp (+312 -7)
➕ tests/core/mtp_rows_test.cpp (+130 -0)
➕ tests/glm_rows_attn_test.cu (+610 -0)
➕ tests/glm_rows_kernels_test.cu (+314 -0)

📄 Description

Depends on #385 (multi-request MTP): this branch is built on it, so the diff here includes #385's commits until it merges; the commits of this PR are the last 5.

Summary

In a batched decode step a DSA layer ran the absorbed attention once a row: one row's split attention fills only 64 thread blocks, so a launch a row leaves much of a large card idle. Two opt-in settings put the rows of a step together, each row running the per-row kernel's own device code, so the output is bitwise the same:

  • MAYA_GLM_ROWS_ATTN=1: the DSA attention of all the rows in one launch (gf::mla_attend_rows; a token of mla_split_mma_kernel may name its own latents and cells), the query and output projections of all rows at once, and the rows' indexer selections in one launch. With KV streaming, a run of one conversation's consecutive rows (an MTP verify window) resolves its selections in one call, so window groups take the batched path too.
  • MAYA_GLM_ROWS_SMALL=1: the rows' indexer scores, KV-streaming resolves and routed-expert grouping in one launch each.

With them off nothing new is allocated. ROWS_ATTN takes 28 MB a GPU and needs the tensor-core attention (compute capability 8.0+, kv_lora 512); elsewhere the rows run one by one as before.

Why

Measured under several concurrent Claude Code sessions (agentic coding: long multi-turn conversations, subagents, tool calls, auto-mode safety checks) through the Anthropic Messages API with --parallel 8:

  • 8 conversations decode at once most of the time. A kernel profile of that decode showed both GPUs kernel-bound (97% / 90% busy), not waiting on each other, but 41% of the kernel time in per-row kernels that use a few SMs; the DSA attention alone 26-29%.
  • Faster decode at 8 running is what drains the queue: with this and the related changes the same workload served 42% more requests an hour (598 vs 420) and the median request was 2.2x faster (13.5 vs 29.5 s), 0 engine errors - a combined effect (with system-prompt reuse, short-read chunking, the EXL3 switch and a larger conversation store); this PR's own share is the A/B below.

Measured

Hardware: 2x NVIDIA RTX PRO 5000 Blackwell 72 GB, each on PCIe 5.0 x8 from its own CPU root port (no fast P2P); Intel Core Ultra 9 285K (8 P + 16 E cores); 96 GB DDR5; driver 615.71.09, CUDA 13.4. Model: GLM-5.3-Flash EXL3 sc 3.10 bpw, every expert in VRAM; split rows 4. 8 conversations of ~33K tokens (then 4), three 5-s windows each, aggregate decode tok/s:

running off ROWS_ATTN=1 + ROWS_SMALL=1
8 178.4 / 179.2 / 178.4 233.6 / 234.4 / 233.6 (+31%) 240.8 / 240.8 / 240.0 (+2.9% more)
4, MTP windows (1 draft) 179.0 / 178.0 / 179.2 225.8 / 225.6 / 222.0 (+25%) 232.2 / 230.4 / 226.6 (+2.6% more)

Per 4-row step on the first GPU: 22.2 -> 17.1 -> 16.7 ms. Caveats: repetitive synthetic text and 33K contexts (live: 40-190K); the expert grouping was timed before upstream's change to moe_win_group_kernel, so ROWS_SMALL's grouping share is likely smaller on main. With Maya-L (~85% of experts in VRAM, same box) both ran live ~6 h, 0 engine errors; no A/B there.

Recommendation

With 3 or more requests decoding on a compute capability 8.0+ GPU, set MAYA_GLM_ROWS_ATTN=1 and MAYA_GLM_ROWS_SMALL=1: same output, a faster step. They do nothing in single-row groups (2 running without MTP windows, or the lone row of a 2 + 1 split) and below compute capability 8.0. With experts partly in RAM the step is dominated by waits for RAM-tier experts, so expect less; streamed from RAM and one GPU were not measured.

Exactness

Bitwise. tests/glm_rows_attn_test.cu (GPU, no model, 828 cases) compares each row's attention with mla() per row byte for byte (2-16 rows, contexts up to ~60K, resident and KV-streamed caches including verify-window rows, FP16 and INT8 latents), and the selections, scores, KV resolves and expert grouping with the per-row and one-thread kernels. Greedy, off vs on, 300 tokens: 12 of 12 identical for each setting.

How it was verified

  • On v1.1.23 (this branch), on the box above: glm_rows_attn_test (828 cases), glm_rows_kernels_test, glm_mv_nt_test, glm_moe_rows_test and the glm_*_parity --selftest tests pass, as on main; every commit builds (nvcc 13.4, sm_75 and sm_120); tools/check_hip_compat.py is clean.
  • The rates, the kernel profile and the greedy identity: these commits on v1.1.21; then ~2.5 h live with EXL3 and ~6 h with Maya-L, 0 engine errors.
  • Not batched on purpose: moe_route (each row's route claims spare expert slots that the next row sees; one launch would change the tiers' behaviour).

🔄 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/391 **Author:** [@somnergy](https://github.com/somnergy) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr/glm-rows-attn` --- ### 📝 Commits (9) - [`6e56c54`](https://github.com/mw00/project-maya/commit/6e56c5468d0dfab123ff1cdb88d627e3ecac7a2b) GLM batched rows: the rows' mHC and KDA recurrence in one launch each, opt-in (MAYA_GLM_ROWS_BATCH) - [`0d7e87f`](https://github.com/mw00/project-maya/commit/0d7e87f917e09855c51472f02c36ba35f1ea1767) GLM batched rows: mv_nt past 8 activations in groups of 8; a gather kernel for a window's KDA inputs - [`61b7264`](https://github.com/mw00/project-maya/commit/61b7264c547a0b7be66a5f6bc276c9cd553e4be0) GLM several conversations: MTP drafting in the batched steps, opt-in (MAYA_GLM_MULTI_MTP) - [`2973a1a`](https://github.com/mw00/project-maya/commit/2973a1a50f7d11c5e623d9085311f20cd36ebea8) GLM batched decode: the rows' DSA attention in one launch, opt-in (MAYA_GLM_ROWS_ATTN) - [`2d2d6dd`](https://github.com/mw00/project-maya/commit/2d2d6dd740a7999d80f9b1877cda53460ec1332b) GLM batched decode: the rows' indexer selections in one launch with MAYA_GLM_ROWS_ATTN - [`b017368`](https://github.com/mw00/project-maya/commit/b0173684097357f61bbc0a3f67be5c8ec227435d) GLM batched decode: a verify window's rows on a streamed layer in the rows' attention - [`966a67b`](https://github.com/mw00/project-maya/commit/966a67b9308efe756b47d99cf99fb662c0299404) GLM batched decode: the rows' indexer scores, KV resolves and expert grouping in fewer launches, opt-in (MAYA_GLM_ROWS_SMALL) - [`561ddec`](https://github.com/mw00/project-maya/commit/561ddeccc4d5743999e88735eb8f6e0cfb6182d6) glm_rows_attn_test: check the rows' KV resolves by what the attention reads - [`df0f599`](https://github.com/mw00/project-maya/commit/df0f599958283f2b9bf3ee5d7532fdc2e374aae2) Merge main into pr/glm-rows-attn (the PRs merged before it, side by side: test lists, settings rows, includes, the prompt read's loop) ### 📊 Changes **20 files changed** (+3279 additions, -192 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+16 -2) 📝 `docs/SETTINGS.md` (+7 -0) 📝 `include/strata/core/glm_model.hpp` (+59 -3) ➕ `include/strata/core/mtp_rows.hpp` (+73 -0) 📝 `include/strata/kernels/glm_fast.hpp` (+59 -7) 📝 `include/strata/kernels/glm_kv_stream.hpp` (+14 -0) 📝 `src/core/glm_fast_path.cu` (+27 -5) 📝 `src/core/glm_fast_state.hpp` (+7 -2) 📝 `src/core/glm_model.cu` (+3 -1) 📝 `src/core/glm_mtp.cu` (+7 -5) ➕ `src/core/glm_mtp_rows.cu` (+889 -0) 📝 `src/core/glm_multi.cu` (+2 -0) 📝 `src/core/glm_rows.cu` (+370 -141) ➕ `src/core/glm_rows_state.hpp` (+76 -0) 📝 `src/kernels/cuda/glm_fast.cu` (+271 -18) 📝 `src/kernels/cuda/glm_kv_stream.cu` (+33 -1) 📝 `src/program/generate.cpp` (+312 -7) ➕ `tests/core/mtp_rows_test.cpp` (+130 -0) ➕ `tests/glm_rows_attn_test.cu` (+610 -0) ➕ `tests/glm_rows_kernels_test.cu` (+314 -0) </details> ### 📄 Description **Depends on #385** (multi-request MTP): this branch is built on it, so the diff here includes #385's commits until it merges; the commits of this PR are the last 5. ## Summary In a batched decode step a DSA layer ran the absorbed attention once a row: one row's split attention fills only 64 thread blocks, so a launch a row leaves much of a large card idle. Two opt-in settings put the rows of a step together, each row running the per-row kernel's own device code, so the output is bitwise the same: - **`MAYA_GLM_ROWS_ATTN=1`**: the DSA attention of all the rows in one launch (`gf::mla_attend_rows`; a token of `mla_split_mma_kernel` may name its own latents and cells), the query and output projections of all rows at once, and the rows' indexer selections in one launch. With KV streaming, a run of one conversation's consecutive rows (an MTP verify window) resolves its selections in one call, so window groups take the batched path too. - **`MAYA_GLM_ROWS_SMALL=1`**: the rows' indexer scores, KV-streaming resolves and routed-expert grouping in one launch each. With them off nothing new is allocated. `ROWS_ATTN` takes 28 MB a GPU and needs the tensor-core attention (compute capability 8.0+, kv_lora 512); elsewhere the rows run one by one as before. ## Why Measured under several concurrent Claude Code sessions (agentic coding: long multi-turn conversations, subagents, tool calls, auto-mode safety checks) through the Anthropic Messages API with `--parallel 8`: - 8 conversations decode at once most of the time. A kernel profile of that decode showed both GPUs kernel-bound (97% / 90% busy), not waiting on each other, but 41% of the kernel time in per-row kernels that use a few SMs; the DSA attention alone 26-29%. - Faster decode at 8 running is what drains the queue: with this and the related changes the same workload served 42% more requests an hour (598 vs 420) and the median request was 2.2x faster (13.5 vs 29.5 s), 0 engine errors - a combined effect (with system-prompt reuse, short-read chunking, the EXL3 switch and a larger conversation store); this PR's own share is the A/B below. ## Measured Hardware: 2x NVIDIA RTX PRO 5000 Blackwell 72 GB, each on PCIe 5.0 x8 from its own CPU root port (no fast P2P); Intel Core Ultra 9 285K (8 P + 16 E cores); 96 GB DDR5; driver 615.71.09, CUDA 13.4. Model: GLM-5.3-Flash EXL3 sc 3.10 bpw, every expert in VRAM; split rows 4. 8 conversations of ~33K tokens (then 4), three 5-s windows each, aggregate decode tok/s: | running | off | `ROWS_ATTN=1` | + `ROWS_SMALL=1` | |---|---|---|---| | 8 | 178.4 / 179.2 / 178.4 | 233.6 / 234.4 / 233.6 (**+31%**) | 240.8 / 240.8 / 240.0 (+2.9% more) | | 4, MTP windows (1 draft) | 179.0 / 178.0 / 179.2 | 225.8 / 225.6 / 222.0 (**+25%**) | 232.2 / 230.4 / 226.6 (+2.6% more) | Per 4-row step on the first GPU: 22.2 -> 17.1 -> 16.7 ms. Caveats: repetitive synthetic text and 33K contexts (live: 40-190K); the expert grouping was timed before upstream's change to `moe_win_group_kernel`, so `ROWS_SMALL`'s grouping share is likely smaller on main. With Maya-L (~85% of experts in VRAM, same box) both ran live ~6 h, 0 engine errors; no A/B there. ## Recommendation With 3 or more requests decoding on a compute capability 8.0+ GPU, set `MAYA_GLM_ROWS_ATTN=1` and `MAYA_GLM_ROWS_SMALL=1`: same output, a faster step. They do nothing in single-row groups (2 running without MTP windows, or the lone row of a 2 + 1 split) and below compute capability 8.0. With experts partly in RAM the step is dominated by waits for RAM-tier experts, so expect less; streamed from RAM and one GPU were not measured. ## Exactness Bitwise. `tests/glm_rows_attn_test.cu` (GPU, no model, 828 cases) compares each row's attention with `mla()` per row byte for byte (2-16 rows, contexts up to ~60K, resident and KV-streamed caches including verify-window rows, FP16 and INT8 latents), and the selections, scores, KV resolves and expert grouping with the per-row and one-thread kernels. Greedy, off vs on, 300 tokens: 12 of 12 identical for each setting. ## How it was verified - On v1.1.23 (this branch), on the box above: `glm_rows_attn_test` (828 cases), `glm_rows_kernels_test`, `glm_mv_nt_test`, `glm_moe_rows_test` and the `glm_*_parity --selftest` tests pass, as on main; every commit builds (nvcc 13.4, sm_75 and sm_120); `tools/check_hip_compat.py` is clean. - The rates, the kernel profile and the greedy identity: these commits on v1.1.21; then ~2.5 h live with EXL3 and ~6 h with Maya-L, 0 engine errors. - Not batched on purpose: `moe_route` (each row's route claims spare expert slots that the next row sees; one launch would change the tiers' behaviour). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:26:14 +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#510
No description provided.