cleanup-hf-model: target any HF cache volume by name and run in a separate compose project - #225
lloydmak99 wants to merge 1 commit into
Conversation
…arate compose project The one-shot cleanup could only reach <project>_huggingface_cache and had to run inside the work project, where compose-manager's --remove-orphans stops the live model. CVMs also carry a second, misspelled work_hugginface_cache volume from older packs, which is where stale checkpoints accumulate. Declare the volume external with an HF_CACHE_VOLUME-selected name, accept a comma or space separated list in MODEL_NAME, validate every token before touching the volume, and document running with "project":"cleanup".
| set -f | ||
| MODELS=$$(printf '%s' "$$MODEL_NAME" | tr ',' ' ') | ||
| set -- $$MODELS |
There was a problem hiding this comment.
set -f (noglob) is set here and never re-enabled, which silently breaks the downstream "Cached model weights" diagnostics at lines 74–75:
if ls "$$HUB"/models--* >/dev/null 2>&1; then
du -sh "$$HUB"/models--* | sort -rh
Because pathname expansion is disabled, the models--* pattern is passed literally to ls/du. Since no file is literally named models--*, the ls check always fails and the script prints (none) even when real model directories exist — so operators can no longer verify what is cached before deletion. This is a regression introduced by this change; the deletion logic itself (rm -rf "$$TARGET") is unaffected because it uses fully-qualified paths.
Glob disabling is only needed around set -- $$MODELS (to stop a token like * from expanding to filenames). Re-enable it immediately afterward so the existing globs work as intended.
Suggestion:
| set -f | |
| MODELS=$$(printf '%s' "$$MODEL_NAME" | tr ',' ' ') | |
| set -- $$MODELS | |
| set -f | |
| MODELS=$$(printf '%s' "$$MODEL_NAME" | tr ',' ' ') | |
| set -- $$MODELS | |
| set +f |
PierreLeGuen
left a comment
There was a problem hiding this comment.
The external-volume declaration and multi-model validation loop are sound, but set -f (line 47) is never cleared, so the pre-deletion models--* listing always prints (none) — the one in-run confirmation that the right volume is mounted before an irreversible rm -rf. Adding set +f after validation fixes it.
Optional follow-ups:
cleanup-hf-model.yaml:74—set -fis enabled at line 47 so thatset -- $MODELSdoes not glob-expand model tokens, but it is never turned back off. Fix: Addset +fimmediately after the validation loop closes (line 66, before the '=== Disk usage ===' section).cleanup-hf-model.yaml:37— The PR makes"project":"cleanup"the recommended invocation, but the service keeps the fixedcontainer_name. Fix: Drop thecontainer_name: hf-cleanuppin so Compose derives project-scoped names (cleanup-hf-cleanup-1`); nothing resolves this container…
Checks: PyYAML parse of cleanup-hf-model.yaml: passed. git diff --check: clean.
Problem
Inference CVMs carry two HuggingFace cache volumes because
prod/small-models.yamlandprod/dsv4-qwen36-gemma4.yamlspell the volumehugginface_cache. Stale checkpoints accumulate in whichever volume a retired pack used. On gpu23 the misspelledwork_hugginface_cacheholds about 1.1 TB that nothing mounts (zai-org/GLM-5-FP8,sgl-project/DeepSeek-V4-Flash-FP8,google/gemma-4-31B-it,Qwen/Qwen3.6-27B-FP8) and the guest is at 1,669 GB of 2,122 GB.cleanup-hf-model.yamlcould not reach that volume: it declared a plainhuggingface_cachevolume, so it only resolved to<project>_huggingface_cache, and in any project other thanworkit silently created a new empty volume. Running it insideworkalso lets compose-manager's--remove-orphansstop the live model. The two alternatives do not work today: compose-manager's/docker/evictfails closed on every prod CVM (itsdocker inspectparser rejects"Cmd": null), and/docker/cleanrunsdocker volume prune -f, which skips named volumes on the guest's Docker 25.0.3.Changes
external: truewithname: ${HF_CACHE_VOLUME:-work_huggingface_cache}, so the utility targets an existing volume by its full name and Compose fails fast instead of creating an empty one.MODEL_NAMEaccepts one or moreorg/repovalues separated by commas or whitespace. Every token is validated (exactly one/, no leading slash, no..) before any listing or deletion.Removed N of M requested model(s).summary; absent models are reported and skipped, not treated as errors."project":"cleanup"and theHF_CACHE_VOLUMEoverride, and keep the warning about running inwork.No file under
prod/orexperiments/changes.Validation
MODEL_NAME=org/repo docker compose -f cleanup-hf-model.yaml configrendersexternal: trueandname: work_huggingface_cache; withHF_CACHE_VOLUME=work_hugginface_cacheit rendersname: work_hugginface_cache.models--org--a,models--org--b,models--org--keep:MODEL_NAME="org/a, org/b org/missing"removed a and b, left keep, logged oneNot foundline andRemoved 2 of 3 requested model(s)., exit 0.MODEL_NAME="../etc"exits 1 withInvalid model tokenand deletes nothing.Rollout Notes
Nothing deploys on merge. After the auto-tag, the gpu23 cleanup is one call, run in its own project so the GLM-5.2 stack in
workis untouched:The live GLM-5.2 W4AFP8 weights are in
work_huggingface_cacheand are not selected. Expected result is about 1.1 TB freed inside the gpu23 guest; the host-side qcow2 does not shrink. gpu03 and gpu13 carry similar leftovers in their misspelled volumes and can use the same call.