[PR #5149] [CLOSED] [Engine] --pipeline-windows 2: no drafter prefill beside a stage-0 window #5326

Closed
opened 2026-11-07 16:34:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5149
Author: @cloud4t0r
Created: 11/3/2026
Status: ❌ Closed

Base: main ← Head: fix/pipeline-prefill-deadlock


📝 Commits (1)

  • e170084 [Engine] --pipeline-windows 2: no drafter prefill beside a stage-0 window

📊 Changes

1 file changed (+21 additions, -0 deletions)

View changed files

📝 src/program/generate.cpp (+21 -0)

📄 Description

Problem and result

With --pipeline-windows 2 on a two-stage layer split (the default on gfx12 HIP builds), the first request of a fresh engine never returns: the prompt is read, 0 tokens come out, and 60 s later the watchdog ends the engine:

strata serve: no progress for 60 s during a request (verify window (pipelined): the CPU experts of layer 16) - stopping the engine so the server starts it again (issue #29)
  expert pool: 48 of 48 jobs claimed, 48 done; 15 of 15 workers parked, 15 sleeping
  verify window: 6 tokens at position 0, host at layer step 36; the GPU rang 36; flags: served 36, plan (A) 36, copies (B) 36

After this patch the same request answers normally: 56-token and 71-token prompts answer, a 1109-token prompt is read at 420.3 tok/s and answered at 59.9 tok/s, several turns in a row. Fixes #5147.

#5147 — the issue, with the eu-stack of the stalled thread, the stall report and the four configurations (default, --pipeline-windows 1, 0, and 2 + STRATA_MTP_STAGE0=0).

Approach

With --pipeline-windows 2 the drafter is placed on the first stage's card (mtp_first, generate.cpp: if (!mtp_first_ok || o.pipeline_windows < 2 || …) return false;). read_windows_pl then calls mtp.prefill(…, sync=false) right after a stage-1 window finishes, while stage 0 still has a window in flight on that same card.

MtpDrafter::prefill blocks the host until its stream is idle: on HIP prefill_per_group_sync() is true, so it takes the per-group loop, which synchronises after every group and never reads the caller's sync at all (src/core/mtp.cpp: the if (!sync) early return only exists in the E-4 branch). A stage-0 window only advances when this same thread serves its doorbells, so the host sits in hipStreamSynchronize and the window it is waiting for can never finish:

#12 hipStreamSynchronize
#13 strata::core::MtpDrafter::prefill(float const*, int const*, long, long, std::string&, bool)
#14 main::lambda#2 (read_windows_pl)

Neither 20 s guard in Verifier::service/done can fire, because the loop never runs again — which is why the report shows 60 s with the expert pool idle rather than a window error.

The fix serves stage 0 to its end before that prefill, when the drafter shares stage 0's card. The same windows are served, in the same order, only a little earlier, so the tokens are unchanged; the rest of the read keeps both stages overlapped.

I did not take the other obvious route — making the per-group loop honour sync=false and return at once. The comment above MtpDrafter::prefill records 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.

--pipeline-windows 0 and 1 take no new code path (mtp_first is false there, and 0 does not enter this loop).

Validation

Revision tested: this branch, e170084e, on upstream/main (ffa80d73). Environment: Fedora 44, kernel 7.3.0-rc7, RX 9070 (gfx1201) as stage 0 + 16 GB RX 6800 (gfx1030) as stage 1, HIP/ROCm from /opt/rocm, engine 0.1.56, model Swift-Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S with --spec 4 --spec-min-p 0.5 --mtp --kv int8 --kv-resident 32768 --max-context 131072 --vision.

Passed:

  • Build: cmake --build build-hip -j 24 --target strata on this branch, Release → [131/134] Linking HIP executable strata; only the pre-existing hipFree/nodiscard warnings in generate.cpp.
  • Run, from the binary built from this branch: 71-token prompt 39.9 tok/s, then a 5-token follow-up at 56.5 tok/s, then a 1109-token prompt read at 418.1 tok/s and answered at 52.3 tok/s. No stall, no no progress line.
  • Same configuration and model before the patch: 2 of 2 fresh engines hung at 0 tokens with the watchdog at 60 s. --pipeline-windows 0 (47.8 tok/s), --pipeline-windows 1 (52.4 tok/s) and --pipeline-windows 2 + STRATA_MTP_STAGE0=0 (46.7 tok/s) all avoided it, which is consistent with the cause (each keeps the drafter away from stage 0's card or leaves this loop). Single runs, 32-57 output tokens, indicative only.
  • After the patch, on the fork's branch: 56-token prompt 56.2 tok/s, 71-token 60.1 tok/s, 1109-token prompt 420.3 tok/s and 62.6 tok/s out.

Failed:

  • none observed.

Not run:

  • CUDA build: no CUDA toolkit on this machine. The change is in shared generate.cpp and nothing CUDA-specific changed, but I did not compile it.
  • SYCL: the SYCL engine has its own copy of this loop (sycl/src/program/generate.cpp), but no mtp_first placement — the drafter stays on the last card there, so this deadlock does not apply. Nothing changed in that copy, and I did not build it.
  • The cost of the drain: stage 0 is served to its end once per drafter prefill, so the prompt read loses that overlap around those prefills. Not measured — before the fix this path never returned, so there is no before/after to compare.

Limits

  • The fix is conditional on mtp_first (drafter on stage 0's card). With STRATA_MTP_STAGE0=0 the drafter sits on the last card and its prefill cannot wait behind a stage-0 window; that path is unchanged and still works.
  • It only covers the pipelined prompt read. The pipelined decode loop never calls MtpDrafter::prefill (it uses chain_launch), so it had no equivalent hole.
  • Unrelated, found on the same rig during the run: long prompts with a token on the batched path give non-finite logits on this hardware (#1208, scope request in #5151); STRATA_HIP_PROMPT_F16=1 is the workaround. Not this change, and not affected by it.

🔄 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/Niko1221/Strata/pull/5149 **Author:** [@cloud4t0r](https://github.com/cloud4t0r) **Created:** 11/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/pipeline-prefill-deadlock` --- ### 📝 Commits (1) - [`e170084`](https://github.com/Niko1221/Strata/commit/e170084e08f18a1cc3906fcdf9675d9d6aa14d7d) [Engine] --pipeline-windows 2: no drafter prefill beside a stage-0 window ### 📊 Changes **1 file changed** (+21 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/program/generate.cpp` (+21 -0) </details> ### 📄 Description ## Problem and result With `--pipeline-windows 2` on a two-stage layer split (the default on gfx12 HIP builds), the **first request of a fresh engine never returns**: the prompt is read, 0 tokens come out, and 60 s later the watchdog ends the engine: ``` strata serve: no progress for 60 s during a request (verify window (pipelined): the CPU experts of layer 16) - stopping the engine so the server starts it again (issue #29) expert pool: 48 of 48 jobs claimed, 48 done; 15 of 15 workers parked, 15 sleeping verify window: 6 tokens at position 0, host at layer step 36; the GPU rang 36; flags: served 36, plan (A) 36, copies (B) 36 ``` After this patch the same request answers normally: 56-token and 71-token prompts answer, a 1109-token prompt is read at 420.3 tok/s and answered at 59.9 tok/s, several turns in a row. Fixes #5147. ## Related discussion [#5147](https://github.com/Niko1221/Strata/issues/5147) — the issue, with the `eu-stack` of the stalled thread, the stall report and the four configurations (default, `--pipeline-windows 1`, `0`, and `2` + `STRATA_MTP_STAGE0=0`). ## Approach With `--pipeline-windows 2` the drafter is placed on the **first** stage's card (`mtp_first`, `generate.cpp`: `if (!mtp_first_ok || o.pipeline_windows < 2 || …) return false;`). `read_windows_pl` then calls `mtp.prefill(…, sync=false)` right after a stage-1 window finishes, while stage 0 still has a window in flight on that same card. `MtpDrafter::prefill` blocks the host until its stream is idle: on HIP `prefill_per_group_sync()` is true, so it takes the per-group loop, which synchronises after every group and never reads the caller's `sync` at all (`src/core/mtp.cpp`: the `if (!sync)` early return only exists in the E-4 branch). A stage-0 window only advances when this same thread serves its doorbells, so the host sits in `hipStreamSynchronize` and the window it is waiting for can never finish: ``` #12 hipStreamSynchronize #13 strata::core::MtpDrafter::prefill(float const*, int const*, long, long, std::string&, bool) #14 main::lambda#2 (read_windows_pl) ``` Neither 20 s guard in `Verifier::service`/`done` can fire, because the loop never runs again — which is why the report shows 60 s with the expert pool idle rather than a window error. The fix serves stage 0 to its end before that prefill, when the drafter shares stage 0's card. The same windows are served, in the same order, only a little earlier, so the tokens are unchanged; the rest of the read keeps both stages overlapped. I did **not** take the other obvious route — making the per-group loop honour `sync=false` and return at once. The comment above `MtpDrafter::prefill` records 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. `--pipeline-windows 0` and `1` take no new code path (`mtp_first` is false there, and `0` does not enter this loop). ## Validation Revision tested: this branch, `e170084e`, on `upstream/main` (`ffa80d73`). Environment: Fedora 44, kernel 7.3.0-rc7, RX 9070 (gfx1201) as stage 0 + 16 GB RX 6800 (gfx1030) as stage 1, HIP/ROCm from `/opt/rocm`, engine 0.1.56, model `Swift-Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S` with `--spec 4 --spec-min-p 0.5 --mtp --kv int8 --kv-resident 32768 --max-context 131072 --vision`. **Passed:** - Build: `cmake --build build-hip -j 24 --target strata` on this branch, Release → `[131/134] Linking HIP executable strata`; only the pre-existing `hipFree`/`nodiscard` warnings in `generate.cpp`. - Run, from the binary built from this branch: 71-token prompt 39.9 tok/s, then a 5-token follow-up at 56.5 tok/s, then a 1109-token prompt read at 418.1 tok/s and answered at 52.3 tok/s. No stall, no `no progress` line. - Same configuration and model before the patch: 2 of 2 fresh engines hung at 0 tokens with the watchdog at 60 s. `--pipeline-windows 0` (47.8 tok/s), `--pipeline-windows 1` (52.4 tok/s) and `--pipeline-windows 2` + `STRATA_MTP_STAGE0=0` (46.7 tok/s) all avoided it, which is consistent with the cause (each keeps the drafter away from stage 0's card or leaves this loop). Single runs, 32-57 output tokens, indicative only. - After the patch, on the fork's branch: 56-token prompt 56.2 tok/s, 71-token 60.1 tok/s, 1109-token prompt 420.3 tok/s and 62.6 tok/s out. **Failed:** - none observed. **Not run:** - CUDA build: no CUDA toolkit on this machine. The change is in shared `generate.cpp` and nothing CUDA-specific changed, but I did not compile it. - SYCL: the SYCL engine has its own copy of this loop (`sycl/src/program/generate.cpp`), but no `mtp_first` placement — the drafter stays on the last card there, so this deadlock does not apply. Nothing changed in that copy, and I did not build it. - The cost of the drain: stage 0 is served to its end once per drafter prefill, so the prompt read loses that overlap around those prefills. Not measured — before the fix this path never returned, so there is no before/after to compare. ## Limits - The fix is conditional on `mtp_first` (drafter on stage 0's card). With `STRATA_MTP_STAGE0=0` the drafter sits on the last card and its prefill cannot wait behind a stage-0 window; that path is unchanged and still works. - It only covers the pipelined *prompt* read. The pipelined decode loop never calls `MtpDrafter::prefill` (it uses `chain_launch`), so it had no equivalent hole. - Unrelated, found on the same rig during the run: long prompts with a token on the batched path give non-finite logits on this hardware ([#1208](https://github.com/Niko1221/Strata/issues/1208), scope request in [#5151](https://github.com/Niko1221/Strata/issues/5151)); `STRATA_HIP_PROMPT_F16=1` is the workaround. Not this change, and not affected by it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:34:22 +07:00
Sign in to join this conversation.
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
Niko1221/Strata#5326
No description provided.