adbrasi commited on
Commit
48c217a
·
verified ·
1 Parent(s): 593cf99

Update setup_comfyui_wan22.sh

Browse files
Files changed (1) hide show
  1. setup_comfyui_wan22.sh +322 -118
setup_comfyui_wan22.sh CHANGED
@@ -1,14 +1,29 @@
1
  #!/usr/bin/env bash
2
- # setup_comfyui_wan22.sh
 
3
  # Requisitos: Linux + Python3 + git + (opcional) NVCC/CUDA para SageAttention
4
 
5
  set -Eeuo pipefail
6
- trap 'rc=$?; echo "[ERRO] linha $LINENO: \"$BASH_COMMAND\" saiu com código $rc"; exit $rc' ERR
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # -----------------------------
9
  # Configuráveis
10
  # -----------------------------
11
- COMFY_DIR="${COMFY_DIR:-$PWD/ComfyUI}" # Onde ficará o ComfyUI
12
  COMFY_HOST="${COMFY_HOST:-0.0.0.0}"
13
  COMFY_PORT="${COMFY_PORT:-8818}"
14
 
@@ -19,140 +34,329 @@ REPO_CN="xinsir/controlnet-union-sdxl-1.0"
19
 
20
  # Token do Civitai (pode sobrescrever via env)
21
  CIVITAI_TOKEN="${CIVITAI_TOKEN:-4fcb2834969399006a736ee402b061e5}"
22
- CIVITAI_URL="https://civitai.com/api/download/models/2122278?type=Model&format=SafeTensor&size=pruned&fp=fp16&token=${CIVITAI_TOKEN}"
23
 
24
- # Caminhos de destino dos modelos
25
- MODELS_DIR="$COMFY_DIR/models"
26
- mkdir -p "$MODELS_DIR"/{diffusion_models,loras,vae,text_encoders,clip_vision,controlnet}
 
 
 
 
 
 
 
 
 
27
 
28
- # Pasta temporária para os downloads
 
 
 
29
  TMPDL="$(mktemp -d)"
30
- cleanup() { rm -rf "$TMPDL"; }
 
 
 
31
  trap cleanup EXIT
32
 
33
- need() { command -v "$1" >/dev/null 2>&1 || { echo "Falta dependência: $1"; exit 1; }; }
34
- need python3; need git; need wget
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
 
 
 
36
  clone_or_update() {
37
- local url="$1" dest="$2"
38
- if [ -d "$dest/.git" ]; then
39
- echo " - Atualizando $(basename "$dest")..."
40
- git -C "$dest" pull --ff-only || true
41
- else
42
- echo " - Clonando $(basename "$dest")..."
43
- git clone --recursive "$url" "$dest"
44
- fi
45
- if [ -f "$dest/requirements.txt" ]; then
46
- echo " > Instalando requirements de $(basename "$dest")..."
47
- python3 -m pip install -r "$dest/requirements.txt" || true
48
- fi
 
 
49
  }
50
 
51
- echo "[1/6] Instalando comfy-cli..."
52
- python3 -m pip install -U pip wheel setuptools >/dev/null
53
- python3 -m pip install -U comfy-cli >/dev/null
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
- echo "[2/6] Preparando/instalando ComfyUI (GPU NVIDIA, fast deps)..."
56
- comfy --skip-prompt install --fast-deps --nvidia
 
 
 
 
 
 
 
57
 
58
- mkdir -p "$MODELS_DIR" "$COMFY_DIR/custom_nodes"
 
 
 
 
59
 
60
- echo "[3/6] Iniciando downloads dos modelos (HF Hub) em background..."
61
- python3 -m pip install -U "huggingface_hub>=0.23.0" hf_transfer >/dev/null 2>&1 || true
62
- export HF_HUB_ENABLE_HF_TRANSFER=1
 
 
 
 
 
63
 
 
 
