fix: make cupy installation opt-in

This commit is contained in:
2026-08-15 22:04:53 +02:00
parent 897e343268
commit 2ee1c6f4cf
3 changed files with 32 additions and 37 deletions
+5 -4
View File
@@ -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](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:
```bash
@@ -44,10 +44,11 @@ Import [`example_workflows/tween_speed_ldf_model_lab.json`](example_workflows/tw
| CUDA | Command |
|------|---------|
| 13.x | `pip install cupy-cuda13x` |
| 12.x | `pip install cupy-cuda12x` |
| 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>
<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 |
| `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 |
| Docker / no build tools | Use the prebuilt wheel: `pip install cupy-cuda12x` (not bare `cupy` which compiles from source) |
| Install hangs or takes very long | Confirm pip selected a prebuilt wheel for your Python and CUDA versions |
| Docker / no build tools | Use the matching prebuilt `cupy-cudaXXx` wheel, not bare `cupy` which compiles from source |
</details>
+8 -33
View File
@@ -1,45 +1,20 @@
import os
import subprocess
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():
# Install core requirements first
"""Install required dependencies without mutating optional GPU packages."""
requirements_path = os.path.join(os.path.dirname(__file__), "requirements.txt")
subprocess.check_call([
sys.executable, "-m", "pip", "install", "-r", requirements_path
])
# Try to install cupy for NVIDIA users (optional, improves performance)
cupy_pkg = get_cupy_package()
if cupy_pkg:
try:
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.")
print(
"[Tween] Optional cupy is not installed automatically. "
"BIM-VFI, SGM-VFI, and GIMM-VFI use the PyTorch fallback unless you "
"install the matching cupy wheel manually; EMA-VFI, SPEED, and "
"LDF-VFI do not use cupy."
)
if __name__ == "__main__":
+19
View File
@@ -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
]]