Skip to content

fix(nvidia): keep MIG indexes stable when a card is skipped - #53

Merged
thxCode merged 4 commits into
gpustack:mainfrom
skandtandon:fix/nvidia-mig-index-skipped-card
Nov 24, 2026
Merged

thxCode merged 4 commits into
gpustack:mainfrom
skandtandon:fix/nvidia-mig-index-skipped-card

Conversation

@skandtandon

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #51. index_mig_devices starts the MIG blocks above the largest index the detected cards report. Since #51 a card that cannot be queried is skipped, and when that card is the one with the largest index, every other card's MIG devices move down by one. An A100 with two instances on card 0 of three cards reports MIG indexes [3, 4]; with card 2 lost it reports [2, 3], so an index handed out earlier now names a different MIG device.

index_mig_devices gets an optional reserved count: card indexes that stay taken even if no detected card reports them. The NVIDIA detector passes the NVML device count when it skipped a card, and 0 otherwise, so nothing changes when every card answers.

Limit: the block size is still the largest slot count among the detected cards, so on a node mixing MIG-capable models where the skipped card hosts the most slots, the blocks can still shift.

Tests

  • test_detect_info_keeps_mig_indexes_when_the_last_card_cannot_be_queried (first commit): the same three cards detected with and without the last card lost must give card 0's MIG devices [3, 4]. Without the fix it fails with [2, 3] == [3, 4]; reverting either half of the fix (the reserved term in the base, or the detector passing it) fails it the same way.
  • pytest tests/gpustack_runtime/detector: 517 passed, 20 skipped. pre-commit (ruff, codespell, commitizen) passes.

…pped

MIG devices are numbered in blocks above the largest card index the
detected cards report. A skipped card no longer reports one, so a MIG
device on another card must keep the index it has when every card
answers.

Signed-off-by: Skand Tandon <21158496+skandtandon@users.noreply.github.com>
index_mig_devices starts the MIG blocks above the largest index the
detected cards report. When the skipped card was the one with the
largest index, every other card's MIG devices moved down by one, so an
index handed out before now names a different MIG device.

Add a reserved count to index_mig_devices and pass the NVML device count
when a card was skipped. With every card detected nothing changes.

Signed-off-by: Skand Tandon <21158496+skandtandon@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 09:18
@gpustack-code-review

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

Copy link
Copy Markdown

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

Reviewed de66a1e..d6d1813 only; earlier commits in this PR were reviewed in a previous run.

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.

🟡 Changes recommended

The reservation logic can renumber existing MIG instances in physical-index-priority mode when another GPU becomes unqueryable, breaking index stability.

1 open issue
What changed in this PR

This follow-up to #51 stabilizes NVIDIA MIG indexes when the highest-index card cannot be queried, preserving assignments for healthy cards.

Changes:

  • Adds an optional reserved card-index count to the shared MIG indexing helper.
  • Passes the NVML device count when NVIDIA detection skips an unqueryable card.
  • Adds a regression test comparing MIG indexes before and after the last card becomes unavailable.
File Description
tests/​gpustack_runtime/​detector/​test_nvidia.py Tests index stability when the last card is lost.
gpustack_runtime/​detector/​nvidia.py Reserves card indexes after a query failure.
gpustack_runtime/​detector/​__types__.py Adds and documents the reservation parameter.

Review effort: Balanced

Comment thread gpustack_runtime/detector/nvidia.py Outdated
ret,
devs_mig_devices,
devs_mig_slots,
reserved=dev_count if unqueryable_error else 0,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, reproduced: with physical index priority, minors 0 and 1 and a third card without a readable minor, losing card 0 moved card 1's MIG indexes from [9, 10] to [10, 11]. The device count only matches the index namespace for enumeration indexes, so the reservation now applies only there (d6d1813), with your case as a test (4090823). In physical-index mode a skipped card with the largest minor can still shift the blocks, as on main.

@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 introduces a 'reserved' parameter to the index_mig_devices function to ensure that MIG device indexes remain stable even when some cards cannot be queried or are skipped. This prevents renumbering of MIG devices when the last card in a sequence fails. I have no feedback to provide as there were no review comments for this pull request.

With GPUSTACK_RUNTIME_DETECT_PHYSICAL_INDEX_PRIORITY the card indexes are
minor numbers and a card without a readable one is already left out, so
the NVML device count is not the index namespace. A card that cannot be
queried must not move another card's MIG indexes.

Signed-off-by: Skand Tandon <21158496+skandtandon@users.noreply.github.com>
Reported in review: with physical index priority, minors 0 and 1 and a
third card without a readable minor, losing card 0 made reserved=3 and
moved card 1's MIG indexes from [9, 10] to [10, 11]. Reserve the NVML
device count only when cards are indexed by enumeration.

Signed-off-by: Skand Tandon <21158496+skandtandon@users.noreply.github.com>

@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 6b740ce 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