Later-card VRAM: audit fixes for failed allocations, the reserve arithmetic as a tested helper, a per-card out-of-memory report (#3638 #3702 #3797)
Problem. On a layer split the later cards are left with very little VRAM after loading (#3702: 68 MiB on the last card; #3638: 268 and 666 MiB, then every batched prompt read of more than ~400 tokens ends non-finite after hours; #3797: the weight arena fails with 320 MiB free and the message does not say who holds the rest). The window-graph eviction (12b0bce95) and the copy stream pool (#3350) are in already; this is the rest of the code audit of what is allocated after load. Audit. The table of every lazy allocation after load (what, when, size, how a failure is handled) is in phaseA-tests/notes-027-gh-eng-d.md. Bugs found and fixed here, each small: - verify.cpp capture / capture_batch and mtp.cpp finish_capture: the cudaGraphUpload and its sync were only printed. The upload is a warm-up, but a failure (no VRAM) stayed as the thread's pending error and the next kernel wrapper's cudaGetLastError ended the engine. The error is now cleared and the first launch uploads the graph. - verify.cpp capture_commit and mtp.cpp finish_capture: the commit graph called cudaGraphInstantiate directly (no eviction of older layouts, unlike the window graphs) and reported the status of the end-of-capture call, which is success, so the message read "no error". capture_commit now goes through instantiate_evicting and reports the instantiate's status. - instantiate_evicting instantiates into a local and sets the member only on success (what a failed instantiate leaves in its output is not specified, and a non-null member means "captured"). - prefill.cpp carve: after a failed take of the shared region the sub-allocators had no base and each cudaMalloc'd its buffer (hundreds of MiB in all) on the card that had just run out. carve now returns at once; the caller reports the failure as before. - generate.cpp: a failed set_stage_helper / set_peer is reported and the run goes on, but its CUDA error stayed pending; cleared. Found and not changed: relend() re-plans only the first participant (#3638 comment). Read: it runs only from the VRAM command, which is off on a layer split, so it cannot touch a later stage's loan. Other candidates (ignored cudaEventCreate for the pipelined fences, unchecked expert copies, cudaFuncSetAttribute flags set before success) are in the notes. Changes for the report of #3797 and the reserve (#3702). - include/strata/program/gpu_report.hpp: on a failed weight-arena allocation (first card and each stage) the engine now also prints, for every card of the run, the free and total memory and the largest other programs that hold memory on it (NVML, loaded at run time; where the driver does not list them it says so). Text only; the failure is the same. tests/program/gpu_report_test.cpp pins the text. - include/strata/program/stage_reserve.hpp: the arithmetic of stage_room (what the split keeps free on a card) moved out of generate.cpp unchanged; tests/program/stage_reserve_test.cpp compares it with the old expression over a grid. The file also holds a PROPOSAL for a larger window term on a later card (96 MiB + 6 MiB per further window size + 48 MiB, 174 MiB for --spec 4) which nothing calls: the default placement is not changed. gates/3702-later-reserve.sh measures it. - The low-VRAM warning of a later card now adds how many MiB the plan meant to keep free there and how far off that was. Tests: gpu_report_test, stage_reserve_test (host only, built on z440). Not covered: no model was run. What the ~700 MiB the plan does not count on the last card is (window graph sets, kernel code loads) needs the run in gates/3702-later-reserve.sh.
This commit is contained in:
1 parent
11b0490228
commit
2a9a67c174
9 files changed
+588
-17
No files matched your search
+21
-7
@@ -2583,6 +2583,12 @@ bool Verifier::capture(int T, std::string& err) {
|
||||
const cudaError_t us = cudaStreamSynchronize(cs_);
|
||||
std::fprintf(stderr, "strata verify: captured the %d-token window (upload %s, sync %s)\n", T,
|
||||
cudaGetErrorString(ue), cudaGetErrorString(us));
|
||||
// The upload only warms the graph; the first launch does it otherwise. A failed one (out of memory on a full card)
|
||||
// must not stay pending: the next kernel wrapper's cudaGetLastError would read it and end the engine (#3702).
|
||||
if (ue != cudaSuccess || us != cudaSuccess) {
|
||||
(void) cudaGetLastError();
|
||||
std::fprintf(stderr, "strata verify: the %d-token window's upload was skipped (the first launch does it)\n", T);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2706,13 +2712,16 @@ bool Verifier::capture_commit(std::string& err) {
|
||||
if (graph) cudaGraphDestroy(graph);
|
||||
return false;
|
||||
}
|
||||
if (ce != cudaSuccess || cudaGraphInstantiate(&commit_exec_, graph, 0) != cudaSuccess) {
|
||||
if (ce != cudaSuccess) {
|
||||
if (graph) cudaGraphDestroy(graph);
|
||||
err = std::string("verify: commit capture: ") + cudaGetErrorString(ce);
|
||||
return false;
|
||||
}
|
||||
// (through the same path as the window graphs: on a full card it frees older batch layouts and retries, and the error
|
||||
// it reports is the instantiate's own)
|
||||
const bool made = instantiate_evicting(commit_exec_, graph, {}, "verify: commit instantiate: ", err, 0);
|
||||
cudaGraphDestroy(graph);
|
||||
return true;
|
||||
return made;
|
||||
}
|
||||
|
||||
void Verifier::stage_inputs(int T, const int32_t* tokens, int64_t pos0) {
|
||||
@@ -3545,8 +3554,8 @@ bool Verifier::capture_batch(const int* rows, int S, int hbase, std::string& err
|
||||
const bool made = instantiate_evicting(ex, graph, bkey(rows, S, hbase), "verify: batch instantiate: ", err);
|
||||
cudaGraphDestroy(graph);
|
||||
if (!made) return false;
|
||||
cudaGraphUpload(ex, cs_);
|
||||
cudaStreamSynchronize(cs_);
|
||||
if (cudaGraphUpload(ex, cs_) != cudaSuccess || cudaStreamSynchronize(cs_) != cudaSuccess)
|
||||
(void) cudaGetLastError(); // only a warm-up: the first launch uploads it (see capture)
|
||||
std::string list;
|
||||
for (int t = 0; t < S; ++t) list += (t ? "," : "") + std::to_string(rows[t]);
|
||||
std::fprintf(stderr, "strata verify: captured the batch window over slots %s\n", list.c_str());
|
||||
@@ -3720,14 +3729,17 @@ bool Verifier::instantiate_evicting(cudaGraphExec_t& ex, cudaGraph_t graph, cons
|
||||
// #997: every layout of active slots keeps its own graph pair (20-30 MiB each on an L40S), and with an expert cache
|
||||
// sized to the reserve the next window graph - a batch layout or a one-request window captured on first use - can
|
||||
// find no VRAM left: free the least recently used layouts until it fits (they are captured again when needed)
|
||||
cudaError_t ie = cudaGraphInstantiate(&ex, graph, 0);
|
||||
// (into a local: what a failed instantiate leaves in the output is not specified, and `ex` is a member that
|
||||
// capture() reads as "captured" when it is not null)
|
||||
cudaGraphExec_t got = nullptr;
|
||||
cudaError_t ie = cudaGraphInstantiate(&got, graph, 0);
|
||||
int freed = 0;
|
||||
for (bool evicted = true; ie == cudaErrorMemoryAllocation && evicted;) {
|
||||
(void) cudaGetLastError();
|
||||
if (!evict_batch_graph(key, evicted, err)) return false;
|
||||
if (evicted) {
|
||||
++freed;
|
||||
ie = cudaGraphInstantiate(&ex, graph, 0);
|
||||
ie = cudaGraphInstantiate(&got, graph, 0);
|
||||
}
|
||||
}
|
||||
if (freed > 0)
|
||||
@@ -3740,7 +3752,7 @@ bool Verifier::instantiate_evicting(cudaGraphExec_t& ex, cudaGraph_t graph, cons
|
||||
if (!evict_window_graph(keep_t, evicted, err)) return false;
|
||||
if (evicted) {
|
||||
++freed_sizes;
|
||||
ie = cudaGraphInstantiate(&ex, graph, 0);
|
||||
ie = cudaGraphInstantiate(&got, graph, 0);
|
||||
}
|
||||
}
|
||||
if (freed_sizes > 0)
|
||||
@@ -3748,9 +3760,11 @@ bool Verifier::instantiate_evicting(cudaGraphExec_t& ex, cudaGraph_t graph, cons
|
||||
"sizes (they are captured again when used; a larger --vram-reserve-mib or "
|
||||
"--vram-reserve-later-mib keeps them)\n", keep_t, freed_sizes);
|
||||
if (ie != cudaSuccess) {
|
||||
got = nullptr;
|
||||
err = std::string(what) + cudaGetErrorString(ie);
|
||||
return false;
|
||||
}
|
||||
ex = got;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user