Spaces:
Runtime error
Runtime error
Commit ·
83cf44b
1
Parent(s): c977821
fix: force-install CUDA torch in app.py before training starts
Browse files
app.py
CHANGED
|
@@ -14,9 +14,23 @@ Training starts automatically when the Space boots.
|
|
| 14 |
Refresh the page or click "Refresh" to see live progress.
|
| 15 |
"""
|
| 16 |
|
| 17 |
-
import sys, os
|
| 18 |
print("=== PYTHON STARTED ===", flush=True)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
import gradio as gr
|
| 21 |
print("=== GRADIO IMPORTED ===", flush=True)
|
| 22 |
|
|
|
|
| 14 |
Refresh the page or click "Refresh" to see live progress.
|
| 15 |
"""
|
| 16 |
|
| 17 |
+
import sys, os, subprocess
|
| 18 |
print("=== PYTHON STARTED ===", flush=True)
|
| 19 |
|
| 20 |
+
# Force CUDA-enabled PyTorch — the default PyPI wheel is CPU-only.
|
| 21 |
+
# This must run before any `import torch` in the process.
|
| 22 |
+
print("Installing CUDA torch...", flush=True)
|
| 23 |
+
_r = subprocess.run(
|
| 24 |
+
[sys.executable, "-m", "pip", "install", "-q",
|
| 25 |
+
"--index-url", "https://download.pytorch.org/whl/cu121",
|
| 26 |
+
"torch>=2.2.0"],
|
| 27 |
+
capture_output=True, text=True,
|
| 28 |
+
)
|
| 29 |
+
if _r.returncode == 0:
|
| 30 |
+
print("CUDA torch installed OK.", flush=True)
|
| 31 |
+
else:
|
| 32 |
+
print("CUDA torch install warning:", _r.stderr[-300:], flush=True)
|
| 33 |
+
|
| 34 |
import gradio as gr
|
| 35 |
print("=== GRADIO IMPORTED ===", flush=True)
|
| 36 |
|