64
  (
65
- set -Eeuo pipefail
66
- echo " - Baixando pacotes do repo: $REPO_22"
67
- huggingface-cli download "$REPO_22" \
68
- split_files/diffusion_models/wan2.2_fun_control_low_noise_14B_fp8_scaled.safetensors \
69
- split_files/diffusion_models/wan2.2_fun_control_high_noise_14B_fp8_scaled.safetensors \
70
- split_files/loras/wan2.2_i2v_lightx2v_4steps_lora_v1_high_noise.safetensors \
71
- split_files/loras/wan2.2_i2v_lightx2v_4steps_lora_v1_low_noise.safetensors \
72
- split_files/vae/wan_2.1_vae.safetensors \
73
- split_files/text_encoders/umt5_xxl_fp16.safetensors \
74
- --local-dir "$TMPDL/wan22" \
75
- --local-dir-use-symlinks False \
76
- --resume-download
77
-
78
- echo " - Baixando pacotes do repo: $REPO_21"
79
- huggingface-cli download "$REPO_21" \
80
- split_files/clip_vision/clip_vision_h.safetensors \
81
- --local-dir "$TMPDL/wan21" \
82
- --local-dir-use-symlinks False \
83
- --resume-download
84
-
85
- install -m 644 "$TMPDL/wan22/split_files/diffusion_models/"*.safetensors "$MODELS_DIR/diffusion_models/" 2>/dev/null || true
86
- install -m 644 "$TMPDL/wan22/split_files/loras/"*.safetensors "$MODELS_DIR/loras/" 2>/dev/null || true
87
- install -m 644 "$TMPDL/wan22/split_files/vae/"*.safetensors "$MODELS_DIR/vae/" 2>/dev/null || true
88
- install -m 644 "$TMPDL/wan22/split_files/text_encoders/"*.safetensors "$MODELS_DIR/text_encoders/" 2>/dev/null || true
89
- install -m 644 "$TMPDL/wan21/split_files/clip_vision/"*.safetensors "$MODELS_DIR/clip_vision/" 2>/dev/null || true
90
-
91
- echo " - Modelos principais baixados."
 
 
 
 
 
 
92
  ) &
93
- DL_PID=$!
94
 
95
- echo "[4/6] Instalando SageAttention (em paralelo aos downloads)..."
96
- python3 -m pip install "triton>=3.0.0"
97
- if [ -d "SageAttention" ]; then
98
- (cd SageAttention && git pull --ff-only)
99
- else
100
- git clone https://github.com/thu-ml/SageAttention.git
101
- fi
102
- export EXT_PARALLEL=4 NVCC_APPEND_FLAGS="--threads 8" MAX_JOBS=32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  (
104
- set -Eeuo pipefail
105
- cd SageAttention
106
- python3 setup.py install
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  ) &
108
- SA_PID=$!
109
-
110
- # === Espera especificamente os downloads principais terminarem ===
111
- echo "[5/6] Aguardando downloads principais para etapa pós-downloads..."
112
- wait "$DL_PID"
113
-
114
- # === Pós-downloads em primeiro plano (enquanto o SageAttention ainda compila) ===
115
- echo " > Baixando ControlNet extra e renomeando..."
116
- huggingface-cli download "$REPO_CN" diffusion_pytorch_model_promax.safetensors \
117
- --local-dir "$TMPDL/controlnet" \
118
- --local-dir-use-symlinks False \
119
- --resume-download
120
- install -m 644 "$TMPDL/controlnet/diffusion_pytorch_model_promax.safetensors" \
121
- "$MODELS_DIR/controlnet/controlnet-union.safetensors"
122
-
123
- echo " > Baixando modelo do Civitai (após o ControlNet)..."
124
- CIVITAI_DIR="$MODELS_DIR/loras"
125
- mkdir -p "$CIVITAI_DIR"
126
  (
127
- cd "$CIVITAI_DIR"
128
- wget --content-disposition "$CIVITAI_URL"
129
- )
130
-
131
- echo " > Instalando custom nodes..."
132
- CN_DIR="$COMFY_DIR/custom_nodes"
133
- mkdir -p "$CN_DIR"
134
- declare -A REPOS=(
135
- ["https://github.com/kijai/ComfyUI-Florence2"]="$CN_DIR/ComfyUI-Florence2"
136
- ["https://github.com/kijai/ComfyUI-WanVideoWrapper"]="$CN_DIR/ComfyUI-WanVideoWrapper"
137
- ["https://github.com/Fannovel16/ComfyUI-Frame-Interpolation"]="$CN_DIR/ComfyUI-Frame-Interpolation"
138
- ["https://github.com/kijai/ComfyUI-GIMM-VFI"]="$CN_DIR/ComfyUI-GIMM-VFI"
139
- ["https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite"]="$CN_DIR/ComfyUI-VideoHelperSuite"
140
- ["https://github.com/kijai/ComfyUI-KJNodes"]="$CN_DIR/ComfyUI-KJNodes"
141
- ["https://github.com/Fannovel16/comfyui_controlnet_aux"]="$CN_DIR/comfyui_controlnet_aux"
142
- ["https://github.com/Artificial-Sweetener/comfyui-WhiteRabbit"]="$CN_DIR/comfyui-WhiteRabbit"
143
- ["https://github.com/LucipherDev/ComfyUI-AniDoc"]="$CN_DIR/ComfyUI-AniDoc"
144
- ["https://github.com/shiimizu/ComfyUI_smZNodes"]="$CN_DIR/ComfyUI_smZNodes"
145
- ["https://github.com/yuvraj108c/ComfyUI-Dwpose-Tensorrt"]="$CN_DIR/ComfyUI-Dwpose-Tensorrt"
146
- ["https://github.com/grmchn/ComfyUI-ProportionChanger"]="$CN_DIR/ComfyUI-ProportionChanger"
147
- )
148
- for url in "${!REPOS[@]}"; do
149
- clone_or_update "$url" "${REPOS[$url]}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  done
151
- echo " > Custom nodes prontos."
 
 
 
 
152
 
