241 lines
4.7 KiB
Bash
241 lines
4.7 KiB
Bash
#!/bin/sh
|
|
|
|
start_comfy() {
|
|
cd "$PROJECT_DIR"
|
|
|
|
require_host_project_path
|
|
|
|
EXTRA_ARGS="$*"
|
|
|
|
echo "Host project: $HOST_PROJECT_PATH"
|
|
echo "Starting ComfyUI..."
|
|
echo "Base directory: $HOST_PROJECT_PATH/gpu/comfy"
|
|
echo "Run directory: $HOST_PROJECT_PATH/comfyui/run"
|
|
|
|
if [ -n "$EXTRA_ARGS" ]; then
|
|
echo "Extra args: $EXTRA_ARGS"
|
|
fi
|
|
|
|
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
|
|
PROJECT_HOST_DIR="$HOST_PROJECT_PATH" \
|
|
COMFY_BASE_HOST="$HOST_PROJECT_PATH/gpu/comfy" \
|
|
COMFY_RUN_HOST="$HOST_PROJECT_PATH/comfyui/run" \
|
|
COMFY_EXTRA_ARGS="$EXTRA_ARGS" \
|
|
docker compose \
|
|
-f "$COMPOSE_FILE" \
|
|
--profile comfy \
|
|
up -d \
|
|
--force-recreate \
|
|
comfyui
|
|
|
|
echo
|
|
|
|
docker ps \
|
|
--filter "name=gpu-node-comfyui" \
|
|
--format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
|
|
}
|
|
|
|
|
|
list_comfy_models() {
|
|
MODELS_DIR="$PROJECT_DIR/gpu/comfy/models"
|
|
|
|
if [ ! -d "$MODELS_DIR" ]; then
|
|
echo "ERROR: Models directory not found: $MODELS_DIR" >&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"}
|
|
|
|
|
|
def is_model_file(name):
|
|
if name in IGNORED_NAMES:
|
|
return False
|
|
|
|
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
|
|
}
|
|
|
|
|
|
comfy_models_command() {
|
|
case "${1:-}" in
|
|
|
|
list)
|
|
shift
|
|
|
|
if [ "$#" -gt 1 ]; then
|
|
echo "Usage: gpuctl comfy models list [type]" >&2
|
|
return 1
|
|
fi
|
|
|
|
list_comfy_models "${1:-}"
|
|
;;
|
|
|
|
*)
|
|
echo "Usage:"
|
|
echo " gpuctl comfy models list [type]"
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
|
|
comfy_command() {
|
|
case "${1:-}" in
|
|
|
|
models)
|
|
shift
|
|
comfy_models_command "$@"
|
|
;;
|
|
|
|
*)
|
|
echo "Usage:"
|
|
echo " gpuctl comfy models list [type]"
|
|
return 1
|
|
;;
|
|
esac
|
|
} |