fix: auto-detect CUDA_HOME from bundled nvidia headers on Linux - #2291
Open
abendrothj wants to merge 1 commit into
Open
fix: auto-detect CUDA_HOME from bundled nvidia headers on Linux#2291abendrothj wants to merge 1 commit into
abendrothj wants to merge 1 commit into
Conversation
MLX's CUDA backend JIT-compiles kernels with NVRTC at runtime (first triggered by the distributed send in ring prefill) and fails with 'Can not find locations of CUDA headers' unless CUDA_HOME/CUDA_PATH is set. The pip nvidia-cuda-runtime package ships the headers; resolve them from the nvidia namespace package in the runner bootstrap when nothing is configured.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MLX's CUDA backend JIT-compiles kernels with NVRTC at runtime, and NVRTC needs the CUDA headers. If neither
CUDA_HOMEnorCUDA_PATHis set, compilation fails with:On a pip-installed Linux CUDA setup the headers are present —
nvidia-cuda-runtimeships them under thenvidianamespace package — but nothing exports their location, so MLX can't find them.The failure is badly timed: it doesn't happen at model load, but at the first NVRTC-compiled kernel. In my case that was the distributed send in ring prefill, so a node came up healthy, loaded weights, and only died once inference actually started.
Fix
In the runner bootstrap, when neither variable is set and we're on Linux, resolve the bundled headers from the
nvidianamespace package and setCUDA_HOME.Deliberately conservative:
CUDA_HOME/CUDA_PATHwins.include/directory actually exists.So a machine with a working CUDA toolchain is unaffected; this only fills in the gap for pip-provided CUDA.
Tests
src/exo/worker/tests/unittests/test_runner/test_cuda_home.pycovers the detection, the non-Linux skip, the existing-value skip, and the missing-headers case.Note on overlap
#2103 and #2129 also touch
bootstrap.py, but only theMLX_METAL_FAST_SYNCHblock — neither setsCUDA_HOME. Different hunk, no functional overlap; happy to rebase behind either if they land first.