[PR #385] [CLOSED] GLM several conversations: MTP drafting in the batched steps, opt-in (MAYA_GLM_MULTI_MTP) #504

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

📋 Pull Request Information

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

Base: main ← Head: pr/glm-multi-mtp


📝 Commits (3)

  • 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)

📊 Changes

17 files changed (+2300 additions, -181 deletions)

View changed files

📝 CMakeLists.txt (+10 -2)
📝 docs/SETTINGS.md (+5 -0)
📝 include/strata/core/glm_model.hpp (+59 -3)
➕ include/strata/core/mtp_rows.hpp (+73 -0)
📝 include/strata/kernels/glm_fast.hpp (+27 -5)
📝 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 (+226 -139)
➕ src/core/glm_rows_state.hpp (+69 -0)
📝 src/kernels/cuda/glm_fast.cu (+140 -12)
📝 src/program/generate.cpp (+312 -7)
➕ tests/core/mtp_rows_test.cpp (+130 -0)
➕ tests/glm_rows_kernels_test.cu (+314 -0)

📄 Description

Summary

With --parallel, a request alone gets the speculative (MTP) decode, but as soon as a second one runs every request gets one token a step and the NextN block sits idle. This adds MTP drafting to the batched steps, off by default:

  • MAYA_GLM_MULTI_MTP=<drafts> (1-7): each running request's batched step carries a verify window - the token it feeds plus the NextN block's drafts - as consecutive rows of its group. The head keeps the rows up to the first draft that differs from the model's pick; after a miss the recurrent (KDA) states are restored from a copy taken before the window and the kept rows replayed. The drafts of all requests run as batched rows of the NextN block. MAYA_GLM_MULTI_MTP_MAX (default 4) uses the windows only while that many requests or fewer run.
  • MAYA_GLM_ROWS_BATCH=1: a batched step's residual mixing (hc) and KDA prep + recurrence in one launch for all rows instead of one a row (the windows use its per-row scratch).
  • mv_nt past 8 activations and a gather kernel for the windows' KDA inputs, adapted from #257 (credited).

With the settings off nothing new is allocated and the scheduler's paths are unchanged.

Why

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

  • The load swings: 8 requests running in bursts, 2-4 between them and at the ends of tasks. With 2-4 running, each request got one token a step while a split's GPUs waited on each other.
  • Serving one request at a time instead (--parallel 1, the existing single-request MTP) gave 79 tok/s per request but left 4.6 requests waiting and served 413 requests an hour, against 598 with --parallel 8 and these changes.
  • The NextN block drafts this kind of text well: 78.5-81% of drafts accepted live.

Measured

Hardware:

  • [A] 2x NVIDIA RTX PRO 5000 Blackwell 72 GB, each on PCIe 5.0 x8 from its own CPU root port (direct GPU-to-GPU copies ~5 GB/s, no fast P2P); Intel Core Ultra 9 285K (8 P + 16 E cores, no AVX-512); 96 GB DDR5; driver 615.71.09, CUDA 13.4.
  • [B] 2x NVIDIA RTX PRO 5000 Blackwell 72 GB, each on PCIe 5.0 x16; AMD EPYC 9734 (the engine on 8 CPUs); 125 GB RAM; driver 595.91.07, CUDA 13.4.
  • [C] 2x NVIDIA RTX 5090 32 GB, each on PCIe 5.0 x8; Intel Core Ultra 7 270K Plus; 93 GB RAM for the engine; driver 595.99.02, CUDA 13.4.

Models: GLM-5.3-Flash EXL3 sc 3.10 bpw (every expert in VRAM on [A] and [B]; ~56% on [C], the rest from RAM and the SSD) and Maya-L (IQ3_S / IQ4_XS experts; ~85% in VRAM on [A], the rest in RAM, CPU lane on).

Every expert in VRAM, [B] (the same changes on an earlier release, before squashing), ~64K-token prompts, 300 greedy tokens, aggregate decode tok/s; every column with split rows 4, even groups, grouped experts, skip empty, ROWS_BATCH=1, PREFILL_GAPS=20:

