mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[PR #557] DeepSeek: answer several conversations at once, scheduled on events, so sub-agents don't wait behind each other (first token 4.8x sooner on real agent traffic) #595
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#595
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/mw00/project-maya/pull/557
Author: @mrsirg97-rgb
Created: 10/27/2026
Status: 🔄 Open
Base:
main← Head:ds4-evt📝 Commits (9)
f751046DeepSeek: several conversations at once (--parallel N) and decode gaps while a prompt is read (#332)cb18af5DeepSeek several conversations: the serve loop on events, prompts read shortest first38dccd9DeepSeek several conversations: shortest remaining work first, measured4b28097DeepSeek several conversations: docs, and a short prompt in a long read's gaps on a fresh engineca1dadcDeepSeek several conversations: the DSpark drafter in parallel, round-robin reads, the scheduling note and benchesd01773fDeepSeek several conversations: a piece each in turn by default, a one-piece prompt ahead of the longer readsc3e1cc8Merge upstream main (v1.1.32) into ds4-evt0752058Merge upstream main (v1.1.33) into ds4-evtd94914dDeepSeek several conversations: one flow setup for both prompt reads; the source tests after the merge📊 Changes
16 files changed (+4352 additions, -248 deletions)
View changed files
📝
CHANGELOG.md(+40 -0)📝
CMakeLists.txt(+6 -0)➕
docs/DS4_SCHEDULING.md(+171 -0)📝
docs/SETTINGS.md(+146 -1)➕
src/ds4/ds4_evt.hpp(+162 -0)📝
src/ds4/ds4_main.cpp(+979 -9)📝
src/ds4/ds4_model.cu(+1064 -236)📝
src/ds4/ds4_model.hpp(+54 -0)➕
src/ds4/ds4_prefill_gaps.hpp(+51 -0)➕
tests/ds4_evt_test.cpp(+148 -0)➕
tests/ds4_prefill_gaps_test.cpp(+63 -0)➕
tools/ds4/agent_bench.py(+280 -0)➕
tools/ds4/parallel_test.py(+436 -0)➕
tools/ds4/schedule_bench.py(+128 -0)➕
tools/test_ds4_parallel.py(+622 -0)📝
tools/test_ds4_prompt_skip.py(+2 -2)📄 Description
DeepSeek: answer several conversations at once, scheduled on events, so sub-agents don't wait behind each other (first token 4.8x sooner on real agent traffic)
Closes #332 ("every other request waits minutes behind a 100K answer").
With
--parallel N(2-8, a layer split with--threads on) the DeepSeek engine answers up to N conversations atonce: each has its own state, its answer's windows are pipelined over the split, a long prompt's read pauses at its
chunk boundaries so the others keep decoding, and a conversation that drafts answers in DSpark rounds exactly as it
does alone.
--parallel 1- the default - is the single path as before, token for token.It builds on #356's conversation slots: a conversation's state is the pieces
slot_savealready takes (window rings,compressor groups, compressed KV and index keys), now one set per lane, and a lane taken by another request sets its
conversation aside and takes it back the same way - so an agent's parent and sub-agents, which #356 stopped from
re-reading each other's prompts as they took turns, can now run at the same time.
Running several at once turned out to be the easy half. The half users feel is what runs next: one read takes
every GPU, so a 250-token question behind a 16,000-token prompt waits for all of it. The serve loop now runs on an
event queue in (priority, id) order, the prompts being read take turns a piece each, and the answers decode in the
read's gaps while the shortest remaining work is theirs - from measured rates, no tuning knobs.
Results
3-GPU split (2x RTX 5090 + RTX 3090), DeepSeek-V4.1-Flash GSQ-RCO IQ2_XXS (~138 GB, about half the experts in VRAM,
the rest on the CPU lane),
--parallel 4, greedy.Real agent traffic.
tools/ds4/agent_bench.py --tracereplays rig's.servedlog: four conversations' busiest10 minutes (73 turns; a turn's new tokens 1-20,653, median 235; one conversation 217K tokens deep) with their real
gaps between turns. Against v1.1.28 as it runs today - one conversation at a time, the drafter on, conversations
kept - and against
--parallelwithout the event loop:--parallel, no eventsThe first token comes 4.8x sooner on the mean, 5.6x at p95; a turn is done 27% sooner at the median - the same
work in about the same wall time, no turn waiting in a line. The cost: the longest turns (p95 done 48.1 s against
36.3), a long answer sharing the GPUs instead of having them.
The final build (with the one-piece rule below) against v1.1.28 again, on the window from 19:50 sharp (69 turns):
The first token 4.9x sooner on the mean, a turn done 38% sooner at the median; the longest turns 60% longer here. The drafter in parallel is most of the gap to
--parallelalone: without it the same build took 882 s.An agent workload (
agent_bench.py: 4 agents x 8 turns at once - a 4-12K-token first prompt, then tool results of150-2,000 tokens, one in ten 5-20K - answers of 64-400 tokens, 0.5-5 s of tool time between), same build, only the
read order differing:
A short prompt that arrives during a long read - #332's case: a 256-token request sent while a 100,000-token
prompt is read gets all 16 of its answer tokens before the long read is through (4 lanes): a prompt whole in one
piece goes ahead of the longer reads, so it waits for the piece being read, not for the whole read. Before, it waited
for all of it.
The trade, measured (
parallel_test.py --lanes 4 --measure: four 2,000-token conversations, N at a time). Withevery prompt in one piece, the reads and answers interleave: the four are done sooner (21.9 s at N=4, 23.5 s at
N=1), and an answer that has begun is paused by each read after it (a conversation's own rate at N=4: 7.2 tok/s on the
mean, 34 alone). Agents see the first token sooner and the whole turn about as soon - the tables above.
What's in it
--parallel N): per-conversation state, lane buffers and a mailbox ring each; windowspipelined over the split; decode gaps at a read's chunk boundaries (
MAYA_DS4_PREFILL_GAPS). A helper GPU's lanedoes not run with N > 1 (the engine says so before the load).
src/ds4/ds4_evt.hpp, the evt engine ofrig, ported - one header, no dependency): the reader's lines, a token done
(a host callback on the head GPU's stream,
Model::multi_on_done) and the choice of the next read are events in(priority, id) order, run by one thread. A read, a drafting round or the expert cache's boundary takes the GPUs once
every issued token is back (
want_devices). Requests past the N states wait for a lane.ahead of the longer reads), the answers a token each between
(
MAYA_DS4_READ_ORDER=ratio: the highest response ratio,(wait + read) / read;arrival: first come);length expected from the answers ended so far, rates measured;
drafts verified in one window - each round taking the GPUs in turn with the reads.
docs/SETTINGS.md(the settings),docs/DS4_SCHEDULING.md(how each rule was chosen, whatwas tried and did not work, the measurements);
tools/ds4/agent_bench.pyandtools/ds4/schedule_bench.pyreproduce the tables.
Fixes that help everyone (N=1 too)
chunks and windows modelled a window from its experts' bytes and left out its fixed costs (the second prompt after a
start: 100 tok/s against 600). It now uses what a full prompt window measured.
value equal to the pull's, so two conversations' requests with the same number found the flags set before their
experts were read (NaN rows, then an illegal address). A pull's number is now
seq * conversations + conversationseqexactly.Behaviour to know
MAYA_DS4_READ_ORDER).MAYA_DS4_PREFILL_GAPS=<percent>for a fixed share,0off) and,like GLM's, not bit-exact: a gap's decode can move experts a later chunk then finds elsewhere. The exactness
checks run with the gaps off.
MAYA_DS4_PREFILL_MIN_CHUNKS(cut short reads so they have gap points) is off: on this split a cut read streamsits routed experts again each chunk (a 4,000-token read ~12 s in four chunks, ~4 s in one).
streams). Exact, and drafting went from 75 ms a round to 3 - but no faster overall (74.9 s against 72.3 on 4 agents
x 2 turns): the CPU lane, which every conversation shares, is the ceiling on this split. Where every expert fits in
VRAM it may pay;
docs/DS4_SCHEDULING.mdhas it.Tested
tools/ds4/parallel_test.py --lanes 2and--lanes 4, with and without--spec 1: every check passes - eachconversation's greedy answer is token for token the one it gets alone (2 and 4 at once), a STOP ends one alone, kept
conversations (slots) work per lane, and the reading check (all 16 of a small answer's tokens before a 100K read is
through).
tests/ds4_evt_test.cpp(the queue's order, update, the engine from 8 threads, pump) andtests/ds4_prefill_gaps_test.cpp; ThreadSanitizer clean on the event engine.ds4_evt.hppis standard C++17threads; not built there yet), a split with every expert in VRAM.
Reproducing
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.