Spaces:
Running on Zero
Running on Zero
Make torch.xpu shim catch-all (no-op for any attribute) to survive further internal probes
Browse files
app.py
CHANGED
|
@@ -11,17 +11,24 @@ import torch
|
|
| 11 |
# versions unconditionally reference `torch.xpu.empty_cache` at import time
|
| 12 |
# (in diffusers.utils.torch_utils), which raises AttributeError. Stub it out.
|
| 13 |
if not hasattr(torch, "xpu"):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
from huggingface_hub import snapshot_download
|
| 27 |
from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError, RevisionNotFoundError
|
|
|
|
| 11 |
# versions unconditionally reference `torch.xpu.empty_cache` at import time
|
| 12 |
# (in diffusers.utils.torch_utils), which raises AttributeError. Stub it out.
|
| 13 |
if not hasattr(torch, "xpu"):
|
| 14 |
+
class _XPUStub:
|
| 15 |
+
"""Stand-in for the `torch.xpu` submodule, absent from this build.
|
| 16 |
+
|
| 17 |
+
Several libraries (diffusers, and even torch's own `torch/random.py`)
|
| 18 |
+
unconditionally reach for `torch.xpu.<attr>` once `hasattr(torch,
|
| 19 |
+
"xpu")` is True, without gating every call behind `is_available()`.
|
| 20 |
+
Rather than chase each attribute one by one, any unknown attribute
|
| 21 |
+
resolves to a harmless no-op that returns 0 (falsy, and safe to use
|
| 22 |
+
in comparisons/indexing like `torch.xpu.current_device()`).
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
def is_available(self):
|
| 26 |
+
return False
|
| 27 |
+
|
| 28 |
+
def __getattr__(self, _name):
|
| 29 |
+
return lambda *args, **kwargs: 0
|
| 30 |
+
|
| 31 |
+
torch.xpu = _XPUStub()
|
| 32 |
|
| 33 |
from huggingface_hub import snapshot_download
|
| 34 |
from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError, RevisionNotFoundError
|