Spaces:
Running
on
Zero
Running
on
Zero
Add dependency installation for musubi-tuner in app.py during startup. Implement best-effort upgrade for pip, setuptools, and wheel, and handle optional Torch extras for editable installation. Fallback to plain install if editable fails, ensuring smoother setup process.
Browse files
app.py
CHANGED
|
@@ -374,6 +374,41 @@ def _startup_clone_musubi_tuner() -> None:
|
|
| 374 |
print(f"[QIE] Clone failed in fallback as well: {e2}")
|
| 375 |
|
| 376 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
@spaces.GPU
|
| 378 |
def run_training(
|
| 379 |
output_name: str,
|
|
@@ -694,6 +729,8 @@ def _startup_download_models() -> None:
|
|
| 694 |
if __name__ == "__main__":
|
| 695 |
# 1) Ensure musubi-tuner is cloned before anything else
|
| 696 |
_startup_clone_musubi_tuner()
|
|
|
|
|
|
|
| 697 |
|
| 698 |
# 2) Download models at startup (blocking by design)
|
| 699 |
_startup_download_models()
|
|
|
|
| 374 |
print(f"[QIE] Clone failed in fallback as well: {e2}")
|
| 375 |
|
| 376 |
|
| 377 |
+
def _run_pip(args: List[str], cwd: Optional[str] = None) -> None:
|
| 378 |
+
cmd = [sys.executable, "-m", "pip"] + args
|
| 379 |
+
try:
|
| 380 |
+
print(f"[QIE] pip {' '.join(args)} (cwd={cwd or os.getcwd()})")
|
| 381 |
+
subprocess.run(cmd, check=True, cwd=cwd)
|
| 382 |
+
except subprocess.CalledProcessError as e:
|
| 383 |
+
print(f"[QIE] pip failed: {e}")
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
def _startup_install_musubi_deps() -> None:
|
| 387 |
+
repo_dir = MUSUBI_TUNER_DIR_RUNTIME
|
| 388 |
+
if not os.path.isdir(repo_dir):
|
| 389 |
+
print(f"[QIE] Skip deps: musubi-tuner not found at {repo_dir}")
|
| 390 |
+
return
|
| 391 |
+
# Upgrade basic build tooling (best-effort)
|
| 392 |
+
try:
|
| 393 |
+
_run_pip(["install", "-U", "pip", "setuptools", "wheel"])
|
| 394 |
+
except Exception:
|
| 395 |
+
pass
|
| 396 |
+
|
| 397 |
+
# Optional Torch extra via env: MUSUBI_TUNER_TORCH_EXTRA=cu124|cu128
|
| 398 |
+
extra = os.environ.get("MUSUBI_TUNER_TORCH_EXTRA", "").strip()
|
| 399 |
+
editable_spec = "." if not extra else f".[{extra}]"
|
| 400 |
+
|
| 401 |
+
# Install musubi-tuner in editable mode to expose entrypoints and deps
|
| 402 |
+
try:
|
| 403 |
+
_run_pip(["install", "-e", editable_spec], cwd=repo_dir)
|
| 404 |
+
except Exception:
|
| 405 |
+
# Fallback: plain install without editable
|
| 406 |
+
try:
|
| 407 |
+
_run_pip(["install", editable_spec], cwd=repo_dir)
|
| 408 |
+
except Exception:
|
| 409 |
+
print("[QIE] WARN: musubi-tuner installation failed. Continuing.")
|
| 410 |
+
|
| 411 |
+
|
| 412 |
@spaces.GPU
|
| 413 |
def run_training(
|
| 414 |
output_name: str,
|
|
|
|
| 729 |
if __name__ == "__main__":
|
| 730 |
# 1) Ensure musubi-tuner is cloned before anything else
|
| 731 |
_startup_clone_musubi_tuner()
|
| 732 |
+
# 1.1) Install musubi-tuner dependencies (best-effort)
|
| 733 |
+
_startup_install_musubi_deps()
|
| 734 |
|
| 735 |
# 2) Download models at startup (blocking by design)
|
| 736 |
_startup_download_models()
|