mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #5147] [Engine] --pipeline-windows 2: the pipelined prompt read hangs for good when the drafter shares stage 0's card #3059
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#3059
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?
Originally created by @cloud4t0r on GitHub (Nov 3, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5147
What happens
Engine 0.1.56 (Strata 0.2.10), a layer split over two cards,
--pipeline-windows 2(the default here): the first request of a fresh engine hangs for good while its prompt is read. No token is produced; 60 s later the watchdog ends the engine:position 0and6 tokensplace it inread_windows_pl(the pipelined prompt read):--short-read 64reads a 56-token prompt through the verify windows, so the first window of the very first request goes down that path. The stall report carries no pipelined-decode block (diag_pipeline_fn), which confirms the decode loop was never entered.Environment
build-hip, Release, HIP)--layer-split autopicked 36 layers on CUDA0 and 12 + the head on CUDA1 (log: NEAR TIE, K=36 / K=33)/opt/rocm(libamdhip64.so.7.16.26385-0000000); MEC firmware 0x86 on the gfx1201, 0xd7a on the gfx1030general.architecture = qwen4exp, 48 layers, 512 experts / top 10, 320,001,536-row PLE table), native pack +--mtp+--spec 4 --spec-min-p 0.5 --kv int8 --kv-resident 32768 --visionEngine command line (
strata launch, paths shortened):Reproduce
Start the engine (
serve/server.py --engine strata --config strata-swift-iq3_s.json) and send one short chat turn ("bonjour mon pote", 56 tokens). Everything else stays as the config has it.--pipeline-windows 2)--pipeline-windows 1--pipeline-windows 0--pipeline-windows 2+STRATA_MTP_STAGE0=0Single runs each, 32 to 57 output tokens, so the speeds are indicative only; the point is which ones return at all. The model and pack are fine: every variant that avoids the hang answers correctly.
Evidence: where the host thread is
eu-stack -p <engine pid>during the hang, on the thread driving the windows:The other threads are idle: pool workers parked,
strata-hostin the stdin loop, the two ROCr event loops waiting onhsakmt_ioctl. One thread spins inhipStreamSynchronize, which is why neither the 20 s guard inVerifier::service/donenor a stage error ever fires — the loop never runs again.Cause
--pipeline-windows 2, the drafter is placed on the first stage's card (mtp_first,src/program/generate.cpp:5579-5583:if (!mtp_first_ok || o.pipeline_windows < 2 || ...) return false;). In the log that is the+220 MiB for the draft headcarved out of CUDA0's cache. With--pipeline-windows 1the same condition is false, and the drafter goes back to the last card — which is exactly the variant that works.read_windows_plcallsmtp.prefill(..., sync=false)on purpose, right after a stage-1 window finishes (src/program/generate.cpp:16223), so the host does not block.prefill_per_group_sync()is true (src/core/mtp.cpp:1525-1535), soMtpDrafter::prefilltakes the per-group loop; only the E-4 branch readssync(if (!sync),src/core/mtp.cpp:1632), and the per-group loop synchronises after every group (src/core/mtp.cpp:1642+).sync=falseis silently ignored on HIP.So the ordering bug is: a blocking drafter prefill is issued while a stage-0 window it shares the card with is in flight.
Proposed fix
Serve stage 0 to its end before that prefill, when the drafter shares stage 0's card (
mtp_first); the rest of the read keeps both stages overlapped. The tokens are unchanged — the same windows are served, only a little earlier.--pipeline-windows 0/1and the caseSTRATA_MTP_STAGE0=0take no new code path.I did not take the other obvious route, making the per-group loop honour
sync=falseand return at once: the comment atsrc/core/mtp.cpp:1575-1584records that the unsynchronised E-4 queue itself hangs on gfx1201 / ROCm 7.2.4, which is why HIP forces the per-group sync in the first place. Fixing the caller keeps that mitigation intact.Cost, stated plainly: stage 0 is drained once per drafter prefill, so the prompt read loses the stage-0/stage-1 overlap around those prefills. I have not measured that cost — before the fix this path never returned.
Validation
cmake --build build-hip -j 24 --target strata→[2/3] Linking HIP executable strata; warnings only, all pre-existing (hipFree/nodiscardingenerate.cppat 20710-20714).--pipeline-windows 2and the drafter on the first card: the first request that used to hang now answers — 56 prompt tokens in 744 ms (75.2 tok/s), 32 generated at 49.4 tok/s; a second turn 51 tokens reused + 5 read, 32 generated at 55.1 tok/s.--pipeline-windows 0, so it is not this fix and not part of this report.generate.cpp, shared by every backend, but nothing CUDA-specific changed; I only have these two AMD cards), and--pipeline-windows 1after the patch (themtp_firstguard leaves that path untouched).sycl/src/program/generate.cpp), but nomtp_firstplacement: the drafter stays on the last card there, which is the variant that works here. Nothing changed in that copy.Why this is not #4668 or #4862
hipStreamSynchronizeinMtpDrafter::prefillon the stack, and the same machine and firmware serve the same model fine withSTRATA_MTP_STAGE0=0.Reproduction status
Reproduced locally: 2 of 2 runs before the patch, and 8 requests with no stall after it.
@udqe commented on GitHub (Nov 3, 2026):
Static-read corroboration (source at main as of 2026-11-03 - note PR #5149's guard is not in this snapshot; read-only, no build). Our stall-relevant observation: a 2x RTX 4090 CUDA pair with
--pipeline-windows 2and an explicit--mtplayer has never hung here, which fits the precondition the title does not yet state: the drafter has to live on stage 0, and on CUDA that is opt-in only.Where the freeze comes from:
read_windows_pl(src/program/generate.cpp:16135, entered for anypipe && n_stages == 2 && pl_pw >= 1including CUDA) records the drafter-prefill event at :16199-16204 and the stage-1 next-window launch waits on it at :16184-16186 ("the drafter has read this parity's previous rows first"), which gates stage 0 through :16165.MtpDrafter::prefill(src/core/mtp.cpp:1564-1666) stages the last stage's residual onto the drafter's own card (:1625/:1657 D2D copies), ends its groups with a blockingcudaStreamSynchronize(:1660), and on a fresh engine the first prefill per length also does a graph upload + sync (:1407-1409, whose comment already describes a launch blocked "behind a device-side spin"). When the drafter is on card 0, all of that blocks the same host thread that must keep raising the spinning stage-0 window's pinned flags - so the event never records and every counter freezes equal, which is exactly the stall line format in verify.cpp:694-696 (the GPU rang %u; flags: served %u, plan (A) %u, copies (B) %u). First-request-only matches the one-time graph capture.Why most boxes do not see it: the drafter lives on the LAST stage by default - generate.cpp:6755-6756
// ... it lives on that deviceOnDevice on_mtp(last_st && !mtp_first ? last_st->dev : -1)- and stage-0 placement (mtp_first) defaults on only for HIP/gfx12 (mtp_first_default_on:2413-2419,#else return false;); CUDA enables it solely viaSTRATA_MTP_STAGE0=1(:5433).--draft dflash2cannot reach the path at all since it forces pipeline windows off (:5417-5418). So the practical scope reads as: pw2 builds where the drafter sits on stage 0 - the default on gfx12, opt-in on CUDA - and PR #5149's "no drafter prefill beside a stage-0 window" matches the mechanism precisely.(ai-assisted; citations: udqe static audit of v0.2.10-era main; our box = 2x RTX 4090 Windows, engine 0.1.56, MTP on the last stage, pw2, 154 boots without this hang - placement default, not luck, per the code above)