prompt read: a Stop is seen by every stage of a layer split and between layers (#6011)

The engine code of #6011 (Keoian, ac3c53bd7 / 81d86884f), applied on f-1116-eng; its docs/DETAILS.md
lines are not taken (new user-visible text, pending).

A Stop while a layer split reads a long prompt took effect late: only the first stage looked for STOP,
and only before each prompt chunk, so every later stage read each chunk it was handed to the end.

- generate.cpp: the later stages get the first stage's should_stop (STRATA_STOP_STAGES=0: only the
  first stage looks, as before). Next to our HIP EXIT hook (kfdq_exit::g_stop), which stays.
- prefill.cpp, the chunk-major batched read: before each layer after a chunk's first, a stage that sees
  STOP ends its expert copies, waits for its streams and its device, logs "stopped in the chunk from
  token N before layer L (STOP)" and returns "cancelled" (STRATA_STOP_LAYERS=0: only between chunks).

A stage that stops leaves no checkpoint part for that chunk, so no incomplete set is saved (the set at a
position is kept only when every stage made its part). The first stage's hand-off cannot wait forever on
a later stage that stopped: it waits for its direct successor's previous chunk, whose "cancelled" ends
that wait, and Prefill::run drains every successor after run_impl, failed or not.

Measured on l620 (RTX PRO 5000, IQ3_S, the shared BASE-05 setup), a same-card split (--layer-split 24
--split-device 0, --prefill 8192), a ~72K-token prompt stopped 6 s in, two runs of each, alternating
(job l620-20261116-1822-5ffc):
  STOP to its DONE:          base 1.04 / 1.17 s, this 0.51 / 0.49 s ("stopped in the chunk from token
                             31810 before layer 28 / 24")
  the short request after:   base 0.34 / 0.34 s, this 0.33 / 0.33 s
  the same prompt in full:   base 12.62 / 12.86 s, this 12.78 / 12.94 s; tokens equal
The PR's own numbers (2x Tesla P100, 49,890 tokens) show the larger effect of a slow card: the next
request waited 1.1 s instead of 17.9 s.
This commit is contained in:
Keoian authored and Niko1221 committed 2026-11-16 18:29:38 +01:00
1 parent 64dde763c6
commit dd1ddc6eab
2 files changed
+28

No files matched your search

+22
View File
@@ -4726,7 +4726,29 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
std::fprintf(stderr, "strata pf-step: chunk from token %lld, layer %lld: %s took %.0f ms (%s / %s)\n",
(long long) p0, (long long) layer, what, ms, cudaGetErrorString(a), cudaGetErrorString(b));
};
// STOP between two layers (STRATA_STOP_LAYERS=0: only between chunks, as before). A cancelled batched read keeps none
// of its session, only the checkpoints saved before it (generate.cpp: pp_exact), so the chunk is given up where it is:
// the expert copies end, then this card finishes what was queued, so the next request starts on a quiet card.
static const bool stop_in_chunk = [] {
const char* v = std::getenv("STRATA_STOP_LAYERS");
return v == nullptr || std::atoi(v) != 0;
}();
for (int64_t l = LB; l < LE; ++l) {
if (l > LB && stop_in_chunk && should_stop && should_stop()) {
a_stop.store(true, std::memory_order_release);
if (issuer.joinable()) issuer.join();
if (stream_all) m.stager->finish();
if (m.pp != nullptr && m.pp->s != nullptr) {
const core::OnDevice od(m.pp->dev);
(void) cudaStreamSynchronize(m.pp->s);
if (m.pp->s_out != nullptr) (void) cudaStreamSynchronize(m.pp->s_out);
}
(void) cudaDeviceSynchronize();
std::fprintf(stderr, "strata prefill: stopped in the chunk from token %lld before layer %lld (STOP)\n",
(long long) p0, (long long) l);
err = "cancelled";
return false;
}
core::progress_beat(); // the serve watchdog: a prompt chunk of 8192 tokens is still moving
if (l > LB) pf_step("reading the prompt (batched, step sync): the experts and the rest of layer", l - 1);
core::progress_at("reading the prompt (batched): layer", l, p0); // #251: a stall names layer and chunk
+6
View File
@@ -15084,6 +15084,12 @@ int main(int argc, char** argv) {
#if defined(STRATA_USE_HIP) && defined(__linux__)
kfdq_exit::g_stop.store(&stop_req); // EXIT (kfd_quiet.hpp): a signal ends the running request like STOP (nothing without the handler)
#endif
// A layer split: the later stages look at STOP too. They read each chunk the first stage hands on, so a cancelled prompt
// waited for the last stage to finish its chunk (2x P100, 8192-token chunks: ~12 s of a 24 s stop). The set of
// checkpoint parts at a position is kept only when every stage made its part, so a stage that stops early leaves none.
// STRATA_STOP_STAGES=0: only the first stage looks (as before).
if (const char* v = std::getenv("STRATA_STOP_STAGES"); v == nullptr || std::atoi(v) != 0)
for (auto& st : stages) st->sp.should_stop = sp.should_stop;
// 149-prefetch STRATA_RAM_ADAPT2: the prompt's routing seeds the RAM policy with a limited weight
// (STRATA_RAM_ADAPT_PROMPT_W, default 0.25: an expert every prompt token routes to counts like ~5 decode routings),
// fading by 5% a decode window; the decode's own counts and the GPU tier are untouched