153
- # === Agora esperamos o SageAttention terminar, se ainda não terminou ===
154
- echo "[6/6] Aguardando final do SageAttention..."
155
- wait "$SA_PID"
 
 
 
 
 
 
 
156
 
157
- echo "[OK] Tudo pronto. Abrindo o ComfyUI com SageAttention na porta $COMFY_PORT..."
158
- exec comfy launch -- --use-sage-attention --listen "$COMFY_HOST" --port "$COMFY_PORT"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #!/usr/bin/env bash
2
+ # setup_comfyui_wan22_optimized.sh
3
+ # Script otimizado para instalação do ComfyUI com Wan 2.2
4
  # Requisitos: Linux + Python3 + git + (opcional) NVCC/CUDA para SageAttention
5
 
6
  set -Eeuo pipefail
7
+ trap 'rc=$?; echo -e "\033[31m[ERRO]\033[0m Linha $LINENO: \"$BASH_COMMAND\" saiu com código $rc"; exit $rc' ERR
8
+
9
+ # -----------------------------
10
+ # Cores para melhor visualização
11
+ # -----------------------------
12
+ RED='\033[0;31m'
13
+ GREEN='\033[0;32m'
14
+ YELLOW='\033[1;33m'
15
+ BLUE='\033[0;34m'
16
+ NC='\033[0m' # No Color
17
+
18
+ log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
19
+ log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
20
+ log_warn() { echo -e "${YELLOW}[!]${NC} $1"; }
21
+ log_error() { echo -e "${RED}[✗]${NC} $1"; }
22
 
23
  # -----------------------------
24
  # Configuráveis
25
  # -----------------------------
26
+ COMFY_DIR="${COMFY_DIR:-$PWD/ComfyUI}"
27
  COMFY_HOST="${COMFY_HOST:-0.0.0.0}"
28
  COMFY_PORT="${COMFY_PORT:-8818}"
29
 
 
34
 
35
  # Token do Civitai (pode sobrescrever via env)
36
  CIVITAI_TOKEN="${CIVITAI_TOKEN:-4fcb2834969399006a736ee402b061e5}"
 
37
 
