model worker

This commit is contained in:
Mikan
2026-10-09 01:00:33 +04:00
parent 654126be43
commit 883188e086
7 changed files with 707 additions and 155 deletions

View File

@@ -35,169 +35,37 @@ start_comfy() {
--format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
}
model_worker_exec() {
docker exec \
gpu-node-model-worker \
python3 \
/app/worker.py \
"$@"
}
list_comfy_models() {
MODELS_DIR="$PROJECT_DIR/gpu/comfy/models"
model_worker_exec list "$@"
}
if [ ! -d "$MODELS_DIR" ]; then
echo "ERROR: Models directory not found: $MODELS_DIR" >&2
add_comfy_model() {
if [ "$#" -ne 2 ]; then
echo "Usage: gpuctl comfy models add <URL> <type>" >&2
return 1
fi
python3 - "$MODELS_DIR" "${1:-}" <<'PY'
import os
import sys
root = os.path.abspath(sys.argv[1])
selected_type = sys.argv[2] if len(sys.argv) > 2 else ""
IGNORED_NAMES = {".gitkeep"}
IGNORED_EXTENSIONS = {".txt"}
model_worker_exec add "$1" "$2"
}
def is_model_file(name):
if name in IGNORED_NAMES:
return False
remove_comfy_model() {
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "Usage: gpuctl comfy models rm <filename> [type]" >&2
return 1
fi
return os.path.splitext(name)[1].lower() not in IGNORED_EXTENSIONS
def human_size(size):
units = ["B", "KB", "MB", "GB", "TB"]
value = float(size)
for unit in units:
if value < 1024 or unit == units[-1]:
return f"{value:.2f} {unit}"
value /= 1024
def collect_files(directory):
result = []
for current, dirs, files in os.walk(directory):
dirs[:] = sorted(
name
for name in dirs
if not os.path.islink(os.path.join(current, name))
)
for name in sorted(files):
path = os.path.join(current, name)
if not is_model_file(name):
continue
if os.path.islink(path):
continue
try:
if os.path.isfile(path):
result.append(
(path, os.path.getsize(path))
)
except OSError as exc:
print(
f"WARNING: Cannot read {path}: {exc}",
file=sys.stderr,
)
return result
groups = []
for name in sorted(os.listdir(root)):
directory = os.path.join(root, name)
if not os.path.isdir(directory):
continue
if os.path.islink(directory):
continue
files = collect_files(directory)
if not files:
continue
size = sum(
file_size
for _, file_size in files
)
groups.append(
(name, files, size)
)
if selected_type:
groups = [
group
for group in groups
if group[0] == selected_type
]
if not groups:
print(
f"ERROR: No models found for type: "
f"{selected_type}"
)
available = []
for name in sorted(os.listdir(root)):
path = os.path.join(root, name)
if not os.path.isdir(path):
continue
if os.path.islink(path):
continue
if collect_files(path):
available.append(name)
print(
"Available types: "
+ (", ".join(available) or "(none)")
)
sys.exit(1)
total_size = 0
total_files = 0
for name, files, size in groups:
print(
f"\n{name}/ — "
f"{len(files)} files — "
f"{human_size(size)}"
)
for path, file_size in files:
relative = os.path.relpath(
path,
root,
)
print(
f" {relative} — "
f"{human_size(file_size)}"
)
total_size += size
total_files += len(files)
print(
f"\nTotal: "
f"{human_size(total_size)} "
f"({total_files} files)"
)
PY
model_worker_exec rm "$@"
}
@@ -212,12 +80,24 @@ comfy_models_command() {
return 1
fi
list_comfy_models "${1:-}"
list_comfy_models "$@"
;;
add)
shift
add_comfy_model "$@"
;;
rm)
shift
remove_comfy_model "$@"
;;
*)
echo "Usage:"
echo " gpuctl comfy models list [type]"
echo " gpuctl comfy models add <URL> <type>"
echo " gpuctl comfy models rm <filename> [type]"
return 1
;;
esac
@@ -235,6 +115,8 @@ comfy_command() {
*)
echo "Usage:"
echo " gpuctl comfy models list [type]"
echo " gpuctl comfy models add <URL> <type>"
echo " gpuctl comfy models rm <filename> [type]"
return 1
;;
esac