mirror of
https://github.com/hasso5703/alzeo.git
synced 2026-12-05 20:34:17 +01:00
The three vLLM lanes' installers (Kolibri, Nemotron, Nemotron Super) share vllm-lane.sh: the engine's cache and port, the preflight and the room, the fetch, the service, the uninstall with its opencode and pi cleanup, the proof. Each carried a copy of its own, a fix in one missing from the next. lanes.sh's lane_prune_images removes a build of a lane's image once no installed unit names it: the two Nemotron lanes run one image, and Bolt's update took away the build Super VL's unit named; and unit_hf_cache and existing, one reading each where a dozen copies were. The seventh lane: Super VL in NVFP4 with its LiLiCorr drafter, four requests at a time over the 1,048,576-token window, 16 images and 2 videos per conversation, served in the Nemotron lane's vLLM image (the card's own build does not hold the window at the card's share once the media limits are set). Its unit, its installer in two halves (--units-only, --prepare, the second building the shared image through install-nemotron.sh), its uninstall, which keeps the image while the Bolt lane runs it, as the Bolt lane's keeps it while this one does; every other unit names it in its Conflicts= and After=, the proxy holds requests for it while it boots; its opencode provider (nemotron-super, 990,000 + 32,000 of its window), pi's levels and check-pins.sh's two checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
294 lines
15 KiB
Python
294 lines
15 KiB
Python
#!/usr/bin/env python3
|
|
"""No engine starts on GPU memory the last one has not given back.
|
|
|
|
Issue #26: a 27B engine died with "CUDA error: operation not permitted" and systemd started
|
|
it again 17 s later, the window sglang#40948 blames for a DGX Spark frozen 9.5 h until a
|
|
power cycle. Measured on the reference box (2026-10-01): a crashed engine's 92 GB comes back
|
|
2 to 5 s after its scheduler dies, so the relaunch lands on free memory; the freeze is the
|
|
other case, a driver that kept a dead engine's memory while the next start piled on top of
|
|
it. Every engine unit now runs engine-preflight.sh first, which refuses a start while what
|
|
is left of an engine holds GPU memory, while the driver holds memory no process accounts
|
|
for, or while nvidia-smi does not answer, and lets anything else through.
|
|
|
|
These run the guard as written against a fake /proc/meminfo, a fake nvidia-smi and a fake
|
|
/proc, and pin where the units and the installers put it."""
|
|
import importlib.util
|
|
import pathlib
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import time
|
|
import unittest
|
|
|
|
REPO = pathlib.Path(__file__).resolve().parents[1]
|
|
GUARD = REPO / "engine-preflight.sh"
|
|
UNITS = {"qwen38-sglang.service.template": "qwen38-sglang.service",
|
|
"qwen38-sglang-1m.service.template": "qwen38-sglang.service",
|
|
"qwen38-flash.service.template": "qwen38-flash.service",
|
|
"qwen38-image.service.template": "qwen38-image.service",
|
|
"qwen38-video.service.template": "qwen38-video.service",
|
|
"qwen38-kolibri.service.template": "qwen38-kolibri.service"}
|
|
# MemTotal minus every category the kernel accounts for: 1.35 GiB, the reference box's own
|
|
# figure with no engine and a desktop session (1.1 GiB measured)
|
|
MEMINFO = """MemTotal: 127535084 kB
|
|
MemFree: 102000000 kB
|
|
MemAvailable: 120000000 kB
|
|
Buffers: 10000 kB
|
|
Cached: 17000000 kB
|
|
SwapCached: 50000 kB
|
|
AnonPages: 4000000 kB
|
|
KReclaimable: 1500000 kB
|
|
SUnreclaim: 1400000 kB
|
|
KernelStack: 40000 kB
|
|
PageTables: 100000 kB
|
|
SecPageTables: 0 kB
|
|
Percpu: 20000 kB
|
|
"""
|
|
|
|
|
|
class Box:
|
|
"""A fake /proc with six processes: 101 an SGLang scheduler, 102 SGLang's launcher
|
|
(a python3 whose command line names sglang), 103 somebody's own training script, 104
|
|
vLLM's engine core (the Kolibri lane), 105 vLLM's API server, 106 somebody's own script
|
|
in a directory named vllm."""
|
|
|
|
def __init__(self):
|
|
self.t = pathlib.Path(tempfile.mkdtemp(prefix="preflight-"))
|
|
self.proc = self.t / "proc"
|
|
for pid, comm, cmd in (("101", "sglang::schedul", "x"),
|
|
("102", "python3", "python3\0-m\0sglang.launch_server"),
|
|
("103", "python3", "python3\0train.py"),
|
|
("104", "VLLM::EngineCor", "VLLM::EngineCore"),
|
|
("105", "python3", "/usr/bin/python3\0/usr/local/bin/vllm\0serve\0Aleph-Alpha/Kolibri-1"),
|
|
("106", "python3", "python3\0/home/u/vllm/benchmarks/bench.py")):
|
|
(self.proc / pid).mkdir(parents=True)
|
|
(self.proc / pid / "comm").write_text(comm + "\n")
|
|
(self.proc / pid / "cmdline").write_text(cmd + "\0")
|
|
self.meminfo(0)
|
|
|
|
def meminfo(self, orphan_gib):
|
|
"""The fake meminfo, with orphan_gib more GiB that no kernel category accounts for."""
|
|
free = 102000000 - int(orphan_gib * 1048576)
|
|
(self.t / "meminfo").write_text(re.sub(r"MemFree: +\d+", f"MemFree: {free}", MEMINFO))
|
|
|
|
def smi(self, body):
|
|
(self.t / "smi").write_text("#!/bin/sh\n" + body + "\n")
|
|
(self.t / "smi").chmod(0o755)
|
|
|
|
def run(self, wait_s=2, smi_timeout_s=10, extra=None):
|
|
env = {"PATH": "/usr/bin:/bin", "QWEN38_PREFLIGHT_MEMINFO": str(self.t / "meminfo"),
|
|
"QWEN38_PREFLIGHT_SMI": str(self.t / "smi"), "QWEN38_PREFLIGHT_PROC": str(self.proc),
|
|
"QWEN38_PREFLIGHT_WAIT_S": str(wait_s), "QWEN38_PREFLIGHT_STEP_S": "1",
|
|
"QWEN38_PREFLIGHT_SMI_TIMEOUT_S": str(smi_timeout_s), **(extra or {})}
|
|
t0 = time.monotonic()
|
|
r = subprocess.run(["bash", str(GUARD), "qwen38-test.service"], capture_output=True, text=True,
|
|
env=env, timeout=120)
|
|
return r.returncode, r.stdout + r.stderr, time.monotonic() - t0
|
|
|
|
def done(self):
|
|
shutil.rmtree(self.t, ignore_errors=True)
|
|
|
|
|
|
class WhatBlocksAStart(unittest.TestCase):
|
|
def setUp(self):
|
|
self.box = Box()
|
|
self.addCleanup(self.box.done)
|
|
|
|
def test_nothing_held_starts_at_once(self):
|
|
self.box.smi("exit 0")
|
|
rc, out, secs = self.box.run()
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn("preflight: qwen38-test.service starts: no GPU memory held from before", out)
|
|
self.assertLess(secs, 2, out)
|
|
|
|
def test_a_scheduler_still_holding_memory_is_refused_and_named(self):
|
|
self.box.smi('echo "101, sglang::scheduler, 89531"')
|
|
rc, out, _ = self.box.run()
|
|
self.assertEqual(rc, 1, out)
|
|
self.assertIn("preflight: qwen38-test.service waits: what is left of an engine still holds 87 GiB", out)
|
|
self.assertIn("preflight: NOT starting qwen38-test.service:", out)
|
|
self.assertIn("101 sglang::schedul 89531 MiB", out)
|
|
self.assertEqual(out.count("waits:"), 1, "one waiting line per reason, not one per poll")
|
|
|
|
def test_the_launcher_and_a_pid_the_system_lost_are_remnants_too(self):
|
|
for line, named in (('echo "102, python3, 40000"', "102 python3 40000 MiB"),
|
|
('echo "999, python3, 30000"', "999 gone 30000 MiB")):
|
|
with self.subTest(named=named):
|
|
self.box.smi(line)
|
|
rc, out, _ = self.box.run()
|
|
self.assertEqual(rc, 1, out)
|
|
self.assertIn(named, out)
|
|
|
|
def test_what_is_left_of_a_vllm_engine_is_a_remnant_too(self):
|
|
"""The Kolibri lane runs vLLM: its engine core and its API server hold the GPU like
|
|
SGLang's scheduler does, and a start on top of them is the same freeze."""
|
|
for line, named in (('echo "104, VLLM::EngineCore, 75000"', "104 VLLM::EngineCor 75000 MiB"),
|
|
('echo "105, python3, 3000"', "105 python3 3000 MiB")):
|
|
with self.subTest(named=named):
|
|
self.box.smi(line)
|
|
rc, out, _ = self.box.run()
|
|
self.assertEqual(rc, 1, out)
|
|
self.assertIn(named, out)
|
|
|
|
def test_another_programs_gpu_memory_never_blocks_a_start(self):
|
|
"""Somebody's own GPU work is no remnant: the lane starts and the journal names it."""
|
|
self.box.smi('echo "103, python3, 16578"')
|
|
rc, out, _ = self.box.run()
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn("other programs hold GPU memory: 103 python3 16578 MiB", out)
|
|
|
|
def test_a_path_with_vllm_in_it_is_not_an_engine(self):
|
|
"""Any command line holding "vllm/" was a remnant, so a script of one's own in a vllm
|
|
checkout held every lane's start (found in review, 2026-10-14)."""
|
|
self.box.smi('echo "106, python3, 3000"')
|
|
rc, out, _ = self.box.run()
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn("other programs hold GPU memory: 106 python3 3000 MiB", out)
|
|
|
|
def test_a_small_remnant_is_below_the_line(self):
|
|
"""The tokenizer of an engine being torn down holds 196 MiB for a few seconds."""
|
|
self.box.smi('echo "101, sglang::scheduler, 196"')
|
|
self.assertEqual(self.box.run()[0], 0)
|
|
self.box.smi('echo "101, sglang::scheduler, 2049"')
|
|
self.assertEqual(self.box.run()[0], 1)
|
|
|
|
def test_memory_the_driver_keeps_for_nobody_is_refused_past_16_gib(self):
|
|
self.box.smi("exit 0")
|
|
self.box.meminfo(14.0) # 1.35 + 14.0 = 15.35 GiB unaccounted: a desktop at its worst
|
|
self.assertEqual(self.box.run()[0], 0)
|
|
self.box.meminfo(15.0) # 16.35 GiB
|
|
rc, out, _ = self.box.run()
|
|
self.assertEqual(rc, 1, out)
|
|
self.assertIn("the GPU driver holds 16.3 GiB that no process accounts for", out)
|
|
|
|
def test_listed_memory_is_not_counted_as_the_drivers_own(self):
|
|
"""An engine holding 50 GiB raises the unaccounted figure by 50 GiB: that is its own,
|
|
not memory the driver keeps for nobody."""
|
|
self.box.meminfo(50.0)
|
|
self.box.smi('echo "103, python3, 51200"')
|
|
self.assertEqual(self.box.run()[0], 0)
|
|
|
|
def test_a_driver_that_does_not_answer_is_refused(self):
|
|
for body in ("exit 9", "sleep 30"):
|
|
with self.subTest(smi=body):
|
|
self.box.smi(body)
|
|
rc, out, secs = self.box.run(wait_s=1, smi_timeout_s=1)
|
|
self.assertEqual(rc, 1, out)
|
|
self.assertIn("the GPU driver does not answer nvidia-smi", out)
|
|
self.assertLess(secs, 15, "a hung nvidia-smi is cut off, not waited for")
|
|
|
|
def test_odd_lines_are_read_or_left_out(self):
|
|
"""[N/A] memory has nothing to count, and a process name may hold commas."""
|
|
self.box.smi('echo "103, python3, [N/A]"; echo ""; echo "103, my,odd,app, 16578"')
|
|
rc, out, _ = self.box.run()
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn("other programs hold GPU memory: 103 python3 16578 MiB", out)
|
|
self.box.smi('echo "101, sglang, odd, 60000"')
|
|
self.assertEqual(self.box.run()[0], 1)
|
|
|
|
def test_memory_released_while_it_waits_lets_the_start_through(self):
|
|
flag = self.box.t / "released"
|
|
self.box.smi(f'[ -f {flag} ] || echo "101, sglang::scheduler, 60000"')
|
|
proc = subprocess.Popen(["sh", "-c", f"sleep 2; touch {flag}"])
|
|
self.addCleanup(proc.wait)
|
|
rc, out, secs = self.box.run(wait_s=20)
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn("waits:", out)
|
|
self.assertIn("starts:", out)
|
|
self.assertLess(secs, 10, out)
|
|
|
|
|
|
class WhereItRuns(unittest.TestCase):
|
|
def test_every_engine_unit_runs_it_before_it_starts(self):
|
|
for tpl, unit in UNITS.items():
|
|
with self.subTest(tpl=tpl):
|
|
text = (REPO / tpl).read_text()
|
|
line = f"ExecStartPre=/bin/bash __HOME__/.config/qwen38/engine-preflight.sh {unit}\n"
|
|
self.assertEqual(text.count(line), 1, tpl)
|
|
self.assertLess(text.index(line), text.index("ExecStart="), tpl)
|
|
rm = re.search(r"ExecStartPre=-/usr/bin/docker rm -f \S+\n", text)
|
|
if rm:
|
|
# the old container goes first, then the guard waits for its memory
|
|
self.assertLess(rm.start(), text.index(line), tpl)
|
|
|
|
def test_no_attempt_outlasts_the_units_start_timeout(self):
|
|
"""systemd kills a start step after TimeoutStartSec (90 s by default, and no engine
|
|
unit sets another): a guard killed mid-wait would refuse with no word said."""
|
|
guard = GUARD.read_text()
|
|
wait = int(re.search(r'WAIT_S="\$\{QWEN38_PREFLIGHT_WAIT_S:-(\d+)\}"', guard).group(1))
|
|
step = int(re.search(r'STEP_S="\$\{QWEN38_PREFLIGHT_STEP_S:-(\d+)\}"', guard).group(1))
|
|
smi = int(re.search(r'SMI_TIMEOUT_S="\$\{QWEN38_PREFLIGHT_SMI_TIMEOUT_S:-(\d+)\}"', guard).group(1))
|
|
self.assertIn('timeout -k 2 "$SMI_TIMEOUT_S"', guard)
|
|
for tpl in UNITS:
|
|
text = (REPO / tpl).read_text()
|
|
m = re.search(r"^TimeoutStartSec=(\d+)", text, re.M)
|
|
budget = int(m.group(1)) if m else 90
|
|
self.assertLess(wait + step + smi + 2 + 5, budget, tpl)
|
|
|
|
def test_every_installer_that_writes_such_a_unit_puts_it_in_place(self):
|
|
"""Run on its own, install-image.sh or install-video.sh would leave a unit naming a
|
|
script that is not there, and the lane would never start."""
|
|
for inst, src in (("install.sh", "$REPO_DIR"), ("install-image.sh", "$HERE"), ("install-video.sh", "$HERE"),
|
|
("vllm-lane.sh", "$HERE")):
|
|
with self.subTest(inst=inst):
|
|
text = (REPO / inst).read_text()
|
|
self.assertIn(f'install -m 755 "{src}/engine-preflight.sh" "$CONFIG_DIR/engine-preflight.sh"', text)
|
|
# written only when it changed, so an unchanged run rewrites nothing
|
|
self.assertIn(f'cmp -s "{src}/engine-preflight.sh" "$CONFIG_DIR/engine-preflight.sh"', text)
|
|
for inst in ("install-image.sh", "install-video.sh"):
|
|
text = (REPO / inst).read_text()
|
|
# in place before the unit naming it is rendered ("$HERE/$UNIT.template")
|
|
self.assertLess(text.index("engine-preflight.sh"), text.index('"$HERE/$UNIT.template"'), inst)
|
|
# the vLLM lanes put it in place through vllm-lane.sh's service step, before their render
|
|
for inst in ("install-kolibri.sh", "install-nemotron.sh", "install-nemotron-super.sh"):
|
|
text = (REPO / inst).read_text()
|
|
self.assertLess(text.index(" vlane_service_files "), text.index('"$HERE/$UNIT.template"'), inst)
|
|
install = (REPO / "install.sh").read_text()
|
|
self.assertLess(install.index('install -m 755 "$REPO_DIR/engine-preflight.sh"'),
|
|
install.index("qwen38-sglang.service.template"))
|
|
|
|
def test_it_is_a_bash_script_that_says_what_it_does_on_one_line(self):
|
|
guard = GUARD.read_text()
|
|
self.assertTrue(guard.startswith("#!/usr/bin/env bash\n"))
|
|
self.assertTrue(GUARD.stat().st_mode & 0o111, "executable in the repo")
|
|
# the three lines the cockpit reads to say why a lane is not up yet
|
|
for said in ('"preflight: $LANE starts:', '"preflight: $LANE waits:', '"preflight: NOT starting $LANE:'):
|
|
self.assertIn(said, guard)
|
|
|
|
|
|
class TheCockpitReadsWhatItWrites(unittest.TestCase):
|
|
"""A contract with dashboard/lifecycle.py, run as written: the cockpit reads these lines
|
|
from the unit's journal, and a pattern written against a remembered line would let the
|
|
two drift apart. It sat in the cockpit's suite, where the mutation gate replays the suite
|
|
for every mutant of lifecycle.py (309 of them), a second each."""
|
|
|
|
def setUp(self):
|
|
self.box = Box()
|
|
self.addCleanup(self.box.done)
|
|
spec = importlib.util.spec_from_file_location("lifecycle_read_by_the_guard_test",
|
|
REPO / "dashboard" / "lifecycle.py")
|
|
self.lc = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(self.lc)
|
|
|
|
def test_its_lines_are_the_words_the_cockpit_reads(self):
|
|
# 3 s, not 1: the guard counts whole seconds ($SECONDS), so with 1 s a first look
|
|
# that ended past the shell's first second refused at once, with no line saying it
|
|
# waited, and this failed once in a full local CI run (2026-10-02; reproduced with an
|
|
# nvidia-smi that answers in 1.2 s). The service's own wait is 60 s.
|
|
self.box.smi('echo "101, sglang::scheduler, 60000"')
|
|
rc, out, _ = self.box.run(wait_s=3)
|
|
self.assertEqual(rc, 1, out)
|
|
held = "what is left of an engine still holds 58 GiB of GPU memory: 101 sglang::schedul 60000 MiB"
|
|
lines = out.splitlines()
|
|
self.assertEqual(self.lc.parse_preflight(lines[:1]), {"verdict": "waits", "reason": held})
|
|
self.assertEqual(self.lc.parse_preflight(lines), {"verdict": "refused", "reason": held})
|
|
self.box.smi("exit 0")
|
|
rc, out, _ = self.box.run()
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertEqual(self.lc.parse_preflight(out.splitlines())["verdict"], "starts")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|