mirror of
https://github.com/hasso5703/alzeo.git
synced 2026-12-06 21:04:21 +01:00
Their check of the model was a start step, whose 78 systemd starts again every 10 s, where RestartPreventExitStatus holds the main process's: it heads ExecStart, and gives a disk mounted late its 90 s. A port taken while the lane runs left it on the old one, where nobody asks: it is restarted. (review of v1.60.0) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
801 lines
45 KiB
Python
801 lines
45 KiB
Python
#!/usr/bin/env python3
|
|
"""The embeddings lane (install-embeddings.sh): the unit its --stage writes, its pins, and the
|
|
shape its engine runs in.
|
|
|
|
pplx-embed-v1-0.6b on Hugging Face's TEI, on the CPU beside every lane: no Conflicts=, no key
|
|
(TEI 1.9.4 writes its arguments to the journal unredacted), 127.0.0.1 alone, its container capped
|
|
by its cgroup and pinned to the A725 cores, the Hugging Face cache mounted read-only and offline.
|
|
--stage runs the installer as written, in a throwaway home, with no sudo and no docker.
|
|
"""
|
|
import pathlib
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
REPO = pathlib.Path(__file__).resolve().parents[1]
|
|
INSTALLER = REPO / "install-embeddings.sh"
|
|
TEXT = INSTALLER.read_text()
|
|
UNIT = "qwen38-embed.service"
|
|
TEMPLATE = (REPO / "qwen38-embed.service.template").read_text()
|
|
PINS = {k: v.strip('"') for k, v in (ln.split("=", 1) for ln in TEXT.splitlines()
|
|
if re.match(r"^EMBED_[A-Z_]+=", ln))}
|
|
MODEL = PINS["EMBED_MODEL"]
|
|
REV = PINS["EMBED_REV"]
|
|
IMAGE = PINS["EMBED_IMAGE"]
|
|
|
|
|
|
def exec_command(unit: str) -> str:
|
|
"""The ExecStart command as systemd runs it: the lines a backslash ends joined."""
|
|
i = unit.index("exec /usr/bin/docker run")
|
|
return unit[i:unit.index("'\n", unit.index("--port", i))].replace("\\\n", " ")
|
|
|
|
|
|
class TheStagedUnit(unittest.TestCase):
|
|
def setUp(self):
|
|
self.t = pathlib.Path(tempfile.mkdtemp(prefix="embed-stage-"))
|
|
self.addCleanup(shutil.rmtree, self.t, True)
|
|
self.home = self.t / "home"
|
|
self.cfg = self.home / ".config" / "qwen38"
|
|
self.cfg.mkdir(parents=True)
|
|
(self.cfg / "api-key").write_text("test-key\n")
|
|
self.units = self.t / "units"
|
|
self.units.mkdir()
|
|
self.hf = self.t / "hf"
|
|
self.out = self.t / "stage.service"
|
|
|
|
def stage(self, env=None):
|
|
e = {"PATH": "/usr/bin:/bin", "HOME": str(self.home), "LANES_UNIT_DIR": str(self.units), **(env or {})}
|
|
r = subprocess.run(["bash", str(INSTALLER), "--stage", str(self.out)],
|
|
capture_output=True, text=True, env=e, timeout=120)
|
|
return r.returncode, r.stdout + r.stderr
|
|
|
|
def a_unit_mounting(self, unit, cache):
|
|
(self.units / unit).write_text(
|
|
f"ExecStart=/bin/bash -c 'exec /usr/bin/docker run --rm --name {unit[:-len('.service')]} "
|
|
f"-v {cache}:/root/.cache/huggingface:ro x'\n")
|
|
|
|
def test_it_serves_the_pinned_model_at_the_pinned_revision_on_the_pinned_image(self):
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
cmd = exec_command(self.out.read_text())
|
|
self.assertIn(IMAGE, cmd)
|
|
self.assertIn(f"--model-id /root/.cache/huggingface/hub/models--{MODEL.replace('/', '--')}/snapshots/{REV}", cmd)
|
|
self.assertIn(f"--revision {REV}", cmd)
|
|
self.assertIn("--dtype float32", cmd)
|
|
self.assertIn("--pooling mean", cmd)
|
|
self.assertIn("--served-model-name pplx-embed-v1-0.6b", cmd)
|
|
|
|
def test_the_engine_reads_the_pinned_snapshot_from_the_mounted_cache_by_its_path(self):
|
|
"""TEI takes a --model-id that is not a folder in its container for a Hub repository, and
|
|
fetches it from the Hub into its image's own HUGGINGFACE_HUB_CACHE (/data, inside the
|
|
container, gone at its --rm) at every start: hf-hub 0.4.3, its Rust client, has no offline
|
|
mode, so HF_HUB_OFFLINE changed nothing, and the cache the unit mounts was never read. The
|
|
box's journal of 2026-11-20 shows it at each start of the lane (Downloading onnx/model.onnx,
|
|
onnx/model.onnx_data and onnx/model.onnx_data_1, 57 to 89 s, then the ORT backend, "batch
|
|
size > 8"), the safetensors the Load fetched left unread (the review of v1.60.0). Given
|
|
the snapshot's folder in the mounted cache, TEI reads it as a local model and asks the Hub
|
|
nothing (router/src/lib.rs at v1.9.4: a model_id that exists as a folder)."""
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
cmd = exec_command(self.out.read_text())
|
|
model_id = re.search(r"--model-id (\S+)", cmd).group(1)
|
|
self.assertEqual(model_id, f"/root/.cache/huggingface/hub/models--{MODEL.replace('/', '--')}/snapshots/{REV}")
|
|
self.assertIn(" -v ", cmd)
|
|
self.assertRegex(cmd, r"-v \S+:/root/\.cache/huggingface:ro ")
|
|
|
|
def test_no_key_and_loopback_only(self):
|
|
"""TEI 1.9.4 logs its argument list unredacted, so no key is passed to it, and without one
|
|
it never listens beyond 127.0.0.1: the proxy is the only door to it (the review of the
|
|
conception, 2026-11-19)."""
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
unit = self.out.read_text()
|
|
self.assertNotIn("api-key", unit)
|
|
self.assertNotIn("API_KEY", unit)
|
|
self.assertNotIn("--api-key", unit)
|
|
self.assertNotIn("Authorization", unit)
|
|
cmd = exec_command(unit)
|
|
self.assertIn("--hostname 127.0.0.1", cmd)
|
|
for bind in re.findall(r"(?:--host(?:name)?\s+|Host=)(?!127\.0\.0\.1)\S+", unit):
|
|
self.fail(f"the lane listens beyond loopback: {bind}")
|
|
|
|
def test_its_container_is_capped_by_its_cgroup_and_pinned_to_the_small_cores(self):
|
|
"""A runaway (an attention of the order of n^2 on a long input) kills this container
|
|
alone, never the box (the unified pool's livelock), and a busy text engine never shares
|
|
the big cores with it."""
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
cmd = exec_command(self.out.read_text())
|
|
mem = re.search(r"--memory (\S+) --memory-swap (\S+)", cmd)
|
|
self.assertIsNotNone(mem, "the container has no cgroup memory cap")
|
|
self.assertEqual(mem.group(1), mem.group(2), "--memory and --memory-swap differ: the cap would swap, not kill")
|
|
self.assertEqual(mem.group(1), PINS["EMBED_MEMORY"])
|
|
self.assertIn(f"--cpuset-cpus {PINS['EMBED_CPUS']}", cmd)
|
|
self.assertIn(f"--max-batch-tokens {PINS['EMBED_MAX_BATCH_TOKENS']}", cmd)
|
|
|
|
def test_the_cache_is_mounted_read_only_and_the_engine_reads_it_offline(self):
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
unit = self.out.read_text()
|
|
self.assertIn("-e HF_HUB_OFFLINE=1", unit)
|
|
m = re.search(r"-v (\S+):/root/\.cache/huggingface:ro", unit)
|
|
self.assertIsNotNone(m, "the Hugging Face cache is not mounted read-only")
|
|
self.assertEqual(m.group(1), str(self.hf) if "HF_CACHE" in (out or "") else str(self.home / ".cache" / "huggingface"))
|
|
|
|
def test_it_runs_beside_every_lane(self):
|
|
"""No Conflicts=: the lane never takes the GPU, so nothing stops for it and it stops for
|
|
nothing (the speech lane's shape, not the engine lanes')."""
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
unit = self.out.read_text()
|
|
self.assertNotIn("\nConflicts=", "\n" + unit)
|
|
|
|
def test_it_starts_after_the_network_and_docker_like_every_docker_unit(self):
|
|
"""Every other docker unit of the repo starts After=network-online.target docker.service;
|
|
without the After= a boot where the lane is enabled raced docker.service, and its run
|
|
died to be restarted 10 s later (the blind review of 2026-11-20)."""
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn("After=network-online.target docker.service", self.out.read_text())
|
|
|
|
def test_the_port_and_its_override(self):
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn("--port 30028", exec_command(self.out.read_text()))
|
|
rc, out = self.stage(env={"EMBED_PORT": "30128"})
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn("--port 30128", exec_command(self.out.read_text()))
|
|
# the proxy follows a port taken here: it reads the --port of the installed unit, not a
|
|
# port written in advance (the blind review of 2026-11-20), and the doc says so
|
|
doc = " ".join((REPO / "docs" / "embed-lane.md").read_text().split())
|
|
self.assertIn("The proxy reads the lane's port from its unit", doc)
|
|
|
|
def test_the_preflight_names_the_model_and_leaves_the_unit_failed(self):
|
|
"""TEI reads the model offline, so a model that is not whole is a start with no reason to
|
|
retry: 78 leaves the unit failed with the line that says what to do."""
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
unit = self.out.read_text()
|
|
pre = re.search(r"ExecStart=/bin/bash -c '(.*?)exec /usr/bin/docker run ", unit, re.S)
|
|
self.assertIsNotNone(pre, "the unit checks nothing before its engine")
|
|
self.assertIn(f"snapshots/{REV}", pre.group(1))
|
|
self.assertIn("model.safetensors", pre.group(1))
|
|
self.assertIn("exit 78", pre.group(1))
|
|
self.assertIn("RestartPreventExitStatus=78", unit)
|
|
self.assertEqual([ln for ln in unit.splitlines() if ln.startswith("ExecStartPre=") and "exit 78" in ln], [],
|
|
"the check is a start step, whose 78 systemd starts again every 10 s")
|
|
# it waits 90 s for a disk mounted late, then 78; with every file there the engine runs at once
|
|
head = " ".join(pre.group(1).replace("\\\n", " ").split())
|
|
files = re.search(r'for f in ([^;]+); do \[ -f', head).group(1).split()
|
|
snap = pathlib.Path(re.search(r'snap="([^"]+)"', head).group(1))
|
|
head = head.replace(str(snap), str(self.t / "snap"))
|
|
for have, rc, waits in (((), 78, 30), (files[:-1], 78, 30), (files, 0, 0)):
|
|
shutil.rmtree(self.t / "snap", True)
|
|
for f in have:
|
|
(self.t / "snap" / f).parent.mkdir(parents=True, exist_ok=True)
|
|
(self.t / "snap" / f).write_text("x")
|
|
r = subprocess.run(["bash", "-c", "sleep(){ echo waited; }; " + head + " exit 0"], capture_output=True, text=True)
|
|
self.assertEqual((r.returncode, r.stdout.count("waited")), (rc, waits), (len(have), r.stderr[-300:]))
|
|
if rc:
|
|
self.assertIn("preflight: qwen38-embed.service lacks its model: ", r.stderr)
|
|
self.assertIn("./install-embeddings.sh --fetch", r.stderr)
|
|
|
|
def test_the_preflight_checks_every_file_the_engine_reads(self):
|
|
"""The checkpoint is whole to lanes.sh's ckpt_cached as soon as model.safetensors is
|
|
there, a convention shared with every lane (the review of 2026-11-19's point 6); the
|
|
tokenizer and the configs count for TEI as much as the weights, so the unit's own
|
|
preflight checks every pinned file: a partial snapshot leaves it failed at 78, which
|
|
RestartPreventExitStatus blocks, instead of TEI dying in a restart loop every 10 s."""
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
pre = re.search(r"ExecStart=/bin/bash -c '(.*?)exec /usr/bin/docker run ", self.out.read_text(), re.S)
|
|
self.assertIsNotNone(pre, "the unit checks nothing before its engine")
|
|
for path in re.findall(r"([\w./]+)=[0-9a-f]{40,64}:\d+", TEXT):
|
|
self.assertIn(path, pre.group(1), f"the preflight does not check {path}")
|
|
|
|
def test_the_cache_the_text_lanes_mount_is_the_one_it_fetches_into(self):
|
|
"""A box whose cache lives on another disk (docs/external-disk.md: HF_CACHE=/mnt/ssd/huggingface
|
|
./install.sh) keeps the model there, read the way the lanes beside it read theirs."""
|
|
self.a_unit_mounting("qwen38-sglang.service", "/mnt/ssd/huggingface")
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertEqual(re.search(r"-v (\S+):/root/\.cache/huggingface:ro", self.out.read_text()).group(1),
|
|
"/mnt/ssd/huggingface")
|
|
|
|
def test_its_own_unit_keeps_priority_over_the_text_lanes(self):
|
|
self.a_unit_mounting(UNIT, "/mnt/own/huggingface")
|
|
self.a_unit_mounting("qwen38-sglang.service", "/mnt/ssd/huggingface")
|
|
rc, out = self.stage()
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertEqual(re.search(r"-v (\S+):/root/\.cache/huggingface:ro", self.out.read_text()).group(1),
|
|
"/mnt/own/huggingface")
|
|
|
|
def test_hf_cache_in_the_environment_wins_over_every_unit(self):
|
|
self.a_unit_mounting("qwen38-sglang.service", "/mnt/ssd/huggingface")
|
|
rc, out = self.stage(env={"HF_CACHE": "/mnt/asked/huggingface"})
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertEqual(re.search(r"-v (\S+):/root/\.cache/huggingface:ro", self.out.read_text()).group(1),
|
|
"/mnt/asked/huggingface")
|
|
|
|
|
|
class TheStaticChecks(unittest.TestCase):
|
|
def test_the_installer_passes_shellcheck_as_the_ci_runs_it(self):
|
|
"""The blind review of 2026-11-19 left the branch's static check RED: SC2034 (IMAGE_GB
|
|
never read), SC2178 (need and size, arrays in lanes.sh, scalars here) and SC2046 (an
|
|
unquoted $(model_files)). The CI checks every script together, which is what made
|
|
lanes.sh's arrays leak into this installer's variables: this pair reproduces it."""
|
|
r = subprocess.run(["shellcheck", "-S", "warning", str(INSTALLER), str(REPO / "lanes.sh")],
|
|
capture_output=True, text=True)
|
|
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
|
|
|
|
|
class TheImagePullChecksItsRoom(unittest.TestCase):
|
|
"""The review of 2026-11-19: IMAGE_GB was declared and never read, so --prepare pulled
|
|
TEI's image with no check of the room, where the model's own fetch refuses before the
|
|
first byte. The pull refuses the same way now, on Docker's own disk, before docker pull."""
|
|
|
|
def prepare(self, free_gib, image_here=False):
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="embed-room-"))
|
|
self.addCleanup(shutil.rmtree, d, True)
|
|
(d / "docker-root").mkdir()
|
|
(d / "home").mkdir()
|
|
bin = d / "bin"; bin.mkdir()
|
|
log = d / "pull.log"
|
|
(bin / "df").write_text(f"#!/bin/sh\necho Avail\necho {free_gib}G\n")
|
|
(bin / "getent").write_text("#!/bin/sh\nexit 2\n")
|
|
(bin / "id").write_text(
|
|
"#!/bin/sh\ncase $1 in"
|
|
" -u) echo 1000 ;; -G) echo 1000 ;; -un|-gn) echo user ;; -nG) echo user ;;"
|
|
" *) exit 1 ;; esac\n")
|
|
(bin / "docker").write_text(
|
|
"#!/bin/sh\n"
|
|
'[ "$1" = info ] && { echo "' + str(d / "docker-root") + '"; exit 0; }\n'
|
|
f'[ "$1 $2" = "image inspect" ] && exit {0 if image_here else 1}\n'
|
|
f'[ "$1" = pull ] && {{ echo "pull $*" >> "{log}"; exit 0; }}\n'
|
|
'exit 0\n')
|
|
# --prepare fetches the model too (ThePreparePosesTheModelToo): a stand-in python3 keeps
|
|
# this class's runs off the network, its own room check is that other class's subject
|
|
(bin / "python3").write_text(
|
|
"#!/bin/sh\n"
|
|
f'[ "$1" = -I ] && [ "$2" = "{REPO / "gguf-fetch.py"}" ] && exit 0\n'
|
|
'exec /usr/bin/python3 "$@"\n')
|
|
for f in ("df", "getent", "id", "docker", "python3"):
|
|
(bin / f).chmod(0o755)
|
|
r = subprocess.run(["bash", str(INSTALLER), "--prepare"], capture_output=True, text=True,
|
|
env={"PATH": f"{bin}:/usr/bin:/bin", "HOME": str(d / "home"),
|
|
"LANES_UNIT_DIR": str(d / "units")},
|
|
timeout=60)
|
|
return r.returncode, r.stdout + r.stderr, log
|
|
|
|
def test_a_disk_too_full_for_the_image_refuses_before_the_pull(self):
|
|
rc, out, log = self.prepare(free_gib=0)
|
|
self.assertNotEqual(rc, 0, out)
|
|
self.assertIn("nothing was pulled", out)
|
|
self.assertIn("GiB free", out)
|
|
self.assertFalse(log.exists(), "docker pull ran although the disk was refused")
|
|
|
|
def test_a_disk_with_room_pulls(self):
|
|
rc, out, log = self.prepare(free_gib=8)
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn(IMAGE, log.read_text())
|
|
|
|
def test_an_image_already_here_needs_no_room(self):
|
|
# the image's own room: none is asked when it is here; the model's is, and the disk
|
|
# below gives it (a disk without room for the model is the other class's refusal)
|
|
rc, out, log = self.prepare(free_gib=8, image_here=True)
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertFalse(log.exists(), out)
|
|
|
|
|
|
class ThePreparePosesTheModelToo(unittest.TestCase):
|
|
""""--prepare is what the cockpit's first Load runs (prepare-lane.sh embeddings runs it), and a
|
|
Load that poses the image alone leaves the start to die at the preflight's 78 on a box without
|
|
the model, an endless reload (the blind review of 2026-11-20): --prepare poses the image AND the
|
|
model, the room checked before the model's first byte as --fetch checks its own, and the fetch
|
|
itself idempotent (gguf-fetch.py verifies what the cache holds and downloads what it lacks)."""
|
|
|
|
def prepare(self, free_gib, image_here=False):
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="embed-prepare-"))
|
|
self.addCleanup(shutil.rmtree, d, True)
|
|
(d / "docker-root").mkdir()
|
|
(d / "home").mkdir()
|
|
bin = d / "bin"; bin.mkdir()
|
|
pull_log = d / "pull.log"
|
|
fetch_log = d / "fetch.log"
|
|
(bin / "df").write_text(f"#!/bin/sh\necho Avail\necho {free_gib}G\n")
|
|
(bin / "getent").write_text("#!/bin/sh\nexit 2\n")
|
|
(bin / "id").write_text(
|
|
"#!/bin/sh\ncase $1 in"
|
|
" -u) echo 1000 ;; -G) echo 1000 ;; -un|-gn) echo user ;; -nG) echo user ;;"
|
|
" *) exit 1 ;; esac\n")
|
|
(bin / "docker").write_text(
|
|
"#!/bin/sh\n"
|
|
'[ "$1" = info ] && { echo "' + str(d / "docker-root") + '"; exit 0; }\n'
|
|
f'[ "$1 $2" = "image inspect" ] && exit {0 if image_here else 1}\n'
|
|
f'[ "$1" = pull ] && {{ echo "pull $*" >> "{pull_log}"; exit 0; }}\n'
|
|
"exit 0\n")
|
|
# the fetch goes through python3 -I gguf-fetch.py: a stand-in records it and answers 0,
|
|
# so no network is asked and the room check is the one under test
|
|
(bin / "python3").write_text(
|
|
"#!/bin/sh\n"
|
|
f'[ "$1" = -I ] && [ "$2" = "{REPO / "gguf-fetch.py"}" ] '
|
|
f'&& {{ echo "fetch $*" >> "{fetch_log}"; exit 0; }}\n'
|
|
'exec /usr/bin/python3 "$@"\n')
|
|
for f in ("df", "getent", "id", "docker", "python3"):
|
|
(bin / f).chmod(0o755)
|
|
r = subprocess.run(["bash", str(INSTALLER), "--prepare"], capture_output=True, text=True,
|
|
env={"PATH": f"{bin}:/usr/bin:/bin", "HOME": str(d / "home"),
|
|
"LANES_UNIT_DIR": str(d / "units")},
|
|
timeout=60)
|
|
return r.returncode, r.stdout + r.stderr, pull_log, fetch_log
|
|
|
|
def test_prepare_fetches_the_model_after_the_image(self):
|
|
rc, out, pull_log, fetch_log = self.prepare(free_gib=8)
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertTrue(pull_log.exists() or "already here" in out, out)
|
|
self.assertTrue(fetch_log.exists(), "--prepare ended before the model was fetched")
|
|
asked = fetch_log.read_text()
|
|
self.assertIn(MODEL, asked)
|
|
self.assertIn(REV, asked)
|
|
|
|
def test_a_disk_too_full_for_the_model_refuses_before_the_fetch(self):
|
|
rc, out, pull_log, fetch_log = self.prepare(free_gib=0, image_here=True)
|
|
self.assertNotEqual(rc, 0, out)
|
|
self.assertIn("nothing was downloaded", out)
|
|
self.assertFalse(fetch_log.exists(), "gguf-fetch.py ran although the disk was refused")
|
|
|
|
|
|
class TheOnnxExportIsServed(unittest.TestCase):
|
|
"""TEI tries its ORT backend first and serves the model's ONNX export when the snapshot holds it,
|
|
its candle backend on the safetensors otherwise. Measured on the reference box on 2026-11-24 with
|
|
the pinned image and a cache that held the pinned files alone: on candle (the nine files), 113
|
|
tokens/s over 16 inputs of 512 tokens and 3.2 GiB at the container's peak; with the ONNX export
|
|
beside them (twelve files), ORT served, 381 tokens/s on the same inputs and 2.87 GiB at the peak
|
|
(~/qa-tools/etudes/embeddings-tei/essai.log and essai-ort.log). The lane pins and fetches the
|
|
export's three files too (Hasan's decision of 2026-11-24), the safetensors kept for candle should
|
|
ORT not start; each pin read again from the Hub's API at the pinned revision."""
|
|
|
|
ONNX = {"onnx/model.onnx": ("06449e3c1566f9bb2e84eef6c7b533d8ee69f5d87a303d7105ead5b343e0608e", 520292),
|
|
"onnx/model.onnx_data": ("8311b0b59f197527388c376017d4c41f484487e0b25e6507aa6f1c84c7a0b2b7", 2094723072),
|
|
"onnx/model.onnx_data_1": ("ca448326b2c590934e0735faef433092801d7d45904e0ce67920218683b20cf2", 306225152)}
|
|
|
|
def pinned(self):
|
|
return {path: (sha, int(size)) for path, sha, size in re.findall(r"([\w./]+)=([0-9a-f]{40,64}):(\d+)", TEXT)}
|
|
|
|
def test_its_three_files_are_pinned_by_their_sha256_and_their_size(self):
|
|
pins = self.pinned()
|
|
for path, pin in self.ONNX.items():
|
|
self.assertEqual(pins.get(path), pin, path)
|
|
|
|
def test_the_room_its_fetch_asks_counts_every_pinned_file(self):
|
|
total = sum(size for _, size in self.pinned().values())
|
|
self.assertEqual(int(PINS["EMBED_GB"]), (total + 999_999_999) // 1_000_000_000)
|
|
|
|
def test_the_unit_names_ort_as_the_backend_that_serves(self):
|
|
flat = " ".join(TEMPLATE.split())
|
|
self.assertNotIn("no ONNX", flat)
|
|
self.assertIn("its ORT backend serves", flat)
|
|
|
|
|
|
class TheFetchTakesTheOnnxExport(ThePreparePosesTheModelToo):
|
|
def test_prepare_fetches_the_export_beside_the_safetensors(self):
|
|
rc, out, _pull_log, fetch_log = self.prepare(free_gib=8)
|
|
self.assertEqual(rc, 0, out)
|
|
asked = fetch_log.read_text()
|
|
self.assertIn("model.safetensors=", asked)
|
|
for path, (sha, size) in TheOnnxExportIsServed.ONNX.items():
|
|
self.assertIn(f"{path}={sha}:{size}", asked)
|
|
|
|
|
|
class TheMeasuresOfTheEngineThatServes(unittest.TestCase):
|
|
"""The pages said the engine that serves was to be measured again: it was, on 2026-11-24."""
|
|
|
|
PAGES = {"docs/embed-lane.md": (REPO / "docs" / "embed-lane.md").read_text(),
|
|
"docs/models/pplx-embed-v1-0.6b.md": (REPO / "docs" / "models" / "pplx-embed-v1-0.6b.md").read_text(),
|
|
"CHANGELOG.md": (REPO / "CHANGELOG.md").read_text().split("\n## v1.59.0", 1)[0]}
|
|
|
|
def test_each_page_says_the_two_backends_measured(self):
|
|
for name, text in self.PAGES.items():
|
|
flat = " ".join(text.split())
|
|
with self.subTest(name):
|
|
self.assertIn("381 tokens/s", flat)
|
|
self.assertIn("113 tokens/s", flat)
|
|
self.assertIn("2.87 GiB", flat)
|
|
self.assertNotIn("to be measured again", flat)
|
|
self.assertNotIn("are measured again", flat)
|
|
|
|
|
|
class TheImageSize(unittest.TestCase):
|
|
"""Three spellings of the image's size lived on the branch (about 300 MB in the installer,
|
|
about 1 GB in the docs and the cockpit), none measured; then a fourth, "4943 MB received" at
|
|
the first Load, which the lane's proof (2026-11-20) never measured: its preuve.log says the
|
|
image was "already here" and the Hugging Face cache grew by 0 MB (the trial of 2026-11-19 had
|
|
put both there), so the 4943 MB its network counter saw over that minute were not the Load's
|
|
(the review of v1.60.0). The one figure is the manifest's: the pinned digest's arm64 manifest
|
|
holds 116,562,311 bytes of layers compressed (ghcr.io's registry API, read again on
|
|
2026-11-24, nothing pulled), about 120 MB to download, beside the model's 2.4 GB."""
|
|
|
|
PLACES = {
|
|
"install-embeddings.sh": TEXT,
|
|
"docs/embed-lane.md": (REPO / "docs" / "embed-lane.md").read_text(),
|
|
"docs/models/pplx-embed-v1-0.6b.md": (REPO / "docs" / "models" / "pplx-embed-v1-0.6b.md").read_text(),
|
|
"dashboard/static/js/base.js": (REPO / "dashboard" / "static" / "js" / "base.js").read_text(),
|
|
"CHANGELOG.md": (REPO / "CHANGELOG.md").read_text().split("\n## v1.58.0", 1)[0],
|
|
}
|
|
|
|
def test_one_measured_figure_everywhere(self):
|
|
for name, text in self.PLACES.items():
|
|
flat = " ".join(text.replace("\u2019", "'").split())
|
|
with self.subTest(name):
|
|
self.assertIn("about 120 MB to download", flat)
|
|
self.assertNotIn("4943", flat)
|
|
self.assertNotIn("about 1 GB", flat)
|
|
self.assertNotIn("about 300 MB", flat)
|
|
|
|
|
|
class TheLlamaCppPathIsSaidWhole(unittest.TestCase):
|
|
"""The lane's pages said the GGUF conversions of the model "force the causal Qwen3 attention,
|
|
which embeds wrong vectors", and stopped there. x42en showed in discussion #69 (2026-11-19)
|
|
that llama-server serves them right with --override-kv qwen3.attention.causal=bool:false
|
|
(cosine 0.58 against TEI without it, 0.9994 with it, on the GPU of their own GB10), and the
|
|
project's answer of 2026-11-23 there takes that path as the lane's once reproduced on the
|
|
reference box. Each page that explains the choice of TEI names the override, who found it,
|
|
and that the path is not yet the lane (the review of v1.60.0; tried on the reference box on
|
|
2026-11-24, it does not hold there yet: TheGpuPathIsNotYet)."""
|
|
|
|
PLACES = {
|
|
"install-embeddings.sh": TEXT,
|
|
"docs/embed-lane.md": (REPO / "docs" / "embed-lane.md").read_text(),
|
|
"docs/models/pplx-embed-v1-0.6b.md": (REPO / "docs" / "models" / "pplx-embed-v1-0.6b.md").read_text(),
|
|
}
|
|
|
|
def test_each_page_names_the_override_and_its_finder(self):
|
|
for name, text in self.PLACES.items():
|
|
flat = " ".join(text.replace("#", " ").split())
|
|
with self.subTest(name):
|
|
self.assertIn("qwen3.attention.causal=bool:false", flat)
|
|
self.assertIn("x42en", flat)
|
|
self.assertIn("discussion 69", flat)
|
|
self.assertIn("not yet", flat)
|
|
|
|
|
|
class TheGpuPathIsNotYet(unittest.TestCase):
|
|
"""x42en's GPU path (llama.cpp, the override of the causal attention) was tried on the reference box
|
|
on 2026-11-24 and does not hold there yet: a request of several texts came back with every value
|
|
null, and a new CUDA context beside the 27B failed at its start on a fragmented memory. The lane
|
|
serves TEI on the CPU, and its pages say why, with those two findings, x42en credited for the
|
|
request, the model, the GGUF they pinned, the override and their measures; and that a 64 GB DGX Spark
|
|
refuses the lane, as every lane never run on one (eabf43ef)."""
|
|
|
|
PAGES = {
|
|
"install-embeddings.sh": TEXT,
|
|
"docs/embed-lane.md": (REPO / "docs" / "embed-lane.md").read_text(),
|
|
"docs/models/pplx-embed-v1-0.6b.md": (REPO / "docs" / "models" / "pplx-embed-v1-0.6b.md").read_text(),
|
|
"CHANGELOG.md": (REPO / "CHANGELOG.md").read_text().split("\n## v1.58.0", 1)[0],
|
|
}
|
|
|
|
def test_each_page_says_why_the_gpu_path_is_not_the_lane_yet(self):
|
|
for name, text in self.PAGES.items():
|
|
flat = " ".join(text.replace("#", " ").split())
|
|
with self.subTest(name):
|
|
self.assertIn("not yet", flat)
|
|
self.assertIn("null", flat) # several texts in one request
|
|
self.assertIn("out of memory", flat) # the CUDA context beside the 27B
|
|
self.assertIn("x42en", flat)
|
|
self.assertIn("bowang0911", flat)
|
|
self.assertIn("qwen3.attention.causal=bool:false", flat)
|
|
self.assertNotIn("A 64 GB DGX Spark holds it", flat)
|
|
|
|
def test_the_pages_say_a_64_gb_box_refuses_it(self):
|
|
for name in ("docs/embed-lane.md", "docs/models/pplx-embed-v1-0.6b.md", "CHANGELOG.md"):
|
|
with self.subTest(name):
|
|
self.assertIn("A 64 GB DGX Spark refuses it", " ".join(self.PAGES[name].split()))
|
|
|
|
|
|
class TheUnitsAreTheRepos(unittest.TestCase):
|
|
"""The lane's pages said "Mio" and "cosinus", French for MiB and cosine, and "the 512 MB step"
|
|
for a rounding to 512 MiB (7680m is 15 times 512 MiB): units the rest of the repo's English
|
|
pages never use (the review of v1.60.0)."""
|
|
|
|
def test_mib_and_cosine(self):
|
|
places = {
|
|
"install-embeddings.sh": TEXT,
|
|
"docs/embed-lane.md": (REPO / "docs" / "embed-lane.md").read_text(),
|
|
"docs/models/pplx-embed-v1-0.6b.md": (REPO / "docs" / "models" / "pplx-embed-v1-0.6b.md").read_text(),
|
|
"README.md": (REPO / "README.md").read_text(),
|
|
"CHANGELOG.md": (REPO / "CHANGELOG.md").read_text().split("\n## v1.58.0", 1)[0],
|
|
}
|
|
for name, text in places.items():
|
|
with self.subTest(name):
|
|
self.assertIsNone(re.search(r"\bMio\b|\bcosinus\b|512 MB step", text))
|
|
|
|
|
|
class TheUpdateSeesALoadedLane(unittest.TestCase):
|
|
"""install.sh tells a lane a first Load began (its image here, its model's folder in the cache its unit
|
|
mounts) from one never loaded, by side_begun: begun, a run updates it (--no-smoke) and its summary says it
|
|
is up to date; not begun, its units only and "its first Load ... fetches its weights". The embed lane's
|
|
probe, side_gguf_begun, looked for a snapshot path followed by a slash (a GGUF file's), and the embed
|
|
unit names its snapshot as a folder: a box whose lane was loaded and served read as never loaded at
|
|
every update (the review of v1.60.0)."""
|
|
|
|
def begun(self, with_repo):
|
|
t = pathlib.Path(tempfile.mkdtemp(prefix="embed-begun-"))
|
|
self.addCleanup(shutil.rmtree, t, True)
|
|
home, hf, bindir = t / "home", t / "hf", t / "bin"
|
|
(home / ".config" / "qwen38").mkdir(parents=True)
|
|
bindir.mkdir()
|
|
(bindir / "docker").write_text("#!/bin/bash\nexit 0\n") # the image is here
|
|
(bindir / "docker").chmod(0o755)
|
|
unit = t / UNIT
|
|
r = subprocess.run(["bash", str(INSTALLER), "--stage", str(unit)], capture_output=True, text=True,
|
|
env={"PATH": "/usr/bin:/bin", "HOME": str(home), "HF_CACHE": str(hf),
|
|
"LANES_UNIT_DIR": str(t)}, timeout=60)
|
|
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
|
if with_repo:
|
|
(hf / "hub" / f"models--{MODEL.replace('/', '--')}" / "snapshots" / REV).mkdir(parents=True)
|
|
sh = (REPO / "install.sh").read_text()
|
|
start = sh.index("side_gguf_begun(){")
|
|
fn = sh[start:sh.index("\n}\n", start) + 3]
|
|
r = subprocess.run(["bash", "-c", f'. "{REPO}/lanes.sh"\n{fn}side_gguf_begun "{unit}"'],
|
|
capture_output=True, text=True, timeout=60,
|
|
env={"PATH": f"{bindir}:/usr/bin:/bin", "HOME": str(home)})
|
|
return r.returncode
|
|
|
|
def test_a_loaded_lane_is_begun_and_one_never_loaded_is_not(self):
|
|
self.assertEqual(self.begun(with_repo=True), 0)
|
|
self.assertNotEqual(self.begun(with_repo=False), 0)
|
|
|
|
|
|
class AnUpdateSeesWhatThePreflightChecks(unittest.TestCase):
|
|
"""lanes.sh's unit_needs says what a unit reads that the box lacks, and an update reads it to decide whether
|
|
the lane's new unit goes in place or waits for its Load (unit_put, decision 1408). For this unit it read the
|
|
snapshot whole off its safetensors alone (ckpt_cached), while the unit's own preflight stops the start at 78
|
|
without any of its twelve files: a new unit whose ONNX export the box lacked went in place over the unit
|
|
that served, as if the box had it all (code review of v1.60.0). It says each file the preflight checks and
|
|
the snapshot lacks, by that same rule."""
|
|
|
|
def needs(self, but=()):
|
|
t = pathlib.Path(tempfile.mkdtemp(prefix="embed-needs-"))
|
|
self.addCleanup(shutil.rmtree, t, True)
|
|
home, hf, bin = t / "home", t / "hf", t / "bin"
|
|
(home / ".config" / "qwen38").mkdir(parents=True)
|
|
bin.mkdir()
|
|
(bin / "docker").write_text("#!/bin/sh\nexit 0\n") # the image is here, docker answers
|
|
(bin / "docker").chmod(0o755)
|
|
unit = t / UNIT
|
|
r = subprocess.run(["bash", str(INSTALLER), "--stage", str(unit)], capture_output=True, text=True,
|
|
env={"PATH": "/usr/bin:/bin", "HOME": str(home), "HF_CACHE": str(hf),
|
|
"LANES_UNIT_DIR": str(t)}, timeout=60)
|
|
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
|
snap = hf / "hub" / f"models--{MODEL.replace('/', '--')}" / "snapshots" / REV
|
|
files = re.search(r'snap="[^"]+"; for f in ([^;]+); do', unit.read_text()).group(1).split()
|
|
for f in files:
|
|
if f not in but:
|
|
(snap / f).parent.mkdir(parents=True, exist_ok=True)
|
|
(snap / f).write_bytes(b"x")
|
|
r = subprocess.run(["bash", "-c", f'set -euo pipefail; . "{REPO}/lanes.sh"; unit_needs "{unit}"'],
|
|
capture_output=True, text=True, timeout=60,
|
|
env={"PATH": f"{bin}:/usr/bin:/bin", "HOME": str(home)})
|
|
self.assertEqual(r.returncode, 0, r.stderr)
|
|
return r.stdout.splitlines(), snap, files
|
|
|
|
def test_the_onnx_export_missing_is_said_file_by_file(self):
|
|
onnx = ("onnx/model.onnx", "onnx/model.onnx_data", "onnx/model.onnx_data_1")
|
|
lines, snap, files = self.needs(but=onnx)
|
|
self.assertEqual(len(files), 12, files)
|
|
self.assertEqual(lines, [f"path {snap}/{f}" for f in onnx])
|
|
|
|
def test_a_small_file_missing_is_said_too(self):
|
|
lines, snap, _files = self.needs(but=("tokenizer.json",))
|
|
self.assertEqual(lines, [f"path {snap}/tokenizer.json"])
|
|
|
|
def test_every_file_there_needs_nothing(self):
|
|
lines, _snap, _files = self.needs()
|
|
self.assertEqual(lines, [])
|
|
|
|
|
|
class TheProofTestsWhatThisRunInstalled(unittest.TestCase):
|
|
"""The proof at the end of a full run asks the engine that runs. A lane that ran before the run was left
|
|
running as it was: a unit this run put in place (an image, a port, a flag moved) or a model file it fetched
|
|
was not what answered, and the proof passed on the old container (code review of v1.60.0). Like the
|
|
other lanes' proofs (install-transcribe.sh, vllm-lane.sh's vlane_prove), a lane that serves files older
|
|
than the ones installed now restarts first; one that serves them already is left as it is. The run is the
|
|
installer as written, against stand-ins for docker, systemd, sudo and curl that write down what they
|
|
are asked."""
|
|
|
|
def full_run(self, started):
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="embed-proof-"))
|
|
self.addCleanup(shutil.rmtree, d, True)
|
|
(d / "docker-root").mkdir()
|
|
(d / "home").mkdir()
|
|
(d / "units").mkdir()
|
|
bin = d / "bin"; bin.mkdir()
|
|
log = d / "systemctl.log"
|
|
fakes = {
|
|
"df": "#!/bin/sh\necho Avail\necho 999G\n",
|
|
"getent": "#!/bin/sh\nexit 2\n",
|
|
"uname": "#!/bin/sh\necho aarch64\n",
|
|
"id": "#!/bin/sh\ncase $1 in -u) echo 1000 ;; -G) echo 1000 ;; -un|-gn) echo user ;; -nG) echo user ;; *) exit 1 ;; esac\n",
|
|
# the image is here, every other docker call answers nothing
|
|
"docker": "#!/bin/sh\n" + '[ "$1" = info ] && { echo "' + str(d / "docker-root") + '"; exit 0; }\nexit 0\n',
|
|
# the model's fetch is gguf-fetch.py's own subject: a stand-in that answers 0, off the network
|
|
"python3": "#!/bin/sh\n" + f'[ "$1" = -I ] && [ "$2" = "{REPO / "gguf-fetch.py"}" ] && exit 0\n'
|
|
'exec /usr/bin/python3 "$@"\n',
|
|
"sudo": '#!/bin/sh\nexec "$@"\n',
|
|
"journalctl": "#!/bin/sh\nexit 0\n",
|
|
# the lane, active since `started` (seconds since the epoch), as systemd says it
|
|
"systemctl": "#!/bin/sh\n" + f'echo "$*" >> "{log}"\n'
|
|
'case "$*" in\n'
|
|
' "is-active --quiet qwen38-embed.service") exit 0 ;;\n'
|
|
' "is-active qwen38-embed.service") echo active ;;\n'
|
|
' "show -p ActiveState --value qwen38-embed.service") echo active ;;\n'
|
|
f' "show -p ExecMainStartTimestamp --value --timestamp=unix qwen38-embed.service") echo "@{started}" ;;\n'
|
|
' "show -p NRestarts --value qwen38-embed.service") echo 0 ;;\n'
|
|
"esac\nexit 0\n",
|
|
# TEI's /health and one vector of 1024 dimensions
|
|
"curl": "#!/bin/sh\nout=\nwhile [ $# -gt 0 ]; do [ \"$1\" = -o ] && { out=\"$2\"; shift; }; shift; done\n"
|
|
'[ -n "$out" ] || exit 0\n'
|
|
"/usr/bin/python3 -c 'import json, sys; json.dump({\"model\": \"pplx-embed-v1-0.6b\", "
|
|
"\"data\": [{\"embedding\": [0.03125] * 1024}]}, open(sys.argv[1], \"w\"))' \"$out\"\n"
|
|
"printf 200\n",
|
|
}
|
|
for name, text in fakes.items():
|
|
(bin / name).write_text(text)
|
|
(bin / name).chmod(0o755)
|
|
r = subprocess.run(["bash", str(INSTALLER)], capture_output=True, text=True,
|
|
env={"PATH": f"{bin}:/usr/bin:/bin", "HOME": str(d / "home"),
|
|
"LANES_UNIT_DIR": str(d / "units")}, timeout=120)
|
|
return r.returncode, r.stdout + r.stderr, log.read_text().splitlines() if log.exists() else []
|
|
|
|
def test_a_lane_that_ran_before_the_run_restarts_on_what_it_installed(self):
|
|
rc, out, asked = self.full_run(started=1000) # long before the unit this run put in place
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertIn("restart qwen38-embed.service", asked, out)
|
|
self.assertNotIn("stop qwen38-embed.service", asked, "the lane is left running, as it was found")
|
|
|
|
def test_a_lane_that_serves_what_is_installed_is_left_as_it_is(self):
|
|
import time
|
|
rc, out, asked = self.full_run(started=int(time.time()) + 100000) # started after every file
|
|
self.assertEqual(rc, 0, out)
|
|
self.assertFalse([a for a in asked if a.split()[:1] in (["restart"], ["start"], ["stop"])], asked)
|
|
|
|
|
|
class TheStoppedLaneOneStatus(unittest.TestCase):
|
|
"""What the proxy answers on /v1/embeddings with the lane stopped is the text engine's own
|
|
400, measured in the lane's proof (preuve.log, 09:15:51 before the lane and 09:20:29 after
|
|
its stop: the same answer both times). The doc said a 503 and the proof's summary a 404:
|
|
one fact, said everywhere. The 503 engine_unavailable is the unit active with its engine
|
|
not answering yet (a start on its way), never a stopped lane."""
|
|
|
|
def test_the_doc_says_the_measured_status(self):
|
|
doc = " ".join((REPO / "docs" / "embed-lane.md").read_text().split())
|
|
self.assertIn("a stopped lane leaves the route to the text engine, whose own answer is a 400", doc)
|
|
self.assertNotIn("a stopped lane answers 503", doc)
|
|
|
|
|
|
class TheLicence(unittest.TestCase):
|
|
"""The model's licence, MIT (read from its card by the API, 2026-11-19), was named nowhere:
|
|
the other model pages name theirs and the cockpit's descriptions carry it in parentheses
|
|
(decision 1489). The page that chooses the lane and the model's own page say it now."""
|
|
|
|
def test_the_model_page_names_it(self):
|
|
page = (REPO / "docs" / "models" / "pplx-embed-v1-0.6b.md").read_text()
|
|
self.assertIn("Its licence is MIT", page)
|
|
|
|
def test_the_cockpit_card_names_it(self):
|
|
base = (REPO / "dashboard" / "static" / "js" / "base.js").read_text()
|
|
card = re.search(r"\[EMBED_UNIT\]: \{title: 'pplx-embed v1 0\.6B'.*?desc: '([^']+)'", base, re.S)
|
|
self.assertIsNotNone(card, "the embeddings card has no description")
|
|
self.assertIn("(MIT)", card.group(1))
|
|
|
|
|
|
class ThePins(unittest.TestCase):
|
|
def test_the_pins_stand_at_column_0(self):
|
|
for name in ("EMBED_MODEL", "EMBED_REV", "EMBED_IMAGE", "EMBED_FILE", "EMBED_MEMORY",
|
|
"EMBED_CPUS", "EMBED_MAX_BATCH_TOKENS"):
|
|
self.assertIn(name, PINS, f"{name} is not pinned at column 0")
|
|
|
|
def test_the_measured_values_say_what_the_measures_set(self):
|
|
"""EMBED_CPUS and EMBED_MAX_BATCH_TOKENS are the trial's result (essai-tei.sh,
|
|
2026-11-19); EMBED_MEMORY is the lane's proof's (2026-11-20): the cgroup's peak
|
|
over the lane's whole life, Load included, was 5304 MiB, and the cap is that
|
|
peak plus 2 GiB of margin, said above them."""
|
|
self.assertEqual(PINS["EMBED_MEMORY"], "7680m")
|
|
self.assertIn("5304 MiB", TEXT)
|
|
self.assertIn("the lane's proof, 2026-11-20", TEXT)
|
|
self.assertIn("essai-tei.sh, 2026-11-19", TEXT)
|
|
self.assertNotIn("PROVISIONAL", TEXT)
|
|
|
|
def test_the_cap_s_arithmetic_says_its_rounding(self):
|
|
"""5304 MiB plus 2 GiB is 7352 MiB, not 7680: the cap is that sum rounded up to the
|
|
512 MiB step (the blind review of 2026-11-20: a reader who redid the calculation
|
|
concluded the figure was wrong). Every place that explains the cap says the rounding."""
|
|
self.assertEqual((5304 + 2048 + 511) // 512 * 512, 7680)
|
|
for name, text in {"install-embeddings.sh": TEXT,
|
|
"CHANGELOG.md": (REPO / "CHANGELOG.md").read_text(),
|
|
"docs/embed-lane.md": (REPO / "docs" / "embed-lane.md").read_text(),
|
|
"docs/models/pplx-embed-v1-0.6b.md":
|
|
(REPO / "docs" / "models" / "pplx-embed-v1-0.6b.md").read_text()}.items():
|
|
flat = " ".join(text.split())
|
|
self.assertIn("512", flat, f"{name} does not say the rounding step")
|
|
self.assertIn("7680", flat, name)
|
|
|
|
def test_the_measure_set_the_batch_bound_and_the_doc_says_what_truncates(self):
|
|
"""2048, not the 8192 of the first draft: the attention of candle on CPU costs of the
|
|
order of n^2, and the measure saw a death at 32768. An input longer than the bound is
|
|
truncated (TEI's --auto-truncate), which the lane's doc says."""
|
|
self.assertEqual(PINS["EMBED_MAX_BATCH_TOKENS"], "2048")
|
|
doc = (REPO / "docs" / "embed-lane.md").read_text()
|
|
self.assertIn("an input longer than it is truncated", doc)
|
|
|
|
def test_the_cpus_are_the_a725_cores_lscpu_lists(self):
|
|
"""The A725 cores are 0-4 and 10-14 (lscpu on the box: the ten cores at 2.8 GHz, the
|
|
X925 at 3.9 GHz are 5-9 and 15-19), and the lane's doc says where the list comes from."""
|
|
self.assertEqual(PINS["EMBED_CPUS"], "0-4,10-14")
|
|
doc = (REPO / "docs" / "embed-lane.md").read_text()
|
|
self.assertIn("read from lscpu", doc)
|
|
|
|
def test_no_page_says_the_engine_returns_the_models_int8(self):
|
|
"""TEI returns normalized floats (measured on the box: cosine 1.0 with the ONNX
|
|
export's int8, min -0.097, max 0.115, norm 1): the model's int8 is its ONNX export's
|
|
own output, and no page of the lane says the engine serves it."""
|
|
pages = [TEXT, TEMPLATE,
|
|
(REPO / "docs" / "embed-lane.md").read_text(),
|
|
(REPO / "docs" / "models" / "pplx-embed-v1-0.6b.md").read_text()]
|
|
for page in pages:
|
|
self.assertNotIn("int8 output", page)
|
|
self.assertIn("normalized", (REPO / "docs" / "embed-lane.md").read_text())
|
|
|
|
def test_the_model_is_pplx_embed_v1_06b_at_its_pinned_revision(self):
|
|
self.assertEqual(MODEL, "perplexity-ai/pplx-embed-v1-0.6b")
|
|
self.assertEqual(REV, "2c4d510dd4a732063c31a0f70193e35067b51fd8")
|
|
self.assertRegex(IMAGE, r"^ghcr\.io/huggingface/text-embeddings-inference@sha256:[0-9a-f]{64}$")
|
|
|
|
def test_the_safetensors_is_pinned_by_its_sha256_and_its_size(self):
|
|
sha, size = PINS["EMBED_FILE"].split("=")[1].split(":")
|
|
self.assertRegex(sha, r"^[0-9a-f]{64}$")
|
|
self.assertEqual(int(size), 2384233112)
|
|
|
|
def test_the_uninstall_keeps_the_model_and_says_so(self):
|
|
self.assertIn("the model is kept", TEXT)
|
|
|
|
|
|
class APortThatMoves(unittest.TestCase):
|
|
"""EMBED_PORT=30128 ./install.sh wrote the unit and left the lane that ran on 30028: the proxy, which reads the unit, asked
|
|
30128 for good, the cockpit showed it starting, and its Load said it was already serving (review of v1.60.0)."""
|
|
|
|
def moved(self, was, now, active, restarts=True):
|
|
with tempfile.TemporaryDirectory() as t:
|
|
for name, body in (("systemctl", f'[ "$1" = is-active ] && exit {0 if active else 3}; exit 1'),
|
|
("sudo", f'echo "sudo $*"; exit {0 if restarts else 1}')):
|
|
f = pathlib.Path(t) / name
|
|
f.write_text("#!/bin/sh\n" + body + "\n")
|
|
f.chmod(0o755)
|
|
r = subprocess.run(["bash", "-euc", f'. "{REPO}/lanes.sh"; beside_port_moved {UNIT} "{was}" "{now}"; echo end'],
|
|
env={"PATH": f"{t}:/usr/bin:/bin", "HOME": t}, capture_output=True, text=True)
|
|
self.assertTrue(r.stdout.endswith("end\n"), r.stderr)
|
|
return r.stdout[:-4]
|
|
|
|
def test_a_lane_that_runs_starts_again_there(self):
|
|
self.assertEqual(self.moved("30028", "30128", True),
|
|
f"sudo systemctl restart {UNIT}\nits port moved from 30028 to 30128: restarted there\n")
|
|
self.assertIn(f"NOTE: {UNIT} still answers on port 30028, and its unit names 30128 now: sudo systemctl restart {UNIT}",
|
|
self.moved("30028", "30128", True, restarts=False))
|
|
for was, now, active in (("30028", "30028", True), ("", "30128", True), ("30028", "30128", False)):
|
|
self.assertEqual(self.moved(was, now, active), "", (was, now, active))
|
|
|
|
def test_both_lanes_do_it_and_an_uninstall_drops_what_waited(self):
|
|
for name in ("install-embeddings.sh", "install-clipstral.sh"):
|
|
text = (REPO / name).read_text()
|
|
body = text[text.index("install_service(){"):text.index("\n}\n", text.index("install_service(){"))]
|
|
self.assertLess(body.index('was="$(installed_flag --port)"'), body.index("unit_put"), name)
|
|
self.assertGreater(body.index('[ "$put" = pending ] || beside_port_moved "$UNIT" "$was" "$PORT"'), body.index("unit_put"))
|
|
gone = text[text.index('if [ "$ACTION" = uninstall ]; then'):]
|
|
self.assertIn('unit_pending_clear "$INSTALLED"', gone[:gone.index("\nfi\n")], name)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|