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
@@ -84,6 +84,8 @@
|
||||
#include "strata/program/logits_selection.hpp"
|
||||
#include "strata/program/conv_cache.hpp"
|
||||
#include "strata/program/split_rules.hpp"
|
||||
#include "strata/program/stage_reserve.hpp"
|
||||
#include "strata/program/gpu_report.hpp"
|
||||
#include "strata/prefill/share_rules.hpp"
|
||||
#include "strata/platform/host_limits.hpp"
|
||||
#include "strata/program/split_ring.hpp"
|
||||
@@ -1593,6 +1595,49 @@ int64_t res_check(const int32_t* d_res, const std::vector<int32_t>& host_res, st
|
||||
return bad;
|
||||
}
|
||||
|
||||
/// #3797: when the engine cannot start for lack of GPU memory, the cards' free and total memory and the largest other
|
||||
/// programs that hold some, as a warning added to the message that says it (program/gpu_report.hpp). Best effort: a
|
||||
/// card that cannot be asked, or a driver that does not list its programs, is left out or said so; it never changes the
|
||||
/// failure and never throws. `devices`: the CUDA ordinals to report (duplicates are skipped).
|
||||
static void print_startup_gpu_report(const std::vector<int>& devices) {
|
||||
namespace gr = strata::program::gpu_report;
|
||||
std::vector<gr::Card> cards;
|
||||
int count = 0, prev = 0;
|
||||
if (cudaGetDeviceCount(&count) != cudaSuccess) { (void) cudaGetLastError(); return; }
|
||||
if (cudaGetDevice(&prev) != cudaSuccess) { (void) cudaGetLastError(); prev = 0; }
|
||||
std::vector<int> seen;
|
||||
for (const int d : devices) {
|
||||
if (d < 0 || d >= count || std::find(seen.begin(), seen.end(), d) != seen.end()) continue;
|
||||
seen.push_back(d);
|
||||
if (cudaSetDevice(d) != cudaSuccess) { (void) cudaGetLastError(); continue; } // no context fits there either
|
||||
size_t free_b = 0, total_b = 0;
|
||||
if (cudaMemGetInfo(&free_b, &total_b) != cudaSuccess) { (void) cudaGetLastError(); continue; }
|
||||
gr::Card c;
|
||||
c.index = d;
|
||||
c.free_mib = (uint64_t) (free_b >> 20);
|
||||
c.total_mib = (uint64_t) (total_b >> 20);
|
||||
cudaDeviceProp prop{};
|
||||
if (cudaGetDeviceProperties(&prop, d) == cudaSuccess) c.name = prop.name;
|
||||
else (void) cudaGetLastError();
|
||||
#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906) && !defined(STRATA_GPU_METAL)
|
||||
char bus[64] = {};
|
||||
if (cudaDeviceGetPCIBusId(bus, (int) sizeof bus, d) == cudaSuccess) c.processes_known = gr::query_other_processes(bus, c.processes);
|
||||
else (void) cudaGetLastError();
|
||||
#endif
|
||||
cards.push_back(std::move(c));
|
||||
}
|
||||
if (prev >= 0 && prev < count) (void) cudaSetDevice(prev);
|
||||
(void) cudaGetLastError();
|
||||
if (cards.empty()) return;
|
||||
#if defined(_WIN32)
|
||||
const uint32_t self = (uint32_t) GetCurrentProcessId();
|
||||
#else
|
||||
const uint32_t self = (uint32_t) getpid();
|
||||
#endif
|
||||
std::fprintf(stderr, "strata generate: GPU memory right now (best effort):\n%s\n",
|
||||
gr::format_gpu_memory_report(cards, self).c_str());
|
||||
}
|
||||
|
||||
/// The pre-launch hook's patch: the changed entries of the host's residency table (`idx`) as (index, entry) pairs into
|
||||
/// the mapped `pairs` (room for `cap`); their count, or -1 when they do not fit (then the whole table goes up).
|
||||
int64_t res_patch_pairs(const std::vector<int32_t>& idx, const std::vector<int32_t>& host_res, int32_t* pairs, size_t cap) {
|
||||
@@ -3920,6 +3965,13 @@ int main(int argc, char** argv) {
|
||||
"nvidia-smi / rocm-smi lists them\n",
|
||||
(unsigned long long) pool_bytes, cudaGetErrorString(ce), (unsigned long long) (free_b >> 20),
|
||||
(unsigned long long) (total_b >> 20));
|
||||
{ // #3797: every card of the run, and who else is on it
|
||||
std::vector<int> report_devs;
|
||||
int cur = 0;
|
||||
if (cudaGetDevice(&cur) == cudaSuccess) report_devs.push_back(cur); else (void) cudaGetLastError();
|
||||
for (const int d : split_devs) report_devs.push_back(d);
|
||||
print_startup_gpu_report(report_devs);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
mem_mark("the CUDA context and the weight arena");
|
||||
@@ -4417,6 +4469,13 @@ int main(int argc, char** argv) {
|
||||
err.empty() ? "the weight arena does not fit" : err.c_str(),
|
||||
(unsigned long long) (pool_s >> 20), (unsigned long long) (free_b >> 20),
|
||||
(unsigned long long) (total_b >> 20));
|
||||
{ // #3797: every card of the run, and who else is on it
|
||||
std::vector<int> report_devs;
|
||||
int cur = 0;
|
||||
if (cudaGetDevice(&cur) == cudaSuccess) report_devs.push_back(cur); else (void) cudaGetLastError();
|
||||
for (const int d : split_devs) report_devs.push_back(d);
|
||||
print_startup_gpu_report(report_devs);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!o.native_dense_gguf.empty() && !st.dense.load(o.native_dense_gguf, st.wt, err, o.native_ple_key)) {
|
||||
@@ -4592,8 +4651,8 @@ int main(int argc, char** argv) {
|
||||
// the entire difference between CUDA0's cache and CUDA1's: 814 slots against 188, 2026-09-30. Both of
|
||||
// those allocations are already made before a stage's cache is sized, so what has to be held back here is
|
||||
// the windows and - only on the stage that carries them - the drafter and the head.
|
||||
const int64_t kWindowMib = 96; // the verify windows; 75 MiB measured, rounded up
|
||||
const int64_t kDrafterMib = 1000; // the MTP drafter (839 MiB) + the head, on the last stage only
|
||||
// (the arithmetic is program/stage_reserve.hpp's: 96 MiB for the verify windows - 75 MiB measured, rounded up -
|
||||
// and 1000 MiB for the MTP drafter and the head on the last stage only; pinned by tests/program/stage_reserve_test.cpp)
|
||||
// --pipeline-windows: a second verifier on every stage (its arena alone is 70-75 MiB and its graphs come on top:
|
||||
// 64 MiB left two RTX 5070 Ti under Linux short of it) and, with the decode pipelined, two copies of the first
|
||||
// stage's GDN state (sized from its session where the first card's cache is sized; this is the split search's
|
||||
@@ -4653,9 +4712,14 @@ int main(int argc, char** argv) {
|
||||
const int64_t pf = search && split_own_auto && !place_with_reserve ? 0 : split_pf_mib;
|
||||
const int64_t base_reserve =
|
||||
later && o.vram_reserve_later_mib >= 0 ? o.vram_reserve_later_mib : o.vram_reserve_mib;
|
||||
const int64_t reserve = (base_reserve + pf + (later ? kWindowMib : kPipeSnapMib) +
|
||||
kPipeWindowMib + (drafter ? kDrafterMib : 0)) << 20;
|
||||
return std::max<int64_t>((int64_t) fb - reserve, 0);
|
||||
strata::program::stage_reserve::Inputs rin;
|
||||
rin.base_reserve_mib = base_reserve;
|
||||
rin.prompt_buffers_mib = pf;
|
||||
rin.later = later;
|
||||
rin.drafter = drafter;
|
||||
rin.pipe_window_mib = kPipeWindowMib;
|
||||
rin.pipe_snap_mib = kPipeSnapMib;
|
||||
return strata::program::stage_reserve::room_bytes((int64_t) fb, rin);
|
||||
};
|
||||
if (multi_gpu && split_auto) {
|
||||
const auto& lay = strata::kernels::cpu::expert_layout();
|
||||
@@ -9018,6 +9082,7 @@ int main(int argc, char** argv) {
|
||||
if (!sp.set_peer(&peer, rows, err)) {
|
||||
std::fprintf(stderr, "strata serve: %s - the prompt path stays on the primary GPU\n", err.c_str());
|
||||
err.clear();
|
||||
(void) cudaGetLastError(); // a failed allocation here must not end the engine at the next kernel's check
|
||||
}
|
||||
}
|
||||
// a layer split: a one-chunk prompt runs the stages one after the other, so each stage's prompt path gets the
|
||||
@@ -9030,6 +9095,7 @@ int main(int argc, char** argv) {
|
||||
if (!paths[i].first->set_stage_helper(paths[(i + 1) % paths.size()].first, err)) {
|
||||
std::fprintf(stderr, "strata serve: %s - stage %zu reads its prompts alone\n", err.c_str(), i);
|
||||
err.clear();
|
||||
(void) cudaGetLastError(); // (as above)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11223,6 +11289,16 @@ int main(int argc, char** argv) {
|
||||
"a full card can stall a request",
|
||||
#endif
|
||||
(long long) (later_reserve + 768 - sf_mib));
|
||||
if (sf_mib < 512) { // #3702: how far the plan was off, so the reserve to ask for is not a guess
|
||||
strata::program::stage_reserve::Inputs rin;
|
||||
rin.base_reserve_mib = later_reserve;
|
||||
rin.prompt_buffers_mib = split_pf_mib;
|
||||
rin.later = true;
|
||||
rin.pipe_window_mib = kPipeWindowMib;
|
||||
const std::string why = strata::program::gpu_report::planned_vs_free_text(
|
||||
strata::program::stage_reserve::reserve_mib(rin), sf_mib);
|
||||
if (!why.empty()) std::fprintf(stderr, "strata serve: CUDA%d: %s\n", stp->dev, why.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
// what the server's Monitor tab shows (servers before 0.1.8 skip unknown lines until READY)
|
||||
|
||||
Reference in new issue
Block a user