Skip to content

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
lemonade-sdk:mainfrom
bong-water-water-bong:fix/nvml-stub-for-hybrid-gpu
Open

fix: LD_PRELOAD NVML stub to suppress CUDA detection on hybrid AMD+NVIDIA systems#20
bong-water-water-bong wants to merge 1 commit into
lemonade-sdk:mainfrom
bong-water-water-bong:fix/nvml-stub-for-hybrid-gpu

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

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:

RuntimeError: Only one platform plugin can be activated, but got: ['cuda', 'rocm']

Why env var approaches don't work

  • CUDA_VISIBLE_DEVICES="" — NVML bypasses the CUDA runtime. It talks directly to the NVIDIA kernel driver via libnvidia-ml.so, so CUDA_VISIBLE_DEVICES has no effect on nvmlDeviceGetCount().
  • CUDA_VISIBLE_DEVICES="" + HIP_VISIBLE_DEVICES=0 — Same problem; NVML doesn't respect either variable.
  • Python monkey-patching — Fragile to vLLM internal API changes (function renames, module restructures).

Solution: LD_PRELOAD NVML stub

A 25-line C file compiled to a shared library. When LD_PRELOADed, it intercepts:

NVML function Stub behavior
nvmlInit() Returns error
nvmlInit_v2() Returns error
nvmlInitWithFlags() Returns error
nvmlDeviceGetCount() Returns 0 devices

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

  • Does not modify upstream wheel contents — respects the repo's inviolable principles
  • NVML C ABI is stable — these function signatures haven't changed in years
  • Works at the dynamic linker level — can't be bypassed by any Python code path
  • Minimal — 25 lines of C, one gcc -shared invocation

How it works end-to-end

  1. Lemonade sets VLLM_TARGET_DEVICE=rocm in the vLLM subprocess environment (PR #2459)
  2. Launcher detects VLLM_TARGET_DEVICE=rocmLD_PRELOADs the stub
  3. vLLM starts → pynvml sees zero NVIDIA GPUs → CUDA platform inactive → ROCm activates ✓

Companion PR

🤖 Generated with Claude Code

…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>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@bong-water-water-bong

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant