Skip to content

fix(nvidia): skip a card that cannot be queried instead of failing detection - #51

Merged
thxCode merged 2 commits into
gpustack:mainfrom
skandtandon:fix/nvidia-skip-unqueryable-device
Nov 24, 2026
Merged

thxCode merged 2 commits into
gpustack:mainfrom
skandtandon:fix/nvidia-skip-unqueryable-device

Conversation

@skandtandon

@skandtandon skandtandon commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

NVIDIADetector.detect_info and detect_usage walk every card by index. Most per-card queries already degrade
on their own (contextlib.suppress(pynvml.NVMLError) or a helper that catches), but these don't:

  • in detect_info: the handle lookup, compute capability, PCI info, name and UUID;
  • in detect_usage: the handle lookup and UUID.

So one card that NVML can't query, for example one that has fallen off the bus (NVML_ERROR_GPU_IS_LOST),
raises out of the walk:

  • detect_info: detect_devices() swallows the exception at debug level and returns no NVIDIA cards, so a
    GPUStack worker on that node reports zero GPUs. A worker that is already running keeps its cached identity for a
    while, but a worker that starts or restarts on a node that already has a lost card reports none of its healthy
    cards. With GPUSTACK_RUNTIME_DETECT=nvidia the error is re-raised instead.
  • detect_usage: detect() already catches this so that the inventory survives (its comment explains why), but
    the usage of every card is still lost on each refresh.

Changes

  • detect_info: the five queries that don't degrade are read together at the top of each card's loop iteration.
    A card whose query fails with an error specific to that card (GPU_IS_LOST, UNKNOWN, RESET_REQUIRED,
    INSUFFICIENT_POWER, IRQ_ISSUE) is skipped with debug_log_warning, as the minor-number check already skips a
    card. The other cards keep their enumeration index.
  • Any other NVML error still fails detection. A host where no card can be queried still raises the last error,
    rather than reporting a host without cards.
  • detect_usage: the same per-card skip for the handle and UUID reads. The skipped card gets no usage, and the
    others keep theirs. If no card can be queried, it raises the last error, as before.
  • The new _is_unqueryable_device_error helper classifies the error by NVMLError.value.
  • get_topology is unchanged: it works on the devices detect_info returned and looks them up by UUID.

Tests

In tests/gpustack_runtime/detector/test_nvidia.py, the fake binding gains query_error_code and
query_error_at, so a card can fail its handle or name query.

  • test_detect_info_skips_a_card_that_cannot_be_queried: each of the five codes at the handle lookup, and
    GPU_IS_LOST at the name query. The result is cards 0 and 2, with their own indexes.
  • test_detect_info_fails_on_another_query_error: NO_PERMISSION still raises.
  • test_detect_info_fails_when_no_card_can_be_queried: still raises.
  • test_detect_usage_fails_when_no_card_can_be_queried: still raises.
  • test_detect_usage_skips_a_card_that_cannot_be_queried: a card lost between the two queries gets no usage; the
    others keep theirs.

Commands run:

  • uv run pytest tests: 837 passed, 20 skipped.
  • With the nvidia.py change reverted, the 7 skip cases fail with the card's NVML error. The three "still fails"
    tests pass on main too, as intended.
  • pre-commit run --files gpustack_runtime/detector/nvidia.py tests/gpustack_runtime/detector/test_nvidia.py:
    passes.
  • Not run on real hardware. The lost card is simulated with the fake binding.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:25
@gpustack-code-review

gpustack-code-review Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

Comment thread gpustack_runtime/detector/nvidia.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change to preserve healthy NVIDIA GPU data when individual cards cannot be queried.

No open issues 🎉

What changed in this PR

This PR makes NVIDIA detection resilient to individual card failures, allowing healthy GPUs to retain their inventory and usage data when another card cannot be queried.

Changes:

  • Skip cards with selected device-specific NVML errors while preserving healthy cards’ enumeration indexes.
  • Continue raising unrelated NVML errors and fail inventory detection when no card can be queried.
  • Add simulated failure tests covering skipped cards, preserved indexes, error propagation, and partial usage results.
File Description
tests/​gpustack_runtime/​detector/​test_nvidia.py Extend the fake NVML binding and test per-card query failures.
gpustack_runtime/​detector/​nvidia.py Classify device-specific errors and skip affected cards during inventory and usage detection.

Review effort: Balanced

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the robustness of the NVIDIA GPU detector by handling cases where a GPU becomes unqueryable (e.g., falls off the bus) during detection. It introduces a helper function to identify specific NVML errors and updates both detect_info and detect_usage to skip problematic devices instead of failing the entire process. I have kept the review comment regarding the potential for stale metrics in detect_usage, as it highlights a valid issue where skipped devices retain their last known values, and provides a clear, actionable path for resolution.

Comment thread gpustack_runtime/detector/nvidia.py Resolved
…tection

detect_info and detect_usage walked every card by index, and the handle,
compute capability, PCI, name and UUID queries had no per-card handling.
One card that NVML cannot query, for example one that has fallen off the
bus (NVML_ERROR_GPU_IS_LOST), raised out of the walk, so the detector
reported no NVIDIA cards at all and the usage of every card was lost.

Skip a card whose query fails with GPU_IS_LOST, UNKNOWN, RESET_REQUIRED,
INSUFFICIENT_POWER or IRQ_ISSUE, with a debug warning, as the minor
number check already skips a card. Other errors still fail, and so does
a host where no card can be queried.

Signed-off-by: Skand Tandon <21158496+skandtandon@users.noreply.github.com>
Like detect_info, detect_usage now raises the last error when every card
was skipped, so that case behaves as it did before: detect() logs it and
reports the information only.

Signed-off-by: Skand Tandon <21158496+skandtandon@users.noreply.github.com>
@skandtandon
skandtandon force-pushed the fix/nvidia-skip-unqueryable-device branch from 04f7af0 to 4d00fb4 Compare November 23, 2026 21:39

@thxCode thxCode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@thxCode
thxCode merged commit e8fb5ca into gpustack:main Nov 24, 2026
7 checks passed
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.

3 participants