Make model prefetching automatic in install/run scripts

install-local-gpu.sh and bring-up-local-gpu.sh now call
prefetch-models.sh --sdxl (host-side download, all models including
SDXL/inpaint, ~13GB) automatically rather than treating it as a manual
DNS-troubleshooting step. install-local-gpu.sh drops back to the
invoking user via sudo -u "$SUDO_USER" -H before running it, since
that script itself runs as root and would otherwise leave downloaded
files root-owned. Both call sites are non-fatal: a prefetch failure
logs a warning and the container still starts, falling back to its
own in-container download attempt.

Updated README to match.
This commit is contained in:
Claude
2026-06-18 17:47:18 +00:00
parent b4a790473c
commit 3f4a6b754c
3 changed files with 34 additions and 10 deletions
+4 -4
View File
@@ -11,7 +11,7 @@ git clone https://github.com/outis1one/editmaskwithai
cd editmaskwithai
# One-time setup: installs nvidia-container-toolkit, configures Docker,
# and sets up a permanent DNS fix so the container can download models.
# sets up a permanent DNS fix, and prefetches all AI models on the host.
chmod +x install-local-gpu.sh
./install-local-gpu.sh
@@ -22,7 +22,7 @@ chmod +x bring-up-local-gpu.sh
Open **http://localhost:3080**
**First startup downloads the AI model for your GPU (~13 GB, one time).** Models are cached in `./data/hf_cache/` and survive rebuilds.
**Models (~13 GB total, one time) download automatically on the host**, outside Docker — both scripts call `./prefetch-models.sh` for you, since in-container DNS is unreliable on some hosts. They're cached in `./data/hf_cache/` and `./data/models/`, and survive rebuilds.
---
@@ -163,7 +163,7 @@ EditmaskwithAI/
├── Dockerfile.gpu
├── install-local-gpu.sh # One-time GPU host setup
├── bring-up-local-gpu.sh # Start/stop the GPU container
├── prefetch-models.sh # Download AI models on the host (DNS-blocked workaround)
├── prefetch-models.sh # Download AI models on the host (called automatically; also runnable standalone)
└── .env.example
```
@@ -232,7 +232,7 @@ You can also pick a specific model per-edit from the Remove Background dialog's
**AI models not downloading (container DNS blocked)**
Easiest fix: download the models on the host instead of inside the container — they land in `./data/`, which is already bind-mounted into the container, so it picks them up with no rebuild:
`install-local-gpu.sh` and `bring-up-local-gpu.sh` already run this for you automatically on every start, so you normally don't need to think about it. If a model still didn't download (no network at the time, etc.), re-run it manually — it lands in `./data/`, which is already bind-mounted into the container, so it's picked up with no rebuild:
```bash
./prefetch-models.sh # SAM + U2Net + BEN2 + BiRefNet-HR (~1.5GB)
+8 -3
View File
@@ -4,9 +4,11 @@
# Run this each time you want to start the app.
# Run ./install-local-gpu.sh once first on a new machine.
#
# If models fail to download inside the container (DNS/firewall blocked),
# run ./prefetch-models.sh first — it downloads them on the host into
# ./data/, which this container already bind-mounts, so no rebuild needed.
# Before starting, this fetches any missing models on the host (outside
# Docker) via ./prefetch-models.sh — in-container DNS/network is unreliable
# on some hosts, so this is the default now, not a manual troubleshooting
# step. It never blocks startup: if it fails (no network, no python3, etc.)
# the container still starts and falls back to its own in-container download.
#
# Usage:
# ./bring-up-local-gpu.sh # start (detached, rebuild if needed)
@@ -29,6 +31,9 @@ cd "$(dirname "$0")"
mkdir -p data/models data/hf_cache data/projects data/patches
if [ $# -eq 0 ]; then
# Best-effort: fetch any missing models on the host first (see header).
./prefetch-models.sh --sdxl \
|| echo "⚠ Model prefetch had failures (see above) — continuing anyway, the container will retry in-container."
exec docker compose -f docker-compose.gpu.yml up -d --build
else
exec docker compose -f docker-compose.gpu.yml "$@"
+22 -3
View File
@@ -170,12 +170,31 @@ else
echo " Minimum driver version: 525"
fi
# ── 6. Prefetch all AI models (host-side, outside Docker) ───────────────────
# In-container DNS/network is unreliable on some hosts, so downloading on the
# host up front (including SDXL/inpaint, ~13GB) is the default now rather
# than a manual troubleshooting step. Best-effort: this script must finish
# (and leave the GPU/Docker setup done) even if prefetch fails outright.
# Run as the real invoking user, not root, so downloaded files (and any
# `pip install --user` side effects) end up owned by that user — this script
# itself is already running as root via the sudo re-exec above.
echo ""
echo "Prefetching AI models (this can take a while for SDXL, ~13GB)..."
if [ -n "${SUDO_USER:-}" ]; then
sudo -u "$SUDO_USER" -H "$REPO_DIR/prefetch-models.sh" --sdxl \
|| echo "⚠ Model prefetch had failures (see above) — continuing anyway, the container will retry in-container."
else
"$REPO_DIR/prefetch-models.sh" --sdxl \
|| echo "⚠ Model prefetch had failures (see above) — continuing anyway, the container will retry in-container."
fi
echo ""
echo "=================================================="
echo " Setup complete."
echo " Start the app with: ./bring-up-local-gpu.sh"
echo ""
echo " If models fail to download inside the container (DNS/firewall"
echo " blocked), fetch them on the host first instead:"
echo " ./prefetch-models.sh"
echo " Models are prefetched automatically by this script and by"
echo " bring-up-local-gpu.sh on every start. If any failed above (no"
echo " network, etc.), re-run manually any time:"
echo " ./prefetch-models.sh --sdxl"
echo "=================================================="