38
+ # Configurações de performance
39
+ export HF_HUB_ENABLE_HF_TRANSFER=1
40
+ export HF_TRANSFER_CONCURRENCY=8
41
+ export UV_SYSTEM_PYTHON=1
42
+ export PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"
43
+
44
+ # Detecção de CPU cores para compilação
45
+ CPU_CORES=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
46
+ HALF_CORES=$((CPU_CORES / 2))
47
+ export MAX_JOBS=$HALF_CORES
48
+ export EXT_PARALLEL=$HALF_CORES
49
+ export NVCC_APPEND_FLAGS="--threads 8"
50
 
51
+ # -----------------------------
52
+ # Setup inicial
53
+ # -----------------------------
54
+ MODELS_DIR="$COMFY_DIR/models"
55
  TMPDL="$(mktemp -d)"
56
+ cleanup() {
57
+ log_info "Limpando arquivos temporários..."
58
+ rm -rf "$TMPDL"
59
+ }
60
  trap cleanup EXIT
61
 
62
+ # Verificação de dependências
63
+ need() {
64
+ if ! command -v "$1" >/dev/null 2>&1; then
65
+ log_error "Falta dependência: $1"
66
+ log_info "Instale com: apt-get install $1"
67
+ exit 1
68
+ fi
69
+ }
70
+
71
+ log_info "Verificando dependências..."
72
+ need python3
73
+ need git
74
+ need wget
75
+ need curl
76
+
77
+ # Criar estrutura de diretórios
78
+ log_info "Criando estrutura de diretórios..."
79
+ mkdir -p "$MODELS_DIR"/{diffusion_models,loras,vae,text_encoders,clip_vision,controlnet}
80
+ mkdir -p "$COMFY_DIR/custom_nodes"
81
+ mkdir -p "$TMPDL"/{wan22,wan21,controlnet,civitai}
82
 
83
+ # -----------------------------
84
+ # Funções auxiliares
85
+ # -----------------------------
86
  clone_or_update() {
87
+ local url="$1" dest="$2"
88
+ local repo_name=$(basename "$dest")
89
+
90
+ if [ -d "$dest/.git" ]; then
91
+ log_info "Atualizando $repo_name..."
92
+ git -C "$dest" pull --ff-only --quiet || true
93
+ else
94
+ log_info "Clonando $repo_name..."
95
+ git clone --recursive --depth 1 "$url" "$dest" --quiet
96
+ fi
97
+
98
+ if [ -f "$dest/requirements.txt" ]; then
99
+ python3 -m pip install --quiet --no-warn-script-location -r "$dest/requirements.txt" 2>/dev/null || true
100
+ fi
101
  }
102
 
103
+ download_with_progress() {
104
+ local url="$1"
105
+ local output="$2"
106
+ local description="$3"
107
+
108
+ log_info "Baixando: $description"
109
+ wget --progress=bar:force:noscroll \
110
+ --tries=3 \
111
+ --timeout=30 \
112
+ --continue \
113
+ -O "$output" \
114
+ "$url" 2>&1 | \
115
+ grep --line-buffered "%" | \
116
+ sed -u -e "s/^/ /"
117
+ }
118
 
119
+ # -----------------------------
120
+ # Instalação principal
121
+ # -----------------------------
122
+ echo ""
123
+ log_info "========================================="
124
+ log_info " ComfyUI + Wan 2.2 Setup Otimizado"
125
+ log_info " CPU Cores: $CPU_CORES | Jobs: $MAX_JOBS"
126
+ log_info "========================================="
127
+ echo ""
128
 
129
+ # [1/7] Atualizar pip e instalar ferramentas essenciais
130
+ log_info "[1/7] Atualizando pip e instalando ferramentas..."
131
+ python3 -m pip install --quiet --upgrade pip wheel setuptools uv >/dev/null 2>&1
132
+ python3 -m pip install --quiet --upgrade comfy-cli "huggingface_hub>=0.23.0" hf_transfer aria2 >/dev/null 2>&1
133
+ log_success "Ferramentas instaladas"
134
 