running MTP off MULTI_MTP=1 (gate 4) MULTI_MTP=3, no gate
8 169.7 170.7 (no drafting above 4) 69.9
4 135.3 157.5 (+16%) 94.1
2 103.9 125.7 (+21%) 121.0
1 55.2 (NextN not loaded) 86.6 (the single-request MTP path) 86.4

Acceptance at ~64K: one draft 79-86% (~1.8 tokens a verify step), three drafts 46-62%. ROWS_BATCH alone ([B], 8 x ~128K): +4.5-5.4% decode.

Live, [A]: EXL3, every expert in VRAM, MULTI_MTP=1 for ~8 h: 78.5-81% of drafts accepted, 1.76-1.80 tokens a verify step, 0 engine errors. Maya-L with 5-8 running: only 17 of 198 requests drafted (accepted drafts 0.7% of the output), while the NextN block held ~4.5 GB that would hold ~370 experts.

Recommendation

With every expert in VRAM and 2-4 requests often running, set MAYA_GLM_MULTI_MTP=1 (and MAYA_GLM_ROWS_BATCH=1); keep the default gate, which turns the windows off above 4 running, where they only cost (8 running without the gate: 117 vs 170 tok/s). One draft, not more: the second and third drafts are accepted much less often and every draft is a row of the group. With experts partly in RAM and 5 or more requests running most of the time, leave it off and keep the NextN block's VRAM for experts (MAYA_GLM_NO_MTP=1). Where experts stream from RAM, and on one GPU, the speed was not measured.

Exactness

  • MULTI_MTP: the kept tokens are the ones the batched step without drafts writes, given the same other settings - a draft is kept only where it equals the model's pick, and a miss is undone by restore + replay. Not bitwise across runs: which experts a step finds in VRAM or on the CPU lane follows the tiers' timing.
  • ROWS_BATCH: the kernels are bitwise equal to the per-row ones (unit test), but at ~126K tokens 5 of 8 greedy streams differed from the setting off ([B]); the cause was not found. docs/SETTINGS.md says so.
  • mv_nt past 8 activations, kda_gather: bitwise.

How it was verified

  • On v1.1.23 (this branch), [A]: glm_rows_kernels_test, glm_mv_nt_test (and its generic variant), glm_moe_rows_test, glm_hc/kda/ffn/dsa/kv_stream_parity --selftest, glm_lat8_test, glm_layer_graph_test, mtp_rows_test and split_groups_test pass, as on main. Every commit builds (nvcc 13.4, sm_75 and sm_120, tests on); tools/check_hip_compat.py is clean.
  • Greedy identity, [B]: engine bench, 8 sequences x 160 tokens, MTP 3 vs off: identical. Server, one run with the same saved prompt states: identical texts across the 8 (no drafting) / 4 / 3 / 2-running rounds, and MTP 3 at 8 and 4 streams equals the single-request MTP path. Across server restarts even the baseline is not reproducible (2 of 8 streams differ against itself).
  • Greedy identity, [C] (these commits on v1.1.20, CPU lane off, since with it on even stock v1.1.20 differs between stream counts): 5 / 4 / 1 streams identical within a run; a gate crossing from 8 to 4 running under load with 0 errors; flags off at the speed of v1.1.20.
  • Stability, [B]: clients killed mid-draft and during a 60K read, 0 engine errors over 17 server runs.
  • Not run: penalties at 5 / 4 streams on these commits, one GPU, speed where experts stream from RAM, an sm_70 build (the CUDA 13 toolchain used here has none).

Together with #386 (prompt-read gaps), running both settings needs one small follow-up commit (no tier update inside a read's gap; no per-request draft steps while a read holds its context). It is ready and goes in after the second of the two.


