Spaces:
Runtime error
Runtime error
Fix: safe HF_HOME fallback when /data unmounted; drop risky local_files_only
Browse files- __pycache__/app.cpython-314.pyc +0 -0
- app.py +13 -15
__pycache__/app.cpython-314.pyc
ADDED
|
Binary file (18 kB). View file
|
|
|
app.py
CHANGED
|
@@ -16,7 +16,14 @@ ported (see BUILD_NOTES.md).
|
|
| 16 |
import os
|
| 17 |
|
| 18 |
# --- 1. Cache env vars FIRST, before importing torch/diffusers/etc. ---------
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
os.environ.setdefault("HF_MODULES_CACHE", "/tmp/hf_modules")
|
| 21 |
os.environ.setdefault("MPLCONFIGDIR", "/tmp/matplotlib")
|
| 22 |
|
|
@@ -51,20 +58,11 @@ INTERMEDIATE_TIMESTEPS = (400, 600, 750, 900)
|
|
| 51 |
# ZeroGPU (CUDA is emulated at import time); only the actual forward passes
|
| 52 |
# need to happen inside a function decorated with @spaces.GPU.
|
| 53 |
# -----------------------------------------------------------------------------
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
local_files_only=True,
|
| 60 |
-
).to("cuda")
|
| 61 |
-
except OSError:
|
| 62 |
-
# Fallback in case preload_from_hub cache isn't populated (e.g. local dev).
|
| 63 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
| 64 |
-
MODEL_ID,
|
| 65 |
-
torch_dtype=torch.float16,
|
| 66 |
-
safety_checker=None,
|
| 67 |
-
).to("cuda")
|
| 68 |
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
| 69 |
|
| 70 |
|
|
|
|
| 16 |
import os
|
| 17 |
|
| 18 |
# --- 1. Cache env vars FIRST, before importing torch/diffusers/etc. ---------
|
| 19 |
+
# Prefer /data (persistent storage) if it's actually mounted and writable;
|
| 20 |
+
# otherwise fall back to a path under /home/user (always writable on
|
| 21 |
+
# ZeroGPU) so we never try to mkdir into a read-only/absent /data.
|
| 22 |
+
_data_cache = "/data/.cache/huggingface"
|
| 23 |
+
if os.path.isdir("/data") and os.access("/data", os.W_OK):
|
| 24 |
+
os.environ.setdefault("HF_HOME", _data_cache)
|
| 25 |
+
else:
|
| 26 |
+
os.environ.setdefault("HF_HOME", "/home/user/.cache/huggingface")
|
| 27 |
os.environ.setdefault("HF_MODULES_CACHE", "/tmp/hf_modules")
|
| 28 |
os.environ.setdefault("MPLCONFIGDIR", "/tmp/matplotlib")
|
| 29 |
|
|
|
|
| 58 |
# ZeroGPU (CUDA is emulated at import time); only the actual forward passes
|
| 59 |
# need to happen inside a function decorated with @spaces.GPU.
|
| 60 |
# -----------------------------------------------------------------------------
|
| 61 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 62 |
+
MODEL_ID,
|
| 63 |
+
torch_dtype=torch.float16,
|
| 64 |
+
safety_checker=None,
|
| 65 |
+
).to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
| 67 |
|
| 68 |
|