From 2d96d5aa5d8e87c5eab588096785cb5e62f3a5c9 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Sat, 27 Jun 2026 19:51:28 +0200 Subject: [PATCH] fix: catch all exceptions when importing cupy, not just ImportError An installed-but-broken cupy (e.g. incompatible with NumPy 2.5, which removed the 'bool8' alias) raises a TypeError during its own import, not an ImportError. The narrow `except ImportError` guard let that propagate and crashed the entire node import chain. Broaden the guard to `except Exception` in all three CUDA-kernel modules so any import-time failure disables cupy and falls back to the pure-PyTorch implementations. Co-Authored-By: Claude Opus 4.8 --- bim_vfi_arch/costvol.py | 7 +++++-- gimm_vfi_arch/generalizable_INR/modules/softsplat.py | 5 ++++- sgm_vfi_arch/softsplat.py | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bim_vfi_arch/costvol.py b/bim_vfi_arch/costvol.py index 06cb6e7..00c0478 100644 --- a/bim_vfi_arch/costvol.py +++ b/bim_vfi_arch/costvol.py @@ -15,8 +15,11 @@ def _ensure_cupy(): try: import cupy as _cupy cupy = _cupy - except ImportError: - pass # cupy unavailable; PyTorch fallback will be used + except Exception: + # Broad catch: an installed-but-broken cupy (e.g. incompatible + # NumPy) raises non-ImportError exceptions at import time. Treat any + # failure as "cupy unavailable"; the PyTorch fallback will be used. + pass ########################################################## diff --git a/gimm_vfi_arch/generalizable_INR/modules/softsplat.py b/gimm_vfi_arch/generalizable_INR/modules/softsplat.py index 2f21014..808388d 100644 --- a/gimm_vfi_arch/generalizable_INR/modules/softsplat.py +++ b/gimm_vfi_arch/generalizable_INR/modules/softsplat.py @@ -11,7 +11,10 @@ import collections try: import cupy -except ImportError: +except Exception: + # Broad catch: an installed-but-broken cupy (e.g. incompatible NumPy) + # raises non-ImportError exceptions at import time. Treat any failure as + # "cupy unavailable" and fall back to the pure-PyTorch implementation. cupy = None import os import re diff --git a/sgm_vfi_arch/softsplat.py b/sgm_vfi_arch/softsplat.py index c47f07a..2319584 100644 --- a/sgm_vfi_arch/softsplat.py +++ b/sgm_vfi_arch/softsplat.py @@ -3,7 +3,10 @@ import collections try: import cupy -except ImportError: +except Exception: + # Broad catch: an installed-but-broken cupy (e.g. incompatible NumPy) + # raises non-ImportError exceptions at import time. Treat any failure as + # "cupy unavailable" and fall back to the pure-PyTorch implementation. cupy = None import os import re