[PR #94] [MERGED] Several conversations at once on a layer split (STRATA_GLM_SEQS, off by default): a pipelined decode across the parts #331

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/94
Author: @0xPreDa
Created: 10/10/2026
Status: ✅ Merged
Merged: 10/11/2026
Merged by: @mw00

Base: main ← Head: pr-multi


📝 Commits (3)

  • 305f450 Fair slices for concurrent requests (STRATA_FAIR_SLICE_S) and the engine's PAUSE
  • f05de97 Several conversations at once on a layer split (STRATA_GLM_SEQS)
  • fc8bb60 generate: kNoImages static, so the multi path's local Ctx has a default constructor on MSVC (#94 on Windows)

📊 Changes

11 files changed (+1917 additions, -46 deletions)

View changed files

📝 CMakeLists.txt (+1 -1)
📝 README.md (+4 -0)
📝 include/strata/core/glm_model.hpp (+45 -0)
➕ serve/fake_multi_engine.py (+74 -0)
📝 serve/server.py (+368 -13)
➕ serve/test_fair.py (+224 -0)
➕ serve/test_multi.py (+122 -0)
📝 src/core/glm_fast_path.cu (+4 -0)
📝 src/core/glm_model.cu (+17 -0)
➕ src/core/glm_multi.cu (+278 -0)
📝 src/program/generate.cpp (+780 -32)

📄 Description

Builds on #93. This branch contains #93's commit: the FairLock and PAUSE it extends. Please review #93 first; the second commit here is this PR's own change.

Why (follows #30)

On a layer split, one part works on a token while the others wait: 3 of 4 cards idle during decode. This PR does not batch rows inside a layer, which is #30's stage 3. It keeps several sequences in flight so that each part works on a different one at the same time.

What changes

Engine

  • Sequence states (src/core/glm_multi.cu). With STRATA_GLM_SEQS=<n>, each part keeps n state arenas, the extra ones sized for STRATA_GLM_SEQ_CTX tokens. A state is the residual, KDA states, DSA caches, position, snapshot and image rows.
    • One is bound at a time by a pointer swap, so the token path, prompt path, snapshots and slots work on it unchanged.
    • The arena layout for the extra contexts is recomputed and checked against load_pack's for the first one; the engine refuses to start on a mismatch.
    • Activations and the tier machinery stay shared: a part still runs one token at a time on its stream. That is why the one-outstanding-route-per-GPU tier protocol still holds.
  • Pipelined decode. multi_issue enqueues one token of one sequence through every part, with per-sequence pinned hop slots and events, then the head and sampler on the tail, and does not wait. multi_take waits for that sequence's token. The tier boundary runs every STRATA_GLM_MULTI_BOUNDARY rounds (default 32), not every token.

Serve loop (run_request's prompt part and pause handling are now shared lambdas; with STRATA_GLM_SEQS unset, the path and its output are unchanged)

  • Protocol. GEN ... rid=<id>. Every line a request causes carries the id: T <rid> <tok>, PP <rid> ..., DONE <rid> ..., ERR <rid> .... STOP <rid> and PAUSE <rid> [keep] end one request; STOP alone ends all of them. READY ... multi=<n>.
  • Choosing a context:
    1. an idle one whose snapshot the prompt extends (nothing read, nothing loaded);
    2. else the least recently used idle one large enough, whose conversation goes to a slot first;
    3. else the request waits inside the engine. A context must leave STRATA_GLM_MULTI_ROOM tokens (default 16384) after the prompt, and max tokens are cut to the context.
  • One request alone keeps the speculative path. A second arrival interrupts it at a token boundary, and from then on all go through the pipeline.

Server

  • FairLock gets n places. Image encodes, context reloads and updates take all of them.
  • Per-request routing of the engine's lines, and an active-request count for status. /slots and /props report n.

README: rows for STRATA_GLM_SEQS / STRATA_GLM_SEQ_CTX, STRATA_GLM_MULTI_ROOM / _BOUNDARY / _SPEC and STRATA_GLM_MULTI_BENCH.

Exactness (STRATA_GLM_MULTI_BENCH=<n>,<prompt>,<gen>: the token path against the pipeline)

  • CPU lane off, the same prompt for 4 sequences: 256 of 256 greedy tokens identical across the solo run, a second solo run and all 4 pipelined sequences.
  • Different prompts: sequence 0 matches solo 256 of 256, with the CPU lane on and off.

Speed (4× RTX 4090, Maya-S24, ctx 262144 + 3 × 65536)

1 conversation 2 4
bench, greedy, total tok/s 76 (token path) — 273
HTTP, temperature 0.7, total tok/s 110 (speculative, with #92) 132 225
agent-coding bench, TTFT p50 at c=4 — — 84 ms (was 15–18 s)
  • VRAM: the 3 extra states at 65536 cost 3.5 GB of expert pool (79.8 → 76 GB, 94% of experts in VRAM).

When not to use it

  • One GPU (1× RTX 4090 + RAM + SSD): 4.0 tok/s solo vs 4.3 total with 2 sequences. There are no other parts to fill, the speculative path is lost and the extra state costs expert slots.
  • RAM-bound splits: not measured. The parts share the CPU lane and RAM bandwidth.

Limitations

  • A new prompt is read while the others wait: no chunked interleave yet.
  • An image encode needs the engine alone.
  • The MTP block's cache is not filled during pipelined phases, so drafts may be accepted less after one.
  • DONE hit counters and STAT lines are engine-wide while several requests run.

Tests

  • serve/test_multi.py, against a scripted multi engine (serve/fake_multi_engine.py): routing, STOP of one request, errors, the n places.
  • The server tests pass, tools/check_hip_compat.py passes, and the tools tests give the same results as main.
  • End to end on 4× RTX 4090:
    • staggered arrivals and a client disconnect;
    • 6 requests on 4 states, with slices;
    • thinking, and an image beside a text request;
    • 41K-token prompts waiting for the large context, with correct answers.
  • In production since 2026-10-10 on that machine, behind an OpenAI-compatible gateway (opencode and chat users).
  • Not tested: AMD, Windows, RAM-bound multi-GPU splits.

🔄 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/94 **Author:** [@0xPreDa](https://github.com/0xPreDa) **Created:** 10/10/2026 **Status:** ✅ Merged **Merged:** 10/11/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr-multi` --- ### 📝 Commits (3) - [`305f450`](https://github.com/mw00/project-maya/commit/305f450d6377349e0ded2f5a5041938bb2309282) Fair slices for concurrent requests (STRATA_FAIR_SLICE_S) and the engine's PAUSE - [`f05de97`](https://github.com/mw00/project-maya/commit/f05de978bd25137be3a0c0b9d90a7a9205ab5256) Several conversations at once on a layer split (STRATA_GLM_SEQS) - [`fc8bb60`](https://github.com/mw00/project-maya/commit/fc8bb60654a7c9b6f104a13f33a51e3db97f2019) generate: kNoImages static, so the multi path's local Ctx has a default constructor on MSVC (#94 on Windows) ### 📊 Changes **11 files changed** (+1917 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+1 -1) 📝 `README.md` (+4 -0) 📝 `include/strata/core/glm_model.hpp` (+45 -0) ➕ `serve/fake_multi_engine.py` (+74 -0) 📝 `serve/server.py` (+368 -13) ➕ `serve/test_fair.py` (+224 -0) ➕ `serve/test_multi.py` (+122 -0) 📝 `src/core/glm_fast_path.cu` (+4 -0) 📝 `src/core/glm_model.cu` (+17 -0) ➕ `src/core/glm_multi.cu` (+278 -0) 📝 `src/program/generate.cpp` (+780 -32) </details> ### 📄 Description **Builds on #93.** This branch contains #93's commit: the FairLock and PAUSE it extends. Please review #93 first; the second commit here is this PR's own change. **Why** (follows #30) On a layer split, one part works on a token while the others wait: 3 of 4 cards idle during decode. This PR does not batch rows inside a layer, which is #30's stage 3. It keeps several sequences in flight so that each part works on a different one at the same time. **What changes** *Engine* - **Sequence states** (`src/core/glm_multi.cu`). With `STRATA_GLM_SEQS=<n>`, each part keeps n state arenas, the extra ones sized for `STRATA_GLM_SEQ_CTX` tokens. A state is the residual, KDA states, DSA caches, position, snapshot and image rows. - One is bound at a time by a pointer swap, so the token path, prompt path, snapshots and slots work on it unchanged. - The arena layout for the extra contexts is recomputed and checked against `load_pack`'s for the first one; the engine refuses to start on a mismatch. - Activations and the tier machinery stay shared: a part still runs one token at a time on its stream. That is why the one-outstanding-route-per-GPU tier protocol still holds. - **Pipelined decode.** `multi_issue` enqueues one token of one sequence through every part, with per-sequence pinned hop slots and events, then the head and sampler on the tail, and does not wait. `multi_take` waits for that sequence's token. The tier boundary runs every `STRATA_GLM_MULTI_BOUNDARY` rounds (default 32), not every token. *Serve loop* (`run_request`'s prompt part and pause handling are now shared lambdas; with `STRATA_GLM_SEQS` unset, the path and its output are unchanged) - **Protocol.** `GEN ... rid=<id>`. Every line a request causes carries the id: `T <rid> <tok>`, `PP <rid> ...`, `DONE <rid> ...`, `ERR <rid> ...`. `STOP <rid>` and `PAUSE <rid> [keep]` end one request; `STOP` alone ends all of them. `READY ... multi=<n>`. - **Choosing a context:** 1. an idle one whose snapshot the prompt extends (nothing read, nothing loaded); 2. else the least recently used idle one large enough, whose conversation goes to a slot first; 3. else the request waits inside the engine. A context must leave `STRATA_GLM_MULTI_ROOM` tokens (default 16384) after the prompt, and max tokens are cut to the context. - **One request alone** keeps the speculative path. A second arrival interrupts it at a token boundary, and from then on all go through the pipeline. *Server* - `FairLock` gets n places. Image encodes, context reloads and updates take all of them. - Per-request routing of the engine's lines, and an active-request count for status. `/slots` and `/props` report n. *README:* rows for `STRATA_GLM_SEQS` / `STRATA_GLM_SEQ_CTX`, `STRATA_GLM_MULTI_ROOM` / `_BOUNDARY` / `_SPEC` and `STRATA_GLM_MULTI_BENCH`. **Exactness** (`STRATA_GLM_MULTI_BENCH=<n>,<prompt>,<gen>`: the token path against the pipeline) - CPU lane off, the same prompt for 4 sequences: 256 of 256 greedy tokens identical across the solo run, a second solo run and all 4 pipelined sequences. - Different prompts: sequence 0 matches solo 256 of 256, with the CPU lane on and off. **Speed** (4× RTX 4090, Maya-S24, ctx 262144 + 3 × 65536) | | 1 conversation | 2 | 4 | |---|---|---|---| | bench, greedy, total tok/s | 76 (token path) | — | 273 | | HTTP, temperature 0.7, total tok/s | 110 (speculative, with #92) | 132 | 225 | | agent-coding bench, TTFT p50 at c=4 | — | — | 84 ms (was 15–18 s) | - VRAM: the 3 extra states at 65536 cost 3.5 GB of expert pool (79.8 → 76 GB, 94% of experts in VRAM). **When not to use it** - **One GPU** (1× RTX 4090 + RAM + SSD): 4.0 tok/s solo vs 4.3 total with 2 sequences. There are no other parts to fill, the speculative path is lost and the extra state costs expert slots. - **RAM-bound splits:** not measured. The parts share the CPU lane and RAM bandwidth. **Limitations** - A new prompt is read while the others wait: no chunked interleave yet. - An image encode needs the engine alone. - The MTP block's cache is not filled during pipelined phases, so drafts may be accepted less after one. - `DONE` hit counters and `STAT` lines are engine-wide while several requests run. **Tests** - `serve/test_multi.py`, against a scripted multi engine (`serve/fake_multi_engine.py`): routing, STOP of one request, errors, the n places. - The server tests pass, `tools/check_hip_compat.py` passes, and the tools tests give the same results as `main`. - End to end on 4× RTX 4090: - staggered arrivals and a client disconnect; - 6 requests on 4 states, with slices; - thinking, and an image beside a text request; - 41K-token prompts waiting for the large context, with correct answers. - In production since 2026-10-10 on that machine, behind an OpenAI-compatible gateway (opencode and chat users). - Not tested: AMD, Windows, RAM-bound multi-GPU splits. --- <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:16 +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#331
No description provided.