serve: capture the verify windows up front, not on the first request
cudaGraphInstantiate allocates device memory for each window size's exec and the
exec is never freed (measured ~22-26 MiB per size on a GTX 1070 Ti, 2026-10-15).
serve captured each size lazily, on the first request that used it, so that
memory came out of - and could outrun - the reserve the auto-cache had been sized
against. A serve planned down to its last ~150 MiB therefore captured the sizes
its first requests asked for and then failed the next
strata serve: verify: instantiate: out of memory
mid-request, which took the engine and the front end down with it (the container
restarted). This is not the sampler or the Qwen3.6 port: the DRY work adds ~4 KB
of device arrays and a 128 KB history row, and the lazy capture predates both.
Every size 1..max_t the serve path can ask for is now captured right after the
verifier is bound (after set_split / set_pcie_mode, which the recorded graph
depends on). That makes the cost part of what the serve free-VRAM check sees and
bounds it before any request runs: a size that does not fit is reported at
startup, naming the knobs that make room, instead of killing a request.
Seen on kontron.local: a GTX 1070 Ti (sm_61) serving Flash-Next Coder IQ1_M with
--ctx 131072 --vram-cap 7680. There the window graphs need ~135 MiB and the plan
left 135 MiB free; --vram-reserve-mib 700 (which skips #496's lowering to 300)
leaves ~630 MiB and all six fit. The cap itself is honoured: the blocker held
back the 424 MiB it should.
This commit is contained in:
1 parent
c8c3ca492c
commit
4ad0206b1f
2 files changed
+31
No files matched your search
@@ -89,6 +89,13 @@ public:
|
||||
/// One window: `tokens[0..T)` at positions pos0.., the pool served per layer; `out[t]` = argmax after token t.
|
||||
/// The PLE rows are gathered here from `ss.ple_prev` and the tokens. Captures the T-token graph on first use.
|
||||
bool run(int T, const int32_t* tokens, int64_t pos0, PoolMultiFn pool, void* user, int32_t* out, std::string& err);
|
||||
/// Capture the T-token window graph NOW instead of on its first `run`. cudaGraphInstantiate allocates device
|
||||
/// memory per window size and the exec is never freed (measured ~22-26 MiB per size on a GTX 1070 Ti,
|
||||
/// 2026-10-15), so a size captured lazily spent the reserve one request at a time until an instantiate ran out
|
||||
/// mid-request and the engine died. `serve` captures every size it can ask for (1..max_t) up front; `run` still
|
||||
/// captures any size that was missed. False with `err` when the capture fails (the buffers or the exec did not
|
||||
/// fit). Set `set_split`/`set_pcie_mode` first: the recorded graph depends on them.
|
||||
bool capture_window(int T, std::string& err) { return capture(T, err); }
|
||||
/// Diagnostics: row `t` of the last window's head logits (n_vocab floats) to the host. Valid after run().
|
||||
bool copy_logits(int t, float* host) const;
|
||||
int64_t vocab() const { return next_ ? next_->vocab() : n_vocab_; }
|
||||
|
||||
@@ -5528,6 +5528,30 @@ int main(int argc, char** argv) {
|
||||
// issue #31's thread dumps show the host stuck in that cudaMemcpyAsync on a driver lock for good. The copy
|
||||
// kernel needs no host CUDA call there, and costs ~1-3% decode on IQ3_S (45.3 -> 44.8 tok/s, 8 requests).
|
||||
ver.set_pcie_mode(o.pcie_mode == "dma" ? 0 : o.pcie_mode == "direct" ? 1 : 2);
|
||||
// ---- CAPTURE EVERY WINDOW SIZE HERE, NOT ON THE FIRST REQUEST THAT USES IT. cudaGraphInstantiate
|
||||
// allocates device memory per size and the exec is never freed (measured ~22-26 MiB per size on a GTX
|
||||
// 1070 Ti, 2026-10-15); a size captured lazily drew on the reserve the cache had been sized against, and a
|
||||
// request that needed a size not yet captured died with "verify: instantiate: out of memory" and took the
|
||||
// engine down with it. Doing it here makes that cost part of what the free-VRAM check below sees and bounds
|
||||
// it before any request runs; a size that does not fit is reported now, with the way to make room.
|
||||
{
|
||||
const int win_max_t = std::max(o.spec, o.batch);
|
||||
const int64_t kWindowGraphMib = 32; // one exec per size; 26 MiB measured on the 1070 Ti, rounded up
|
||||
for (int T = 1; T <= win_max_t; ++T) {
|
||||
for (int st = 0; st < n_stages; ++st) {
|
||||
std::string cerr;
|
||||
if (!stage_ver(st).capture_window(T, cerr)) {
|
||||
std::fprintf(stderr, "strata serve: %s\n", cerr.c_str());
|
||||
std::fprintf(stderr, "strata serve: the verify window needs one captured graph per size "
|
||||
"(1..%d), about %lld MiB of VRAM beyond its buffers; it does not fit "
|
||||
"beside this cache - lower --max-context, raise --vram-reserve-mib, or "
|
||||
"close other programs that use the GPU\n",
|
||||
win_max_t, (long long) win_max_t * (long long) kWindowGraphMib);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::vector<int64_t> cur;
|
||||
// ---- the conversation cache (see ConvCheckpoint). `live` is what the session holds right now: the tokens
|
||||
// it has consumed, so a request that starts with exactly them continues without any copy. `checks` are the
|
||||
|
||||
Reference in new issue
Block a user