Repository navigation
Studio: automatic GPU placement caches failed probes, skips MIG winners, never blocks the event loop - #14118
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…oop gate never waits on detection
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46e0b445a9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not hw.DETECTION_COMPLETE.is_set(): | ||
| return None |
There was a problem hiding this comment.
Avoid re-entering hardware detection from the event loop
The completion check does not guarantee that the subsequent auto_cuda_ranking_possible() call is nonblocking: a forced detection can acquire _DETECT_LOCK and clear DETECTION_COMPLETE immediately after this check, after which auto_cuda_ranking_possible() calls get_device() and waits on that lock from the event-loop thread. This can still stall all async request handling for the duration of a slow detection pass; compute the cached result without calling get_device(), or move the potentially locking call to the worker.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d0f8e74: auto_cuda_ranking_possible_cached no longer calls auto_cuda_ranking_possible(). It answers from memory only (the cached physical count unmasked, or the numeric CUDA mask parsed by the same rule as get_parent_visible_gpu_ids), so a forced re-detection holding _DETECT_LOCK cannot stall the event loop. A stray HIP/ROCR mask still defers to the worker gate. Added test_cached_gate_never_calls_get_device.
| mig = hw._nvidia_mig_gpu_indices_or_none() | ||
| if mig is None or set(visible) & mig: | ||
| return 0 | ||
| return winner |
There was a problem hiding this comment.
Detect MIG mode even when no instances exist
On a host where a physical GPU has MIG mode enabled but currently has no GPU/compute instances, nvidia-smi -L contains no indented MIG row, so _nvidia_mig_gpu_indices_or_none() returns an empty set and this branch accepts the physical-row winner. If that unavailable physical row wins as ordinal 1 while only card 0 is CUDA-visible, the returned ordinal does not exist and placement silently falls back unpinned after the scope/set-device failure. MIG mode itself, or the physical-row-to-CUDA-ordinal mapping, must be verified before returning the row-ranked winner.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d0f8e74: _nvidia_mig_gpu_indices_or_none now unions the -L instance rows with cards whose mig.mode.current is Enabled (new nvidia.get_mig_mode_gpu_indices_or_none, cached per static generation with the same failure backoff as the -L probe). A MIG-mode card with no instances therefore keeps card 0, and a failed mode query reads as unknown, which also keeps card 0.
| t.join() | ||
| if was: |
There was a problem hiding this comment.
Restore the detection event to its original state
When this test starts with DETECTION_COMPLETE clear, detect_hardware() sets it and the cleanup never clears it again because it only handles the originally-set case. The first parameterized invocation therefore leaves the shared hardware module in the inconsistent state DEVICE is None (restored by monkeypatch) while the completion event remains set, making later hardware and route tests order-dependent; restore both event states in the finally block.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d0f8e74: the finally block now clears DETECTION_COMPLETE when it started clear, so the event is restored either way.
…te answers from memory only
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
Three small costs in the automatic GPU placement added by #14020, all on multi-GPU NVIDIA hosts:
hardware._nvidia_mig_gpu_indices_or_none()ran its ownnvidia-smi -L, bypassing the MIG discovery cache from Studio: read whole-GPU uuid masks from nvidia-smi rows and cache the MIG set #14017. A successful listing was served by gpu_query's cache, but a failed one had no backoff, and withUNSLOTH_GPU_QUERY_CACHE=0every call spawned nvidia-smi (one per automatic route, two per catalog refresh).Under
CUDA_DEVICE_ORDER=FASTEST_FIRSTwith a numeric mask, a failed bus-id join was never cached, so everyauto_select_gpu_ids()re-spawned the driver-API child (about 300 ms here, up to its 15 s timeout on a hung driver).nvidia-smi CSV output is not quoted, so a GPU name containing a comma made
get_card_identities()return nothing. Every catalog refresh then ranked live, and identical cards under FASTEST_FIRST got an explicit card 0 instead of staying unpinned.On a MIG host, automatic image/video placement ranked cards by their physical nvidia-smi rows and could return card 1, which CUDA maps to a MIG slice (or to nothing before driver R570). Main before Studio: automatic image/video loads pick the freest GPU, and GPU picks respect what each card can run #13928 stayed on the current card there.
The event-loop gate
auto_cuda_ranking_possible_cached()calledget_device()for non-CUDA hosts, which waits on the hardware-detection lock while a detection pass runs, stalling the event loop (about 1.3 s per call in a spoofed run) on Mac, CPU and XPU hosts too.Fix
_nvidia_mig_gpu_indices_or_none()delegates tonvidia.get_mig_gpu_indices_or_none(), so it shares that cache, its failure backoff and its sequence-number rules.A failed bus-id join is remembered for 300 s per (mask, order, static generation); hardware re-detection still retires it at once.
Card identities rejoin a name that spans several CSV fields, as the inventory parser already does.
A row-ranked winner other than card 0 is only taken when MIG discovery confirms no MIG card among the visible ones; otherwise card 0 stays explicit.
The cached gate answers from memory only: non-CUDA or ROCm is False, and detection still in flight defers to the worker thread.
Single-GPU, CPU, Apple and ROCm hosts never reach items 1-4.
Tests
New
tests/test_media_auto_gpu_mig_and_event_loop.py: 6 of 7 fail on main, all pass here.New
tests/test_media_auto_gpu_probe_caches.py: 3 of its 5 tests fail on main, all pass here.test_mig_listing_parses_slicesdisables gpu_query's cache in its stub now that the helper shares it.GPU / hardware / media suites: 3467 passed, 3 skipped. The 3 failures in
test_rocm_windows_vram_7452.pyare the same on main.