fix: LD_PRELOAD NVML stub to suppress CUDA detection on hybrid AMD+NVIDIA systems - #20
Open
bong-water-water-bong wants to merge 1 commit into
Conversation
…IDIA systems On laptops with both AMD iGPU and NVIDIA dGPU, vLLM's platform detection finds both CUDA (pynvml sees the dGPU via NVML) and ROCm and raises: RuntimeError: Only one platform plugin can be activated, but got: ['cuda', 'rocm'] Add a tiny LD_PRELOAD stub (nvml_stub.c) that intercepts nvmlInit and nvmlDeviceGetCount, making NVML report zero NVIDIA GPUs. When the launcher detects VLLM_TARGET_DEVICE=rocm, it preloads the stub so pynvml sees no NVIDIA hardware, the CUDA platform stays inactive, and ROCm activates normally through HIP/ROCm libraries. This is more robust than env var approaches (CUDA_VISIBLE_DEVICES does not block NVML) or Python monkey-patching (fragile to vLLM internal API changes). The NVML C ABI is stable across driver versions. Co-Authored-By: Claude <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This was referenced Jun 27, 2026
Author
|
Companion to lemonade#2598 — same class of hybrid AMD+NVIDIA GPU crash, applied at the llama.cpp backend level there and at the vLLM platform-detection level here. Both fixes use the same strategy: hide NVIDIA GPUs from the ROCm path rather than asking users to blacklist kernel modules or disable hardware. Rebased and ready for review — would appreciate a look from the lemonade-sdk team. |
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
On laptops with both AMD iGPU and NVIDIA dGPU, vLLM's platform detection finds both CUDA (pynvml sees the dGPU via NVML) and ROCm and raises:
Why env var approaches don't work
CUDA_VISIBLE_DEVICES=""— NVML bypasses the CUDA runtime. It talks directly to the NVIDIA kernel driver vialibnvidia-ml.so, soCUDA_VISIBLE_DEVICEShas no effect onnvmlDeviceGetCount().CUDA_VISIBLE_DEVICES="" + HIP_VISIBLE_DEVICES=0— Same problem; NVML doesn't respect either variable.Solution: LD_PRELOAD NVML stub
A 25-line C file compiled to a shared library. When
LD_PRELOADed, it intercepts:nvmlInit()nvmlInit_v2()nvmlInitWithFlags()nvmlDeviceGetCount()This makes pynvml see zero NVIDIA GPUs, so the CUDA platform plugin never activates — while ROCm probes through HIP/ROCm libraries normally.
Why this is robust
gcc -sharedinvocationHow it works end-to-end
VLLM_TARGET_DEVICE=rocmin the vLLM subprocess environment (PR #2459)VLLM_TARGET_DEVICE=rocm→LD_PRELOADs the stubCompanion PR
🤖 Generated with Claude Code