[Engine] prompt read: STOP is seen by every stage of a layer split and between layers

A Stop during a long prompt read took effect only when the first card started its next 8192-token chunk, and the
second card read every chunk it was handed to the end: on 2x P100 the next request waited 18-20 s. Now every stage
checks STOP before each chunk (STRATA_STOP_STAGES=0: as before), and every stage checks between layers inside a
chunk (STRATA_STOP_LAYERS=0: as before), stops its expert copies, waits for its queued work and returns "cancelled".
Measured on 2x P100: the next request 17.9 -> 1.1 s and 20.1 -> 1.2 s; normal prompt reads unchanged; requests after
a stop in the middle of a chunk give the same logprobs as after the old stop.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N976Q2e2TARptyrfV8H8mz
This commit is contained in:
KeoianandClaude Fable 5.2 committed 2026-11-15 07:30:26 +00:00
1 parent 13eedf5524
commit ac3c53bd7c
2 files changed
+28

No files matched your search

+22
View File
@@ -4049,7 +4049,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
@@ -13883,6 +13883,12 @@ int main(int argc, char** argv) {
return true;
};
sp.should_stop = [&] { return stop_req.load(); };
// 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