mirror of
https://github.com/hasso5703/alzeo.git
synced 2026-12-06 21:04:21 +01:00
The Load's prepare fetched the new revision with `switch-model.sh <target> --fetch`, which stops right after the download, so on the serving lane's short path (prepare, apply_pending, restart, no switch) the new checkpoint's config.json was never YaRN-patched for a 1M unit (which does not load on an unpatched config), never restored for a native one, Arete's fp8 KV cache was never declared, and the chat template was never regenerated from the new revision (sixth review of v1.52.0, 2026-11-19, GLM 5.3, defect 1, verified in the code and on the box: the 27B serves the 1M window). The switch's steps 2, 2a and 2b are now one function, lanes.sh's `patch_served_checkpoint`, which the switch calls with the unit in place and prepare-lane.sh, when an update waits for this Load and this Load loads its target, with the unit that waits and the cache it mounts: the 27B and the flash serve their new revision with those steps done, on the short path as on the other. The patches are idempotent, so a journey that runs both changes nothing twice. tests/test_prepare_load_wait.py runs the prepare on a fabricated cache and fails on the code before (config unpatched, no template); test_switch_native_restore and test_arete_target read the function where it now lives. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
181 lines
9.8 KiB
Python
181 lines
9.8 KiB
Python
#!/usr/bin/env python3
|
|
"""The arete target is served with the 27B lane's fp8 KV cache, declared in its checkpoint's config.
|
|
|
|
atakans/Arete-27B-NVFP4 declares no KV cache, and SGLang gives such a checkpoint a bf16 one and about
|
|
half the pool. The A/B of 2026-11-14 served it with the lane's declaration written into its config:
|
|
target cache fp8, draft cache bf16, pool 905,941 tokens (patch-kv.py says why that and not the flag the
|
|
FP8 targets pass). So its switch and its install write that declaration, after the window's configs (a
|
|
YaRN restore puts back a config.json saved before it), and nothing else: its unit is stock's, with no
|
|
--kv-cache-dtype, and no other target's config is touched. run.sh, which serves what ./install.sh
|
|
--no-service prepared, refuses it undeclared. The scripts' own lines run here, patch-yarn.py and
|
|
patch-kv.py replaced by stubs that record their calls in one log, in order."""
|
|
import pathlib
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
REPO = pathlib.Path(__file__).resolve().parents[1]
|
|
SWITCH = (REPO / "switch-model.sh").read_text()
|
|
INSTALL = (REPO / "install.sh").read_text()
|
|
RUN = (REPO / "run.sh").read_text()
|
|
LANES = (REPO / "lanes.sh").read_text()
|
|
PINS = dict(re.findall(r'^([A-Z0-9_]+_(?:REPO|REV))="([^"$]+)"', INSTALL, re.M))
|
|
ARETE = (PINS["ARETE_REPO"], PINS["ARETE_REV"])
|
|
TARGETS_27B = {"stock": "STOCK", "uncensored": "UNC", "fp8": "FP8", "uncensored-fp8": "UNCFP8", "arete": "ARETE"}
|
|
# the switch's steps 2, 2a and 2b after the fetch, as one function lanes.sh holds and the switch
|
|
# calls with the unit in place (prepare-lane.sh calls it with the unit that waits)
|
|
FN = LANES[LANES.index("patch_served_checkpoint(){"):LANES.index("\n}\n", LANES.index("patch_served_checkpoint(){")) + 3]
|
|
|
|
|
|
def block(text, start, end_after):
|
|
"""text from the line holding `start` to the end of the first `fi` line after the line holding `end_after`."""
|
|
s = text.rindex("\n", 0, text.index(start)) + 1
|
|
return text[s:text.index("\nfi\n", text.index(end_after, s)) + 4]
|
|
|
|
|
|
def stubs(d, kv_rc=0):
|
|
"""patch-yarn.py, patch-kv.py and patch-template.py in d, each line of the shared log: the script, then its arguments."""
|
|
for name, rc in (("patch-yarn.py", 0), ("patch-kv.py", kv_rc), ("patch-template.py", 0)):
|
|
(d / name).write_text(
|
|
"import os, sys\n"
|
|
"open(os.path.join(os.path.dirname(sys.argv[0]), 'calls'), 'a').write("
|
|
"os.path.basename(sys.argv[0]) + ' ' + ' '.join(sys.argv[1:]) + '\\n')\n"
|
|
f"sys.exit({rc})\n")
|
|
|
|
|
|
def bash(script, d):
|
|
r = subprocess.run(["bash", "-c", 'set -euo pipefail\ndie(){ echo "DIE: $*"; exit 1; }\n' + script],
|
|
capture_output=True, text=True, timeout=30)
|
|
calls = d / "calls"
|
|
return r.stdout + r.stderr, calls.read_text().splitlines() if calls.exists() else []
|
|
|
|
|
|
class TheSwitch(unittest.TestCase):
|
|
# steps 2, 2a and 2b after the fetch, as lanes.sh's patch_served_checkpoint runs them for the switch
|
|
def switch(self, choice, window, kv_rc=0):
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="arete-switch-"))
|
|
self.addCleanup(shutil.rmtree, d, True)
|
|
stubs(d, kv_rc)
|
|
(d / "unit").write_text(f"ExecStart=... --context-length {window} ...\n")
|
|
repo, rev = PINS[TARGETS_27B[choice] + "_REPO"], PINS[TARGETS_27B[choice] + "_REV"]
|
|
script = (f'_lanes_dir(){{ echo "{d}"; }}\nCONFIG_DIR="{d}"\n' + FN +
|
|
f'patch_served_checkpoint 27b {choice} "{d}/unit" /hf {repo} {rev}\necho REACHED\n')
|
|
return bash(script, d)
|
|
|
|
def test_arete_gets_the_declaration_after_the_window_in_both_modes(self):
|
|
repo, rev = ARETE
|
|
for window, yarn in ((1010000, f"patch-yarn.py /hf {repo} {rev}"), (262144, f"patch-yarn.py --restore /hf {repo} {rev}")):
|
|
with self.subTest(window=window):
|
|
out, calls = self.switch("arete", window)
|
|
self.assertEqual(calls[:2], [yarn, f"patch-kv.py /hf {repo} {rev}"], out)
|
|
self.assertIn("patch-template.py /hf", calls[2], out)
|
|
self.assertIn("REACHED", out)
|
|
|
|
def test_no_other_target_has_its_config_declared(self):
|
|
for choice in ("stock", "uncensored", "fp8", "uncensored-fp8"):
|
|
for window in (1010000, 262144):
|
|
with self.subTest(choice=choice, window=window):
|
|
out, calls = self.switch(choice, window)
|
|
self.assertEqual([c for c in calls if c.startswith("patch-kv.py")], [], out)
|
|
self.assertEqual(len(calls), 2, out) # the window's config, then the template
|
|
self.assertIn("REACHED", out)
|
|
|
|
def test_a_declaration_that_fails_stops_the_switch_before_the_unit(self):
|
|
out, _ = self.switch("arete", 1010000, kv_rc=3)
|
|
self.assertIn("DIE: the fp8 KV cache declaration failed", out)
|
|
self.assertNotIn("REACHED", out)
|
|
|
|
def test_its_unit_is_stocks_with_no_kv_flag(self):
|
|
# the KV line of the rewritten unit, as switch-model.sh decides it and then checks it
|
|
lines = block(SWITCH, ' case "$CHOICE" in\n fp8|uncensored-fp8) NEW_KV=', ' *) NEW_KV=""')
|
|
lines = lines[:lines.index(" esac\n") + len(" esac\n")]
|
|
for choice, kv in (("arete", ""), ("stock", ""), ("fp8", "--kv-cache-dtype fp8_e4m3 ")):
|
|
with self.subTest(choice):
|
|
r = subprocess.run(["bash", "-c", f"set -eu\nCHOICE={choice}\n{lines}printf '%s' \"$NEW_KV\""],
|
|
capture_output=True, text=True, timeout=30)
|
|
self.assertEqual((r.returncode, r.stdout), (0, kv), r.stderr)
|
|
|
|
|
|
class TheInstaller(unittest.TestCase):
|
|
FUNC = INSTALL[INSTALL.index("apply_context_configs(){"):INSTALL.index("\n}\n", INSTALL.index("apply_context_configs(){")) + 3]
|
|
|
|
def configs(self, choice, mode, units_only=0, kv_rc=0):
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="arete-install-"))
|
|
self.addCleanup(shutil.rmtree, d, True)
|
|
stubs(d, kv_rc)
|
|
repo, rev = PINS[TARGETS_27B[choice] + "_REPO"], PINS[TARGETS_27B[choice] + "_REV"]
|
|
script = (f'REPO_DIR="{d}"; HF_CACHE=/hf; MODEL_CHOICE={choice}; MODEL_REPO={repo}; MODEL_REV={rev}; '
|
|
f'LANE=27b; CONTEXT_MODE={mode}; UNITS_ONLY={units_only}; KEEP_MODEL_VERBATIM=0; NO_SERVICE=0; '
|
|
f'SGL_UNIT_PATH="{d}/none"; DRAFT2_REPO=org/draft; DRAFT2_REV=dddd\n'
|
|
+ self.FUNC + "apply_context_configs\necho REACHED\n")
|
|
return bash(script, d)
|
|
|
|
def test_arete_gets_the_declaration_last_in_both_modes(self):
|
|
repo, rev = ARETE
|
|
for mode, opt in (("1m", ""), ("native", "--restore ")):
|
|
with self.subTest(mode):
|
|
out, calls = self.configs("arete", mode)
|
|
self.assertEqual(calls, [f"patch-yarn.py {opt}/hf {repo} {rev}", f"patch-yarn.py {opt}/hf org/draft dddd",
|
|
f"patch-kv.py /hf {repo} {rev}"], out)
|
|
self.assertIn("REACHED", out)
|
|
|
|
def test_no_other_target_has_its_config_declared(self):
|
|
for choice in ("stock", "uncensored", "fp8", "uncensored-fp8"):
|
|
for mode in ("1m", "native"):
|
|
with self.subTest(choice=choice, mode=mode):
|
|
out, calls = self.configs(choice, mode)
|
|
self.assertEqual(len(calls), 2, out)
|
|
self.assertFalse(any(c.startswith("patch-kv.py") for c in calls), out)
|
|
|
|
def test_a_lane_installed_on_demand_leaves_it_to_its_first_load(self):
|
|
out, calls = self.configs("arete", "1m", units_only=1)
|
|
self.assertEqual(calls, [], out)
|
|
self.assertIn("REACHED", out)
|
|
|
|
def test_a_declaration_that_fails_stops_the_install(self):
|
|
out, _ = self.configs("arete", "1m", kv_rc=3)
|
|
self.assertIn("DIE: the fp8 KV cache declaration failed", out)
|
|
self.assertNotIn("REACHED", out)
|
|
|
|
def test_its_unit_is_stocks_with_no_kv_flag(self):
|
|
lines = block(INSTALL, 'case "$MODEL_CHOICE" in\n fp8|uncensored-fp8) KV_CACHE_ARGS=', ' *) KV_CACHE_ARGS=""')
|
|
lines = lines[:lines.index("esac\n") + len("esac\n")]
|
|
for choice, kv in (("arete", ""), ("stock", ""), ("uncensored-fp8", "--kv-cache-dtype fp8_e4m3 ")):
|
|
with self.subTest(choice):
|
|
r = subprocess.run(["bash", "-c", f"set -eu\nMODEL_CHOICE={choice}\n{lines}printf '%s' \"$KV_CACHE_ARGS\""],
|
|
capture_output=True, text=True, timeout=30)
|
|
self.assertEqual((r.returncode, r.stdout), (0, kv), r.stderr)
|
|
|
|
|
|
class RunSh(unittest.TestCase):
|
|
LINES = block(RUN, 'if [ "$MODEL_CHOICE" = arete ]; then', 'if [ "$MODEL_CHOICE" = arete ]; then')
|
|
|
|
def run_check(self, choice, check_rc):
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="arete-run-"))
|
|
self.addCleanup(shutil.rmtree, d, True)
|
|
stubs(d, check_rc)
|
|
repo, rev = PINS[TARGETS_27B[choice] + "_REPO"], PINS[TARGETS_27B[choice] + "_REV"]
|
|
script = (f'REPO_DIR="{d}"; HF_CACHE=/hf; MODEL_CHOICE={choice}; MODEL_REPO={repo}; MODEL_REV={rev}; '
|
|
f'PREP="MODEL_CHOICE={choice} ./install.sh --no-service"\n' + self.LINES + "echo REACHED\n")
|
|
return bash(script, d)
|
|
|
|
def test_an_undeclared_arete_is_refused_with_its_preparation(self):
|
|
out, calls = self.run_check("arete", 2)
|
|
self.assertEqual(calls, [f"patch-kv.py --check /hf {ARETE[0]} {ARETE[1]}"])
|
|
self.assertIn("DIE: checkpoint atakans/Arete-27B-NVFP4 does not declare the fp8 KV cache", out)
|
|
self.assertIn("Run: MODEL_CHOICE=arete ./install.sh --no-service", out)
|
|
self.assertNotIn("REACHED", out)
|
|
|
|
def test_a_declared_arete_runs_and_the_others_are_not_asked(self):
|
|
out, calls = self.run_check("arete", 0)
|
|
self.assertIn("REACHED", out)
|
|
out, calls = self.run_check("stock", 2)
|
|
self.assertEqual(calls, [])
|
|
self.assertIn("REACHED", out)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|