From e7318fa23d0b5150718149f91095f381a403cf8a Mon Sep 17 00:00:00 2001 From: Norihiro Nishimura <14284244+Norhiro@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:03:03 +0100 Subject: [PATCH] layer-major prefill on a split: a stale hand_in_ left by a chunk-major prompt no longer turns layer-major off (#3976) run_impl never clears a later stage's hand_in_, so after one short prompt (read chunk-major) every later prompt was declined with "a layer split's chunk hand-off is in use". lm_prepare_chain now declines only when a hand-off is really in flight (a stage's next_run_ is valid) and otherwise clears the stale hand-in pointers. --- src/prefill/prefill.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index 2ffcc018..fd75b6ab 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -5779,6 +5779,16 @@ int64_t Prefill::lm_prepare(int64_t n, std::string& why, int64_t cap) { // A layer split: every stage gets the same super-chunk (the smallest any of them fits), re-sized until they agree. int64_t Prefill::lm_prepare_chain(int64_t n, std::string& why) { + // a later stage's hand_in_ still points at the last chunk a chunk-major prompt handed it (run_impl never clears it): + // with no hand-off in flight that is stale, not in use (a short prompt first would otherwise turn layer-major off + // for every later prompt) + for (Prefill* p = this; p->next_ != nullptr; p = p->next_) + if (p->next_run_.valid()) { why = "a layer split's chunk hand-off is in flight"; return 0; } + for (Prefill* p = next_; p != nullptr; p = p->next_) { + p->hand_in_ = nullptr; + p->hand_ev_ = nullptr; + p->hand_pieces_ = 0; + } int64_t cap = 0; for (int round = 0; round < 4; ++round) { bool same = true;