Files
alzeo/tests/test_install_disk_need.py
T
Hasan BasbunarandClaude Opus 5.5 52970656fd on demand: the 27B beside a serving flash too; each text lane's image read from its line, its room counted at its first Load
The validated design (2026-10-14) puts the other text lane on demand, whichever it is; the 27B
installed beside a serving flash (MODEL_CHOICE=flash) was still installed whole, ~15 GB of
image and ~28 GB of checkpoints. It is on demand now, as the flash beside the 27B is: its unit
only, and its first Load runs ./prepare-lane.sh 27b, which pulls the image its unit runs, fetches
the DFlash2 draft its unit names in that image, sets the draft's config for the window the unit
serves (the YaRN patch for 1M, put back for the native one, as install.sh does), and fetches the
target's checkpoint by the switch's own --fetch; the Load's switch then patches the target's
config and writes its template. A 27B is prepared when its image and its draft are on the box
(every box installed before this is), and --with-27b or --all-weights installs it whole.

Found while proving the first Load on the reference box (2026-10-15):
- A units-only run still asked for the whole lane's room (180 GB for the flash's checkpoint,
  50 for its PLE table, 35 for its image) and was refused on a disk that could not hold them,
  so the lane did not even get its units. It takes no room now; prepare-lane.sh checks the
  room for each download before its first byte: the image's on Docker's disk before the pull,
  the checkpoint's in the switch's fetch as before, and the flash lane's PLE table (47.7 GiB,
  written at every boot) after the checkpoint, when the two may share a disk.
- The flash lane's image was read with a pattern of the digest pins, so an image an operator
  named by tag (FLASH_IMAGE=lmsysorg/sglang:dev-qwen38-next-local, as install.sh's own advice
  says) read as not prepared, and its lane would have been put back to units on the next run.
  Every reader (install.sh, prepare-lane.sh, the cockpit) takes the word on the line before the
  server command now, the line both templates give the image, whatever its form (lanes.sh's
  engine_image; the cockpit's engine_image does the same).

Tests: the parent asks for the 27B's units only when it is new, its image is not here or its
draft is not in the cache, and not when both are, under --all-weights or --with-27b; the mode
refuses anything but the two text lanes; the 27B's configs wait for its first Load (no YaRN call
in units-only, one otherwise); a units-only run of either lane passes a disk of 10 GB that a
whole install of either is refused on. prepare-lane.sh 27b run as written: the image pulled
(its room checked first) and tagged, the draft fetched in that image at its revision, its config
patched for 1M and put back for native, the target the unit serves fetched; a token goes by its
name only; a custom model or no unit is refused. prepare-lane.sh flash: an image named by tag is
pulled (and needs no local tag), no room for the image is refused before the pull, no room for
the PLE table after the checkpoint (a table already there takes its own). The cockpit says the
27B is prepared with its image and its draft's config and weights (a ref such as main read
through refs/), and the flash with its image in either form; its prepare action takes 27b. The
installer and cockpit tests that cut install.sh by its text define UNITS_ONLY as a whole
install does. 434 installer and 191 cockpit tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 01:21:37 +02:00

115 lines
5.1 KiB
Python

