Skip to content

Studio: cache and coalesce nvidia-smi reads in the backend - #11995

Merged
danielhanchen merged 19 commits into
mainfrom
studio-nvidia-smi-cache
Sep 27, 2026
Merged

danielhanchen merged 19 commits into
mainfrom
studio-nvidia-smi-cache

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Problem

The Studio backend shells out to nvidia-smi from every hardware poll, fit check and model load. On a busy multi-GPU host with a congested driver (measured on 8x B200) each call took 25 to 100 s, /api/system/hardware took up to 671 s, one utilisation read 221 s, get_device 64 s and get_gpu_summary 55 s, and pages stalled for minutes.

Two things compound:

  1. Nothing is shared. Every request runs its own nvidia-smi, so a page that opens six panels starts six CLIs on a driver that is already struggling (measured below: 172 CLI runs for 178 hardware requests).
  2. subprocess.run(..., timeout=5) does not bound the call. On timeout it kills the child and then calls process.wait() with no deadline (CPython subprocess.run, POSIX branch), so a child stuck in a driver ioctl holds the request until the kernel lets it die. After that the caller falls back to torch, which queries each GPU with mem_get_info and opens a CUDA context on it.

Change

One helper, utils/hardware/gpu_query.py, that every nvidia-smi call in the backend now goes through (run_nvidia_smi). It is a drop-in for subprocess.run: same CompletedProcess, same FileNotFoundError / OSError / TimeoutExpired, so every caller keeps its parsing and its existing fallback chain.

  • Static and display reads are shared. Concurrent identical queries share one child (single flight), so a page load no longer starts one CLI per panel on a driver that is already congested.
  • Per-category policy (from the query's fields, see the table):
    • static (GPU list, names, total memory, compute capability): cached 60 s (the same TTL as the eGPU-aware physical inventory), dropped on hardware re-detection. An expired entry waits for a new answer rather than being served while one refreshes, so an unplugged card is not reported. A read never joins a child started before a re-detection, nor one already running longer than its own timeout (a hung child).
    • display (the hardware panel pollers, inside display_reads()): 3 s, then stale-while-revalidate with one background refresh, at most 60 s old. /api/system already has its own 10 s cache, so it uses display_reads(max_stale=0): each miss waits for a new (shared) reading, and only a hung CLI falls back to the last good one.
    • critical (everything else: fit checks, llama.cpp placement, GPU auto-selection, training coexistence, settle loops): never cached and never shared. Every call starts its own nvidia-smi after the call began and waits its whole timeout, exactly as on main. Memory another process allocates raises no Studio event, so no reuse window is safe for a decision; an instrumented model load issued one critical read with or without caching, so this costs nothing measurable. Its answer still refreshes the display cache.
  • Invalidation on Studio's own changes. utils/gpu_memory_events.py holds a generation counter, bumped on entry and on exit of every load, unload and training start or stop (llama.cpp, transformers, orchestrator, diffusion, video, sd.cpp, audio, speech-to-text, RAG embedding server, LLM and diffusion training) and right after each llama-server spawn. The next display read then fetches afresh, so the panel shows the new usage at once.
  • Bounded wait. The child runs on a daemon thread and the caller waits only its own timeout (plus 1 s for the kernel to reap a killed child), not until a child stuck in a driver ioctl is finally reaped. A static or display child may keep running (up to 120 s) and its answer fills the cache for the next caller.
  • When the CLI does not answer in time: a static read gets the last good answer, a display read the last good answer up to 60 s old and never one taken before a Studio load or unload. Everything else, and every critical read, gets the original TimeoutExpired, so the caller's own fallback runs exactly as before (for llama.cpp that is its MIG- and CUDA_VISIBLE_DEVICES-aware NVML branch).
  • Cache key includes the binary nvidia-smi resolves to on PATH, so a PATH change is never answered by another binary's output. The lookup never raises.
  • fresh_reads() forces a new reading for display-context code that compares consecutive samples (VRAM settle loops) or pairs a reading with another measurement under a fence.
  • display_reads() is used only by the display pollers: /api/train/hardware, /api/train/hardware/visible and the /api/system panel poll (not refresh_memory=true).

Failures: a missing nvidia-smi and other OSErrors pass through untouched. A non-zero exit or an answer with no rows (for example exit 6, "No devices were found") is returned to the caller as before, is never served from the cache, and replaces any older cached answer, so a card that went away is not reported from the cache. So AMD/ROCm (amd-smi, sysfs), Apple (ioreg/MLX), Intel XPU, CPU-only and Windows paths behave exactly as before. In-process torch reads (mem_get_info, memory_allocated, get_device_properties) are already cheap and live, and are untouched. UNSLOTH_GPU_QUERY_CACHE=0 turns the whole layer off (plain subprocess.run). The TTLs can be tuned with UNSLOTH_GPU_QUERY_{STATIC,DISPLAY}_TTL and UNSLOTH_GPU_QUERY_BACKGROUND_TIMEOUT.

Site inventory

Every place the backend runs nvidia-smi (7 command lines):

Site Query Category
nvidia.get_physical_gpu_count -L static
nvidia._query_gpu_inventory (physical inventory, backend-visible GPU info, /api/system/gpu-visibility, include_details) index,name,memory.total static
LlamaCppBackend._cuda_compute_caps index,compute_cap static
LlamaCppBackend._probe_nvlink_topology topo -m static, cache=False: _nvlink_topology already caches it per process and has its own refresh=True
nvidia.get_primary_gpu_utilization utilisation, temperature, memory used/total, power critical by default, display under display_reads()
nvidia.get_visible_gpu_utilization same, per visible GPU critical by default, display under display_reads()
LlamaCppBackend._get_gpu_memory index,memory.free,memory.total critical

Consumers of the live readings, by category:

Consumer Category Why
GET /api/train/hardware (get_gpu_utilization) display training-page poll
GET /api/train/hardware/visible display System view poll
main._get_cached_system_gpu_info (/api/system) display, critical when refresh_memory=true panel poll, already behind a 10 s cache
get_gpu_memory_info / _context_free_cuda_memory_info (get_gpu_summary, /api/system/hardware, log_gpu_memory) critical vram_free_gb feeds training-method auto-selection
auto_select_gpu_ids critical GPU placement for training / transformers
routes/training_vram.py (2 reads) critical "does training fit next to the resident chat model"
LlamaCppBackend._get_gpu_memory / _get_gpu_free_memory (7 callers in llama_cpp, /api/inference pre-load path, RAG embedding server and embeddings._resolve_auto) critical GGUF GPU selection, layer placement, --fit decision
LlamaCppBackend._wait_for_vram_settle fresh compares consecutive samples
InferenceOrchestrator._wait_for_worker_vram_settle fresh compares consecutive samples
InferenceOrchestrator post-handoff reading (under _send_order_lock) fresh paired with the worker's own bytes under a fence
routes/inference reclaimable-VRAM _read_live fresh paired with owners' reclaimable bytes
routes/inference._wait_for_native_audio_gpu_free_gb fresh polls for memory to come free

Counts: 7 CLI sites (4 static, 3 live). 13 live consumer sites: 3 display, 5 critical (training_vram counted as its 2 reads, the llama.cpp probe once for its 10 callers), 5 fresh. Unchanged and not routed: 29 in-process mem_get_info / trusted_mem_get_info sites, plus the torch memory_* / get_device_properties / device_count reads, amd-smi, sysfs, ioreg and Windows perf counters.

Measurements

Host: 8x NVIDIA B200, driver currently healthy (/usr/bin/nvidia-smi about 0.15 s). The GPUs also run other jobs, so free memory, and which GPU a load picks, varies between runs. Studio was built from this branch and from main with UNSLOTH_STUDIO_HOME=<scratch> ./install.sh --local and UNSLOTH_TORCH_INDEX_URL=https://download.pytorch.org/whl/cu130, then driven over HTTP. Times are median / max in seconds. "Page" means the six hardware requests the Settings / System view fires, sent concurrently. "Burst" means 16 concurrent /api/system/hardware calls.

Real /usr/bin/nvidia-smi, no shim on PATH (10 sequential calls per endpoint):

Request before after
/api/system/hardware 0.171 / 0.381 0.009 / 0.190
/api/system/hardware?include_details=true 0.280 / 0.624 0.011 / 0.104
/api/train/hardware 0.172 / 0.327 0.004 / 0.005
/api/train/hardware/visible 0.164 / 0.268 0.004 / 0.005
/api/system/gpu-visibility 0.106 / 0.256 0.005 / 0.005
page (6 concurrent) 0.607 / 1.101 0.117 / 0.392
burst (16 concurrent) 1.403 / 1.599 0.191 / 0.303
GGUF load, unsloth/gemma-3-270m-it-GGUF UD-Q4_K_XL, 3 warm loads 2.58, 3.76, 4.42 3.13, 2.39, 2.54

nvidia-smi runs for the same 178 requests (counted with a pass-through wrapper): 172 before, 8 after.

Slow or hung driver, emulated with a pass-through wrapper that sleeps before calling the real nvidia-smi (3 calls per endpoint):

Request 4 s per call, before 4 s per call, after 12 s per call, before 12 s per call, after
/api/system/hardware 4.19 4.20 (critical: stays fresh) 5.02 1.01
/api/system/hardware?include_details=true 8.32 4.21 15.04 1.01
/api/train/hardware 4.18 0.004 5.02 0.004
/api/system/gpu-visibility 4.14 0.004 10.02 0.005
page (6 concurrent) 8.59 4.22 15.07 1.02
GGUF load (2 loads) 14.56, 14.61 10.46, 10.50 32.45, 32.48 13.45, 5.87

These slow-driver numbers are from the previous revision, in which a fit check could reuse a reading for 1 s or fall back to NVML after a short wait. Fit checks now read afresh and wait their whole timeout, exactly as on main, so the rows that go through a fit check (/api/system/hardware, include_details=true, page, and the GGUF loads) are expected to match the "before" column on a slow driver rather than the "after" one. The display rows (/api/train/hardware, /api/system/gpu-visibility) and the healthy-driver table above are unaffected: those reads are still cached and shared. This trade was made on purpose: faster fit checks on a slow driver are not worth acting on stale memory numbers.

With 12 s per call, main answered /api/train/hardware from the torch fallback (gpu_utilization_pct, temperature_c and power_draw_w all null). This branch answered from the last good reading. A killed sleep exits immediately, so this emulation cannot reproduce a child stuck in the driver, which is what made the 25 to 100 s calls. test_a_child_the_kernel_cannot_reap_does_not_hold_the_caller covers that case: with a runner that returns only after 12 s, each caller gets its answer at its own timeout (5 s, plus 1 s reaping grace), not after the 12 s.

Fit checks still see fresh numbers

Live, on both builds: load gemma-3-270m with the real free VRAM, prime a critical read (/api/system/hardware reports about 176 GB free), switch the wrapper to report 100 MiB free on every GPU, and start the second load under 1 ms after the primed read returned:

Load before after
real free VRAM pinned to one GPU (CUDA_VISIBLE_DEVICES=4 on that run), --fit off -ngl -1 pinned to one GPU (CUDA_VISIBLE_DEVICES=7 on that run), --fit off -ngl -1
100 MiB free on every GPU not pinned: all 8 GPUs, --fit on not pinned: all 8 GPUs, --fit on
/api/system/hardware vram_free_gb afterwards 0.0 0.0

Studio's own placement check sees the cards as full and hands the load to llama.cpp's --fit instead of pinning a GPU, same as on main.

Tests

tests/test_gpu_query_cache.py (38 tests) drives a real executable named nvidia-smi on PATH whose answers, latency and exit status each test controls. It covers:

  • classification; single flight for display reads (16 threads, 1 child); a different query is not merged;
  • fit checks: each concurrent one runs its own CLI; 16 threads under constantly changing memory never get a reading taken before their call began; another process's allocation is seen by the very next fit check; a cached display reading never answers one; one never joins an older in-flight run; on a slow but answering driver it waits its whole timeout and gets the answer; on a hung CLI it gets no old reading, and llama.cpp's own MIG-aware NVML fallback runs instead of any stand-in;
  • display stale-while-revalidate, display stale on a hung CLI, a display read after a load fetching afresh inside a 3600 s TTL, a display read not joining a child started before an invalidation;
  • the static inventory cached until re-detection, and not joining a child started before one;
  • every real load/unload/training entry point carrying the invalidation decorator; invalidation even when a load raises;
  • the bounded wait, including the unreapable child, and a read after a hung child not waiting on it;
  • a failed or empty answer (exit 6, check=True) replacing the cached one, an older answer never overwriting a newer empty one, an expired inventory not served after a card goes away;
  • failures not cached; a missing CLI reported absent; UNSLOTH_GPU_QUERY_CACHE=0; results returned as copies.

10 of these fail against the previous revision of this PR and pass now. The backend's other tests that touch these paths (60 files, 8481 tests) give identical results on this branch and on the pre-PR base in the same environment.

Five independent reviews of the previous revision (call-site routing, concurrency, compatibility with main, memory staleness, invocation design) all found the two problems this revision fixes: the 1 s critical reuse window, and a timeout stand-in that bypassed llama.cpp's MIG/UUID handling. Their suites pass on this revision: memory-safety matrix 17/17, regressions 10/10, main compatibility 138/138 cells, platform contracts 23/23.

studio/backend/tests as CI runs it (-n 32, same ignores and -k) on this host, before and after rebasing onto current main:

  • No new failures.
  • The failures that remain also fail on main in the same checkout: sandbox/bubblewrap, cache-dir containment, offline media assembler and similar host-environment tests.
  • A timing-sensitive test or two flake under full parallel load and pass on rerun.
  • conftest.py resets the cache per test, so one test's fake CLI cannot answer for the next.

ruff check, scripts/verify_import_hoist.py (compare mode, every modified file), scripts/lint_duplicate_definitions.py, ruff format plus scripts/enforce_kwargs_spacing.py on the new files, and codespell on the new files are clean.

Settings no longer says "No GPU detected" on a slow driver

When the driver is congested, nvidia-smi times out and the torch fallback's device queries fail along with it, so /api/system reported available: False and Settings > Resources showed "No GPU detected" on a host that had reported its GPU one poll earlier.

On NVIDIA hosts (CUDA without ROCm), get_backend_visible_gpu_info now keeps the last inventory that found devices (per visibility mask) and returns it marked stale: true, with live usage unknown, until a probe answers again. Only nvidia-smi answering with zero rows, or exiting 6 ("No devices were found", as it does after an eGPU is unplugged), counts as proof there is no GPU. An older, slower probe never overrides a newer answer. A failed read with no earlier inventory still reports none, and a different mask never inherits one.

Emulated on a B200 with a proxy nvidia-smi plus failing torch device queries (/api/system gpu block, query cache off):

phase main this PR
healthy read available, 1 device available, 1 device
nvidia-smi failing available False, 0 devices available, 1 device, stale
nvidia-smi slow (15 s) available False, 0 devices available, 1 device, stale
recovered available, 1 device available, 1 device, not stale

Tests: tests/test_gpu_inventory_stale.py (11). ROCm, XPU, MLX and CPU hosts return the probe's own answer, exactly as on main. All 13 test files that touch the visibility probe or the route cache pass (991).

Not verified

  • A real congested driver. This host's driver is healthy; the slow cases above are an emulation.
  • AMD/ROCm, Apple, Intel XPU and Windows hardware. Those paths do not call nvidia-smi and are not routed through the helper, but they were not run live.
  • Training start/stop invalidation live. It is covered by the decorator and unit tests, not by a live training run.

Every nvidia-smi call in studio/backend now goes through
utils/hardware/gpu_query.run_nvidia_smi, a drop-in for subprocess.run:

- concurrent identical queries share one child process
- static queries (-L, name/memory.total, compute_cap) are cached for
  600 s and dropped on hardware re-detection
- live queries are cached for 1 s by default (fit checks, placement,
  GPU selection) and for 3 s with stale-while-revalidate under
  display_reads() (the hardware panel polls)
- a generation counter (utils/gpu_memory_events.py) is bumped on every
  model load/unload, training start/stop and llama-server spawn; a
  decision-critical read never reuses an older sample
- fresh_reads() bypasses the cache for VRAM settle loops and fenced
  readings
- the caller waits only its own timeout; subprocess.run's unbounded
  wait() after killing a child stuck in the driver no longer holds a
  request
- when the CLI does not answer: last good answer (for fit checks only a
  recent same-generation sample, rewritten to the lowest free / highest
  used seen), then NVML via studio/nvidia_probe.py, then the caller's
  existing fallback exactly as before

Non-NVIDIA hosts, missing nvidia-smi and non-zero exits are unchanged.
UNSLOTH_GPU_QUERY_CACHE=0 disables the layer.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-09-27T11:40:08.781318Z 3944929 New commits
🔒 Security Review ✅ Completed 2026-09-26T06:25:11.471749Z a7c2ec0 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

pre-commit-ci Bot and others added 4 commits September 26, 2026 01:49
A timed-out fit check used to get the lowest free memory seen in the last 60 s.
Memory another process allocated since then was invisible to it, while the old
code fell back to a fresh torch or NVML reading. Fit checks now take only a new
NVML reading or the caller's own fallback, never join a child older than the
critical TTL, and do not start another child behind a stuck one. Display reads
may be at most 60 s stale instead of 300 s.
…n timeout fallback

A fit check (placement, GPU auto-selection, training coexistence) reused a reading
up to 1 s old or joined a query already in flight. Another process's allocation
raises no Studio event, so that window could pick a GPU that had just filled up.
Critical reads now always start their own nvidia-smi and wait their whole timeout,
as before. The NVML stand-in on a hung CLI is removed: it returned the parent GPU
for a MIG slice and ignored CUDA_VISIBLE_DEVICES, while llama.cpp's own NVML branch
handles both. Static reads no longer join a query started before a re-detection.
…ncurrent fit checks

A PATH change must not be answered by a different nvidia-smi's cached output. The
lookup never raises. Adds a 16-thread test that every fit-check answer is a reading
taken after its call began, and makes the MIG fallback test fail when a whole-GPU
NVML answer stands in for llama.cpp's own fallback.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: a7c2ec0b32

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 490dba717e

ℹ️ 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".

Comment on lines +1659 to 1660
@_invalidates_gpu_memory("training start")
@owned_job()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Invalidate when the training worker changes GPU residency

When training starts asynchronously, this decorator's exit invalidation occurs immediately after proc.start() and start_training() returns, before the worker actually loads anything onto the GPU. A display poll in that interval can therefore cache the pre-load reading under the newest generation, and the later allocation does not invalidate it; stopping has the symmetric problem because stop_training() only queues a stop request before its decorator exits. Invalidate from the worker-resident and worker-termination paths so the hardware panel refreshes when VRAM actually changes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Display-only: fit, placement and training coexistence checks always run a new nvidia-smi and never read this cache. A display reading is at most one poll behind the worker's allocation (3 s TTL, then one background refresh), which is the intended trade-off for the panels.

On a congested driver nvidia-smi times out and the torch fallback's device queries fail
with it, so /api/system reported available: False and Settings > Resources said
"No GPU detected" on a host that had reported its GPU one poll earlier.

get_backend_visible_gpu_info now keeps the last inventory that found devices (per device
type and visibility mask) and returns it marked stale, with live usage unknown, until a
probe answers again. Only nvidia-smi answering with zero rows counts as proof there is no
GPU; a failed read with no earlier inventory still reports none.
@danielhanchen

Copy link
Copy Markdown
Member Author

Added 01dbe8e: on a congested driver nvidia-smi times out and the torch fallback fails with it, so /api/system reported no GPU and Settings > Resources said "No GPU detected" one poll after showing the card. The last inventory that found devices is now kept (marked stale, live usage unknown) until a probe answers again; only nvidia-smi answering with zero rows reports none. New tests/test_gpu_inventory_stale.py (5 tests, all fail on main); the 13 test files touching the probe pass (991).

@danielhanchen danielhanchen self-assigned this Sep 27, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 27, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 45c6363b07

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 27, 2026
@danielhanchen
danielhanchen merged commit 0d2905f into main Sep 27, 2026
57 of 60 checks passed
@danielhanchen
danielhanchen deleted the studio-nvidia-smi-cache branch September 27, 2026 12:29
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…#11995)

* Studio: cache and coalesce nvidia-smi reads in the backend

Every nvidia-smi call in studio/backend now goes through
utils/hardware/gpu_query.run_nvidia_smi, a drop-in for subprocess.run:

- concurrent identical queries share one child process
- static queries (-L, name/memory.total, compute_cap) are cached for
  600 s and dropped on hardware re-detection
- live queries are cached for 1 s by default (fit checks, placement,
  GPU selection) and for 3 s with stale-while-revalidate under
  display_reads() (the hardware panel polls)
- a generation counter (utils/gpu_memory_events.py) is bumped on every
  model load/unload, training start/stop and llama-server spawn; a
  decision-critical read never reuses an older sample
- fresh_reads() bypasses the cache for VRAM settle loops and fenced
  readings
- the caller waits only its own timeout; subprocess.run's unbounded
  wait() after killing a child stuck in the driver no longer holds a
  request
- when the CLI does not answer: last good answer (for fit checks only a
  recent same-generation sample, rewritten to the lowest free / highest
  used seen), then NVML via studio/nvidia_probe.py, then the caller's
  existing fallback exactly as before

Non-NVIDIA hosts, missing nvidia-smi and non-zero exits are unchanged.
UNSLOTH_GPU_QUERY_CACHE=0 disables the layer.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: never answer a fit check from an old nvidia-smi reading

A timed-out fit check used to get the lowest free memory seen in the last 60 s.
Memory another process allocated since then was invisible to it, while the old
code fell back to a fresh torch or NVML reading. Fit checks now take only a new
NVML reading or the caller's own fallback, never join a child older than the
critical TTL, and do not start another child behind a stuck one. Display reads
may be at most 60 s stale instead of 300 s.

* Studio: fit checks always read nvidia-smi afresh; keep llama.cpp's own timeout fallback

A fit check (placement, GPU auto-selection, training coexistence) reused a reading
up to 1 s old or joined a query already in flight. Another process's allocation
raises no Studio event, so that window could pick a GPU that had just filled up.
Critical reads now always start their own nvidia-smi and wait their whole timeout,
as before. The NVML stand-in on a hung CLI is removed: it returned the parent GPU
for a MIG slice and ignored CUDA_VISIBLE_DEVICES, while llama.cpp's own NVML branch
handles both. Static reads no longer join a query started before a re-detection.

* Studio: key cached nvidia-smi answers on the resolved binary; test concurrent fit checks

A PATH change must not be answered by a different nvidia-smi's cached output. The
lookup never raises. Adds a 16-thread test that every fit-check answer is a reading
taken after its call began, and makes the MIG fallback test fail when a whole-GPU
NVML answer stands in for llama.cpp's own fallback.

* Studio: invalidate the GPU memory cache around the sd.cpp load thread

* Studio: keep the last good GPU inventory when a probe times out or fails

On a congested driver nvidia-smi times out and the torch fallback's device queries fail
with it, so /api/system reported available: False and Settings > Resources said
"No GPU detected" on a host that had reported its GPU one poll earlier.

get_backend_visible_gpu_info now keeps the last inventory that found devices (per device
type and visibility mask) and returns it marked stale, with live usage unknown, until a
probe answers again. Only nvidia-smi answering with zero rows counts as proof there is no
GPU; a failed read with no earlier inventory still reports none.

* Trim comments in nvidia-smi query cache change

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio tests: reset the last good GPU inventory between tests

* Studio: drop a cached inventory once nvidia-smi answers with no rows; key the last good inventory on ROCR_VISIBLE_DEVICES

* Studio: a failed or empty nvidia-smi answer replaces the cached one; no pre-load display reading on timeout

* Studio: cache the nvidia-smi GPU inventory for 60 s, like the eGPU-aware physical inventory

* Studio: an expired GPU inventory waits for a new nvidia-smi answer; check=True failures replace cached answers

* Studio: treat nvidia-smi 'No devices were found' as an answer; never wait on a hung inventory child

* Studio: invalidate GPU readings on STT and diffusion training lifecycles; an older inventory probe never overrides a newer one

* Studio: /api/system reads a new nvidia-smi answer on each cache miss instead of serving the previous one

* Studio: keep the last good GPU inventory on NVIDIA only; other backends behave as on main

* Trim comments in nvidia-smi query cache change

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant