Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion build_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant list() conversion - nvidia.__path__ is already indexable, can use nvidia.__path__[0] directly

Suggested change
cuda_root = Path(list(nvidia.__path__)[0])
cuda_root = Path(nvidia.__path__[0])

else:
raise RuntimeError("Could not locate nvidia package directory.")
Comment on lines +242 to +247
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix correctly handles namespace packages here, but transformer_engine/common/__init__.py line 249-252 has the same issue with nvidia.__file__:

  • Line 249 checks if nvidia.__file__ is None, but namespace packages will raise AttributeError when accessing __file__ (the attribute doesn't exist, it doesn't return None)
  • Line 252 uses Path(nvidia.__file__).parent which will also fail with namespace packages

Consider applying the same fix pattern (__path__) to _nvidia_cudart_include_dir() in that file. Should this PR also fix the similar nvidia.__file__ usage in transformer_engine/common/__init__.py line 249-252, or will that be addressed in a separate PR?


return [
subdir / "include"
for subdir in cuda_root.iterdir()
Expand Down
Loading