clipstral: its container is given its model's folder alone, not the cache whose root holds an account's token

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hasan BasbunarandClaude Opus 5.5 committed 2026-12-01 11:54:41 +01:00
1 parent 1546336469
commit f668fdbb23
3 files changed
+18 -8

No files matched your search

+2 -2
View File
@@ -86,8 +86,8 @@ on one.
Its container is capped by its cgroup (`--memory` and `--memory-swap` equal) and pinned to the ten A725 cores
(`--cpuset-cpus 0-4,10-14`), never the X925 the text engines' busy threads run on. It decodes images its clients send, so
it is given little: a read-only file system, every capability dropped but the one to read a cache whose files are its
owner's only (`DAC_OVERRIDE`), no new privileges, no GPU, no key of the box; what it can read is its code and the Hugging
Face cache, as every lane does. `CLIPSTRAL_MEMORY`, `CLIPSTRAL_CPUS`,
owner's only (`DAC_OVERRIDE`), no new privileges, no GPU, no key of the box; what it can read is its code and its model's
folder, not the Hugging Face cache beside it, whose root holds an account's token. `CLIPSTRAL_MEMORY`, `CLIPSTRAL_CPUS`,
`CLIPSTRAL_THREADS` and `CLIPSTRAL_DTYPE` are the pins of `install-clipstral.sh`; `CLIPSTRAL_PORT` moves its port, which the
proxy and the cockpit read in its unit.
+6 -3
View File
@@ -19,8 +19,11 @@ ExecStartPre=-/usr/bin/docker rm -f qwen38-clipstral
# This repo's own server (clipstral-server.py) and module (clipstral_model.py), in the 27B lane's SGLang image, whose
# torch, tokenizers and Pillow they run on: nothing of the model's repository but its weights and its tokenizer is read,
# and none of its Python is run.
# --model-id: the model's folder at its pinned revision in the Hugging Face cache mounted read-only; the revision beside
# it repeats the pin for the readers of this unit.
# --model-id: the model's folder at its pinned revision in the Hugging Face cache, of which the model's own folder alone is
# mounted, read-only: the cache's root holds the account's token, and this container decodes its clients' images. Where
# that cache is, for the readers of this unit (lanes.sh's unit_hf_cache, the cockpit's), in the words of the other units:
# -v __HF_CACHE__:/root/.cache/huggingface
# The revision beside it repeats the pin for the readers of this unit.
# --host 127.0.0.1: no key, so never beyond this box: the only door to it is the proxy, with the box's key.
# --read-only, --cap-drop ALL: it decodes images its clients send, and writes nothing. DAC_OVERRIDE alone is given back,
# to read a cache whose files are its owner's only.
@@ -37,7 +40,7 @@ ExecStart=/bin/bash -c 'for t in {0..30}; do lacks=""; \
--network host --no-healthcheck --pids-limit 512 \
--read-only --tmpfs /tmp:size=64m --cap-drop ALL --cap-add DAC_OVERRIDE --security-opt no-new-privileges \
-e HF_HUB_OFFLINE=1 -e CUDA_VISIBLE_DEVICES= -e DNNL_DEFAULT_FPMATH_MODE=__CLIPSTRAL_FPMATH__ \
-v __HF_CACHE__:/root/.cache/huggingface:ro \
--mount type=bind,source=__HF_CACHE__/hub/models--__CLIPSTRAL_MODEL_DASH__,target=/root/.cache/huggingface/hub/models--__CLIPSTRAL_MODEL_DASH__,readonly \
--mount type=bind,source=__CLIPSTRAL_CODE__,target=/clipstral,readonly \
--entrypoint python3 __IMAGE__ \
-I -B /clipstral/clipstral-server.py \
+10 -3
View File
@@ -31,6 +31,7 @@ PINS = {k: v.strip('"') for k, v in (ln.split("=", 1) for ln in TEXT.splitlines(
MODEL, REV, IMAGE = PINS["CLIPSTRAL_MODEL"], PINS["CLIPSTRAL_REV"], PINS["CLIPSTRAL_IMAGE"]
CODE = ("clipstral-server.py", "clipstral_model.py")
CODE_ID = hashlib.sha256(b"".join((REPO / f).read_bytes() for f in CODE)).hexdigest()[:12]
REPO_DIR = "models--" + PINS["CLIPSTRAL_MODEL"].replace("/", "--")
PREFLIGHT = r'snap="([^"]+)"; for f in ([^;]+); do \[ -f "\$snap/\$f" \]'
_spec = importlib.util.spec_from_file_location("clipstral_check", REPO / "clipstral-check.py")
CHECK = importlib.util.module_from_spec(_spec)
@@ -92,10 +93,13 @@ class ItsUnit(Staged):
def test_its_container_writes_nothing_and_reads_what_it_is_given(self):
cmd = re.sub(r"\s+", " ", command(self.stage()))
for flag in ("--rm", "--read-only", "--cap-drop ALL", "--cap-add DAC_OVERRIDE", "--security-opt no-new-privileges", "--no-healthcheck",
"--tmpfs /tmp:size=64m", f"-v {self.hf}:/root/.cache/huggingface:ro", "-e HF_HUB_OFFLINE=1"):
"--tmpfs /tmp:size=64m", "-e HF_HUB_OFFLINE=1",
f"--mount type=bind,source={self.hf}/hub/{REPO_DIR},target=/root/.cache/huggingface/hub/{REPO_DIR},readonly"):
self.assertIn(flag, cmd, flag)
self.assertEqual(re.findall(r"--cap-add (\S+)", cmd), ["DAC_OVERRIDE"], "one right given back")
self.assertEqual(re.findall(r"-v \S+:ro|-v \S+", cmd), [f"-v {self.hf}:/root/.cache/huggingface:ro"])
# the model's folder alone: the root of the cache holds the account's token (review of v1.60.0)
self.assertEqual(re.findall(r"-v \S+", cmd), [])
self.assertEqual(re.findall(r"source=([^,]+),", cmd), [f"{self.hf}/hub/{REPO_DIR}", f"{self.cfg}/clipstral/{CODE_ID}"])
def test_capped_by_its_cgroup_and_pinned_to_the_small_cores(self):
cmd = command(self.stage())
@@ -179,7 +183,10 @@ class ItsUnit(Staged):
r = subprocess.run(["bash", str(INSTALLER), "--stage", str(self.out)], capture_output=True, text=True, timeout=60,
env={"PATH": "/usr/bin:/bin", "HOME": str(self.home), "LANES_UNIT_DIR": str(self.units)})
self.assertEqual(r.returncode, 0, r.stderr)
self.assertIn("-v /mnt/disk/hf:/root/.cache/huggingface:ro", command(self.out.read_text()))
self.assertIn(f"source=/mnt/disk/hf/hub/{REPO_DIR},", command(self.out.read_text()))
# where its readers find the cache in it (its own unit first, at the next run)
r = subprocess.run(["bash", "-c", f'. "{REPO}/lanes.sh"; unit_hf_cache "{self.out}"'], capture_output=True, text=True)
self.assertEqual(r.stdout.strip(), "/mnt/disk/hf")
class ItsCode(unittest.TestCase):