diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index e3f3ded6c2..b821601760 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -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 diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 6eea65a221..61abe68df4 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -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