[PR #587] [CLOSED] DeepSeek --parallel on #557's event scheduler: prompts read a piece at a time, so answers and short questions don't wait for a long read (p95 first token 2.2x sooner) #609

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/587
Author: @mrsirg97-rgb
Created: 10/28/2026
Status: ❌ Closed

Base: main ← Head: ds4-pieces


📝 Commits (4)

  • 1b3c66c DeepSeek --parallel: prompts read a piece at a time (a chunk per pipeline stage), every answer a token between pieces, a one-piece prompt ahead of longer reads; MAYA_DS4_READ_ORDER=arrival keeps the old order. agent_bench 4x8 on 3 GPUs: first token 5.23 s mean / 13.5 s p95 against 6.14 / 29.1, turn done and wall the same; parallel_test --lanes 4 token for token
  • 8185908 DeepSeek --parallel on events (ds4_evt.hpp, #557's): the reader's lines and the turns - a round of tokens or a prompt's piece - each queueing the next; a line outranks a turn, nothing polls (Lines::poll goes). parallel_test --lanes 4 and 2 every check; agent_bench 4x8 first token 5.20 s mean / 13.4 s p95, wall 190.3 s (as before)
  • e90b747 DeepSeek --parallel: a prompt read alone goes in one run and yields to a request at the next chunk all stages reach (Model::set_yield: the Stop's cut, keeping what it read); a piece tells the model how much of its prompt follows, so the long prompt's skip counts from the prompt's end; MAYA_DS4_READ_PIECE (chunks a stage) and MAYA_DS4_READ_ROUNDS (tokens each between pieces). 3 GPUs: a 101K prompt alone 49.2 s, against 58.7 s before and 49.1 s read whole; a question 5 s into it, first token 19.3 s (47 s read whole); parallel_test --lanes 4 and 2 every check; agent_bench 4x8 first token 5.21 s mean / 13.6 s p95, wall 190.4 s (as before)
  • 86a3757 DeepSeek --parallel: a yield lands sooner - in a run that may yield, no GPU starts chunk k before chunk k - (stages + 1) is through every layer (a host ran ~2 chunks ahead of its GPU and each stage ~2 ahead of the next: the cut came 5 chunks past the done ones); MAYA_DS4_READ_SHARE= lets running answers write for that share of the time between pieces (off: on agent_bench it made first tokens later). 3 GPUs: a question 5 s into a 101K read, first token 15.7 s (19.3 s before); the read alone 49.0 s; agent_bench 4x8 first token 5.27 s mean / 13.6 s p95, wall 188.2 s; parallel_test --lanes 4 and 2 every check

📊 Changes

7 files changed (+1266 additions, -126 deletions)

View changed files

📝 docs/SETTINGS.md (+22 -3)
➕ src/ds4/ds4_evt.hpp (+162 -0)
📝 src/ds4/ds4_main.cpp (+298 -104)
📝 src/ds4/ds4_model.cu (+68 -17)
📝 src/ds4/ds4_model.hpp (+12 -2)
➕ tools/ds4/agent_bench.py (+283 -0)
➕ tools/ds4/parallel_test.py (+421 -0)

📄 Description

#557's event scheduler on v1.1.34's batched --parallel, as discussed in #557.

The loop runs on events (ds4_evt.hpp). The reader's lines and the turns are events
run one at a time; a line outranks a turn, each turn queues the next as it ends, and with nothing running the loop
waits for a line instead of polling between steps.

What it schedules: in v1.1.34 a new request's prompt is read whole while every other conversation waits. Now the
prompts being read take turns, a piece each - a chunk per pipeline stage, so a split's GPUs all stay busy - and
every running request writes a token (one step_multi) between two pieces. A prompt whole in one piece goes ahead of
the longer reads, so a short question doesn't wait behind them. MAYA_DS4_READ_ORDER=arrival keeps v1.1.34's order
for A/B runs.

Results

3 GPUs (2x RTX 5090 + RTX 3090, layer split), DeepSeek-V4.1-Flash GSQ-RCO IQ2_XXS (about half the experts in RAM),
--parallel 4, the same binary for both rows.

Agent workload (tools/ds4/agent_bench.py: 4 agents x 8 turns at once - 4-12K-token first prompts, tool results of
150-2,000 tokens, one in ten 5-20K, answers of 64-400 tokens, 0.5-5 s of tool time between):

First token mean / p50 / p95 (s) Turn done mean / p95 (s) Wall (s)
v1.1.34's reading (MAYA_DS4_READ_ORDER=arrival) 6.14 / 2.55 / 29.1 19.98 / 35.2 190.6
a piece each 5.23 / 2.37 / 13.5 19.98 / 35.5 190.5

The first token 15% sooner on the mean and 2.2x sooner at p95; a turn done and the wall the same. A second run of
the default gave 5.22 / 13.5 / 190.4, and the final build (the loop on events) 5.20 / 13.4 / 190.3: v1.1.34 hands
every answer's token back in one call, so the events change the shape, not these numbers - they are what the in-read
gaps (below) build on. Pieces of one chunk were slower (first token 7.13 s, wall 212.1 s): every piece
fills the pipeline again, so a piece is a chunk per stage.

Real agent traffic (--trace: a 10-minute window of rig's .served log, 4 conversations, 73 turns, a turn's new
tokens median 235): a tie, first token 1.91 against 1.86 s, wall 473.5 against 473.6 s. Nearly every turn there fits
in one piece, so pieces and whole reads are the same reads; the gain is where long prompts meet.

What's in it

  • src/ds4/ds4_main.cpp: the prompt reader in three steps - prompt_begin (pictures, reuse, slots),
    prompt_piece (the next tokens, PP lines, a STOP), prompt_end (checkpoints). The one-conversation path calls
    them back to back, as before. In --parallel a request's prompt is begun at admission and read in turn; a STOP
    while it waits for its turn ends it there and keeps the conversation it continued. A prompt with pictures is read
    whole (the images the model holds are not per conversation).
  • src/ds4/ds4_evt.hpp (#557's, rig's evt in C++, 140 lines): the --parallel loop runs on its events - the
    reader's lines, and the turns (a round of tokens or a prompt's piece), each queueing the next as it ends. A line
    outranks a turn, so every request that came is admitted before the next turn; with nothing running the loop waits
    for a line instead of polling. Lines::poll goes (nothing reads between steps any more).
  • Model::prompt_chunk() and Model::pipeline_stages() (the piece's size).
  • docs/SETTINGS.md: the DeepSeek --parallel section.
  • tools/ds4/parallel_test.py and tools/ds4/agent_bench.py from #557 (the checks and the tables above), trimmed to
    this engine.

Each piece is a whole number of the uncut read's chunks, so a prompt reads through the same chunk boundaries as before.

Tested

  • tools/ds4/parallel_test.py --lanes 4 and --lanes 2 (greedy): the conversations at once each answer token for token what they
    answer alone; a STOP ends one alone and the other's answer is whole and its own; a kept conversation's next turn
    reuses its lane (2023 of 2032 tokens); a small request sent during a ~100K-token read gets 4 of its 16 tokens before
    the read's last piece (with arrival the long prompt is read whole before the small one starts).
  • tools/test_ds4_*.py and tools/test_maya_parallel.py.
  • One machine, Linux, 3 GPUs. Not tested: one GPU, tensor parallel, AMD, Windows.

Next, if wanted

#557 also decoded inside a piece (the answers' gaps at a read's chunk boundaries), which is the rest of the first-token
gain on the agent workload and why its reading check got 16 of 16; that needs ds4_model.cu and would be its own PR.
With the loop on events, those gaps are one more event: a read's chunk boundary hands the devices to a round.

Reproducing

python tools/ds4/parallel_test.py --pack <pack> --exe build/maya-ds4 --lanes 4
python tools/ds4/agent_bench.py --pack <pack> --exe "build/maya-ds4:MAYA_DS4_READ_ORDER=arrival" --exe build/maya-ds4
python tools/ds4/agent_bench.py --pack <pack> --exe ... --trace <rig .served> --spec

🔄 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/587 **Author:** [@mrsirg97-rgb](https://github.com/mrsirg97-rgb) **Created:** 10/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `ds4-pieces` --- ### 📝 Commits (4) - [`1b3c66c`](https://github.com/mw00/project-maya/commit/1b3c66c60cee753c7c8c94b521696568f8b23ad9) DeepSeek --parallel: prompts read a piece at a time (a chunk per pipeline stage), every answer a token between pieces, a one-piece prompt ahead of longer reads; MAYA_DS4_READ_ORDER=arrival keeps the old order. agent_bench 4x8 on 3 GPUs: first token 5.23 s mean / 13.5 s p95 against 6.14 / 29.1, turn done and wall the same; parallel_test --lanes 4 token for token - [`8185908`](https://github.com/mw00/project-maya/commit/8185908a766c2534189ccf964471f0373e82a5d9) DeepSeek --parallel on events (ds4_evt.hpp, #557's): the reader's lines and the turns - a round of tokens or a prompt's piece - each queueing the next; a line outranks a turn, nothing polls (Lines::poll goes). parallel_test --lanes 4 and 2 every check; agent_bench 4x8 first token 5.20 s mean / 13.4 s p95, wall 190.3 s (as before) - [`e90b747`](https://github.com/mw00/project-maya/commit/e90b747a9a56f09cbc4431a6cd994b6e1cc4c3d7) DeepSeek --parallel: a prompt read alone goes in one run and yields to a request at the next chunk all stages reach (Model::set_yield: the Stop's cut, keeping what it read); a piece tells the model how much of its prompt follows, so the long prompt's skip counts from the prompt's end; MAYA_DS4_READ_PIECE (chunks a stage) and MAYA_DS4_READ_ROUNDS (tokens each between pieces). 3 GPUs: a 101K prompt alone 49.2 s, against 58.7 s before and 49.1 s read whole; a question 5 s into it, first token 19.3 s (47 s read whole); parallel_test --lanes 4 and 2 every check; agent_bench 4x8 first token 5.21 s mean / 13.6 s p95, wall 190.4 s (as before) - [`86a3757`](https://github.com/mw00/project-maya/commit/86a37576c355573d4e7e9a228a708d0ffb860e77) DeepSeek --parallel: a yield lands sooner - in a run that may yield, no GPU starts chunk k before chunk k - (stages + 1) is through every layer (a host ran ~2 chunks ahead of its GPU and each stage ~2 ahead of the next: the cut came 5 chunks past the done ones); MAYA_DS4_READ_SHARE=<percent> lets running answers write for that share of the time between pieces (off: on agent_bench it made first tokens later). 3 GPUs: a question 5 s into a 101K read, first token 15.7 s (19.3 s before); the read alone 49.0 s; agent_bench 4x8 first token 5.27 s mean / 13.6 s p95, wall 188.2 s; parallel_test --lanes 4 and 2 every check ### 📊 Changes **7 files changed** (+1266 additions, -126 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+22 -3) ➕ `src/ds4/ds4_evt.hpp` (+162 -0) 📝 `src/ds4/ds4_main.cpp` (+298 -104) 📝 `src/ds4/ds4_model.cu` (+68 -17) 📝 `src/ds4/ds4_model.hpp` (+12 -2) ➕ `tools/ds4/agent_bench.py` (+283 -0) ➕ `tools/ds4/parallel_test.py` (+421 -0) </details> ### 📄 Description #557's event scheduler on v1.1.34's batched `--parallel`, as discussed in #557. **The loop runs on events** (`ds4_evt.hpp`). The reader's lines and the turns are events run one at a time; a line outranks a turn, each turn queues the next as it ends, and with nothing running the loop waits for a line instead of polling between steps. **What it schedules:** in v1.1.34 a new request's prompt is read whole while every other conversation waits. Now the prompts being read take turns, **a piece each** - a chunk per pipeline stage, so a split's GPUs all stay busy - and every running request writes a token (one `step_multi`) between two pieces. A prompt whole in one piece goes ahead of the longer reads, so a short question doesn't wait behind them. `MAYA_DS4_READ_ORDER=arrival` keeps v1.1.34's order for A/B runs. ## Results 3 GPUs (2x RTX 5090 + RTX 3090, layer split), DeepSeek-V4.1-Flash GSQ-RCO IQ2_XXS (about half the experts in RAM), `--parallel 4`, the same binary for both rows. **Agent workload** (`tools/ds4/agent_bench.py`: 4 agents x 8 turns at once - 4-12K-token first prompts, tool results of 150-2,000 tokens, one in ten 5-20K, answers of 64-400 tokens, 0.5-5 s of tool time between): | | First token mean / p50 / p95 (s) | Turn done mean / p95 (s) | Wall (s) | | --- | ---: | ---: | ---: | | v1.1.34's reading (`MAYA_DS4_READ_ORDER=arrival`) | 6.14 / 2.55 / 29.1 | 19.98 / 35.2 | 190.6 | | **a piece each** | **5.23 / 2.37 / 13.5** | 19.98 / 35.5 | 190.5 | The first token 15% sooner on the mean and **2.2x sooner at p95**; a turn done and the wall the same. A second run of the default gave 5.22 / 13.5 / 190.4, and the final build (the loop on events) 5.20 / 13.4 / 190.3: v1.1.34 hands every answer's token back in one call, so the events change the shape, not these numbers - they are what the in-read gaps (below) build on. Pieces of one chunk were slower (first token 7.13 s, wall 212.1 s): every piece fills the pipeline again, so a piece is a chunk per stage. **Real agent traffic** (`--trace`: a 10-minute window of rig's `.served` log, 4 conversations, 73 turns, a turn's new tokens median 235): a tie, first token 1.91 against 1.86 s, wall 473.5 against 473.6 s. Nearly every turn there fits in one piece, so pieces and whole reads are the same reads; the gain is where long prompts meet. ## What's in it - `src/ds4/ds4_main.cpp`: the prompt reader in three steps - `prompt_begin` (pictures, reuse, slots), `prompt_piece` (the next tokens, PP lines, a STOP), `prompt_end` (checkpoints). The one-conversation path calls them back to back, as before. In `--parallel` a request's prompt is begun at admission and read in turn; a STOP while it waits for its turn ends it there and keeps the conversation it continued. A prompt with pictures is read whole (the images the model holds are not per conversation). - `src/ds4/ds4_evt.hpp` (#557's, rig's evt in C++, 140 lines): the `--parallel` loop runs on its events - the reader's lines, and the turns (a round of tokens or a prompt's piece), each queueing the next as it ends. A line outranks a turn, so every request that came is admitted before the next turn; with nothing running the loop waits for a line instead of polling. `Lines::poll` goes (nothing reads between steps any more). - `Model::prompt_chunk()` and `Model::pipeline_stages()` (the piece's size). - `docs/SETTINGS.md`: the DeepSeek `--parallel` section. - `tools/ds4/parallel_test.py` and `tools/ds4/agent_bench.py` from #557 (the checks and the tables above), trimmed to this engine. Each piece is a whole number of the uncut read's chunks, so a prompt reads through the same chunk boundaries as before. ## Tested - `tools/ds4/parallel_test.py --lanes 4` and `--lanes 2` (greedy): the conversations at once each answer token for token what they answer alone; a STOP ends one alone and the other's answer is whole and its own; a kept conversation's next turn reuses its lane (2023 of 2032 tokens); a small request sent during a ~100K-token read gets 4 of its 16 tokens before the read's last piece (with `arrival` the long prompt is read whole before the small one starts). - `tools/test_ds4_*.py` and `tools/test_maya_parallel.py`. - One machine, Linux, 3 GPUs. Not tested: one GPU, tensor parallel, AMD, Windows. ## Next, if wanted #557 also decoded inside a piece (the answers' gaps at a read's chunk boundaries), which is the rest of the first-token gain on the agent workload and why its reading check got 16 of 16; that needs `ds4_model.cu` and would be its own PR. With the loop on events, those gaps are one more event: a read's chunk boundary hands the devices to a round. ## Reproducing python tools/ds4/parallel_test.py --pack <pack> --exe build/maya-ds4 --lanes 4 python tools/ds4/agent_bench.py --pack <pack> --exe "build/maya-ds4:MAYA_DS4_READ_ORDER=arrival" --exe build/maya-ds4 python tools/ds4/agent_bench.py --pack <pack> --exe ... --trace <rig .served> --spec --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:27:27 +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#609
No description provided.