From 7237bea69fd4d1eb6c340b33c350ce80cb666f78 Mon Sep 17 00:00:00 2001 From: Santosh Bhavani Date: Thu, 8 Jan 2026 16:44:47 -0800 Subject: [PATCH] fix(build): Handle namespace packages for PyPI CUDA detection The nvidia package from PyPI (e.g., nvidia-nccl-cu12/cu13) is a PEP 420 namespace package that doesn't have __file__ attribute. This caused get_cuda_include_dirs() to fail with TypeError when building with only NCCL from PyPI. Use nvidia.__path__[0] which works for both namespace packages and regular packages. Fixes: NVIDIA/TransformerEngine#2331 Signed-off-by: Santosh Bhavani --- build_tools/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build_tools/utils.py b/build_tools/utils.py index 8a52440310..a05b745d18 100644 --- a/build_tools/utils.py +++ b/build_tools/utils.py @@ -239,7 +239,13 @@ def get_cuda_include_dirs() -> Tuple[str, str]: except ModuleNotFoundError as e: raise RuntimeError("CUDA not found.") - cuda_root = Path(nvidia.__file__).parent + # Handle namespace packages (PEP 420) which don't have __file__ + # The nvidia package from PyPI CUDA packages is a namespace package + if hasattr(nvidia, "__path__") and nvidia.__path__: + cuda_root = Path(list(nvidia.__path__)[0]) + else: + raise RuntimeError("Could not locate nvidia package directory.") + return [ subdir / "include" for subdir in cuda_root.iterdir()