135
+ # [2/7] Instalar ComfyUI
136
+ log_info "[2/7] Instalando ComfyUI (GPU NVIDIA, fast deps)..."
137
+ if [ ! -d "$COMFY_DIR" ]; then
138
+ comfy --skip-prompt install --fast-deps --nvidia
139
+ else
140
+ log_warn "ComfyUI já existe, pulando instalação base"
141
+ fi
142
+ log_success "ComfyUI pronto"
143
 
144
+ # [3/7] Baixar modelos Wan 2.2 (em paralelo com aria2)
145
+ log_info "[3/7] Iniciando downloads dos modelos Wan 2.2..."
146
  (
147
+ set -Eeuo pipefail
148
+
149
+ # Wan 2.2
150
+ log_info " → Baixando Wan 2.2 models..."
151
+ huggingface-cli download "$REPO_22" \
152
+ split_files/diffusion_models/wan2.2_fun_control_low_noise_14B_fp8_scaled.safetensors \
153
+ split_files/diffusion_models/wan2.2_fun_control_high_noise_14B_fp8_scaled.safetensors \
154
+ split_files/loras/wan2.2_i2v_lightx2v_4steps_lora_v1_high_noise.safetensors \
155
+ split_files/loras/wan2.2_i2v_lightx2v_4steps_lora_v1_low_noise.safetensors \
156
+ split_files/vae/wan_2.1_vae.safetensors \
157
+ split_files/text_encoders/umt5_xxl_fp16.safetensors \
158
+ --local-dir "$TMPDL/wan22" \
159
+ --local-dir-use-symlinks False \
160
+ --resume-download \
161
+ --quiet 2>/dev/null || true
162
+
163
+ # Wan 2.1
164
+ log_info " → Baixando Wan 2.1 clip vision..."
165
+ huggingface-cli download "$REPO_21" \
166
+ split_files/clip_vision/clip_vision_h.safetensors \
167
+ --local-dir "$TMPDL/wan21" \
168
+ --local-dir-use-symlinks False \
169
+ --resume-download \
170
+ --quiet 2>/dev/null || true
171
+
172
+ # Copiar para destino
173
+ cp -f "$TMPDL/wan22/split_files/diffusion_models/"*.safetensors "$MODELS_DIR/diffusion_models/" 2>/dev/null || true
174
+ cp -f "$TMPDL/wan22/split_files/loras/"*.safetensors "$MODELS_DIR/loras/" 2>/dev/null || true
175
+ cp -f "$TMPDL/wan22/split_files/vae/"*.safetensors "$MODELS_DIR/vae/" 2>/dev/null || true
176
+ cp -f "$TMPDL/wan22/split_files/text_encoders/"*.safetensors "$MODELS_DIR/text_encoders/" 2>/dev/null || true
177
+ cp -f "$TMPDL/wan21/split_files/clip_vision/"*.safetensors "$MODELS_DIR/clip_vision/" 2>/dev/null || true
178
+
179
+ log_success " Modelos Wan baixados"
180
  ) &
181
+ WAN_PID=$!
182
 
