fix: make cupy installation opt-in
This commit is contained in:
@@ -33,7 +33,7 @@ Import [`example_workflows/tween_speed_ldf_model_lab.json`](example_workflows/tw
|
|||||||
|
|
||||||
### cupy (accelerates BIM-VFI, SGM-VFI, and GIMM-VFI)
|
### cupy (accelerates BIM-VFI, SGM-VFI, and GIMM-VFI)
|
||||||
|
|
||||||
[cupy](https://cupy.dev/) provides GPU-accelerated optical flow warping. **EMA-VFI, SPEED, and LDF-VFI do not use it.**
|
[cupy](https://cupy.dev/) provides GPU-accelerated optical flow warping. It is deliberately **not installed automatically**, because replacing or mixing CUDA-specific cupy wheels can disrupt other ComfyUI nodes. BIM-VFI, SGM-VFI, and GIMM-VFI work without it through their PyTorch fallback. **EMA-VFI, SPEED, and LDF-VFI do not use it.**
|
||||||
|
|
||||||
1. Find your CUDA version:
|
1. Find your CUDA version:
|
||||||
```bash
|
```bash
|
||||||
@@ -44,10 +44,11 @@ Import [`example_workflows/tween_speed_ldf_model_lab.json`](example_workflows/tw
|
|||||||
|
|
||||||
| CUDA | Command |
|
| CUDA | Command |
|
||||||
|------|---------|
|
|------|---------|
|
||||||
|
| 13.x | `pip install cupy-cuda13x` |
|
||||||
| 12.x | `pip install cupy-cuda12x` |
|
| 12.x | `pip install cupy-cuda12x` |
|
||||||
| 11.x | `pip install cupy-cuda11x` |
|
| 11.x | `pip install cupy-cuda11x` |
|
||||||
|
|
||||||
> Make sure to run pip in the same Python environment as ComfyUI. If cupy is missing, the Load node shows an error with your CUDA version and the exact install command.
|
> Make sure to run pip in the same Python environment as ComfyUI, and uninstall any different cupy wheel variant first. If cupy is absent or incompatible, Tween safely uses its PyTorch fallback.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>cupy troubleshooting</summary>
|
<summary>cupy troubleshooting</summary>
|
||||||
@@ -56,8 +57,8 @@ Import [`example_workflows/tween_speed_ldf_model_lab.json`](example_workflows/tw
|
|||||||
|---------|----------|
|
|---------|----------|
|
||||||
| `ModuleNotFoundError: No module named 'cupy'` | Install cupy using the steps above |
|
| `ModuleNotFoundError: No module named 'cupy'` | Install cupy using the steps above |
|
||||||
| `cupy` installed but `ImportError` at runtime | CUDA version mismatch — uninstall and reinstall the correct version |
|
| `cupy` installed but `ImportError` at runtime | CUDA version mismatch — uninstall and reinstall the correct version |
|
||||||
| Install hangs or takes very long | cupy wheels are ~800 MB, be patient |
|
| Install hangs or takes very long | Confirm pip selected a prebuilt wheel for your Python and CUDA versions |
|
||||||
| Docker / no build tools | Use the prebuilt wheel: `pip install cupy-cuda12x` (not bare `cupy` which compiles from source) |
|
| Docker / no build tools | Use the matching prebuilt `cupy-cudaXXx` wheel, not bare `cupy` which compiles from source |
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|||||||
+8
-33
@@ -1,45 +1,20 @@
|
|||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def get_cupy_package():
|
|
||||||
"""Detect PyTorch's CUDA version and return the matching cupy package name."""
|
|
||||||
try:
|
|
||||||
import torch
|
|
||||||
if not torch.cuda.is_available():
|
|
||||||
return None
|
|
||||||
cuda_version = torch.version.cuda
|
|
||||||
if cuda_version is None:
|
|
||||||
return None
|
|
||||||
major = int(cuda_version.split(".")[0])
|
|
||||||
cupy_pkg = f"cupy-cuda{major}x"
|
|
||||||
return cupy_pkg
|
|
||||||
except Exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def install():
|
def install():
|
||||||
# Install core requirements first
|
"""Install required dependencies without mutating optional GPU packages."""
|
||||||
requirements_path = os.path.join(os.path.dirname(__file__), "requirements.txt")
|
requirements_path = os.path.join(os.path.dirname(__file__), "requirements.txt")
|
||||||
subprocess.check_call([
|
subprocess.check_call([
|
||||||
sys.executable, "-m", "pip", "install", "-r", requirements_path
|
sys.executable, "-m", "pip", "install", "-r", requirements_path
|
||||||
])
|
])
|
||||||
|
print(
|
||||||
# Try to install cupy for NVIDIA users (optional, improves performance)
|
"[Tween] Optional cupy is not installed automatically. "
|
||||||
cupy_pkg = get_cupy_package()
|
"BIM-VFI, SGM-VFI, and GIMM-VFI use the PyTorch fallback unless you "
|
||||||
if cupy_pkg:
|
"install the matching cupy wheel manually; EMA-VFI, SPEED, and "
|
||||||
try:
|
"LDF-VFI do not use cupy."
|
||||||
subprocess.check_call([
|
)
|
||||||
sys.executable, "-m", "pip", "install", cupy_pkg
|
|
||||||
])
|
|
||||||
print(f"[Tween] cupy installed ({cupy_pkg}) — fast CUDA kernels enabled")
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
print(f"[Tween] WARNING: Could not install {cupy_pkg}. "
|
|
||||||
f"BIM-VFI, SGM-VFI, and GIMM-VFI will use slower PyTorch fallback.")
|
|
||||||
else:
|
|
||||||
print("[Tween] cupy skipped (no NVIDIA CUDA). "
|
|
||||||
"BIM-VFI, SGM-VFI, and GIMM-VFI will use PyTorch fallback.")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import install as tween_install
|
||||||
|
|
||||||
|
|
||||||
|
def test_installer_never_installs_optional_cupy(monkeypatch):
|
||||||
|
calls = []
|
||||||
|
monkeypatch.setattr(subprocess, "check_call", calls.append)
|
||||||
|
|
||||||
|
tween_install.install()
|
||||||
|
|
||||||
|
requirements_path = os.path.join(
|
||||||
|
os.path.dirname(tween_install.__file__), "requirements.txt"
|
||||||
|
)
|
||||||
|
assert calls == [[
|
||||||
|
sys.executable, "-m", "pip", "install", "-r", requirements_path
|
||||||
|
]]
|
||||||
Reference in New Issue
Block a user