Aduc-sdr-2_5s / start.sh
euIaxs22's picture
Update start.sh
243f9ce verified
raw
history blame
3.22 kB
#!/usr/bin/env bash
set -euo pipefail
: "${APP_DIR:=/app}"
export PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True,max_split_size_mb:128"
export CUDA_MODULE_LOADING="LAZY"
echo "======================================================="
echo " VINCIE - Start (VINCIE-3B, 8x L40S)"
echo "======================================================="
# 1) Builder (garante Apex/Flash e deps CUDA)
echo "🛠️ Iniciando o builder.sh para compilar/instalar dependências CUDA..."
if [ -f "/app/builder.sh" ]; then
/bin/bash /app/builder.sh
echo "✅ Builder finalizado."
else
echo "⚠️ Aviso: builder.sh não encontrado. Pulando etapa de compilação de dependências."
fi
# 2) Env da UI
export GRADIO_SERVER_NAME="0.0.0.0"
export GRADIO_SERVER_PORT="${PORT:-7860}"
export GRADIO_ENABLE_QUEUE="True"
# 3) Preflight: repo + snapshot + symlinks idempotentes
python3 - <<'PY'
import os, sys, subprocess
from pathlib import Path
from services.vincie import VincieService
repo_dir = Path("/app/VINCIE")
ckpt_repo = repo_dir / "ckpt" / "VINCIE-3B"
ckpt_app = Path("/app/ckpt") / "VINCIE-3B"
def ensure_symlink(link: Path, target: Path):
if link.is_symlink():
# relinka se o alvo mudou
if link.resolve() != target:
link.unlink()
link.symlink_to(target, target_is_directory=True)
elif link.exists():
# se for pasta/arquivo, remove para padronizar como symlink
subprocess.run(["rm","-rf",str(link)], check=True)
link.symlink_to(target, target_is_directory=True)
else:
link.parent.mkdir(parents=True, exist_ok=True)
link.symlink_to(target, target_is_directory=True)
# 3.1 baixa repo + snapshot
svc = VincieService()
svc.ensure_repo()
svc.ensure_model()
snapshot = Path(str(svc.ckpt_dir))
# 3.2 cria symlink dentro do repo e também em /app/ckpt
ensure_symlink(ckpt_repo, snapshot)
ensure_symlink(ckpt_app, snapshot)
# 3.3 valida itens essenciais
need = [snapshot/"dit.pth", snapshot/"vae.pth", snapshot/"llm14b"]
missing = [str(p) for p in need if not p.exists()]
if missing:
raise SystemExit(f"[preflight] faltam itens no snapshot: {missing}")
# 3.4 symlink opcional de models (heranças YAML)
models_link = Path("/app/models")
models_src = repo_dir / "models"
if models_src.exists() and (not models_link.exists()):
try:
models_link.symlink_to(models_src, target_is_directory=True)
print(f"[preflight] linked {models_link} -> {models_src}")
except Exception as e:
print("[preflight] warn: link models failed:", e)
print(f"[preflight] OK: repo={repo_dir}, ckpt(link)={ckpt_repo} -> {snapshot}")
PY
# 4) PYTHONPATH (imports upstream)
export VINCIE_DIR="${VINCIE_DIR:-/app/VINCIE}"
: "${PYTHONPATH:=}"
if [ -n "${PYTHONPATH}" ]; then
export PYTHONPATH="${VINCIE_DIR}:${PYTHONPATH}"
else
export PYTHONPATH="${VINCIE_DIR}"
fi
# 5) Diagnóstico mínimo
echo "🔎 ckpt (repo):"
ls -la /app/VINCIE/ckpt || true
ls -la /app/VINCIE/ckpt/VINCIE-3B | head -n 20 || true
echo "🔎 ckpt (/app):"
ls -la /app/ckpt || true
ls -la /app/ckpt/VINCIE-3B | head -n 20 || true
# 6) Sobe a UI
echo "🚀 Iniciando a interface web VINCIE (app_vince.py)..."
cd "$APP_DIR"
python3 /app/app_vince.py