[PR #93] [MERGED] Fair slices for concurrent requests (STRATA_FAIR_SLICE_S, off by default) and the engine's PAUSE #330

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/93
Author: @0xPreDa
Created: 10/10/2026
Status: ✅ Merged
Merged: 10/11/2026
Merged by: @mw00

Base: main ← Head: pr-fair-slices


📝 Commits (1)

  • 305f450 Fair slices for concurrent requests (STRATA_FAIR_SLICE_S) and the engine's PAUSE

📊 Changes

5 files changed (+480 additions, -7 deletions)

View changed files

📝 README.md (+1 -0)
📝 serve/server.py (+200 -5)
➕ serve/test_fair.py (+224 -0)
📝 src/core/glm_fast_path.cu (+4 -0)
📝 src/program/generate.cpp (+51 -2)

📄 Description

Why

The server runs one request at a time behind a lock. A short request, such as an agent's title or summary side request, or a second user, waited for the whole of a long answer.

What changes

  • Server: arrival order. The FIFO is a FairLock that serves waiters in arrival order (threading.Lock promises no order) and can tell the holder someone is waiting.
  • Server: STRATA_FAIR_SLICE_S=<s> (0, off, by default). An answer that has been decoding for s seconds while another request waits yields the engine and queues again behind it. It then resumes with prompt + the ids it already wrote, so the client sees one uninterrupted stream. The thinking budget carries over. Image requests are never sliced.
  • Engine: PAUSE. It is a STOP that moves the snapshot from the prompt to the last fed token. The resumed request then reads one token instead of everything it wrote. READY advertises pause.
  • Engine: PAUSE keep, for a request's first slice. The prompt's state goes to a slot and is anchored there: its own continuations do not supersede it until it is taken back. Without this, the chat's next turn re-read the whole conversation, because its history drops the reasoning and so does not extend the written answer.
  • Engine: decode_spec on a split now restores the head group's KDA states from the backup it already keeps when it returns. The whole model then stands exactly at pos_, so a snapshot taken right after is consistent. This is a few MB of device copy at the end of a request. Nothing else read that state.
  • A README row for the new setting.

Measured (4× RTX 4090, Maya-S24, slice 15–20 s)

  • A short question asked during a 3000-token answer: time to first token 34 s → 13–17 s. The long answer took +2.4 s, of which about 2 s was the short one's own work.
  • Switching away from a 100K-token conversation and back costs 1.5–3 s (slot save 0.6–1 s, load 0.7–1.4 s).
    • Without PAUSE, the tokens written since the slice were also re-read: about 1 s per 2000 tokens.
  • Next turn of a sliced 100K-token chat: 2.5 s to first token, against about 40 s without PAUSE keep.
  • Text at the seam reads coherently, and the model still quotes figures from the 100K-token document correctly after a resume. The engine is not bit-reproducible at temperature 0 between runs, even warm, so a token-for-token A/B over HTTP is not possible.

Default behaviour

With the setting off, two things change: queued requests are served in arrival order, and the head KDA restore above runs at the end of each split speculative decode.

Notes

  • Each switch writes a slot to disk. Slower SSDs pay more per switch, so the slice should be longer there.
  • Tests: serve/test_fair.py (8 tests). The server tests pass, tools/check_hip_compat.py passes, and the tools tests give the same results as main.
  • Not tested: AMD, Windows, one GPU.

🔄 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/93 **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-fair-slices` --- ### 📝 Commits (1) - [`305f450`](https://github.com/mw00/project-maya/commit/305f450d6377349e0ded2f5a5041938bb2309282) Fair slices for concurrent requests (STRATA_FAIR_SLICE_S) and the engine's PAUSE ### 📊 Changes **5 files changed** (+480 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+1 -0) 📝 `serve/server.py` (+200 -5) ➕ `serve/test_fair.py` (+224 -0) 📝 `src/core/glm_fast_path.cu` (+4 -0) 📝 `src/program/generate.cpp` (+51 -2) </details> ### 📄 Description **Why** The server runs one request at a time behind a lock. A short request, such as an agent's title or summary side request, or a second user, waited for the whole of a long answer. **What changes** - **Server: arrival order.** The FIFO is a `FairLock` that serves waiters in arrival order (`threading.Lock` promises no order) and can tell the holder someone is waiting. - **Server: `STRATA_FAIR_SLICE_S=<s>`** (0, off, by default). An answer that has been decoding for s seconds while another request waits yields the engine and queues again behind it. It then resumes with prompt + the ids it already wrote, so the client sees one uninterrupted stream. The thinking budget carries over. Image requests are never sliced. - **Engine: `PAUSE`.** It is a STOP that moves the snapshot from the prompt to the last fed token. The resumed request then reads one token instead of everything it wrote. `READY` advertises `pause`. - **Engine: `PAUSE keep`**, for a request's first slice. The prompt's state goes to a slot and is anchored there: its own continuations do not supersede it until it is taken back. Without this, the chat's next turn re-read the whole conversation, because its history drops the reasoning and so does not extend the written answer. - **Engine: `decode_spec` on a split** now restores the head group's KDA states from the backup it already keeps when it returns. The whole model then stands exactly at `pos_`, so a snapshot taken right after is consistent. This is a few MB of device copy at the end of a request. Nothing else read that state. - A README row for the new setting. **Measured** (4× RTX 4090, Maya-S24, slice 15–20 s) - A short question asked during a 3000-token answer: time to first token 34 s → 13–17 s. The long answer took +2.4 s, of which about 2 s was the short one's own work. - Switching away from a 100K-token conversation and back costs 1.5–3 s (slot save 0.6–1 s, load 0.7–1.4 s). - Without PAUSE, the tokens written since the slice were also re-read: about 1 s per 2000 tokens. - Next turn of a sliced 100K-token chat: 2.5 s to first token, against about 40 s without `PAUSE keep`. - Text at the seam reads coherently, and the model still quotes figures from the 100K-token document correctly after a resume. The engine is not bit-reproducible at temperature 0 between runs, even warm, so a token-for-token A/B over HTTP is not possible. **Default behaviour** With the setting off, two things change: queued requests are served in arrival order, and the head KDA restore above runs at the end of each split speculative decode. **Notes** - Each switch writes a slot to disk. Slower SSDs pay more per switch, so the slice should be longer there. - Tests: `serve/test_fair.py` (8 tests). The server tests pass, `tools/check_hip_compat.py` passes, and the tools tests give the same results as `main`. - Not tested: AMD, Windows, one GPU. --- <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#330
No description provided.