Spaces:
Sleeping
Sleeping
Update model_handler.py
Browse files- model_handler.py +33 -0
model_handler.py
CHANGED
|
@@ -2,6 +2,39 @@
|
|
| 2 |
Model handler for WAN-VACE video generation
|
| 3 |
"""
|
| 4 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import time
|
| 6 |
from typing import Optional, Tuple, Any
|
| 7 |
from transformers import UMT5EncoderModel
|
|
|
|
| 2 |
Model handler for WAN-VACE video generation
|
| 3 |
"""
|
| 4 |
import torch
|
| 5 |
+
|
| 6 |
+
# -----------------------------------------------------------------------------
|
| 7 |
+
# XPU shim for CPU‑only environments
|
| 8 |
+
#
|
| 9 |
+
# Newer versions of `diffusers` attempt to call `torch.xpu.empty_cache()` for
|
| 10 |
+
# Intel GPU support. If the installed PyTorch build does not include XPU
|
| 11 |
+
# support (as is the case on CPU‑only environments), accessing `torch.xpu`
|
| 12 |
+
# results in an AttributeError. To avoid this, we define a dummy `xpu`
|
| 13 |
+
# namespace on the `torch` module when it is missing. This namespace
|
| 14 |
+
# implements the minimal methods used by `diffusers` (`empty_cache`,
|
| 15 |
+
# `is_available`, and `device_count`).
|
| 16 |
+
#
|
| 17 |
+
# Intel’s `intel-extension-for-pytorch` provides XPU support, but even when
|
| 18 |
+
# installed, some CPU builds of PyTorch may not expose `torch.xpu`. This
|
| 19 |
+
# shim ensures that the application runs regardless of whether XPU support is
|
| 20 |
+
# present.
|
| 21 |
+
# -----------------------------------------------------------------------------
|
| 22 |
+
if not hasattr(torch, "xpu"):
|
| 23 |
+
class _DummyXPU:
|
| 24 |
+
@staticmethod
|
| 25 |
+
def empty_cache() -> None:
|
| 26 |
+
# No‑op: nothing to clear on CPU‑only builds.
|
| 27 |
+
return None
|
| 28 |
+
@staticmethod
|
| 29 |
+
def is_available() -> bool:
|
| 30 |
+
# Always report unavailable on CPU‑only builds.
|
| 31 |
+
return False
|
| 32 |
+
@staticmethod
|
| 33 |
+
def device_count() -> int:
|
| 34 |
+
# Zero XPU devices available.
|
| 35 |
+
return 0
|
| 36 |
+
# Attach dummy XPU to torch
|
| 37 |
+
torch.xpu = _DummyXPU() # type: ignore[attr-defined]
|
| 38 |
import time
|
| 39 |
from typing import Optional, Tuple, Any
|
| 40 |
from transformers import UMT5EncoderModel
|