Skip to content

Commit 281be46

Browse files
author
Tharit Tangkijwanichakul
committed
change from checking cupy.cuda.nccl import to nccl.available
1 parent f9f5d13 commit 281be46

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

pylops_mpi/utils/deps.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@
1111
def nccl_import(message: Optional[str] = None) -> str:
1212
nccl_test = (
1313
# detect if nccl is available and the user is expecting it to be used
14-
# CuPy must be checked first otherwise util.find_spec assumes it presents and check nccl immediately and lead to crash
15-
util.find_spec("cupy") is not None and util.find_spec("cupy.cuda.nccl") is not None and int(os.getenv("NCCL_PYLOPS_MPI", 1)) == 1
14+
# cupy.cuda.nccl comes with cupy installation so check the cupy
15+
util.find_spec("cupy") is not None and int(os.getenv("NCCL_PYLOPS_MPI", 1)) == 1
1616
)
1717
if nccl_test:
18-
# try importing it
19-
try:
20-
import_module("cupy.cuda.nccl") # noqa: F401
21-
22-
# if succesful, set the message to None
18+
# if cupy is present, this import will not throw error. The NCCL existence is checked with nccl.avaiable
19+
import cupy.cuda.nccl as nccl
20+
if nccl.available:
21+
# if succesfull, set the message to None
2322
nccl_message = None
24-
# if unable to import but the package is installed
25-
except (ImportError, ModuleNotFoundError) as e:
23+
else:
24+
# if unable to import but the package is installed
2625
nccl_message = (
27-
f"Fail to import cupy.cuda.nccl, Falling back to pure MPI (error: {e})."
28-
"Please ensure your CUDA NCCL environment is set up correctly "
29-
"for more detials visit 'https://docs.cupy.dev/en/stable/install.html'"
30-
)
26+
f"cupy is installed but cupy.cuda.nccl not available, Falling back to pure MPI."
27+
"Please ensure your CUDA NCCL environment is set up correctly "
28+
"for more details visit 'https://docs.cupy.dev/en/stable/install.html'"
29+
)
3130
print(UserWarning(nccl_message))
3231
else:
3332
nccl_message = (

0 commit comments

Comments
 (0)