Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,17 +15,23 @@ from huggingface_hub import snapshot_download
|
|
| 15 |
import zipfile
|
| 16 |
import json
|
| 17 |
from pathlib import Path
|
| 18 |
-
|
| 19 |
-
print(f"[DIAG] diffusers version : {diffusers.__version__}", flush=True)
|
| 20 |
|
| 21 |
def _get_subprocess_env() -> dict:
|
| 22 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
import site
|
| 24 |
import glob as _glob
|
| 25 |
|
| 26 |
env = os.environ.copy()
|
| 27 |
|
| 28 |
-
# 1.
|
| 29 |
nvidia_paths: list[str] = []
|
| 30 |
all_site = site.getsitepackages()
|
| 31 |
try:
|
|
@@ -35,53 +41,44 @@ def _get_subprocess_env() -> dict:
|
|
| 35 |
for sp in all_site:
|
| 36 |
matches = _glob.glob(os.path.join(sp, "nvidia", "*", "lib"))
|
| 37 |
nvidia_paths.extend(m for m in matches if os.path.isdir(m))
|
| 38 |
-
|
| 39 |
-
# 2. PyTorch-eigenes lib/-Verzeichnis
|
| 40 |
torch_lib = os.path.join(os.path.dirname(torch.__file__), "lib")
|
| 41 |
-
|
| 42 |
-
# 3. System-CUDA-Pfade als Fallback
|
| 43 |
system_cuda = [
|
| 44 |
-
"/usr/local/cuda-13/lib64",
|
| 45 |
-
"/usr/local/cuda-
|
| 46 |
-
"/usr/local/cuda-12/lib64",
|
| 47 |
-
"/usr/local/cuda-12.8/lib64",
|
| 48 |
-
"/usr/local/cuda/lib64",
|
| 49 |
-
"/usr/local/cuda/targets/x86_64-linux/lib",
|
| 50 |
"/usr/lib/x86_64-linux-gnu",
|
| 51 |
]
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
all_paths = nvidia_paths + [torch_lib] + system_valid
|
| 55 |
existing_ld = env.get("LD_LIBRARY_PATH", "")
|
| 56 |
env["LD_LIBRARY_PATH"] = ":".join(
|
| 57 |
-
|
| 58 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
return env
|
| 60 |
|
| 61 |
|
| 62 |
def _log_cuda_diagnostics():
|
| 63 |
-
"""Loggt torch-Version, CUDA
|
| 64 |
import glob as _glob
|
|
|
|
|
|
|
| 65 |
print(f"[DIAG] torch version : {torch.__version__}", flush=True)
|
| 66 |
print(f"[DIAG] torch CUDA build : {torch.version.cuda}", flush=True)
|
| 67 |
print(f"[DIAG] CUDA available : {torch.cuda.is_available()}", flush=True)
|
| 68 |
print(f"[DIAG] sys.executable : {sys.executable}", flush=True)
|
| 69 |
-
|
| 70 |
env = _get_subprocess_env()
|
| 71 |
ld_path = env.get("LD_LIBRARY_PATH", "")
|
| 72 |
print(f"[DIAG] LD_LIBRARY_PATH : {ld_path}", flush=True)
|
| 73 |
-
|
| 74 |
found = []
|
| 75 |
for d in ld_path.split(":"):
|
| 76 |
-
if
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
if found:
|
| 81 |
-
print(f"[DIAG] libcudart found : {found}", flush=True)
|
| 82 |
-
else:
|
| 83 |
-
print("[DIAG] libcudart found : NICHT GEFUNDEN", flush=True)
|
| 84 |
-
|
| 85 |
import importlib.util
|
| 86 |
p3d = importlib.util.find_spec("pytorch3d")
|
| 87 |
print(f"[DIAG] pytorch3d spec : {p3d}", flush=True)
|
|
|
|
| 15 |
import zipfile
|
| 16 |
import json
|
| 17 |
from pathlib import Path
|
| 18 |
+
|
|
|
|
| 19 |
|
| 20 |
def _get_subprocess_env() -> dict:
|
| 21 |
+
"""Baut die Subprocess-Umgebung mit korrekten CUDA- und Library-Pfaden.
|
| 22 |
+
|
| 23 |
+
Wichtige Fixes:
|
| 24 |
+
- LD_LIBRARY_PATH: libcudart.so via nvidia pip-Pakete findbar machen
|
| 25 |
+
- PYTORCH_CUDA_ALLOC_CONF: expandable_segments:True nutzt NVML, das im
|
| 26 |
+
Subprocess auf ZeroGPU Blackwell + torch 2.11.0 nicht stabil ist.
|
| 27 |
+
Im Subprocess max_split_size_mb:512 verwenden (NVML-frei, stabil).
|
| 28 |
+
"""
|
| 29 |
import site
|
| 30 |
import glob as _glob
|
| 31 |
|
| 32 |
env = os.environ.copy()
|
| 33 |
|
| 34 |
+
# 1. CUDA-Library-Pfade für libcudart
|
| 35 |
nvidia_paths: list[str] = []
|
| 36 |
all_site = site.getsitepackages()
|
| 37 |
try:
|
|
|
|
| 41 |
for sp in all_site:
|
| 42 |
matches = _glob.glob(os.path.join(sp, "nvidia", "*", "lib"))
|
| 43 |
nvidia_paths.extend(m for m in matches if os.path.isdir(m))
|
|
|
|
|
|
|
| 44 |
torch_lib = os.path.join(os.path.dirname(torch.__file__), "lib")
|
|
|
|
|
|
|
| 45 |
system_cuda = [
|
| 46 |
+
"/usr/local/cuda-13/lib64", "/usr/local/cuda-13.0/lib64",
|
| 47 |
+
"/usr/local/cuda-12/lib64", "/usr/local/cuda/lib64",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
"/usr/lib/x86_64-linux-gnu",
|
| 49 |
]
|
| 50 |
+
extra = [p for p in system_cuda if os.path.isdir(p)]
|
|
|
|
|
|
|
| 51 |
existing_ld = env.get("LD_LIBRARY_PATH", "")
|
| 52 |
env["LD_LIBRARY_PATH"] = ":".join(
|
| 53 |
+
nvidia_paths + [torch_lib] + extra + ([existing_ld] if existing_ld else [])
|
| 54 |
)
|
| 55 |
+
|
| 56 |
+
# 2. CUDA-Allocator: expandable_segments:True braucht NVML, das im
|
| 57 |
+
# ZeroGPU-Subprocess mit torch 2.11.0 zu CUDACachingAllocator-Assertions führt.
|
| 58 |
+
# Im Subprocess stabilen Fallback verwenden.
|
| 59 |
+
env["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:512"
|
| 60 |
+
|
| 61 |
return env
|
| 62 |
|
| 63 |
|
| 64 |
def _log_cuda_diagnostics():
|
| 65 |
+
"""Loggt torch-Version, CUDA, libcudart-Pfad und pytorch3d beim Start."""
|
| 66 |
import glob as _glob
|
| 67 |
+
import diffusers
|
| 68 |
+
print(f"[DIAG] diffusers version : {diffusers.__version__}", flush=True)
|
| 69 |
print(f"[DIAG] torch version : {torch.__version__}", flush=True)
|
| 70 |
print(f"[DIAG] torch CUDA build : {torch.version.cuda}", flush=True)
|
| 71 |
print(f"[DIAG] CUDA available : {torch.cuda.is_available()}", flush=True)
|
| 72 |
print(f"[DIAG] sys.executable : {sys.executable}", flush=True)
|
|
|
|
| 73 |
env = _get_subprocess_env()
|
| 74 |
ld_path = env.get("LD_LIBRARY_PATH", "")
|
| 75 |
print(f"[DIAG] LD_LIBRARY_PATH : {ld_path}", flush=True)
|
|
|
|
| 76 |
found = []
|
| 77 |
for d in ld_path.split(":"):
|
| 78 |
+
if d:
|
| 79 |
+
found.extend(_glob.glob(os.path.join(d, "libcudart.so*")))
|
| 80 |
+
print(f"[DIAG] libcudart found : {found}", flush=True)
|
| 81 |
+
print(f"[DIAG] subprocess ALLOC : {env.get('PYTORCH_CUDA_ALLOC_CONF')}", flush=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
import importlib.util
|
| 83 |
p3d = importlib.util.find_spec("pytorch3d")
|
| 84 |
print(f"[DIAG] pytorch3d spec : {p3d}", flush=True)
|