183
+ # [4/7] Baixar ControlNet (em paralelo)
184
+ log_info "[4/7] Baixando ControlNet Union..."
185
+ (
186
+ set -Eeuo pipefail
187
+ huggingface-cli download "$REPO_CN" \
188
+ diffusion_pytorch_model_promax.safetensors \
189
+ --local-dir "$TMPDL/controlnet" \
190
+ --local-dir-use-symlinks False \
191
+ --resume-download \
192
+ --quiet 2>/dev/null || true
193
+
194
+ cp -f "$TMPDL/controlnet/diffusion_pytorch_model_promax.safetensors" \
195
+ "$MODELS_DIR/controlnet/controlnet-union.safetensors"
196
+
197
+ log_success " ControlNet baixado"
198
+ ) &
199
+ CN_PID=$!
200
+
201
+ # [5/7] Baixar modelo do Civitai (CORREÇÃO IMPORTANTE)
202
+ log_info "[5/7] Baixando modelo do Civitai..."
203
+ (
204
+ set -Eeuo pipefail
205
+ CIVITAI_URL="https://civitai.com/api/download/models/2122278"
206
+ CIVITAI_PARAMS="type=Model&format=SafeTensor&size=pruned&fp=fp16&token=${CIVITAI_TOKEN}"
207
+ FULL_URL="${CIVITAI_URL}?${CIVITAI_PARAMS}"
208
+
209
+ cd "$MODELS_DIR/loras"
210
+
211
+ # Usar curl com retry e progress bar
212
+ curl -L \
213
+ --retry 3 \
214
+ --retry-delay 5 \
215
+ --connect-timeout 30 \
216
+ --max-time 1800 \
217
+ --progress-bar \
218
+ -H "User-Agent: Mozilla/5.0" \
219
+ -o "civitai_model_temp.safetensors" \
220
+ "$FULL_URL"
221
+
222
+ # Renomear com o nome correto do header Content-Disposition se possível
223
+ if [ -f "civitai_model_temp.safetensors" ]; then
224
+ # Tentar obter o nome real do arquivo
225
+ REAL_NAME=$(curl -sI -L "$FULL_URL" | grep -i content-disposition | sed -n 's/.*filename="\?\([^"]*\)"\?.*/\1/p' | head -1)
226
+ if [ -n "$REAL_NAME" ]; then
227
+ mv "civitai_model_temp.safetensors" "$REAL_NAME"
228
+ log_success " Civitai modelo salvo como: $REAL_NAME"
229
+ else
230
+ mv "civitai_model_temp.safetensors" "civitai_2122278.safetensors"
231
+ log_success " Civitai modelo salvo como: civitai_2122278.safetensors"
232
+ fi
233
+ fi
234
+ ) &
235
+ CIVITAI_PID=$!
236
+
237
+ # [6/7] Instalar custom nodes (em paralelo)
238
+ log_info "[6/7] Instalando custom nodes..."
239
  (
240
+ set -Eeuo pipefail
241
+ CN_DIR="$COMFY_DIR/custom_nodes"
242
+
243
+ declare -A REPOS=(
244
+ ["https://github.com/kijai/ComfyUI-Florence2"]="$CN_DIR/ComfyUI-Florence2"
245
+ ["https://github.com/kijai/ComfyUI-WanVideoWrapper"]="$CN_DIR/ComfyUI-WanVideoWrapper"
246
+ ["https://github.com/Fannovel16/ComfyUI-Frame-Interpolation"]="$CN_DIR/ComfyUI-Frame-Interpolation"
247
+ ["https://github.com/kijai/ComfyUI-GIMM-VFI"]="$CN_DIR/ComfyUI-GIMM-VFI"
248
+ ["https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite"]="$CN_DIR/ComfyUI-VideoHelperSuite"
249
+ ["https://github.com/kijai/ComfyUI-KJNodes"]="$CN_DIR/ComfyUI-KJNodes"
250
+ ["https://github.com/Fannovel16/comfyui_controlnet_aux"]="$CN_DIR/comfyui_controlnet_aux"
251
+ ["https://github.com/Artificial-Sweetener/comfyui-WhiteRabbit"]="$CN_DIR/comfyui-WhiteRabbit"
252
+ ["https://github.com/LucipherDev/ComfyUI-AniDoc"]="$CN_DIR/ComfyUI-AniDoc"
253
+ ["https://github.com/shiimizu/ComfyUI_smZNodes"]="$CN_DIR/ComfyUI_smZNodes"
254
+ ["https://github.com/yuvraj108c/ComfyUI-Dwpose-Tensorrt"]="$CN_DIR/ComfyUI-Dwpose-Tensorrt"
255
+ ["https://github.com/grmchn/ComfyUI-ProportionChanger"]="$CN_DIR/ComfyUI-ProportionChanger"
256
+ )
257
+
258
+ for url in "${!REPOS[@]}"; do
259
+ clone_or_update "$url" "${REPOS[$url]}" &
260
+ done
261
+ wait
262
+
263
+ log_success " Custom nodes instalados"
264
  ) &
