Repository navigation
[Bugfix] Reject negative --device-ids indices instead of selecting the wrong device - #49053
Conversation
…e wrong device When CUDA_VISIBLE_DEVICES is set, --device-ids values are treated as indices into the visible set. The range check only guarded the upper bound (i >= len(cvd_ids)), so a negative index such as -1 passed validation and cvd_ids[i] silently negative-indexed into the list, resolving to a valid-but-wrong physical device instead of erroring. Complete the bounds check to 0 <= i < len(cvd_ids) so an out-of-range negative index raises the same 'out of range' ValueError as a too-large one. Add a regression test alongside the existing out-of-range test. Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
294e81c to
34aff41
Compare
|
Gentle ping @hmellor (CODEOWNER for CI is currently sitting on Recap: |
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
|
/ci run |
|
❌ This PR is 1 commit behind upstream |
|
/ci run --allow-stale |
|
/ci run --allow-stale |
|
✅ Triggered Buildkite CI #93570 for commit
|
|
/ci retry |
…e wrong device (vllm-project#49053) Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Purpose
EngineArgs._resolve_device_idscomposes--device-idswithCUDA_VISIBLE_DEVICES: when CVD is set, each--device-idsvalue is treated as an index into the visible set. The range check only guarded the upper bound:A negative index (for example
--device-ids -1) makesi >= len(cvd_ids)evaluate toFalse, so no error is raised andcvd_ids[i]silently negative-indexes into the list, resolving to a valid-but-wrong physical device. WithCUDA_VISIBLE_DEVICES=4,5and--device-ids -1, the method returns physical device[5]instead of rejecting the input.This completes the bounds check to
not 0 <= i < len(cvd_ids)so an out-of-range negative index raises the same "out of range"ValueErroras a too-large one, matching the intent of the existingtest_device_ids_with_cvd_out_of_rangetest.This changes only input validation (silent mis-selection becomes a clear error); it does not affect model output, accuracy, or serving numerics, so no model-evaluation results apply.
Not a duplicate: the only open PRs touching this area, #46132 and #41776, add MIG/UUID parsing for
CUDA_VISIBLE_DEVICES; neither changes the_resolve_device_idsindex bounds check. No open issue tracks this.Test Plan
Added
tests/engine/test_arg_utils.py::TestDeviceIds::test_device_ids_with_cvd_negative_index, mirroring the existingtest_device_ids_with_cvd_out_of_range:Test Result
_resolve_device_idsdoes not load a model, so I validated the exact logic on CPU by executing the method against a stubbed platform (a full CUDA build was not available on my machine); the added test runs in CI:EngineArgs(model="m", device_ids=[-1])withCUDA_VISIBLE_DEVICES=4,5returned[5](no error raised).ValueError: --device-ids index -1 is out of range for CUDA_VISIBLE_DEVICES=4,5 (2 devices visible).device_ids=[0, 1]still resolves to[4, 5].AI assistance disclosure: AI assistance was used to help identify and prepare this change, per the repository's contribution policy. The fix is a single bounds-check completion plus a regression test, and I have reviewed every changed line.