mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3307] [Engine] a long prompt can borrow the MTP drafter's memory while it reads #4558
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4558
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/Niko1221/Strata/pull/3307
Author: @gopinath87607
Created: 10/20/2026
Status: 🔄 Open
Base:
main← Head:prefill-mtp-room📝 Commits (3)
67146caserve: STRATA_MTP_ROOM_MIN - a long prompt takes the MTP drafter's 512 experts (decode-only) as ringce88207serve: STRATA_MTP_ROOM_MIN counts the tokens a request reads, not the whole prompt41bff1ddocs: the prompt room's read threshold, measured on the Q8_0 4-way rig📊 Changes
7 files changed (+567 additions, -37 deletions)
View changed files
📝
docs/DETAILS.md(+14 -0)➕
docs/MTP_PROMPT_ROOM.md(+237 -0)📝
include/strata/core/mtp.hpp(+31 -0)📝
include/strata/prefill/prefill.hpp(+31 -0)📝
src/core/mtp.cpp(+53 -0)📝
src/prefill/prefill.cpp(+49 -1)📝
src/program/generate.cpp(+152 -36)📄 Description
Problem and result
A long prompt's ring is bounded by the VRAM the prompt path can borrow, so on a full card the read waits on the ring. The MTP drafter's 512 routed experts are 708 MB (675 MiB) that only the decode reads - a prompt's passes run the draft layer's dense tensors and its K/V - so while a request that reads enough tokens is being read, that block can become the prompt path's ring. Before: the ring is whatever the layout could free elsewhere. After:
STRATA_MTP_ROOM_MIN=TOKENS(opt-in) lends the block in place for such a request and takes it back before the first decode window; a turn that reuses a cached prefix and reads only a few hundred tokens does not take the room or pay its two 675 MiB DMAs.Related discussion
The original pull request and its discussion: #2830 (closed when its fork was deleted; this PR replaces it). The work comes from the Maya checkout (
project-maya), local commits7df369c(STRATA_GLM_ROOM_MIN),d4d0792(the tail's slots rounded up to the largest blob) and5ccf9a4(the in-place shape, for the MTP config's NextN block). Counting what a request reads, rather than the whole prompt, is this port's change, made after the report below.Approach
STRATA_MTP_ROOM_MIN=TOKENS(--servewith--mtp): a request that reads at least TOKENS prompt tokens (0: every request) uses the MTP drafter's 512 routed experts as the prompt path's ring while it is read. TOKENS counts the tokens this request reads, not the whole prompt: a turn that reuses a cached conversation prefix and reads a few hundred tokens gains nothing from the room. The prompt path's ring is pointed at the block itself:slot i = experts_base + (i - rule) * MAXBLOB(135 slots on a Q8_0 pack, whose largest blob is 4.98 MiB). Opening and closing a room moves the ring count alone (Prefill::set_ring_room_active): the block is never freed, never allocated again and never moves, so no prompt path is laid out again, the decode's captured round/step graphs stay valid (nothing is dropped), and what comes back before the first window is the decode's own bytes (MtpDrafter::experts_reclaim). In the measured shape's successor this is two 675 MiB DMAs around the read.The room is opened after the reused prefix is known (
read_from) and immediately beforelend(), so a relayout still re-carves with the room; a request that must be re-read from 0 (STRATA_CKPT_REREAD) counts all of its tokens.Limits, refused with the reason at start:
--serveonly,--mtpneeded,--batchnot supported (its slot drafters share the solo drafter's weights). A layer split is fine (the room goes to the prompt path on the drafter's card),--pipeline-windowsis fine (the room closes before the request's first window), and--prefill-head-aliasis fine.Unset (the default)
mtp_room_minis-1and not one line of the room runs; the prompt path is laid out exactly as before. The new code is reachable only behind that check. This is by construction, not by a measurement.=0keeps the behaviour that was measured: every request takes the room (the 2026-10-19 control did, on 7-token continuations).Validation
Tested revision:
41bff1d3(three commits on477ac13c; not rebased, and GitHub reports it merges cleanly with currentmaine88ee39d). Environment: Linux, CUDA 13.2,sm_86+sm_120; the Q8_0 4-way rig is 2x RTX 3060 12 GB and 2x RTX 5060 8 GB.Passed:
ninja -C build strataon the parent engine and on41bff1d3- both exit 0; the two binaries differ by this work.STRATA_MTP_ROOM_MIN=1024. One 5,042-token chat and three continuations that echoed the answer back. The parent lent the room for the whole 5,096-token prompt on continuations that read 61, 7 and 7 tokens (lend ~102 ms + reclaim ~104 ms); this commit lent nothing. Read time 2,054 -> 1,813 ms, 360 -> 153 ms, 344 -> 152 ms; time to first token 2.110 -> 1.869 s, 0.409 -> 0.203 s, 0.390 -> 0.199 s. AMIN=0control on this binary still opened the room on the 7-token continuations (time to first token 0.432 / 0.415 s), so=0is unchanged and the difference is the room, not the binary. The cold request still took the room in both arms.--serve --mtp(Q2_0 drafter, 675 MiB),--resident-budget-gib 40,--kv k8v4 --kv-resident 20480,--prefill auto. The auto chunk was 6,656 tokens with a 96-slot ring; the room added 303 slots (399 in all), chunk unchanged.STRATA_MTP_ROOM_MIN=0against the same build unset (paired A/B, 3 pairs, prompt tok/s): 4K 448.4 -> 527.2 (+17%), 16K 558.9 -> 658.1 (+17%), 32K 584.0 -> 719.7 (+23%); decode moved -0.27 / +1.42 / -0.17 (noise). The lend cost 107 ms per roomed request.STRATA_PREFILL_RINGalone showed the ring was the limit (192 slots: +9.8% / +6.2% / +2.3%, decode -3.1 to -3.6 tok/s). First-token logits after a 15,521-token prompt were bitwise equal to the unset run (two runs per arm, all four identical), the 48-token greedy replies matched, and the drafter's acceptance after reclaim was normal (27 of 34).Failed:
Not run:
generate.cppcarries no per-backend code, so both builds compile the same change.--prefill-head-alias.e88ee39d: this head is based on477ac13cand was not rebased; GitHub reports it merges cleanly.The measurements above are listed with what they were measured on. No blanket speedup is claimed: the knob is how you measure it, the same prompt with the variable set and unset,
PPline againstPPline.7df369crecords the room as not yet measured, with its standing baseline 89.5 s (1,123 tok/s) on its byte-identical 100,535-token read.Limits
--serve --mtponly;--batchis refused because its slot drafters share the solo drafter's weights.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.