q36 engine: a hybrid start that cannot fit its buffers says so with the numbers

With many slots on a small card (8 sessions on a 12 GB RTX 3060, UD-Q6_K_XL) the sessions left too little VRAM for the hybrid
mode's staging pair, CPU-output buffer and expert slots, and the start died in a bare cudaMalloc failure. place_experts now adds
up what it is about to allocate and exits 1 with "not enough VRAM left for the hybrid experts' buffers and slots (N MiB needed,
M MiB free ...)" and the way out (fewer slots, a shorter --max-context, fewer --expert-slots). Only a start that would have
crashed changes; the placement and every answer are as before.

tools/qwen35/q36_vram_refusal.py: demanding starts (8 slots, long contexts, every expert as a slot) must reach READY or exit 1
with one of the engine's refusals, never a raw allocation failure.
This commit is contained in:
Niko1221 committed 2026-10-14 12:33:29 +02:00
1 parent 8bfef49c5f
commit c2947a9230
2 files changed
+87

No files matched your search

+16
View File
@@ -2530,6 +2530,22 @@ bool place_experts(Model& m, Engine& E, double vram_gib, int threads, int hybrid
const size_t left = budget2 > total_main ? budget2 - total_main : 0;
S = (int) std::min<size_t>((size_t) ne, left / m.mtp.stride);
}
{ // what the hybrid mode allocates next (the staging pair, the CPU part's outputs, the slots) against the VRAM the
// sessions and the context left: said with the numbers instead of a cudaMalloc failure (8 slots on a 12 GB card)
const size_t Tn = (size_t) E.tmax, Nn = (size_t) g.n_embd, Kn = (size_t) m.top_k;
size_t need = staging + Tn * Kn * Nn * 4 + Tn * Kn * 4;
for (Layer* L : all) {
if (mtp_only && L != &m.mtp) need += L->stride * (size_t) ne + kMmqTail;
else need += (S > 0 ? (size_t) S * L->stride + kMmqTail : 0);
}
if (need > fr) {
err = "not enough VRAM left for the hybrid experts' buffers and slots (" + std::to_string((need >> 20)) +
" MiB needed, " + std::to_string(fr >> 20) + " MiB free after the weights, the context and the sessions): use "
"fewer slots (\"parallel\" / --batch), a shorter --max-context" +
(slots > 0 ? ", or fewer --expert-slots" : "");
return false;
}
}
// host memory: every expert, pinned where the driver allows it (the prompt's stream and the slot copies)
size_t host = 0;
for (Layer* L : all)
+71
View File
@@ -0,0 +1,71 @@
"""q36_vram_refusal.py --exe E --model M : an engine start that does not fit the card says so with the numbers.
Starts the engine (--serve) with demanding configurations (many slots, a long context, every expert asked for as a slot) and
checks that each start either reaches READY or exits 1 with one of the engine's own refusals ("not enough VRAM for N slots ...",
"not enough VRAM left for the hybrid experts' buffers and slots ...") - never a bare cudaMalloc failure. On a card that holds
every configuration the check only reports that they started. The engine is stopped right after READY.
python q36_vram_refusal.py --exe build/strata-q36 --model Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf
"""
import argparse, subprocess, sys, threading, time
CONFIGS = [
["--max-context", "8192", "--batch", "8", "--expert-slots", "256"],
["--max-context", "32768", "--batch", "8", "--expert-slots", "256"],
["--max-context", "8192", "--batch", "8"],
["--max-context", "32768", "--batch", "8"],
["--max-context", "131072", "--batch", "8"],
]
CLEAR = ("not enough VRAM for", "not enough VRAM left for the hybrid experts")
RAW = ("cudaMalloc", "hipMalloc", "out of memory")
def run(exe, model, extra, timeout):
p = subprocess.Popen([exe, "--serve", "--model", model, *extra], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True, bufsize=1)
err = []
t = threading.Thread(target=lambda: err.extend(p.stderr), daemon=True)
t.start()
ready = False
try:
for line in p.stdout:
if line.startswith("READY"):
ready = True
p.stdin.write("STOP\n")
p.stdin.flush()
break
p.wait(timeout=timeout)
except subprocess.TimeoutExpired:
p.kill()
t.join(5)
return ready, p.returncode, "".join(err)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--exe", required=True)
ap.add_argument("--model", required=True)
ap.add_argument("--timeout", type=int, default=900)
a = ap.parse_args()
ok = True
for extra in CONFIGS:
time.sleep(5) # the previous engine's VRAM is back
ready, rc, err = run(a.exe, a.model, extra, a.timeout)
if ready:
print("START %-62s ready" % " ".join(extra))
continue
clear = [l for l in err.splitlines() if any(c in l for c in CLEAR)]
raw = [l for l in err.splitlines() if any(r in l for r in RAW)]
good = bool(clear) and not raw and rc == 1
ok &= good
if not good:
for l in err.splitlines()[-6:]:
print(" | " + l[:240])
print("%s %-62s exit %s: %s" % ("REFUSE" if good else "FAIL ", " ".join(extra), rc,
(clear or raw or err.splitlines()[-1:] or ["(no output)"])[0][:260]))
print("GATE", "PASS" if ok else "FAIL")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())