serve: a checkpoint whose copy runs out of memory is skipped, it no longer ends the engine (#3350)

A conversation checkpoint is an optimization, like parking, but the writer treated a failed copy as fatal: "conversation
snapshot running-state copy: out of memory" (cudaErrorMemoryAllocation from the snapshot copy: the private copy stream's
first creation or the driver's staging on a nearly full card, not host RAM) made the prefill fail and the engine exit,
21 times in 4 h for one reporter and 16 in 34 h for another, each exit a reload and the in-flight requests lost.

Now, after a failed save, checkpoint_failure_is_survivable() clears the non-sticky allocation error and synchronizes the
device: when that is clean the checkpoint is skipped with a line on stderr and the request goes on (a layer split's stage
part is left empty, which already means "no checkpoint at this length"; the message-boundary / turn / root checkpoints
after a prompt chunk do the same). A device that is unwell (a sticky error, a GPU that stopped answering) still ends the
request exactly as before. Same edits in sycl/src/program/generate.cpp.

STRATA_TEST_COPY_FAIL_AT=N (tests only, like STRATA_TEST_SLOW_COPY_US): the N-th snapshot copy of the process fails with
cudaErrorMemoryAllocation, so the case can be made without a full card. Unset, nothing changes.
Not changed: "verify: instantiate: out of memory" (graph capture), which the reporter saw once.
This commit is contained in:
Niko1221 committed 2026-10-26 18:36:32 +01:00
1 parent 3cd33d504c
commit f62589fdbe
3 files changed
+85 -8

No files matched your search

+12
View File
@@ -6,6 +6,7 @@
#include <cuda_runtime.h>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <cstddef>
#include <cstdlib>
@@ -35,9 +36,20 @@ inline cudaError_t private_stream(cudaStream_t& s) {
return cudaSuccess;
}
/// STRATA_TEST_COPY_FAIL_AT=N (tests only, #3350): the N-th snapshot / checkpoint copy of the process fails with
/// cudaErrorMemoryAllocation, as when a card has no memory left for the copy. Unset: nothing.
inline long test_copy_fail_at() {
static const long v = [] { const char* e = std::getenv("STRATA_TEST_COPY_FAIL_AT"); return e ? std::atol(e) : 0L; }();
return v;
}
/// `queued`: the copy is only queued on the private stream, and the caller synchronizes the device (or orders a
/// later launch after it with order_after_queued) before anything reads the target or writes the source.
inline cudaError_t copy_nonblocking(void* dst, const void* src, size_t bytes, bool queued = false) {
if (const long at = test_copy_fail_at(); at > 0) {
static std::atomic<long> copies{0};
if (++copies == at) return cudaErrorMemoryAllocation;
}
cudaStream_t s = nullptr;
cudaError_t e = private_stream(s);
if (e != cudaSuccess) return e;
+34 -4
View File
@@ -1745,6 +1745,15 @@ bool checkpoint_save(ConvCheckpoint& c, const strata::core::SessionState& ss, co
return false;
}
/// #3350: a conversation checkpoint is an optimization, like parking. After a failed save: true when the failure was
/// only the copy's memory (a host or driver allocation, which does not stick), so the caller goes on without that
/// checkpoint; false when the GPU itself is unwell (a sticky error comes back from the synchronize), which still ends
/// the request as before.
bool checkpoint_failure_is_survivable() {
(void) cudaGetLastError(); // clears a failed allocation; a sticky error is not cleared and is returned again below
return cudaDeviceSynchronize() == cudaSuccess;
}
/// Puts a checkpoint's running state back; the positional cells below it are the caller's to guarantee.
bool checkpoint_restore(const ConvCheckpoint& c, strata::core::SessionState& ss, const strata::core::ModelGeometry& g) {
std::string error;
@@ -10060,7 +10069,15 @@ int main(int argc, char** argv) {
} else {
saved = checkpoint_at(done, nullptr, tail_checkpoint && !periodic_checkpoint);
}
if (!saved) { e = "saving a conversation checkpoint failed" + ckpt_why; return false; }
if (!saved) {
// #3350: only a GPU that is unwell ends the request; a copy that ran out of memory skips this checkpoint
if (!ckpt_why.empty() || !checkpoint_failure_is_survivable()) {
e = "saving a conversation checkpoint failed" + ckpt_why;
return false;
}
std::fprintf(stderr, "strata serve: checkpoint at %lld skipped: its state could not be copied out (see "
"above); the request goes on without it\n", (long long) done);
}
if (periodic_checkpoint) pp_next_check = done + o.prompt_cache_every;
if (tail_checkpoint) pp_tail_saved = true;
}
@@ -10077,7 +10094,16 @@ int main(int argc, char** argv) {
part_next[i] = done + o.prompt_cache_every;
ConvCheckpoint part; // this stage's state at `done` (its stream is synchronized)
part.ids.assign(cur.begin(), cur.begin() + done);
if (!checkpoint_save(part, stage_ss, g)) { e = "saving a checkpoint part failed"; return false; }
if (!checkpoint_save(part, stage_ss, g)) {
// #3350: the copy ran out of memory (not the GPU): leave this part out. The set at `done` is then
// incomplete and the checkpoint is skipped below, as for a part that was never made
if (!checkpoint_failure_is_survivable()) { e = "saving a checkpoint part failed"; return false; }
std::fprintf(stderr, "strata serve: checkpoint at %lld skipped: stage %zu's state could not be copied "
"out (see above); the request goes on without it\n", (long long) done, i);
std::lock_guard<std::mutex> lk(part_mu);
part_at[done].resize(stages.size() + 1); // (marks the set as seen; its empty parts make it incomplete)
return true;
}
std::lock_guard<std::mutex> lk(part_mu);
auto& v = part_at[done];
v.resize(stages.size() + 1);
@@ -14278,8 +14304,12 @@ int main(int argc, char** argv) {
at = to;
if ((to == turn_at || to == root_at || to == message_at || to == pin_at) &&
!checkpoint_at(to, nullptr, to == message_at && to != turn_at && to != root_at && to != pin_at)) { // the tail kind leaves first
std::printf("ERR saving a conversation checkpoint failed%s\n", ckpt_why.c_str());
return 1;
if (!ckpt_why.empty() || !checkpoint_failure_is_survivable()) { // #3350: only an unwell GPU ends the request
std::printf("ERR saving a conversation checkpoint failed%s\n", ckpt_why.c_str());
return 1;
}
std::fprintf(stderr, "strata serve: checkpoint at %lld skipped: its state could not be copied out (see "
"above); the request goes on without it\n", (long long) to);
}
if (to == pin_at && !pin_checkpoint(pin_at))
std::fprintf(stderr, "strata serve: pin=%lld: its checkpoint was not kept\n", (long long) pin_at);
+39 -4
View File
@@ -1434,6 +1434,20 @@ bool checkpoint_save(ConvCheckpoint& c, const strata::core::SessionState& ss, co
return false;
}
/// #3350: a conversation checkpoint is an optimization, like parking. After a failed save: true when the failure was
/// only the copy's memory (a host or driver allocation, which does not stick), so the caller goes on without that
/// checkpoint; false when the GPU itself is unwell (a sticky error comes back from the synchronize), which still ends
/// the request as before.
bool checkpoint_failure_is_survivable() {
// SYCL has no sticky error state to clear: the queues either drain or throw (a lost device)
try {
dpct::get_current_device().queues_wait_and_throw();
return true;
} catch (...) {
return false;
}
}
/// Puts a checkpoint's running state back; the positional cells below it are the caller's to guarantee.
bool checkpoint_restore(const ConvCheckpoint& c, strata::core::SessionState& ss, const strata::core::ModelGeometry& g) {
std::string error;
@@ -7952,7 +7966,15 @@ int main(int argc, char **argv) try {
} else {
saved = checkpoint_at(done, nullptr, tail_checkpoint && !periodic_checkpoint);
}
if (!saved) { e = "saving a conversation checkpoint failed" + ckpt_why; return false; }
if (!saved) {
// #3350: only a GPU that is unwell ends the request; a copy that ran out of memory skips this checkpoint
if (!ckpt_why.empty() || !checkpoint_failure_is_survivable()) {
e = "saving a conversation checkpoint failed" + ckpt_why;
return false;
}
std::fprintf(stderr, "strata serve: checkpoint at %lld skipped: its state could not be copied out (see "
"above); the request goes on without it\n", (long long) done);
}
if (periodic_checkpoint) pp_next_check = done + o.prompt_cache_every;
if (tail_checkpoint) pp_tail_saved = true;
}
@@ -7969,7 +7991,16 @@ int main(int argc, char **argv) try {
part_next[i] = done + o.prompt_cache_every;
ConvCheckpoint part; // this stage's state at `done` (its stream is synchronized)
part.ids.assign(cur.begin(), cur.begin() + done);
if (!checkpoint_save(part, stage_ss, g)) { e = "saving a checkpoint part failed"; return false; }
if (!checkpoint_save(part, stage_ss, g)) {
// #3350: the copy ran out of memory (not the GPU): leave this part out. The set at `done` is then
// incomplete and the checkpoint is skipped below, as for a part that was never made
if (!checkpoint_failure_is_survivable()) { e = "saving a checkpoint part failed"; return false; }
std::fprintf(stderr, "strata serve: checkpoint at %lld skipped: stage %zu's state could not be copied "
"out (see above); the request goes on without it\n", (long long) done, i);
std::lock_guard<std::mutex> lk(part_mu);
part_at[done].resize(stages.size() + 1); // (marks the set as seen; its empty parts make it incomplete)
return true;
}
std::lock_guard<std::mutex> lk(part_mu);
auto& v = part_at[done];
v.resize(stages.size() + 1);
@@ -10680,8 +10711,12 @@ int main(int argc, char **argv) try {
at = to;
if ((to == turn_at || to == root_at || to == message_at) &&
!checkpoint_at(to, nullptr, to == message_at && to != turn_at && to != root_at)) { // the tail kind leaves first
std::printf("ERR saving a conversation checkpoint failed%s\n", ckpt_why.c_str());
return 1;
if (!ckpt_why.empty() || !checkpoint_failure_is_survivable()) { // #3350: only an unwell GPU ends the request
std::printf("ERR saving a conversation checkpoint failed%s\n", ckpt_why.c_str());
return 1;
}
std::fprintf(stderr, "strata serve: checkpoint at %lld skipped: its state could not be copied out (see "
"above); the request goes on without it\n", (long long) to);
}
if (trace && to == message_at)
std::fprintf(stderr, "strata serve: message boundary checkpoint: %lld tokens, %lld tail\n",