From 6cf6e12ed373f77181a5912933268fabd209eb03 Mon Sep 17 00:00:00 2001 From: Mikan <72257910+Mikan-DS@users.noreply.github.com> Date: Tue, 6 Oct 2026 02:30:59 +0400 Subject: [PATCH] llama --- .env.example | 3 + .gitignore | 30 ++++++++++ START_GPU_NODE.bat | 25 ++++++++ compose.yaml | 84 +++++++++++++++++++++++++++ gpu/Dockerfile | 3 + ssh/Dockerfile | 31 ++++++++++ ssh/entrypoint.sh | 10 ++++ ssh/gpuctl | 138 +++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 324 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 START_GPU_NODE.bat create mode 100644 compose.yaml create mode 100644 gpu/Dockerfile create mode 100644 ssh/Dockerfile create mode 100644 ssh/entrypoint.sh create mode 100644 ssh/gpuctl diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f53b772 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +TAILSCALE_HOSTNAME=gpu-node +TS_AUTHKEY= +LLAMA_MODELS_PATH=./gpu/llama_models \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dfd22e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# SSH +ssh/authorized_keys + +# Tailscale +tailscale/state/ +tailscale/config/ + +# GPU models / generated data +gpu/llama_models/* +gpu/comfy/models/* +gpu/comfy/input/* +gpu/comfy/output/* +gpu/comfy/custom_nodes/* +gpu/comfy/user/* +gpu/comfy/run/* + +# Environment / secrets +.env +*.env + +# Python +__pycache__/ +*.py[cod] +.venv/ + +# OS / IDE +.DS_Store +Thumbs.db +.idea/ +.vscode/ \ No newline at end of file diff --git a/START_GPU_NODE.bat b/START_GPU_NODE.bat new file mode 100644 index 0000000..de89675 --- /dev/null +++ b/START_GPU_NODE.bat @@ -0,0 +1,25 @@ +@echo off +cd /d "%~dp0" + +echo ======================================== +echo SALEM AI GPU NODE +echo ======================================== +echo. + +echo Starting Docker services... +docker compose up -d + +if errorlevel 1 ( + echo. + echo ERROR: Failed to start GPU node. + pause + exit /b 1 +) + +echo. +echo GPU node started successfully. +echo. +docker ps --filter "name=gpu-node-" + +echo. +pause \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..8a5594c --- /dev/null +++ b/compose.yaml @@ -0,0 +1,84 @@ +name: gpu-node + +services: + tailscale: + image: tailscale/tailscale:latest + container_name: gpu-node-tailscale + + hostname: ${TAILSCALE_HOSTNAME:-gpu-node} + + environment: + TS_AUTHKEY: ${TS_AUTHKEY} + TS_STATE_DIR: /var/lib/tailscale + TS_SERVE_CONFIG: /config/serve.json + + volumes: + - ./tailscale/state:/var/lib/tailscale + - ./tailscale/config:/config:ro + + networks: + - gpu-node + + restart: unless-stopped + + ssh: + build: + context: ./ssh + + container_name: gpu-node-ssh + hostname: ssh-operator + + volumes: + - ./ssh/authorized_keys:/mounted-authorized-keys:ro + - /var/run/docker.sock:/var/run/docker.sock + - ./:/project:ro + + networks: + - gpu-node + + restart: unless-stopped + + gpu-test: + profiles: + - test + build: + context: ./gpu + + container_name: gpu-node-gpu-test + + gpus: all + + networks: + - gpu-node + + restart: "no" + + llama: + profiles: + - llama + + image: ghcr.io/ggml-org/llama.cpp:server-cuda + + container_name: gpu-node-llama + + gpus: all + + volumes: + - ${LLAMA_MODELS_HOST:-./gpu/llama_models}:/models + + command: + - --host + - 0.0.0.0 + - --port + - "8080" + - --model + - /models/model.gguf + + networks: + - gpu-node + + restart: "no" + +networks: + gpu-node: + name: gpu-node \ No newline at end of file diff --git a/gpu/Dockerfile b/gpu/Dockerfile new file mode 100644 index 0000000..2b85d4a --- /dev/null +++ b/gpu/Dockerfile @@ -0,0 +1,3 @@ +FROM nvidia/cuda:12.8.1-base-ubuntu24.04 + +CMD ["nvidia-smi"] \ No newline at end of file diff --git a/ssh/Dockerfile b/ssh/Dockerfile new file mode 100644 index 0000000..e3c4200 --- /dev/null +++ b/ssh/Dockerfile @@ -0,0 +1,31 @@ +FROM alpine:3.22 + +RUN apk add --no-cache \ + openssh-server \ + docker-cli \ + docker-cli-compose \ + && addgroup -g 1001 docker-host \ + && adduser -D -s /bin/sh operator \ + && adduser operator docker-host \ + && passwd -d operator \ + && mkdir -p /home/operator/.ssh \ + && ssh-keygen -A + +RUN printf '%s\n' \ + 'PasswordAuthentication no' \ + 'KbdInteractiveAuthentication no' \ + 'PubkeyAuthentication yes' \ + 'PermitRootLogin no' \ + >> /etc/ssh/sshd_config + +COPY entrypoint.sh /entrypoint.sh +COPY gpuctl /usr/local/bin/gpuctl + +RUN sed -i 's/\r$//' /usr/local/bin/gpuctl \ + && chmod +x /entrypoint.sh /usr/local/bin/gpuctl + +RUN chmod +x /entrypoint.sh /usr/local/bin/gpuctl + +EXPOSE 22 + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/ssh/entrypoint.sh b/ssh/entrypoint.sh new file mode 100644 index 0000000..67b7306 --- /dev/null +++ b/ssh/entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +cp /mounted-authorized-keys /home/operator/.ssh/authorized_keys + +chown -R operator:operator /home/operator/.ssh +chmod 700 /home/operator/.ssh +chmod 600 /home/operator/.ssh/authorized_keys + +exec /usr/sbin/sshd -D -e \ No newline at end of file diff --git a/ssh/gpuctl b/ssh/gpuctl new file mode 100644 index 0000000..9525f1d --- /dev/null +++ b/ssh/gpuctl @@ -0,0 +1,138 @@ +#!/bin/sh + +set -eu + +PROJECT_DIR="/project" + +get_host_project_dir() { + docker inspect gpu-node-ssh \ + --format '{{range .Mounts}}{{if eq .Destination "/project"}}{{.Source}}{{end}}{{end}}' +} + +case "${1:-}" in + + status) + docker ps \ + --filter "name=gpu-node-" \ + --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' + ;; + + start) + case "${2:-}" in + + llama) + cd "$PROJECT_DIR" + + HOST_PROJECT_DIR="$(get_host_project_dir)" + + if [ -z "$HOST_PROJECT_DIR" ]; then + echo "ERROR: cannot determine host project directory" + exit 1 + fi + + echo "Starting llama..." + echo "Models: $HOST_PROJECT_DIR/gpu/llama_models" + + LLAMA_MODELS_HOST="$HOST_PROJECT_DIR/gpu/llama_models" \ + docker compose --profile llama up -d llama + + echo + docker ps \ + --filter "name=gpu-node-llama" \ + --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' + ;; + + comfy) + cd "$PROJECT_DIR" + + HOST_PROJECT_DIR="$(get_host_project_dir)" + + if [ -z "$HOST_PROJECT_DIR" ]; then + echo "ERROR: cannot determine host project directory" + exit 1 + fi + + echo "Starting ComfyUI..." + echo "Models: $HOST_PROJECT_DIR/gpu/comfy_models" + + COMFY_MODELS_HOST="$HOST_PROJECT_DIR/gpu/comfy_models" \ + docker compose --profile comfy up -d comfyui + + echo + docker ps \ + --filter "name=gpu-node-comfyui" \ + --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' + ;; + + *) + echo "Usage: gpuctl start {llama|comfy}" + exit 1 + ;; + esac + ;; + + stop) + case "${2:-}" in + + llama) + docker stop gpu-node-llama + ;; + + comfy) + docker stop gpu-node-comfyui + ;; + + *) + echo "Usage: gpuctl stop {llama|comfy}" + exit 1 + ;; + esac + ;; + + restart) + case "${2:-}" in + + llama) + docker restart gpu-node-llama + ;; + + comfy) + docker restart gpu-node-comfyui + ;; + + *) + echo "Usage: gpuctl restart {llama|comfy}" + exit 1 + ;; + esac + ;; + + logs) + case "${2:-}" in + + llama) + docker logs --tail 100 gpu-node-llama + ;; + + comfy) + docker logs --tail 100 gpu-node-comfyui + ;; + + *) + echo "Usage: gpuctl logs {llama|comfy}" + exit 1 + ;; + esac + ;; + + *) + echo "Usage:" + echo " gpuctl status" + echo " gpuctl start {llama|comfy}" + echo " gpuctl stop {llama|comfy}" + echo " gpuctl restart {llama|comfy}" + echo " gpuctl logs {llama|comfy}" + exit 1 + ;; + +esac