gtaayush010 commited on
Commit
8a5d5c5
·
verified ·
1 Parent(s): dd13b42

Create setup.sh

Browse files
Files changed (1) hide show
  1. setup.sh +182 -0
setup.sh ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+
4
+ # Install directly in the SSH user's home directory
5
+ INSTALL_BASE="${HOME}"
6
+ AI_TOOLKIT_DIR="${INSTALL_BASE}/ai-toolkit"
7
+ UI_PORT=8675
8
+
9
+ SETUP_LOG="/tmp/ai_toolkit_setup.log"
10
+ UI_LOG="/tmp/ai_toolkit_ui.log"
11
+
12
+ : > "${SETUP_LOG}"
13
+
14
+ # Color formatting
15
+ if [ -t 1 ]; then
16
+ RESET=$'\033[0m'
17
+ BOLD=$'\033[1m'
18
+ RED=$'\033[31m'
19
+ GREEN=$'\033[32m'
20
+ YELLOW=$'\033[33m'
21
+ BLUE=$'\033[34m'
22
+ CYAN=$'\033[36m'
23
+ else
24
+ RESET=""
25
+ BOLD=""
26
+ RED=""
27
+ GREEN=""
28
+ YELLOW=""
29
+ BLUE=""
30
+ CYAN=""
31
+ fi
32
+
33
+ log() { printf "%b[%s]%b %s\n" "${BLUE}" "INFO" "${RESET}" "$1"; }
34
+ err() { printf "%b[%s]%b %s\n" "${RED}" "ERROR" "${RESET}" "$1" >&2; exit 1; }
35
+ ok() { printf "%b[%s]%b %s\n" "${GREEN}" "OK" "${RESET}" "$1"; }
36
+ section() { printf "\n%b%s%b\n" "${BOLD}${CYAN}" "$1" "${RESET}"; }
37
+ kv() { printf " %b%-22s%b %s\n" "${YELLOW}" "$1" "${RESET}" "$2"; }
38
+
39
+ run_logged() {
40
+ local label="$1"
41
+ local logfile="$2"
42
+ shift 2
43
+
44
+ printf " %b[%s]%b %s\n" "${BLUE}" ".." "${RESET}" "$label"
45
+ if "$@" >>"${logfile}" 2>&1; then
46
+ printf " %b[%s]%b %s\n" "${GREEN}" "OK" "${RESET}" "$label"
47
+ else
48
+ printf " %b[%s]%b %s\n" "${RED}" "FAIL" "${RESET}" "$label" >&2
49
+ printf "%s\n" "--- last 30 lines from ${logfile} ---" >&2
50
+ tail -n 30 "${logfile}" >&2 || true
51
+ exit 1
52
+ fi
53
+ }
54
+
55
+ # ------------------ 1. WORKSPACE PREPARATION ------------------
56
+ section "1. Preparing Workspace Directory"
57
+ mkdir -p "${INSTALL_BASE}"
58
+ ok "Installation home directory: ${INSTALL_BASE}"
59
+
60
+ kv "Install Base (Home)" "${INSTALL_BASE}"
61
+ kv "ai-toolkit Path" "${AI_TOOLKIT_DIR}"
62
+ kv "Setup Log" "${SETUP_LOG}"
63
+
64
+ # ------------------ 2. SYSTEM DEPENDENCIES & NVM NODE.JS 24 ------------------
65
+ section "2. Installing System Dependencies & Node.js 24 via NVM"
66
+
67
+ run_logged "apt update" "${SETUP_LOG}" sudo apt-get update -y || apt-get update -y
68
+ run_logged "apt packages" "${SETUP_LOG}" sudo apt-get install -y \
69
+ curl git screen python3 python3-venv python3-pip \
70
+ zip unzip nano ffmpeg build-essential || apt-get install -y \
71
+ curl git screen python3 python3-venv python3-pip \
72
+ zip unzip nano ffmpeg build-essential
73
+
74
+ # Download and install nvm & Node.js 24
75
+ log "Installing nvm and Node.js 24..."
76
+ export NVM_DIR="$HOME/.nvm"
77
+ if [ ! -s "$NVM_DIR/nvm.sh" ]; then
78
+ run_logged "download nvm" "${SETUP_LOG}" bash -lc 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash'
79
+ fi
80
+
81
+ # Load nvm into script context
82
+ \. "$HOME/.nvm/nvm.sh"
83
+
84
+ run_logged "install Node.js 24" "${SETUP_LOG}" nvm install 24
85
+ nvm use 24
86
+
87
+ log "Node.js version: $(node -v)"
88
+ log "npm version: $(npm -v)"
89
+
90
+ # Install uv for fast Python package installation
91
+ if ! command -v uv >/dev/null 2>&1; then
92
+ run_logged "install uv" "${SETUP_LOG}" bash -lc 'curl -Ls https://astral.sh/uv/install.sh | sh'
93
+ fi
94
+ export PATH="${HOME}/.cargo/bin:/root/.cargo/bin:$PATH"
95
+
96
+ ok "System dependencies & Node.js 24 installed"
97
+
98
+ # ------------------ 3. AI-TOOLKIT REPO & PYTHON VENV ------------------
99
+ section "3. Cloning ai-toolkit & Setting up Environment"
100
+
101
+ cd "${INSTALL_BASE}"
102
+
103
+ if [ ! -d "${AI_TOOLKIT_DIR}" ]; then
104
+ run_logged "git clone ai-toolkit" "${SETUP_LOG}" git clone --recursive https://github.com/ostris/ai-toolkit.git "${AI_TOOLKIT_DIR}"
105
+ else
106
+ log "ai-toolkit directory exists. Fetching updates..."
107
+ cd "${AI_TOOLKIT_DIR}"
108
+ git pull || true
109
+ fi
110
+
111
+ cd "${AI_TOOLKIT_DIR}"
112
+ run_logged "git submodules update" "${SETUP_LOG}" git submodule update --init --recursive
113
+
114
+ # Create Virtual Environment
115
+ if [ ! -d "venv" ]; then
116
+ run_logged "create venv" "${SETUP_LOG}" python3 -m venv venv
117
+ fi
118
+
119
+ source venv/bin/activate
120
+ run_logged "upgrade pip" "${SETUP_LOG}" pip install --upgrade pip
121
+
122
+ # Install PyTorch & Dependencies via uv using specified CUDA 12.8 wheel index
123
+ log "Installing PyTorch 2.11.0 (CUDA 12.8)..."
124
+ run_logged "install torch cu128" "${SETUP_LOG}" uv pip install torch==2.11.0 torchvision==0.26.0 torchaudio==2.11.0 --index-url https://download.pytorch.org/whl/cu128
125
+
126
+ if [ -f "requirements.txt" ]; then
127
+ run_logged "install requirements.txt" "${SETUP_LOG}" uv pip install -r requirements.txt
128
+ fi
129
+
130
+ if [ -f "setup.py" ] || [ -f "pyproject.toml" ]; then
131
+ run_logged "install ai-toolkit package" "${SETUP_LOG}" uv pip install -e . || true
132
+ fi
133
+
134
+ run_logged "install HF hub & utilities" "${SETUP_LOG}" uv pip install \
135
+ huggingface_hub[cli] hf_transfer tensorboard wandb bitsandbytes diffusers transformers peft accelerate
136
+
137
+ # Create standard subdirectories in ai-toolkit
138
+ mkdir -p dataset config models output
139
+
140
+ ok "Python environment setup complete"
141
+
142
+ # ------------------ 4. AI-TOOLKIT WEB UI SETUP ------------------
143
+ section "4. Setting up AI-Toolkit Web UI"
144
+
145
+ if [ -d "${AI_TOOLKIT_DIR}/ui" ]; then
146
+ cd "${AI_TOOLKIT_DIR}/ui"
147
+ run_logged "npm install (ui dependencies)" "${SETUP_LOG}" npm install
148
+ ok "Web UI dependencies installed"
149
+ else
150
+ err "ui directory not found in ai-toolkit."
151
+ fi
152
+
153
+ # ------------------ 5. LAUNCH WEB UI SCREEN SESSION ------------------
154
+ section "5. Launching Web UI"
155
+
156
+ screen -dmS aitoolkit_ui bash -lc "
157
+ export NVM_DIR=\"\$HOME/.nvm\"
158
+ [ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\"
159
+ nvm use 24
160
+ cd ${AI_TOOLKIT_DIR}/ui
161
+ source ../venv/bin/activate
162
+ export HF_HUB_ENABLE_HF_TRANSFER=1
163
+ echo '=== STARTING AI-TOOLKIT WEB UI (Port ${UI_PORT}) ==='
164
+ npm run build_and_start > ${UI_LOG} 2>&1
165
+ exec bash
166
+ "
167
+ log "Screen session 'aitoolkit_ui' launched on port ${UI_PORT}"
168
+
169
+ # ------------------ SUMMARY ------------------
170
+ section "Setup Complete!"
171
+ kv "ai-toolkit Path" "${AI_TOOLKIT_DIR}"
172
+ kv "Node.js Version" "$(node -v)"
173
+ kv "PyTorch Version" "2.11.0 (cu128)"
174
+ kv "Web UI Port" "${UI_PORT}"
175
+ kv "Screen Session" "screen -r aitoolkit_ui"
176
+
177
+ section "🌐 Direct Connection Info"
178
+ echo " • Access URL: http://<YOUR_VM_IP>:${UI_PORT}"
179
+ echo " • Local/SSH: http://localhost:${UI_PORT}"
180
+ echo " • Attach UI: screen -r aitoolkit_ui"
181
+ echo ""
182
+ ok "Done!"