Repository navigation
Studio: pick up a GPU whose driver loads after Studio starts - #13232
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. |
…stamp the TTL after the probe
|
Codex Review: Didn't find any major issues. 🎉 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". |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
NilayYadav
left a comment
There was a problem hiding this comment.
Review + reproduction evidence
Pinned review: 52c70872e4911b5645b646b729ee4a95c646366f. No blocking findings; three non-blocking suggestions below.
I reproduced the late second GPU on fresh upstream main (Linux, 2 x NVIDIA L4, Chromium 1440x900). The second card was hidden from nvidia-smi at startup and exposed mid-session, which stands in for a driver that finishes loading after Studio starts:
- main
b15cda912a: more than 3 minutes after the second card appeared,/api/system/gpu-visibilitystill returnedparent_visible_gpu_ids: [0]with one device. Settings > System listed onlyGPU 0, with the VRAM tile at0 GiB / 22.5 GiB. Loadingunsloth/Qwen3-0.6B-GGUFwithgpu_ids: [1]returned HTTP 400:Invalid gpu_ids [1]: IDs must be physical GPU IDs between 0 and 0. Rejected IDs: [1]. Parent-visible GPUs: [0]. - PR head
52c70872e4: 87 s after the card appeared, the log printedPhysical GPU count grew from 1 to 2; using the new GPUs.parent_visible_gpu_idsbecame[0, 1], Settings > System listedGPU 0andGPU 1, and the VRAM tile read0 GiB / 45 GiB. The same load withgpu_ids: [1]returned HTTP 200"status": "loaded", "gpu_ids": [1].nvidia-smishowed the 976 MiB llama-server on GPU 1, and a chat completion against it answered normally.
- Unchanged flows: at startup both sides were identical: one row,
[0], andgpu_ids: [0]loads on GPU 0 (HTTP 200, 976 MiB on GPU 0). The Studio logs had the same warnings on both sides; the PR added only the single "grew" info line. - Tests: the new
test_physical_gpu_count_refresh.pygives 12 passed on the PR and 6 failed on main (growth, torch-fallback replacement, MIG rows, TTL stamp, memory table). Across the 21 existing test files that touch these helpers: 2080 passed and 7 skipped on both main and the PR. The one failure,test_gpu_query_cache::test_studio_load_unload_and_training_methods_invalidate, fails on main too. - Other platforms: ROCm, XPU, MLX and CPU never stamp the refresh timestamp, so they take main's branch unchanged.
- Cost: steady state is one
nvidia-smi -Lper minute per process. The cached path stays in the nanoseconds.
Suggestions (non-blocking, not reproduced on this hardware):
- Diffusers loads on a late card.
detect_hardware()initialises CUDA in the Studio process (torch.cuda.get_device_properties(0)), and diffusers image loads run in that process (core/inference/diffusion_device.py:364). With a real late driver,gpu_ids: [1]now passes validation for an in-process diffusers load, but that process's torch cannot open the card. The load would then fail withinvalid device ordinalafter the resident model is evicted, where main gave a clean 400. llama-server, training and export spawn fresh processes and are fine. A guard inresolve_selected_cuda_ordinalwould turn this back into a clear "restart Studio to use this GPU" message: when CUDA is already initialised, refuse an ordinal at or abovetorch.cuda.device_count(). - Event loop.
_resolve_gguf_gpu_ids_for_requestisasyncand callsresolve_requested_gpu_idsinline (routes/inference.py:15558). That call can now runnvidia-smi -Lonce a minute, so a slow driver would stall the loop for up to the 5 s timeout. Its siblings in the same helper already useasyncio.to_thread:
resolved = await asyncio.to_thread(
resolve_requested_gpu_ids,
gpu_ids,
is_vulkan = ids_are_vulkan_ordinals,
)- Log noise. On CUDA hosts with no working
nvidia-smi(for exampleNVIDIA_DRIVER_CAPABILITIES=computecontainers), the first call still stamps_physical_gpu_count_checked_at. Every later refresh then logsnvidia-smi -L failedat warning level once a minute. Skipping the stamp when the startup probe returnedNonewould avoid this.
Conclusion: real defect (issue #9510, item 4), fixed on the reported path with no regression in the startup or GPU 0 flows. Ready to merge once upstream CI finishes green. The suggestions above can follow separately.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |

Fixes the "extra GPU loads its driver late and Studio never notices" part of #9510
The bug
get_physical_gpu_count()caches thenvidia-smi -Lcount for the life of the process, and nothing outside the tests ever resets it. If a second GPU's driver finishes loading after Studio has started (common with autostart at login, eGPUs, or a slow second card), Studio keeps thinking the host has one GPU until it is restarted.The cached count feeds
_get_parent_visible_gpu_spec()when no visibility mask is set (numeric_ids = list(range(get_physical_gpu_count()))), so the late card is:get_backend_visible_gpu_info()drops rows outside the parent-visible ids), and#9858 already handles the "no usable GPU at startup, one appears later" case through re-detection. It does not cover going from one GPU to two, because the count cache is not part of that reset.
The fix
On NVIDIA, a cached count is re-read at most once a minute and kept only if it grew:
nvidia-smithere would stall the event loop (0.1 to 0.3 s here, up to the 5 s timeout on a busy driver).nvidia-smitimeout cannot hide a card.GPU N:rows ofnvidia-smi -Lcount on a re-read, so MIG instances created after startup never look like new GPUs. Startup counting is unchanged.gpu_query's own 60 s cache entry fornvidia-smi -L(Studio: cache and coalesce nvidia-smi reads in the backend #11995).nvidia-smifailed at startup and the count came from the torch fallback, a later SMI answer that is larger replaces it, which is what a fresh start would have produced.min_per_gpu_N) is sized from the parent-visible ids as well as the visible count, so auto-selection over a grown inventory still checks the per-GPU fit.amd-smiis uncached and can take seconds, and torch cannot see devices that appear after CUDA initialises anyway.After the fix, the same sequence gives:
Verification
studio/backend/tests/test_physical_gpu_count_refresh.py(13 cases): a late second GPU becomes selectable, no re-probe inside the TTL, a failed / lower / zero probe never hides a GPU, MIG child rows are not GPUs, the TTL starts after the probe, the memory table covers every parent-visible GPU, the re-probe never blocks the caller (a wedged driver returns the cached count in under 1 s), and MLX / ROCm are never re-probed. Each of them fails on main or on the earlier revision it guards against.nvidia-smion PATH that adds MIG rows and then a second GPU mid-run (TTLs shortened to 2 s):gpu_ids=[1]refusedgpu_ids=[1]acceptedget_physical_gpu_count()callnvidia-smion the same host: 8 GPUs, ids[0..7], unchanged.studio/backend/tests(5,000+ tests) gives the same result on main and on this branch; the failures present on this host are on main too.