[PR #636] DeepSeek --parallel: who drafts in a round of several by a measured cost policy, in place of the one-pass gate (MAYA_DS4_MULTI_DRAFT_POLICY); --multi-check holds the expert cache #642

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/636
Author: @somnergy
Created: 10/28/2026
Status: 🔄 Open

Base: main ← Head: pr/ds4-multi-draft


📝 Commits (5)

  • 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
  • a43df58 DeepSeek --parallel: who drafts in a round of several, a measured cost policy (MAYA_DS4_MULTI_DRAFT_POLICY, on by default) in place of the one-pass gate; --multi-check holds the expert cache

📊 Changes

7 files changed (+1621 additions, -167 deletions)

View changed files

📝 docs/SETTINGS.md (+47 -9)
➕ src/ds4/ds4_evt.hpp (+162 -0)
📝 src/ds4/ds4_main.cpp (+590 -138)
📝 src/ds4/ds4_model.cu (+98 -17)
📝 src/ds4/ds4_model.hpp (+20 -3)
➕ tools/ds4/agent_bench.py (+283 -0)
➕ tools/ds4/parallel_test.py (+421 -0)

📄 Description

DeepSeek --parallel with #611's drafting: a round of several now decides who drafts, and how many drafts each, from measured costs. This replaces the all-or-nothing gate "draft only where every drafter fits one pass". With four requests and DSpark's 5-row block, that gate never drafts. MAYA_DS4_MULTI_DRAFT_POLICY=0 restores the gate exactly. --multi-check also holds the expert cache for the whole check.

Depends on #587. The branch is #587's four commits (86a3757) plus one commit, this PR. #611's core is used as it is: verify_multi, draft_multi, step_multi_spec, the cut and cool. Only the choice of who drafts changes. This replaces the earlier version of the PR, which carried its own verify_multi / draft_multi. The 8-row window cap from that version is gone, because windows of 9-16 rows are exact on the async path (see the #608 correction).

What it does

  • The cost policy (MAYA_DS4_MULTI_DRAFT_POLICY=1, the default). As it serves, the engine:

    • times its rounds by the window's rows;
    • times the drafter's calls by the number of conversations in each call;
    • averages each conversation's acceptance per draft, and the drafts its own cut keeps.

    Each round it prices the plans "the j conversations with the best acceptance draft, (16 − n) / j each at most", each with the drafter calls it needs: one pass holds three with DSpark's block, and more drafters take another call. It takes the plan that expects the most tokens per millisecond, if that beats a round without drafts by MAYA_DS4_MULTI_DRAFT_MARGIN (0.03). Otherwise the round is a token of each.

    • With four requests the plan can be three drafting 4 each in one pass, two drafting 5, one, or none, as measured.
    • A conversation the plan leaves out still drafts every MAYA_DS4_MULTI_DRAFT_RETRY rounds (8). The gap doubles up to MAYA_DS4_MULTI_DRAFT_PROBE_CAP (128), so its acceptance stays measured.
    • Until the engine has timed two window sizes and one drafter call, rounds go as with the gate.
  • draft_groups(). A round's drafters go to draft_multi in calls of as many as one pass holds (Model::draft_pass()). A single leftover drafter drafts alone with draft().

  • --multi-check.

    • It holds the expert cache for the whole check (Model::cache_hold). The swaps already in progress switch in first; after that nothing switches, swaps or fills until the release. So the runs alone and together see the same expert placement when experts are on the CPU lane. Otherwise an expert the cache moved between the GPU and the lane in between would round differently.
    • Its last drafting phase drafts in passes, as the server does, and reports the rounds that needed two calls.
  • Logs. MAYA_DS4_MULTI_DRAFT_LOG=1 writes a line for each round of several (drafts kept / offered per request, drafter and round time, tokens against the plan's expectation), plus each request's averages when it ends.

  • Docs. docs/SETTINGS.md: the "Two or more" bullet is updated and a new bullet, "Who drafts in a round of several", is added.

A request alone is unchanged. Greedy, the choice of who drafts changes only how many tokens a round takes, not which tokens.

Settings

setting default what it does
MAYA_DS4_MULTI_DRAFT_POLICY 1 1: the measured cost policy; 0: v1.1.36's gate (draft where all drafters fit one pass, else none)
MAYA_DS4_MULTI_DRAFT_MARGIN 0.03 how much a drafting plan must beat a round without drafts by
MAYA_DS4_MULTI_DRAFT_RETRY / _PROBE_CAP 8 / 128 a left-out conversation's probe gap, doubling up to the cap
MAYA_DS4_MULTI_DRAFT_LOG 0 1: a line per round of several and per-request averages

Results

Setup: two 72 GB Blackwell cards (GPU peer copies at 54 GB/s each way), a 64-core Zen 4 host. DeepSeek-V4.1-Flash, IQ2_XXS GSQ-RCO pack, DSpark drafter on, --parallel 4 --tp 1 (layer split), 512K context. Pooled tok/s, greedy (T=0), conversations started together. "v1.1.36 + #587" is the same build without this commit.

Verdict by hardware class:

  • Two GPUs, layer split: copy-style text (~92-96 % of drafts kept) at 4 requests is +9 %: the gate drafts nothing there, while the policy drafts three or four requests a round. At 2 requests (where the gate already drafts) and on prose (~60 % kept, where the policy mostly declines), the numbers are within run-to-run noise, at 0-5 % below. These are single runs, so treat them as noise until repeated.
  • Two GPUs, tensor parallel 2: not measured with this commit.
  • One GPU, experts mostly in RAM: not measured here. On that class #611 measured the drafter's pass as relatively costly, which is what the policy prices.
essay, 1 essay, 2 essay, 4 copy, 2 copy, 4
v1.1.36 + #587 (the gate) 87.0 110.2 147.2 125.3 108.8
this PR (the policy) 84.6 109.8 141.8 118.8 118.6

Copy prompt: "output this code again with a one-line comment above each function", over ~1.5K-token source files. Essay: 700-token prose answers. Measured with MAYA_DS4_MULTI_DRAFT_LOG=1. Its round lines show the plan's expected rate close to the measured one, for example "2 answering, 7 rows: drafter 2.7 ms, round 39.5 ms, 7 tokens (166 tok/s; the plan expected 166, without drafts 103)".

Exactness

Measured on a two-GPU layer split at --parallel 4, with the expert cache held:

  • --multi-check --n 160:
    • plain rows bit for bit, 636 of 636;
    • each conversation's tokens with the drafter the same as alone, both with drafts made one after another and in drafter passes (6 rounds drafted in one pass, 54 in two or more).
  • tools/ds4/parallel_test.py --lanes 4 --spec 1: every check passes (together = alone for all four, stop, slots).

These ran on the commit before a one-line change, which made the settings also read their STRATA_ names, the way the server passes them. Without the settings set, that change is a no-op.

Suggested settings

requests at once two GPUs, layer split two GPUs, TP2 one GPU / experts mostly in RAM
1 no effect (the lone path) no effect no effect
2-4 the default (POLICY=1) not measured (the default should apply) not measured; POLICY=0 if the drafter is slow there
8 not measured not measured not measured

Checks

  • Build: maya-ds4 (sm_120, CUDA 13.4), no new warnings in the changed files.
  • tools/check_hip_compat.py: passes.
  • Unit tests: serve/test_multi.py (13), tools/test_maya_parallel.py (11) and tools/test_ds4*.py (33) pass.
  • Platforms: Linux only. Not tested on AMD or Windows.

🔄 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/636 **Author:** [@somnergy](https://github.com/somnergy) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/ds4-multi-draft` --- ### 📝 Commits (5) - [`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 - [`a43df58`](https://github.com/mw00/project-maya/commit/a43df5894991ff652178084ddf4836182af24654) DeepSeek --parallel: who drafts in a round of several, a measured cost policy (MAYA_DS4_MULTI_DRAFT_POLICY, on by default) in place of the one-pass gate; --multi-check holds the expert cache ### 📊 Changes **7 files changed** (+1621 additions, -167 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+47 -9) ➕ `src/ds4/ds4_evt.hpp` (+162 -0) 📝 `src/ds4/ds4_main.cpp` (+590 -138) 📝 `src/ds4/ds4_model.cu` (+98 -17) 📝 `src/ds4/ds4_model.hpp` (+20 -3) ➕ `tools/ds4/agent_bench.py` (+283 -0) ➕ `tools/ds4/parallel_test.py` (+421 -0) </details> ### 📄 Description DeepSeek `--parallel` with #611's drafting: a round of several now decides who drafts, and how many drafts each, from measured costs. This replaces the all-or-nothing gate "draft only where every drafter fits one pass". With four requests and DSpark's 5-row block, that gate never drafts. `MAYA_DS4_MULTI_DRAFT_POLICY=0` restores the gate exactly. `--multi-check` also holds the expert cache for the whole check. **Depends on #587.** The branch is #587's four commits (86a3757) plus one commit, this PR. #611's core is used as it is: `verify_multi`, `draft_multi`, `step_multi_spec`, the cut and `cool`. Only the choice of who drafts changes. This replaces the earlier version of the PR, which carried its own `verify_multi` / `draft_multi`. The 8-row window cap from that version is gone, because windows of 9-16 rows are exact on the async path (see the #608 correction). ## What it does - **The cost policy** (`MAYA_DS4_MULTI_DRAFT_POLICY=1`, the default). As it serves, the engine: - times its rounds by the window's rows; - times the drafter's calls by the number of conversations in each call; - averages each conversation's acceptance per draft, and the drafts its own cut keeps. Each round it prices the plans "the j conversations with the best acceptance draft, (16 − n) / j each at most", each with the drafter calls it needs: one pass holds three with DSpark's block, and more drafters take another call. It takes the plan that expects the most tokens per millisecond, if that beats a round without drafts by `MAYA_DS4_MULTI_DRAFT_MARGIN` (0.03). Otherwise the round is a token of each. - With four requests the plan can be three drafting 4 each in one pass, two drafting 5, one, or none, as measured. - A conversation the plan leaves out still drafts every `MAYA_DS4_MULTI_DRAFT_RETRY` rounds (8). The gap doubles up to `MAYA_DS4_MULTI_DRAFT_PROBE_CAP` (128), so its acceptance stays measured. - Until the engine has timed two window sizes and one drafter call, rounds go as with the gate. - **`draft_groups()`.** A round's drafters go to `draft_multi` in calls of as many as one pass holds (`Model::draft_pass()`). A single leftover drafter drafts alone with `draft()`. - **`--multi-check`.** - It holds the expert cache for the whole check (`Model::cache_hold`). The swaps already in progress switch in first; after that nothing switches, swaps or fills until the release. So the runs alone and together see the same expert placement when experts are on the CPU lane. Otherwise an expert the cache moved between the GPU and the lane in between would round differently. - Its last drafting phase drafts in passes, as the server does, and reports the rounds that needed two calls. - **Logs.** `MAYA_DS4_MULTI_DRAFT_LOG=1` writes a line for each round of several (drafts kept / offered per request, drafter and round time, tokens against the plan's expectation), plus each request's averages when it ends. - **Docs.** `docs/SETTINGS.md`: the "Two or more" bullet is updated and a new bullet, "Who drafts in a round of several", is added. A request alone is unchanged. Greedy, the choice of who drafts changes only how many tokens a round takes, not which tokens. ## Settings | setting | default | what it does | |---|---|---| | `MAYA_DS4_MULTI_DRAFT_POLICY` | 1 | 1: the measured cost policy; 0: v1.1.36's gate (draft where all drafters fit one pass, else none) | | `MAYA_DS4_MULTI_DRAFT_MARGIN` | 0.03 | how much a drafting plan must beat a round without drafts by | | `MAYA_DS4_MULTI_DRAFT_RETRY` / `_PROBE_CAP` | 8 / 128 | a left-out conversation's probe gap, doubling up to the cap | | `MAYA_DS4_MULTI_DRAFT_LOG` | 0 | 1: a line per round of several and per-request averages | ## Results Setup: two 72 GB Blackwell cards (GPU peer copies at 54 GB/s each way), a 64-core Zen 4 host. DeepSeek-V4.1-Flash, IQ2_XXS GSQ-RCO pack, DSpark drafter on, `--parallel 4 --tp 1` (layer split), 512K context. Pooled tok/s, greedy (T=0), conversations started together. "v1.1.36 + #587" is the same build without this commit. Verdict by hardware class: - **Two GPUs, layer split:** copy-style text (~92-96 % of drafts kept) at 4 requests is **+9 %**: the gate drafts nothing there, while the policy drafts three or four requests a round. At 2 requests (where the gate already drafts) and on prose (~60 % kept, where the policy mostly declines), the numbers are within run-to-run noise, at 0-5 % below. These are single runs, so treat them as noise until repeated. - **Two GPUs, tensor parallel 2:** not measured with this commit. - **One GPU, experts mostly in RAM:** not measured here. On that class #611 measured the drafter's pass as relatively costly, which is what the policy prices. | | essay, 1 | essay, 2 | essay, 4 | copy, 2 | copy, 4 | |---|---|---|---|---|---| | v1.1.36 + #587 (the gate) | 87.0 | 110.2 | 147.2 | 125.3 | 108.8 | | this PR (the policy) | 84.6 | 109.8 | 141.8 | 118.8 | **118.6** | Copy prompt: "output this code again with a one-line comment above each function", over ~1.5K-token source files. Essay: 700-token prose answers. Measured with `MAYA_DS4_MULTI_DRAFT_LOG=1`. Its round lines show the plan's expected rate close to the measured one, for example "2 answering, 7 rows: drafter 2.7 ms, round 39.5 ms, 7 tokens (166 tok/s; the plan expected 166, without drafts 103)". ## Exactness Measured on a two-GPU layer split at `--parallel 4`, with the expert cache held: - **`--multi-check --n 160`:** - plain rows bit for bit, 636 of 636; - each conversation's tokens with the drafter the same as alone, both with drafts made one after another and in drafter passes (6 rounds drafted in one pass, 54 in two or more). - **`tools/ds4/parallel_test.py --lanes 4 --spec 1`:** every check passes (together = alone for all four, stop, slots). These ran on the commit before a one-line change, which made the settings also read their `STRATA_` names, the way the server passes them. Without the settings set, that change is a no-op. ## Suggested settings | requests at once | two GPUs, layer split | two GPUs, TP2 | one GPU / experts mostly in RAM | |---|---|---|---| | 1 | no effect (the lone path) | no effect | no effect | | 2-4 | the default (`POLICY=1`) | not measured (the default should apply) | not measured; `POLICY=0` if the drafter is slow there | | 8 | not measured | not measured | not measured | ## Checks - **Build:** `maya-ds4` (sm_120, CUDA 13.4), no new warnings in the changed files. - **`tools/check_hip_compat.py`:** passes. - **Unit tests:** `serve/test_multi.py` (13), `tools/test_maya_parallel.py` (11) and `tools/test_ds4*.py` (33) pass. - **Platforms:** Linux only. Not tested on AMD or Windows. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#642
No description provided.