From 005e43fdb6275f2f426d6562e63be95fca394dd1 Mon Sep 17 00:00:00 2001 From: Hasan Basbunar Date: Sat, 24 Oct 2026 16:02:49 +0200 Subject: [PATCH] vLLM lanes: one function writes a lane's patched template, also on an install of the units alone The Flash FP4-Local and Ornith installers wrote their patched chat template with the same lines each, and their --units-only path put a unit that mounts the template without writing it: an update that took that path on a box that had served the lane (its image pruned since, so the lane looked not begun) left a unit whose start docker refuses (found by the code review on 2026-10-24; the kept unit of the commit before covers a lane that starts at boot, this covers the rest). vllm-lane.sh's vlane_template writes it from each lane's one TEMPLATE_FIXES line (VAR=value for patch-template.py's environment, --options for its command line), and vlane_template_if_cached does it on --units-only when the pinned checkpoint is in the cache; without it, the first Load writes it, as before. tests/lane-templates-check.py reads TEMPLATE_FIXES to hold the installers to its table. tests/test_vlane_template.py fails on the old tree. Co-Authored-By: Claude Opus 5.5 --- install-flash-local.sh | 7 ++-- install-ornith-122b.sh | 9 ++--- tests/lane-templates-check.py | 18 +++++++-- tests/test_lane_templates_check.py | 2 +- tests/test_ornith_lane.py | 2 +- tests/test_vlane_template.py | 63 ++++++++++++++++++++++++++++++ vllm-lane.sh | 24 ++++++++++++ 7 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 tests/test_vlane_template.py diff --git a/install-flash-local.sh b/install-flash-local.sh index 4a6629ad..3a02e173 100755 --- a/install-flash-local.sh +++ b/install-flash-local.sh @@ -160,10 +160,8 @@ fi # it. Written again at every install and every switch; left as it is, mtime included, when nothing # changed. TEMPLATE="$CONFIG_DIR/chat-template-flash-local.jinja" -lane_template(){ - LEAN_DEFAULT=0 python3 "$HERE/patch-template.py" "$HF_CACHE" "$TEMPLATE" "$MODEL_REV" "$MODEL" \ - || die "the chat template could not be patched (the lines above say why)" -} +TEMPLATE_FIXES=(LEAN_DEFAULT=0) +lane_template(){ vlane_template "$TEMPLATE" "${TEMPLATE_FIXES[@]}"; } # The n-gram table: where the engine reads it, copied first when the cache is on another disk than # the home directory's (ple-table.py). TABLE_MOUNTS is the unit's -v arguments for the copies, empty @@ -283,6 +281,7 @@ if [ "$MODE" = units ]; then echo "OK: $(uname -m), key present; the image and the checkpoint come with the lane's first Load" # a checkpoint already in the cache (an install.sh run after a Load) keeps the table's mounts lane_table mounts + vlane_template_if_cached "$TEMPLATE" "${TEMPLATE_FIXES[@]}" install_service step "Done: the Flash FP4-Local lane is installed; its first Load prepares it" echo " the cockpit: Load on Flash FP4-Local (NVIDIA) in the Lanes view pulls its image (about 18 GB, 10 to" diff --git a/install-ornith-122b.sh b/install-ornith-122b.sh index 4083e6a8..6b4b208c 100755 --- a/install-ornith-122b.sh +++ b/install-ornith-122b.sh @@ -129,17 +129,15 @@ render_unit(){ "$HERE/$UNIT.template" > "$1" } -# The checkpoint's chat template with the one fix it needs (patch-template.py --patches): it +# The checkpoint's chat template with the one fix it needs (vlane_template, TEMPLATE_FIXES): it # refused a system message past the first one, which opencode 1.19.4 sends, and every opencode request # on this lane got a 400 (2026-10-24); that message becomes a , as on the 27B and the # two flash lanes. The template has no reasoning effort of its own (the proxy gives it one through # enable_thinking), so that is its only fix. Written again at every install and every switch, and left # as it is, mtime included, when nothing changed. TEMPLATE="$CONFIG_DIR/chat-template-ornith-122b.jinja" -lane_template(){ - python3 "$HERE/patch-template.py" --patches=system-reminder "$HF_CACHE" "$TEMPLATE" "$MODEL_REV" "$MODEL" \ - || die "the chat template could not be patched (the lines above say why)" -} +TEMPLATE_FIXES=(--patches=system-reminder) +lane_template(){ vlane_template "$TEMPLATE" "${TEMPLATE_FIXES[@]}"; } # This lane's own folders: vLLM's compile cache, FlashInfer's and Triton's kernels and b12x's # kernel choices, built at the first boot. @@ -187,6 +185,7 @@ vlane_preflight engine-preflight.sh engine-secrets.sh vllm_engine_auth.py ckpt-f vlane_room "$FLASH_LOCAL_IMAGE" "$MODEL" if [ "$MODE" = units ]; then echo "OK: $(uname -m), key present; the image and the checkpoint come with the lane's first Load" + vlane_template_if_cached "$TEMPLATE" "${TEMPLATE_FIXES[@]}" install_service step "Done: the Ornith 1.5 122B lane is installed; its first Load prepares it" echo " the cockpit: Load on Ornith 1.5 122B in the Lanes view pulls its image (the Flash FP4-Local lane's," diff --git a/tests/lane-templates-check.py b/tests/lane-templates-check.py index 96d40fda..b1f5c56e 100644 --- a/tests/lane-templates-check.py +++ b/tests/lane-templates-check.py @@ -62,6 +62,20 @@ def pin(text, prefix): return repo.group(1), rev.group(1) +def fixes_of(installer_text): + """What an installer tells patch-template.py, from its one TEMPLATE_FIXES line (vlane_template in + vllm-lane.sh runs it with them): None when it patches nothing, else {"patches": its --patches, and + each VAR=value of its environment}.""" + m = re.search(r"^TEMPLATE_FIXES=\(([^)]*)\)$", installer_text, re.M) + if not m: + return None if "vlane_template" not in installer_text else {"unread": "TEMPLATE_FIXES"} + spec = {} + for item in m.group(1).split(): + key, _, value = item.lstrip("-").partition("=") + spec[key] = value + return spec + + def lane_specs(repo_dir=REPO): """Every text target: (name, repo, revision, patch environment or None). The 27B and flash targets are install.sh's (its case of MODEL_REPO lines), patched with the four fixes at every install and @@ -78,9 +92,7 @@ def lane_specs(repo_dir=REPO): raise SystemExit(f"the vLLM lanes are {installers}, this check knows {known}: add the new lane to VLLM_LANES") for name, (installer, prefix, env) in VLLM_LANES.items(): text = (repo_dir / installer).read_text() - patched = "patch-template.py" in text - asked = re.search(r'patch-template\.py" --patches=(\S+) ', text) - if patched != (env is not None) or (asked.group(1) if asked else None) != (env or {}).get("patches"): + if fixes_of(text) != env: raise SystemExit(f"{installer} serves its template otherwise than VLLM_LANES says for {name}") specs.append((name, *pin(text, prefix), env)) switch = re.search(r'^case "\$CHOICE" in ([a-z0-9|-]+)\) ;;', (repo_dir / "switch-model.sh").read_text(), re.M) diff --git a/tests/test_lane_templates_check.py b/tests/test_lane_templates_check.py index 79ae806b..5531fa60 100644 --- a/tests/test_lane_templates_check.py +++ b/tests/test_lane_templates_check.py @@ -57,7 +57,7 @@ class TheLanesItKnows(unittest.TestCase): def test_an_installer_that_serves_its_template_otherwise_stops_it(self): d = self.copy() f = d / "install-ornith-122b.sh" - f.write_text(f.read_text().replace(" --patches=system-reminder ", " ")) + f.write_text(f.read_text().replace("TEMPLATE_FIXES=(--patches=system-reminder)", "TEMPLATE_FIXES=()")) with self.assertRaisesRegex(SystemExit, "install-ornith-122b.sh serves its template otherwise"): ltc.lane_specs(d) diff --git a/tests/test_ornith_lane.py b/tests/test_ornith_lane.py index db55b416..7dc0cd49 100644 --- a/tests/test_ornith_lane.py +++ b/tests/test_ornith_lane.py @@ -112,7 +112,7 @@ class TheStagedUnit(unittest.TestCase): self.assertLess(step3.index('vlane_fetch "$MODEL" "$MODEL_REV"'), step3.index("lane_template")) pre = TEXT[TEXT.index("vlane_preflight "):TEXT.index("vlane_room ")] self.assertIn("patch-template.py", pre) - self.assertIn('patch-template.py" --patches=system-reminder ', TEXT) + self.assertIn("TEMPLATE_FIXES=(--patches=system-reminder)", TEXT) def test_the_window_is_a_million_with_yarn_written_where_the_layers_read_it(self): # The model card's form, --hf-overrides '{"rope_scaling": ...}', sets a field at the top of the diff --git a/tests/test_vlane_template.py b/tests/test_vlane_template.py new file mode 100644 index 00000000..3300f8f6 --- /dev/null +++ b/tests/test_vlane_template.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +"""The vLLM lanes that patch their chat template write it through one function, also on an install of +the units alone when the pinned checkpoint is in the cache. + +The Flash FP4-Local and Ornith lanes' units mount their patched template, and their installers' --units-only +path put the unit without writing it: an update that took that path on a box that had served the lane (its +image pruned since) left a unit whose start docker refuses (code review, 2026-10-24). vllm-lane.sh's own +vlane_template_if_cached runs here on a throwaway cache, with patch-template.py itself.""" +import importlib.util +import os +import pathlib +import shutil +import subprocess +import tempfile +import unittest + +REPO = pathlib.Path(__file__).resolve().parents[1] +spec = importlib.util.spec_from_file_location("patch_template", REPO / "patch-template.py") +pt = importlib.util.module_from_spec(spec) +spec.loader.exec_module(pt) +MODEL, REV = "org/lane", "f" * 40 + + +class TheTemplateOfAnInstallOfTheUnitsAlone(unittest.TestCase): + def setUp(self): + self.d = pathlib.Path(tempfile.mkdtemp(prefix="vlane-template-")) + self.addCleanup(shutil.rmtree, self.d, True) + self.out = self.d / "chat-template-lane.jinja" + self.body = "HEAD\n" + pt.SYSTEM_ANCHOR + "\nTAIL\n" + + def cache(self): + snap = self.d / "hf" / "hub" / f"models--{MODEL.replace('/', '--')}" / "snapshots" / REV + snap.mkdir(parents=True) + (snap / "chat_template.jinja").write_text(self.body) + + def run_it(self, *fixes): + script = "\n".join([ + "set -euo pipefail", 'die(){ echo "die: $*"; exit 1; }', f'HERE="{REPO}"', + f'. "{REPO}/vllm-lane.sh"', f'HF_CACHE="{self.d}/hf"', f"MODEL={MODEL}", f"MODEL_REV={REV}", + f'vlane_template_if_cached "{self.out}" ' + " ".join(fixes), "echo DONE"]) + return subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=60, + env=dict(os.environ, PATH="/usr/bin:/bin")) + + def test_written_with_the_lanes_fixes_when_the_checkpoint_is_cached(self): + self.cache() + r = self.run_it("--patches=system-reminder") + self.assertIn("DONE", r.stdout, r.stdout + r.stderr) + self.assertEqual(self.out.read_text(), self.body.replace(pt.SYSTEM_ANCHOR, pt.SYSTEM_PATCHED)) + + def test_nothing_written_and_no_failure_without_the_checkpoint(self): + r = self.run_it("--patches=system-reminder") + self.assertIn("DONE", r.stdout, r.stdout + r.stderr) + self.assertFalse(self.out.exists()) + + def test_a_fix_that_is_neither_a_variable_nor_an_option_stops_it(self): + self.cache() + r = self.run_it("system-reminder") + self.assertNotEqual(r.returncode, 0) + self.assertIn("neither VAR=value nor --option", r.stdout) + + +if __name__ == "__main__": + unittest.main() diff --git a/vllm-lane.sh b/vllm-lane.sh index 8fee6a95..fefc9105 100644 --- a/vllm-lane.sh +++ b/vllm-lane.sh @@ -161,6 +161,30 @@ vlane_service_files(){ # $1... the lane's cache folders || install -m 644 "$HERE/vllm_engine_auth.py" "$CONFIG_DIR/vllm-auth/vllm_engine_auth.py" } +# The checkpoint's own chat template with this lane's fixes (patch-template.py), written to $1: again at +# every install and every switch, and left as it is, mtime included, when nothing changed. The rest is +# the lane's TEMPLATE_FIXES: VAR=value for patch-template.py's environment, --options for its command +# line. One function for the vLLM lanes that patch their template (Flash FP4-Local, Ornith), which had +# the same lines each (code review, 2026-10-24). +vlane_template(){ # $1 the file, then the lane's TEMPLATE_FIXES + local out="$1" a envs=() opts=() + shift + for a in "$@"; do + case "$a" in --*) opts+=("$a") ;; *=*) envs+=("$a") ;; *) die "vlane_template: $a is neither VAR=value nor --option" ;; esac + done + env ${envs[@]+"${envs[@]}"} python3 "$HERE/patch-template.py" ${opts[@]+"${opts[@]}"} "$HF_CACHE" "$out" "$MODEL_REV" "$MODEL" \ + || die "the chat template could not be patched (the lines above say why)" +} + +# The same when the units alone are installed (--units-only), if the pinned checkpoint is in the cache +# already: the unit mounts the template, and an update that took this path on a box that had served the +# lane (its image pruned since) put a unit whose start docker refuses (code review, 2026-10-24). Without +# the checkpoint, the lane's first Load writes it before starting it. +vlane_template_if_cached(){ # $1 the file, then the lane's TEMPLATE_FIXES + [ -f "$HF_CACHE/hub/models--${MODEL//\//--}/snapshots/$MODEL_REV/chat_template.jinja" ] || return 0 + vlane_template "$@" +} + # The rendered unit put in place (lanes.sh's unit_put), and what that means for a lane that serves: # it goes on serving the unit, the runtime and the start scripts it started with, said here when no # proof follows to restart it, whether this run or an earlier update changed them (an update leaves