Skip to content

[NUMA+Ray] Fix NUMA NVML handle resolution under shuffled CUDA_VISIBLE_DEVICES - #24766

Merged
ByronHsu merged 1 commit into
mainfrom
byron/upstream-fix-numa-cuda-visible-devices
May 10, 2026
Merged

[NUMA+Ray] Fix NUMA NVML handle resolution under shuffled CUDA_VISIBLE_DEVICES#24766
ByronHsu merged 1 commit into
mainfrom
byron/upstream-fix-numa-cuda-visible-devices

Conversation

@ByronHsu

@ByronHsu ByronHsu commented May 9, 2026

Copy link
Copy Markdown
Collaborator

Motivation

pynvml.nvmlDeviceGetHandleByIndex enumerates GPUs in PCI bus order and ignores CUDA_VISIBLE_DEVICES. Under a reordered CVD (e.g. Ray's GPU allocator producing 3,6,5,4,0,7,1,2), numa_utils._query_numa_node_for_gpu passes a CUDA logical index and gets back the wrong physical GPU's NUMA affinity, so scheduler subprocesses get bound to the wrong NUMA node.

Modifications

Resolve the CUDA logical id via torch.cuda._get_nvml_device_index (which honors CUDA_VISIBLE_DEVICES) before calling nvmlDeviceGetHandleByIndex. Falls back to the original index (with a warning) on torch builds that don't expose the helper.

Also enriches the numactl debug_str with logical/physical GPU ids and CUDA_VISIBLE_DEVICES.

Checklist

  • Format your code according to the Code Formatting with Pre-Commit.
  • Update documentation / docstrings as needed.
  • For reviewers: if you intend to acknowledge my contribution, please do so by including Co-authored-by: bingyuhsu <byronhsu1230@gmail.com> in the commit message after the PR is merged.

`nvmlDeviceGetHandleByIndex` enumerates GPUs in PCI bus order and
ignores `CUDA_VISIBLE_DEVICES`, so passing a CUDA logical index returned
the wrong physical GPU under shuffled CVD (e.g. Ray's GPU allocator
producing `3,6,5,4,0,7,1,2`), binding scheduler subprocesses to the
wrong NUMA node.

Resolve CUDA logical GPU ids through PyTorch's NVML index helper
(`torch.cuda._get_nvml_device_index`) so NUMA binding follows reordered
`CUDA_VISIBLE_DEVICES` while keeping a fallback for older torch builds.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@ByronHsu ByronHsu changed the title Fix NUMA NVML handle resolution under shuffled CUDA_VISIBLE_DEVICES [NUMA+Ray] Fix NUMA NVML handle resolution under shuffled CUDA_VISIBLE_DEVICES May 9, 2026
@ByronHsu

ByronHsu commented May 9, 2026

Copy link
Copy Markdown
Collaborator Author

/tag-and-run-ci

@ByronHsu

ByronHsu commented May 9, 2026

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci label May 9, 2026
@ByronHsu
ByronHsu merged commit 7edb4c3 into main May 10, 2026
136 of 172 checks passed
@ByronHsu
ByronHsu deleted the byron/upstream-fix-numa-cuda-visible-devices branch May 10, 2026 04:18
ByronHsu added a commit that referenced this pull request May 10, 2026
…der shuffled CUDA_VISIBLE_DEVICES (#24901)

Co-authored-by: Byron Hsu <byron@periodiclabs.ai>
Co-authored-by: Cursor <cursoragent@cursor.com>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
…E_DEVICES (sgl-project#24766)

Co-authored-by: Byron Hsu <byron@periodiclabs.ai>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants