Spaces:
Running on Zero
Running on Zero
Import spaces before torch (ZeroGPU init order requirement)
Browse files
app.py
CHANGED
|
@@ -18,6 +18,16 @@ import os
|
|
| 18 |
import sys
|
| 19 |
import subprocess
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def _ensure_featup():
|
| 23 |
try:
|
|
|
|
| 18 |
import sys
|
| 19 |
import subprocess
|
| 20 |
|
| 21 |
+
# ZeroGPU requirement: `spaces` must be imported BEFORE any CUDA-initializing
|
| 22 |
+
# package (torch, etc.). Importing torch first and then spaces raises
|
| 23 |
+
# "CUDA has been initialized before importing the `spaces` package."
|
| 24 |
+
# This is the first import that touches CUDA indirectly, so do it up front.
|
| 25 |
+
# Guarded with try/except so local dev (where `spaces` isn't installed) works.
|
| 26 |
+
try:
|
| 27 |
+
import spaces # noqa: F401 (must be imported before torch on ZeroGPU)
|
| 28 |
+
except ImportError:
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
|
| 32 |
def _ensure_featup():
|
| 33 |
try:
|