Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,6 +54,26 @@ def bootstrap():
|
|
| 54 |
if patched_files:
|
| 55 |
print(f"Patched Dict[str, ...] -> dict in: {patched_files}", flush=True)
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
unirig_reqs = os.path.join(REPO_DIR, "requirements.txt")
|
| 58 |
if os.path.exists(unirig_reqs):
|
| 59 |
skip_prefixes = ("flash_attn", "flash-attn", "bpy")
|
|
|
|
| 54 |
if patched_files:
|
| 55 |
print(f"Patched Dict[str, ...] -> dict in: {patched_files}", flush=True)
|
| 56 |
|
| 57 |
+
# PyTorch 2.6+ changed torch.load's default to weights_only=True, which
|
| 58 |
+
# breaks loading UniRig's official checkpoints (they contain a pickled
|
| 59 |
+
# `Box` object, not just tensors). Since this checkpoint is the trusted,
|
| 60 |
+
# official one from VAST-AI/UniRig on Hugging Face, we patch torch.load
|
| 61 |
+
# globally via sitecustomize.py so EVERY python process (including the
|
| 62 |
+
# ones the shell scripts spawn) picks up weights_only=False by default.
|
| 63 |
+
import site
|
| 64 |
+
site_packages = site.getsitepackages()[0]
|
| 65 |
+
sitecustomize_path = os.path.join(site_packages, "sitecustomize.py")
|
| 66 |
+
with open(sitecustomize_path, "w") as f:
|
| 67 |
+
f.write(
|
| 68 |
+
"import torch\n"
|
| 69 |
+
"_original_torch_load = torch.load\n"
|
| 70 |
+
"def _patched_torch_load(*args, **kwargs):\n"
|
| 71 |
+
" kwargs.setdefault('weights_only', False)\n"
|
| 72 |
+
" return _original_torch_load(*args, **kwargs)\n"
|
| 73 |
+
"torch.load = _patched_torch_load\n"
|
| 74 |
+
)
|
| 75 |
+
print(f"Wrote torch.load patch to {sitecustomize_path}", flush=True)
|
| 76 |
+
|
| 77 |
unirig_reqs = os.path.join(REPO_DIR, "requirements.txt")
|
| 78 |
if os.path.exists(unirig_reqs):
|
| 79 |
skip_prefixes = ("flash_attn", "flash-attn", "bpy")
|