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 <noreply@anthropic.com>
This commit is contained in:
2026-06-27 19:51:28 +02:00
parent 0c62c6eef4
commit 2d96d5aa5d
3 changed files with 13 additions and 4 deletions
+5 -2
View File
@@ -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
##########################################################
@@ -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
+4 -1
View File
@@ -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