🔄 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/385 **Author:** [@somnergy](https://github.com/somnergy) **Created:** 10/22/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/glm-multi-mtp` --- ### 📝 Commits (3) - [`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) ### 📊 Changes **17 files changed** (+2300 additions, -181 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+10 -2) 📝 `docs/SETTINGS.md` (+5 -0) 📝 `include/strata/core/glm_model.hpp` (+59 -3) ➕ `include/strata/core/mtp_rows.hpp` (+73 -0) 📝 `include/strata/kernels/glm_fast.hpp` (+27 -5) 📝 `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` (+226 -139) ➕ `src/core/glm_rows_state.hpp` (+69 -0) 📝 `src/kernels/cuda/glm_fast.cu` (+140 -12) 📝 `src/program/generate.cpp` (+312 -7) ➕ `tests/core/mtp_rows_test.cpp` (+130 -0) ➕ `tests/glm_rows_kernels_test.cu` (+314 -0) </details> ### 📄 Description ## Summary With `--parallel`, a request alone gets the speculative (MTP) decode, but as soon as a second one runs every request gets one token a step and the NextN block sits idle. This adds MTP drafting to the batched steps, off by default: - **`MAYA_GLM_MULTI_MTP=<drafts>`** (1-7): each running request's batched step carries a verify window - the token it feeds plus the NextN block's drafts - as consecutive rows of its group. The head keeps the rows up to the first draft that differs from the model's pick; after a miss the recurrent (KDA) states are restored from a copy taken before the window and the kept rows replayed. The drafts of all requests run as batched rows of the NextN block. **`MAYA_GLM_MULTI_MTP_MAX`** (default 4) uses the windows only while that many requests or fewer run. - **`MAYA_GLM_ROWS_BATCH=1`**: a batched step's residual mixing (hc) and KDA prep + recurrence in one launch for all rows instead of one a row (the windows use its per-row scratch). - `mv_nt` past 8 activations and a gather kernel for the windows' KDA inputs, adapted from #257 (credited). With the settings off nothing new is allocated and the scheduler's paths are unchanged. ## Why Measured under several concurrent Claude Code sessions (agentic coding: long multi-turn conversations, subagents, tool calls, auto-mode safety checks) driving one server through the Anthropic Messages API with `--parallel 8`: - The load swings: 8 requests running in bursts, 2-4 between them and at the ends of tasks. With 2-4 running, each request got one token a step while a split's GPUs waited on each other. - Serving one request at a time instead (`--parallel 1`, the existing single-request MTP) gave 79 tok/s per request but left 4.6 requests waiting and served 413 requests an hour, against 598 with `--parallel 8` and these changes. - The NextN block drafts this kind of text well: 78.5-81% of drafts accepted live. ## Measured Hardware: - **[A]** 2x NVIDIA RTX PRO 5000 Blackwell 72 GB, each on PCIe 5.0 x8 from its own CPU root port (direct GPU-to-GPU copies ~5 GB/s, no fast P2P); Intel Core Ultra 9 285K (8 P + 16 E cores, no AVX-512); 96 GB DDR5; driver 615.71.09, CUDA 13.4. - **[B]** 2x NVIDIA RTX PRO 5000 Blackwell 72 GB, each on PCIe 5.0 x16; AMD EPYC 9734 (the engine on 8 CPUs); 125 GB RAM; driver 595.91.07, CUDA 13.4. - **[C]** 2x NVIDIA RTX 5090 32 GB, each on PCIe 5.0 x8; Intel Core Ultra 7 270K Plus; 93 GB RAM for the engine; driver 595.99.02, CUDA 13.4. Models: GLM-5.3-Flash EXL3 sc 3.10 bpw (every expert in VRAM on [A] and [B]; ~56% on [C], the rest from RAM and the SSD) and Maya-L (IQ3_S / IQ4_XS experts; ~85% in VRAM on [A], the rest in RAM, CPU lane on). **Every expert in VRAM, [B]** (the same changes on an earlier release, before squashing), ~64K-token prompts, 300 greedy tokens, aggregate decode tok/s; every column with split rows 4, even groups, grouped experts, skip empty, `ROWS_BATCH=1`, `PREFILL_GAPS=20`: | running | MTP off | `MULTI_MTP=1` (gate 4) | `MULTI_MTP=3`, no gate | |---|---|---|---| | 8 | 169.7 | 170.7 (no drafting above 4) | 69.9 | | 4 | 135.3 | **157.5 (+16%)** | 94.1 | | 2 | 103.9 | **125.7 (+21%)** | 121.0 | | 1 | 55.2 (NextN not loaded) | 86.6 (the single-request MTP path) | 86.4 | Acceptance at ~64K: one draft 79-86% (~1.8 tokens a verify step), three drafts 46-62%. `ROWS_BATCH` alone ([B], 8 x ~128K): +4.5-5.4% decode. **Live, [A]:** EXL3, every expert in VRAM, `MULTI_MTP=1` for ~8 h: 78.5-81% of drafts accepted, 1.76-1.80 tokens a verify step, 0 engine errors. Maya-L with 5-8 running: only 17 of 198 requests drafted (accepted drafts 0.7% of the output), while the NextN block held ~4.5 GB that would hold ~370 experts. ## Recommendation With every expert in VRAM and 2-4 requests often running, set `MAYA_GLM_MULTI_MTP=1` (and `MAYA_GLM_ROWS_BATCH=1`); keep the default gate, which turns the windows off above 4 running, where they only cost (8 running without the gate: 117 vs 170 tok/s). One draft, not more: the second and third drafts are accepted much less often and every draft is a row of the group. With experts partly in RAM and 5 or more requests running most of the time, leave it off and keep the NextN block's VRAM for experts (`MAYA_GLM_NO_MTP=1`). Where experts stream from RAM, and on one GPU, the speed was not measured. ## Exactness - `MULTI_MTP`: the kept tokens are the ones the batched step without drafts writes, given the same other settings - a draft is kept only where it equals the model's pick, and a miss is undone by restore + replay. Not bitwise across runs: which experts a step finds in VRAM or on the CPU lane follows the tiers' timing. - `ROWS_BATCH`: the kernels are bitwise equal to the per-row ones (unit test), but at ~126K tokens 5 of 8 greedy streams differed from the setting off ([B]); the cause was not found. `docs/SETTINGS.md` says so. - `mv_nt` past 8 activations, `kda_gather`: bitwise. ## How it was verified - **On v1.1.23 (this branch), [A]:** `glm_rows_kernels_test`, `glm_mv_nt_test` (and its generic variant), `glm_moe_rows_test`, `glm_hc/kda/ffn/dsa/kv_stream_parity --selftest`, `glm_lat8_test`, `glm_layer_graph_test`, `mtp_rows_test` and `split_groups_test` pass, as on main. Every commit builds (nvcc 13.4, sm_75 and sm_120, tests on); `tools/check_hip_compat.py` is clean. - **Greedy identity, [B]:** engine bench, 8 sequences x 160 tokens, MTP 3 vs off: identical. Server, one run with the same saved prompt states: identical texts across the 8 (no drafting) / 4 / 3 / 2-running rounds, and MTP 3 at 8 and 4 streams equals the single-request MTP path. Across server restarts even the baseline is not reproducible (2 of 8 streams differ against itself). - **Greedy identity, [C]** (these commits on v1.1.20, CPU lane off, since with it on even stock v1.1.20 differs between stream counts): 5 / 4 / 1 streams identical within a run; a gate crossing from 8 to 4 running under load with 0 errors; flags off at the speed of v1.1.20. - **Stability, [B]:** clients killed mid-draft and during a 60K read, 0 engine errors over 17 server runs. - **Not run:** penalties at 5 / 4 streams on these commits, one GPU, speed where experts stream from RAM, an sm_70 build (the CUDA 13 toolchain used here has none). Together with #386 (prompt-read gaps), running both settings needs one small follow-up commit (no tier update inside a read's gap; no per-request draft steps while a read holds its context). It is ready and goes in after the second of the two. --- <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:10 +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#504
No description provided.