[PR #392] [MERGED] GLM prompt on a split: cut a one-chunk read into chunks so the parts pipeline it, opt-in (MAYA_GLM_PREFILL_MIN_CHUNKS) #509

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

📋 Pull Request Information

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

Base: main ← Head: pr/glm-prefill-min-chunks


📝 Commits (4)

  • 7e860cf GLM several conversations: read a new prompt in pieces between decode steps, opt-in (MAYA_GLM_PREFILL_INTERLEAVE)
  • ca030cc GLM several conversations: decode gaps at a prompt read's chunk boundaries, opt-in (MAYA_GLM_PREFILL_GAPS)
  • 833778b GLM prompt on a split: cut a one-chunk read into chunks so the parts pipeline it, opt-in (MAYA_GLM_PREFILL_MIN_CHUNKS)
  • a27cb3b Merge main into pr/glm-prefill-min-chunks (the PRs merged before it, side by side: test lists, settings rows, includes, the prompt read's loop)

📊 Changes

11 files changed (+1016 additions, -26 deletions)

View changed files

📝 CMakeLists.txt (+3 -1)
📝 docs/SETTINGS.md (+3 -0)
📝 include/strata/core/glm_model.hpp (+21 -0)
➕ include/strata/core/prefill_chunks.hpp (+57 -0)
➕ include/strata/core/prefill_gaps.hpp (+77 -0)
➕ include/strata/core/prefill_pieces.hpp (+57 -0)
📝 serve/fake_multi_engine.py (+35 -4)
📝 serve/test_multi.py (+80 -0)
📝 src/core/glm_prefill.cu (+101 -5)
📝 src/program/generate.cpp (+342 -16)
➕ tests/core/prefill_pieces_test.cpp (+240 -0)

📄 Description

Depends on #386 (decode gaps / interleave): this branch is built on it and uses its per-call chunk floor, so the diff here includes #386's commits until it merges; the commit of this PR is the last one.

Summary

A prompt-path call that fits in one chunk runs on a split's GPUs one after the other, each idle half the time. MAYA_GLM_PREFILL_MIN_CHUNKS=<n>[,<min tokens>] (off by default) cuts every call on a split into at least <n> chunks (1-8), none shorter than <min tokens> (512), so the parts pipeline it: each works n / (n + parts - 1) of the call instead of 1 / parts. Reads under 2 x <min tokens> stay whole; long reads keep as many chunks as they need; one GPU: no effect. It shares one computation with #386's interleaved pieces (strata/core/prefill_chunks.hpp), and with #386's gaps a boundary's gap now waits until the budget earned is at least half a decode round (STRATA_GLM_PREFILL_GAP_CREDIT=0: a gap at every boundary).

Why

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

  • Most reads are short increments onto restored conversations: in a 45-minute sample, 95% of 319 reads had under 8K new tokens, a third under 512.
  • Such a read fits one chunk, and GPU traces showed exactly the problem: one GPU busy while the other waits, ~50% each, while reads took ~56% of the wall time before these changes.

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; --parallel 8, split rows 4. A turn of N new tokens on a restored conversation, read time (ms), alone and with 3 requests decoding (MAYA_GLM_PREFILL_GAPS=20):

new tokens alone: off -> 4 decoding: off -> 4
512 623 -> 624 753 -> 752
1K 1128 -> 943 (-16%) 1349 -> 1078 (-20%)
2K 2025 -> 1574 (-22%) 2350 -> 1972 (-16%)
4K 3110 -> 2842 (-9%) 3589 -> 3504 (-2%)
8K 5851 -> 5740 (-2%) 6774 -> 6850 (+1%)

First token 200-490 ms sooner at 1-4K; the others' decode unchanged (51.4 vs 51.6 tok/s); GPU SM use during a 2K read 31/29% -> 69/57%. 2 is close behind; 8 chunks did not beat 4.

Maya-L (IQ3_S / IQ4_XS experts, ~85% in VRAM, the rest in RAM; same box), from the engine's stage lines of 208 live reads: every chunk stages nearly every expert not in VRAM over PCIe whatever its length - a ~591-token chunk took 583 / 636 ms a GPU, of it 395 / 481 ms copies (~900-1150 experts) - so more chunks cost more there.

Recommendation

With every expert in VRAM on a 2-GPU split, set MAYA_GLM_PREFILL_MIN_CHUNKS=4: short reads 16-22% faster. With experts partly in RAM (or streamed from RAM), leave it off: each extra chunk re-stages the experts not in VRAM, and a fit to the live reads predicts 1-4K reads 20-35% slower with it (predicted, not A/B-measured). On one GPU it does nothing; more than two GPUs were not measured. For EXL3 packs, #388 makes the short chunks themselves cheaper.

Exactness

Not bit-exact: the chunk length changes the prompt's arithmetic, as --prefill N does. With identical chunking the greedy tokens were identical across engines; wherever the chunking differed, 48 greedy tokens diverged after 1-30 tokens. The gap credit rule changes when a gap runs, not what is computed (it never had to skip a gap in these runs).

How it was verified

  • tests/core/prefill_pieces_test (CPU): the chunks as before when off (against the old formula), exactly the floor's count for 2-4 chunks, multiples of 64, never past the largest chunk or under the minimum, the parse, the gap-due rule.
  • On v1.1.23 (this branch): builds (nvcc 13.4, sm_75 and sm_120); prefill_pieces_test passes on the box above; the serve tests pass; tools/check_hip_compat.py is clean.
  • The table: the same change on v1.1.21, fresh engines, a baseline repeat matching to the millisecond with identical tokens; then several hours live with 8 conversations, 0 engine errors.

🔄 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/392 **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-prefill-min-chunks` --- ### 📝 Commits (4) - [`7e860cf`](https://github.com/mw00/project-maya/commit/7e860cff772f492db855164cf0f58c3f2e7598e8) GLM several conversations: read a new prompt in pieces between decode steps, opt-in (MAYA_GLM_PREFILL_INTERLEAVE) - [`ca030cc`](https://github.com/mw00/project-maya/commit/ca030ccfabdab928420e89b82d8a838592a00806) GLM several conversations: decode gaps at a prompt read's chunk boundaries, opt-in (MAYA_GLM_PREFILL_GAPS) - [`833778b`](https://github.com/mw00/project-maya/commit/833778b8505e08ba4ef6f2e709ce0c8a9a1d6284) GLM prompt on a split: cut a one-chunk read into chunks so the parts pipeline it, opt-in (MAYA_GLM_PREFILL_MIN_CHUNKS) - [`a27cb3b`](https://github.com/mw00/project-maya/commit/a27cb3bd29688adbf6613b29c2f629ce284d62f7) Merge main into pr/glm-prefill-min-chunks (the PRs merged before it, side by side: test lists, settings rows, includes, the prompt read's loop) ### 📊 Changes **11 files changed** (+1016 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+3 -1) 📝 `docs/SETTINGS.md` (+3 -0) 📝 `include/strata/core/glm_model.hpp` (+21 -0) ➕ `include/strata/core/prefill_chunks.hpp` (+57 -0) ➕ `include/strata/core/prefill_gaps.hpp` (+77 -0) ➕ `include/strata/core/prefill_pieces.hpp` (+57 -0) 📝 `serve/fake_multi_engine.py` (+35 -4) 📝 `serve/test_multi.py` (+80 -0) 📝 `src/core/glm_prefill.cu` (+101 -5) 📝 `src/program/generate.cpp` (+342 -16) ➕ `tests/core/prefill_pieces_test.cpp` (+240 -0) </details> ### 📄 Description **Depends on #386** (decode gaps / interleave): this branch is built on it and uses its per-call chunk floor, so the diff here includes #386's commits until it merges; the commit of this PR is the last one. ## Summary A prompt-path call that fits in one chunk runs on a split's GPUs one after the other, each idle half the time. **`MAYA_GLM_PREFILL_MIN_CHUNKS=<n>[,<min tokens>]`** (off by default) cuts every call on a split into at least `<n>` chunks (1-8), none shorter than `<min tokens>` (512), so the parts pipeline it: each works n / (n + parts - 1) of the call instead of 1 / parts. Reads under 2 x `<min tokens>` stay whole; long reads keep as many chunks as they need; one GPU: no effect. It shares one computation with #386's interleaved pieces (`strata/core/prefill_chunks.hpp`), and with #386's gaps a boundary's gap now waits until the budget earned is at least half a decode round (`STRATA_GLM_PREFILL_GAP_CREDIT=0`: a gap at every boundary). ## Why Measured under several concurrent Claude Code sessions (agentic coding: long multi-turn conversations, subagents, tool calls) through the Anthropic Messages API with `--parallel 8`: - Most reads are short increments onto restored conversations: in a 45-minute sample, 95% of 319 reads had under 8K new tokens, a third under 512. - Such a read fits one chunk, and GPU traces showed exactly the problem: one GPU busy while the other waits, ~50% each, while reads took ~56% of the wall time before these changes. ## 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; `--parallel 8`, split rows 4. A turn of N new tokens on a restored conversation, read time (ms), alone and with 3 requests decoding (`MAYA_GLM_PREFILL_GAPS=20`): | new tokens | alone: off -> `4` | decoding: off -> `4` | |---|---|---| | 512 | 623 -> 624 | 753 -> 752 | | 1K | 1128 -> **943 (-16%)** | 1349 -> **1078 (-20%)** | | 2K | 2025 -> **1574 (-22%)** | 2350 -> **1972 (-16%)** | | 4K | 3110 -> 2842 (-9%) | 3589 -> 3504 (-2%) | | 8K | 5851 -> 5740 (-2%) | 6774 -> 6850 (+1%) | First token 200-490 ms sooner at 1-4K; the others' decode unchanged (51.4 vs 51.6 tok/s); GPU SM use during a 2K read 31/29% -> 69/57%. `2` is close behind; 8 chunks did not beat 4. Maya-L (IQ3_S / IQ4_XS experts, ~85% in VRAM, the rest in RAM; same box), from the engine's stage lines of 208 live reads: every chunk stages nearly every expert not in VRAM over PCIe whatever its length - a ~591-token chunk took 583 / 636 ms a GPU, of it 395 / 481 ms copies (~900-1150 experts) - so more chunks cost more there. ## Recommendation With every expert in VRAM on a 2-GPU split, set `MAYA_GLM_PREFILL_MIN_CHUNKS=4`: short reads 16-22% faster. With experts partly in RAM (or streamed from RAM), leave it off: each extra chunk re-stages the experts not in VRAM, and a fit to the live reads predicts 1-4K reads 20-35% slower with it (predicted, not A/B-measured). On one GPU it does nothing; more than two GPUs were not measured. For EXL3 packs, #388 makes the short chunks themselves cheaper. ## Exactness Not bit-exact: the chunk length changes the prompt's arithmetic, as `--prefill N` does. With identical chunking the greedy tokens were identical across engines; wherever the chunking differed, 48 greedy tokens diverged after 1-30 tokens. The gap credit rule changes when a gap runs, not what is computed (it never had to skip a gap in these runs). ## How it was verified - `tests/core/prefill_pieces_test` (CPU): the chunks as before when off (against the old formula), exactly the floor's count for 2-4 chunks, multiples of 64, never past the largest chunk or under the minimum, the parse, the gap-due rule. - On v1.1.23 (this branch): builds (nvcc 13.4, sm_75 and sm_120); `prefill_pieces_test` passes on the box above; the serve tests pass; `tools/check_hip_compat.py` is clean. - The table: the same change on v1.1.21, fresh engines, a baseline repeat matching to the millisecond with identical tokens; then several hours live with 8 conversations, 0 engine errors. --- <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: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#509
No description provided.