#!/usr/bin/env python3
"""install.sh measures what is left to download, on the disk it will land on.
huggingface_hub creates a checkpoint's snapshot folder before the first byte of its
first file (file_download.py, 1.31.0, the version in the pinned image), and install.sh
read "a snapshot folder exists" as "the checkpoint is cached": its disk need dropped from
180 to 10 GB, so a flash download interrupted at 74 GB of 124, then resumed, was checked
against 10 and could fill the disk. The PLE table the flash lane writes at every boot
(47.7 GiB) was checked against HF_CACHE's disk, never PLE_DIR's (found in review,
2026-09-24).
The installer's own lines run here against a fake cache, with df and stat answered by
stubs where a test needs two disks.
"""
import json
import pathlib
import subprocess
import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
TEXT = (REPO / "install.sh").read_text()
START = TEXT.index("NEED_GB=45; DOCKER_NEED_GB=40")
END = TEXT.index('[ -n "$FREE_DISK_GB" ] && [ "$FREE_DISK_GB" -ge "$NEED_GB" ] || die', START)
BLOCK = TEXT[START:END]
SHARDS = [f"model-0000{i}-of-00004.safetensors" for i in range(1, 5)]
def cache(root, shards_done, blob_gb=0.0, index=True):
"""A repo folder the way huggingface_hub leaves it: blobs, and a snapshot whose
files are links to them, a link appearing only once its blob is whole."""
repo = root / "hub" / "models--org--model"
snap = repo / "snapshots" / "abc123"
blobs = repo / "blobs"
snap.mkdir(parents=True)
blobs.mkdir(parents=True)
if index:
(snap / "model.safetensors.index.json").write_text(json.dumps(
{"weight_map": {f"t{i}": s for i, s in enumerate(SHARDS)}}))
for i, s in enumerate(SHARDS[:shards_done]):
(blobs / f"b{i}").write_bytes(b"x")
(snap / s).symlink_to(f"../../blobs/b{i}")
if blob_gb:
with open(blobs / "partial.incomplete", "wb") as f:
f.truncate(int(blob_gb * 1024 ** 3)) # sparse: its apparent size is what counts
return root
def run(lane, root, free_gb=1000, ple_other_disk=None):
t = pathlib.Path(tempfile.mkdtemp(prefix="disk-need-bin-"))
stub, ple = "", f"{root}/ple"
if ple_other_disk is not None:
# PLE_DIR on a second disk, whose folder exists but not the table's own: stat
# names another device for it, df gives it its own space
(root / "otherdisk").mkdir()
ple = f"{root}/otherdisk/ple"
(t / "stat").write_text("#!/bin/sh\ncase \"$*\" in *otherdisk*) echo 99;; *) echo 1;; esac\n")
(t / "df").write_text(f"#!/bin/sh\necho Avail; echo {ple_other_disk}G\n")
for f in ("stat", "df"):
(t / f).chmod(0o755)
stub = f'PATH="{t}:$PATH"\n'
script = (stub + "set -euo pipefail\ndie(){ echo \"DIE: $*\"; exit 1; }\n"
f'HF_CACHE="{root}"; MODEL_REPO=org/model; MODEL_REV=abc123; LANE={lane}\n'
f'PLE_DIR="{ple}"; FREE_DISK_GB={free_gb}; UNITS_ONLY=0 # a whole install (an on-demand one takes no room)\n'
+ BLOCK + 'echo "NEED=$NEED_GB"\n')
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=60)
out = r.stdout + r.stderr
for ln in out.splitlines():
if ln.startswith("NEED="):
return int(ln[5:]), out
return None, out
class TheNeedIsWhatIsLeft(unittest.TestCase):
def tmp(self):
return pathlib.Path(tempfile.mkdtemp(prefix="disk-need-"))
def test_a_snapshot_folder_alone_is_not_a_cached_checkpoint(self):
need, out = run("27b", cache(self.tmp(), shards_done=0))
self.assertEqual(need, 45, out)
def test_a_whole_checkpoint_needs_working_room_only(self):
need, out = run("27b", cache(self.tmp(), shards_done=4))
self.assertEqual(need, 10, out)
def test_an_interrupted_download_is_charged_what_is_left(self):
"""The 2026-09-18 case: 74 GB of the flash checkpoint in cache, no PLE table yet."""
need, out = run("flash", cache(self.tmp(), shards_done=2, blob_gb=74))
self.assertEqual(need, 180 - 74 + 50, out)
def test_a_single_file_checkpoint_counts_when_its_file_is_there(self):
root = cache(self.tmp(), shards_done=0, index=False)
snap = root / "hub/models--org--model/snapshots/abc123"
(root / "hub/models--org--model/blobs/whole").write_bytes(b"x")
(snap / "model.safetensors").symlink_to("../../blobs/whole")
need, out = run("27b", root)
self.assertEqual(need, 10, out)
class ThePleTableIsCheckedOnItsOwnDisk(unittest.TestCase):
def test_a_ple_dir_on_a_full_disk_is_refused(self):
root = cache(pathlib.Path(tempfile.mkdtemp(prefix="disk-need-")), shards_done=4)
need, out = run("flash", root, ple_other_disk=20)
self.assertIsNone(need, out)
self.assertIn("PLE_DIR", out)
def test_a_ple_dir_on_its_own_roomy_disk_adds_nothing_here(self):
root = cache(pathlib.Path(tempfile.mkdtemp(prefix="disk-need-")), shards_done=4)
need, out = run("flash", root, ple_other_disk=500)
self.assertEqual(need, 10, out)
if __name__ == "__main__":
unittest.main(verbosity=2)