-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup-hf-model.yaml
More file actions
117 lines (109 loc) · 4.17 KB
/
Copy pathcleanup-hf-model.yaml
File metadata and controls
117 lines (109 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
x-logging-conf: &logging-conf
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
labels: "com.datadoghq.ad.logs"
# One-shot cleanup: removes one or more models from an existing HuggingFace
# cache volume on a CVM.
#
# Recommended usage (compose-manager `compose/up`):
# curl -sS 'http://<host_ip>:8080/compose/up' \
# -H 'Authorization: Bearer <CM_TOKEN>' -H 'Content-Type: application/json' \
# -d '{"tag":"<tag>","file":"cleanup-hf-model.yaml","project":"cleanup",
# "force_recreate":true,
# "env":{"MODEL_NAME":"zai-org/GLM-5-FP8, Qwen/Qwen3.6-27B-FP8",
# "HF_CACHE_VOLUME":"work_hugginface_cache"}}'
#
# Notes:
# - MODEL_NAME accepts one or more `org/repo` values separated by commas and/or
# whitespace and maps each to its on-disk `models--org--repo` directory.
# - HF_CACHE_VOLUME selects an EXISTING Docker volume by its full name (default:
# `work_huggingface_cache`). The external declaration makes Compose fail fast
# instead of silently creating an empty project-scoped volume.
# - Older `small-models.yaml` / `dsv4-qwen36-gemma4.yaml` packs produced the
# misspelled `work_hugginface_cache` volume; select it explicitly when needed.
# - WARNING: Running without `"project":"cleanup"` uses the default `work`
# project, where compose-manager's `--remove-orphans` will stop live model
# containers. The separate `cleanup` project avoids touching the live stack.
# - Safe to run while inference is up: weights are already loaded into GPU
# memory; only a future restart would need to re-download.
# - `force_recreate:true` is required to re-run on the same instance with a
# different MODEL_NAME (otherwise the previous Exited container is reused).
services:
hf-cleanup:
image: alpine:3.20
container_name: hf-cleanup
restart: "no"
entrypoint: ["sh", "-c"]
command:
- |
set -eu
: "$${MODEL_NAME:?MODEL_NAME env var is required (e.g. zai-org/GLM-5-FP8)}"
echo "HF_CACHE_VOLUME=$$HF_CACHE_VOLUME"
set -f
MODELS=$$(printf '%s' "$$MODEL_NAME" | tr ',' ' ')
set -- $$MODELS
if [ "$$#" -eq 0 ]; then
echo "Invalid MODEL_NAME: at least one org/repo is required." >&2
exit 1
fi
for MODEL in "$$@"; do
case "$$MODEL" in
/*|*/|*/*/*|*..*)
echo "Invalid model token '$$MODEL': expected exactly one org/repo with no leading slash or '..'." >&2
exit 1
;;
*/*) ;;
*)
echo "Invalid model token '$$MODEL': expected exactly one org/repo with no leading slash or '..'." >&2
exit 1
;;
esac
done
echo "=== Disk usage ==="
df -h /root/.cache 2>/dev/null || df -h /
echo ""
echo "=== Cached model weights ==="
HUB=/root/.cache/huggingface/hub
if ls "$$HUB"/models--* >/dev/null 2>&1; then
du -sh "$$HUB"/models--* | sort -rh
else
echo "(none)"
fi
echo ""
echo "Total HF cache: $$(du -sh $$HUB 2>/dev/null | cut -f1)"
echo ""
echo "=== Cleanup ==="
TOTAL=$$#
REMOVED=0
for MODEL in "$$@"; do
SAFE=$$(printf '%s' "$$MODEL" | sed 's|/|--|g')
TARGET="$$HUB/models--$$SAFE"
echo "MODEL_NAME=$$MODEL"
echo "TARGET=$$TARGET"
if [ ! -d "$$TARGET" ]; then
echo "Not found — nothing to remove."
continue
fi
echo "Removing $$(du -sh "$$TARGET" | cut -f1) ..."
rm -rf "$$TARGET"
REMOVED=$$((REMOVED + 1))
echo "Removed $$TARGET"
done
echo "Disk after: $$(df -h /root/.cache 2>/dev/null | tail -1 || df -h / | tail -1)"
echo "Removed $$REMOVED of $$TOTAL requested model(s)."
volumes:
- huggingface_cache:/root/.cache/huggingface
environment:
- MODEL_NAME=${MODEL_NAME}
- HF_CACHE_VOLUME=${HF_CACHE_VOLUME:-work_huggingface_cache}
logging: *logging-conf
networks:
default:
external: true
name: dstack_default
volumes:
huggingface_cache:
external: true
name: ${HF_CACHE_VOLUME:-work_huggingface_cache}