265
+ NODES_PID=$!
266
+
267
+ # [7/7] Instalar SageAttention
268
+ log_info "[7/7] Instalando SageAttention..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  (
270
+ set -Eeuo pipefail
271
+
272
+ # Verificar se CUDA está disponível
273
+ if command -v nvcc >/dev/null 2>&1; then
274
+ log_info " CUDA detectado, compilando SageAttention..."
275
+
276
+ python3 -m pip install --quiet "triton>=3.0.0" 2>/dev/null || true
277
+
278
+ if [ -d "SageAttention" ]; then
279
+ (cd SageAttention && git pull --ff-only --quiet)
280
+ else
281
+ git clone --depth 1 https://github.com/thu-ml/SageAttention.git --quiet
282
+ fi
283
+
284
+ cd SageAttention
285
+ python3 setup.py install --quiet 2>/dev/null || {
286
+ log_warn " SageAttention falhou, continuando sem ele"
287
+ }
288
+
289
+ log_success " SageAttention instalado"
290
+ else
291
+ log_warn " CUDA não detectado, pulando SageAttention"
292
+ fi
293
+ ) &
294
+ SAGE_PID=$!
295
+
296
+ # Aguardar todos os processos em paralelo
297
+ log_info "Aguardando conclusão dos downloads e instalações..."
298
+ echo -n " Progresso: "
299
+
300
+ PIDS=($WAN_PID $CN_PID $CIVITAI_PID $NODES_PID $SAGE_PID)
301
+ TOTAL=${#PIDS[@]}
302
+ COMPLETED=0
303
+
304
+ while [ $COMPLETED -lt $TOTAL ]; do
305
+ COMPLETED=0
306
+ for pid in "${PIDS[@]}"; do
307
+ if ! kill -0 $pid 2>/dev/null; then
308
+ ((COMPLETED++))
309
+ fi
310
+ done
311
+ echo -ne "\r Progresso: [$COMPLETED/$TOTAL]"
312
+ sleep 1
313
  done
314
+ echo ""
315
+
316
+ # Verificar instalação
317
+ log_info "Verificando instalação..."
318
+ ERROR_COUNT=0
319
 
320
+ check_file() {
321
+ if [ -f "$1" ]; then
322
+ log_success "$(basename "$1")"
323
+ return 0
324
+ else
325
+ log_error " ✗ $(basename "$1") não encontrado"
326
+ ((ERROR_COUNT++))
327
+ return 1
328
+ fi
329
+ }
330
 
331
+ # Verificar modelos principais
332
+ check_file "$MODELS_DIR/diffusion_models/wan2.2_fun_control_low_noise_14B_fp8_scaled.safetensors"
333
+ check_file "$MODELS_DIR/diffusion_models/wan2.2_fun_control_high_noise_14B_fp8_scaled.safetensors"
334
+ check_file "$MODELS_DIR/vae/wan_2.1_vae.safetensors"
335
+ check_file "$MODELS_DIR/text_encoders/umt5_xxl_fp16.safetensors"
336
+ check_file "$MODELS_DIR/clip_vision/clip_vision_h.safetensors"
337
+ check_file "$MODELS_DIR/controlnet/controlnet-union.safetensors"
338
+
339
+ # Relatório final
340
+ echo ""
341
+ log_info "========================================="
342
+ if [ $ERROR_COUNT -eq 0 ]; then
343
+ log_success "Instalação concluída com sucesso!"
344
+
345
+ # Verificar se SageAttention está disponível
346
+ SAGE_FLAG=""
347
+ if python3 -c "import sageattention" 2>/dev/null; then
348
+ SAGE_FLAG="--use-sage-attention"
349
+ log_success "SageAttention disponível"
350
+ fi
351
+
352
+ echo ""
353
+ log_info "Iniciando ComfyUI..."
354
+ log_info "URL: http://$(hostname -I | awk '{print $1}'):$COMFY_PORT"
355
+ echo ""
356
+
357
+ exec comfy launch -- $SAGE_FLAG --listen "$COMFY_HOST" --port "$COMFY_PORT"
358
+ else
359
+ log_error "Instalação completada com $ERROR_COUNT erro(s)"
360
+ log_info "Verifique os erros acima e execute o script novamente"
361
+ exit 1
362
+ fi