Skip to content

Look for nvidia-smi everywhere it actually is - #11119

Merged
danielhanchen merged 10 commits into
mainfrom
av-fp-nvsmi-discovery
Sep 17, 2026
Merged

danielhanchen merged 10 commits into
mainfrom
av-fp-nvsmi-discovery

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Based on main, independent of the other installer PRs open right now.

The problem

$HasNvidiaSmi does not mean "nvidia-smi exists". It means "an NVIDIA GPU is present", and the wheel index decision hangs off it. A host where nvidia-smi is not found silently gets CPU-only PyTorch, and nothing in the transcript says why.

Two directories were searched. There are real hosts where a real GPU sits in neither:

Location Why it is missed today
SysNative From a 32-bit process, System32 is redirected to SysWOW64, which has no nvidia-smi. SysNative is the alias that reaches the real System32.
ProgramW6432 In that same process $env:ProgramFiles is Program Files (x86). ProgramW6432 is the 64-bit tree whatever the process bitness.
Program Files (x86) Not the driver's own location, but a machine that once had a 32-bit toolkit can carry a working copy.
DriverStore\FileRepository Where the driver package itself lives. Present on hosts where the copy into System32 did not happen, which is the #9255 population.

There were also three separate candidate lists, twice in install.ps1 and once in studio/setup.ps1, and they disagreed with each other.

The change

One shared Get-NvidiaSmiCandidatePaths replaces all three, character-identical between install.ps1 and studio/setup.ps1, the same way the driver-library inventory already is, and asserted to stay that way.

No native call, no new type, no process spawn added on the common path. This is the part of the NVIDIA work that has zero antivirus surface and is worth doing on its own merits.

One deliberate behaviour change

The two call sites disagreed on whether System32 or the legacy NVSMI directory came first, and a single list cannot keep both orders. System32 wins, because that is where the current driver puts its copy; NVSMI is the legacy location and a machine carrying both can have an older binary there reporting an older CUDA version.

This affects only a host that has nvidia-smi in both places, and only in which of two working binaries answers. Nothing is removed from either list.

The DriverStore scan is bounded on purpose: that directory holds every driver package the machine has ever had, so it is filtered to NVIDIA's own prefix and the newest few by write time, never walked whole. Candidates reached two ways are probed once, since each probe is a process spawn with a wall-clock bound behind it.

Testing

New tests/studio/test_nvidia_smi_discovery.ps1, 12 checks, wired into cross-platform-parity-ci.yml on both the pwsh 7 and the Windows PowerShell 5.1 legs.

It drives the real list against a planted filesystem rather than reading the source. Each location gets its own row with exactly one copy planted, so a location dropped from the list fails on its own check and is not masked by another. There are two controls: nothing planted must find nothing, and a machine missing every directory must not throw.

Five mutations were introduced and each was caught by its own check and no other: dropping SysNative, dropping ProgramW6432, unbounding the DriverStore scan, removing the deduplication, and no longer testing that the file exists.

tests/studio/install/test_woa_torch_index_persistence.py has two guards that this moves. Both were updated to follow the indirection rather than weakened, and the second caught a real break while I was making it: the composed pwsh scripts inject function bodies by name, and they were injecting a body that now reaches a helper they were not also injecting. PowerShell writes an error and carries on with $null, so that would have been a silent false pass.

Full sweep of tests/python and tests/studio: 14833 passed, 385 skipped. The 10 failures in that run are present on main unchanged and none is introduced here.

No effect on installation, update, shortcuts or login

Nothing about what is installed, where it goes, or how it is launched changes. The only difference is that some hosts with an NVIDIA GPU now find it, where before they were sent to CPU-only wheels.

HasNvidiaSmi does not mean nvidia-smi exists. It means an NVIDIA GPU is
present, and the wheel index decision hangs off it: a host where nvidia-smi
is not found silently gets CPU-only PyTorch.

Two directories were searched, and there are real hosts where a real GPU sits
in neither of them:

  SysNative      From a 32-bit process, System32 is redirected to SysWOW64,
                 which has no nvidia-smi. SysNative reaches the real one.
  ProgramW6432   In that same process ProgramFiles is Program Files (x86).
  x86 tree       A machine that once had a 32-bit toolkit can carry a copy.
  DriverStore    Where the driver package itself lives, present on hosts
                 where the copy into System32 did not happen (#9255).

There were also three separate candidate lists, in install.ps1 twice and
studio/setup.ps1 once, and they disagreed. One shared
Get-NvidiaSmiCandidatePaths replaces all three, character-identical between
the two files the same way the driver-library inventory already is.

Nothing is removed. One ordering does change and is worth stating plainly:
the call sites disagreed on whether System32 or the legacy NVSMI directory
came first, and a single list cannot keep both. System32 wins, because that
is where the current driver puts its copy and a machine carrying both can
have an older binary under NVSMI reporting an older CUDA version. It affects
only a host that has both, and only in which of two working binaries answers.

The DriverStore scan is bounded on purpose: that directory holds every driver
package the machine has ever had, so it is filtered to NVIDIA's own prefix and
the newest few by write time, never walked whole. Candidates reached two ways
are probed once, because each probe is a process spawn with a wall-clock bound.

No native call and no new type, so this adds nothing to the scanned surface.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 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 ✅ Completed 2026-09-17T12:23:00.214135Z 420d4f1 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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 16, 2026
…t one found

An adversarial audit of this PR found the regression the reordering could
cause, and it was right.

Listing a GPU is not the same as being able to report a CUDA version. A
partially installed or stale utility answers -L and still prints a banner
Get-TorchIndexUrl cannot parse, and that path falls back to cu126. Taking the
first binary that merely lists a GPU could therefore hand a cu128-capable
host cu126, purely because of which directory is searched first, which is the
one thing this change alters.

The loop now makes two passes: prefer a candidate that answers both
questions, and settle for one that only lists a GPU if none does. That second
half matters as much as the first, since without it a host whose only
nvidia-smi cannot name a version would go from detected to not detected at
all.

Driven rather than read: two candidates both list a GPU, only the second
names a version, and the second must win. Reverting to the single pass fails
that check; dropping the fallback fails the one beside it.
@danielhanchen

Copy link
Copy Markdown
Member Author

Adversarial verification pass, and the regression it found in this PR

I ran this through an independent adversarial audit whose brief was to falsify the claim that this is a pure hardening change. It found one genuine regression, in the single behaviour this PR deliberately alters, and it was right.

Preferring System32 could downgrade the CUDA family

Listing a GPU is not the same as being able to report a CUDA version. A partially installed or stale utility answers -L and still prints a banner Get-TorchIndexUrl cannot parse, and that path falls back to cu126.

So with both binaries present and only the legacy one able to name a version:

Condition Before this PR After, as first written
Both answer -L; NVSMI reports CUDA 12.8; the System32 banner has no parseable version; no driver library NVSMI, cu128 System32, cu126

That is a real downgrade caused purely by which directory is searched first, which is the one thing this PR changes.

Fixed in aa90a39a3. The detection loop now makes two passes: prefer a candidate that answers both questions, and settle for one that only lists a GPU if none does. The second half matters as much as the first, because without it a host whose only nvidia-smi cannot name a version would go from detected to not detected at all.

Driven rather than read, against the real loop with two stubbed candidates:

PASS  the candidate that reports a CUDA version wins over the one searched first
PASS  with no version anywhere, the first listing candidate is still taken

Reverting to the single pass fails the first; dropping the fallback fails the second.

What the audit did not find

  • No persistent writes. Get-NvidiaSmiCandidatePaths is read-only: Test-Path and a bounded Get-ChildItem, nothing else. Scanned the whole function body for write operations.
  • No new work on a healthy host. A PATH binary that passes Test-NvidiaSmiHasGpu sets $HasNvidiaSmi and the candidate list is never reached, in both install.ps1 and studio/setup.ps1. Confirmed by AST routing: one definition, call sites guarded by -not $HasNvidiaSmi, and every straight-line call after its definition.
  • No AMD or Intel suppression. Finding an NVIDIA executable is not enough; -L must report a GPU, exactly as before.
  • No effect on the release or update path beyond the script bytes themselves, which is what any installer change does.

Cross-platform

Staging CI on six OSes: Linux x64, Linux ARM64, Windows x64, Apple Silicon macOS, Intel macOS, Windows ARM64. One Intel macOS run failed on pwsh itself crashing at startup (Microsoft.PowerShell.ManagedPSEntry+StartupException, procargs errno 5) inside a test class this PR does not touch, at 1 failed / 785 passed; re-running to confirm it is environmental rather than assuming it.

Local: tests/studio/install/test_woa_torch_index_persistence.py plus the parity suites, 1057 passed, 1 skipped. Full tests/python and tests/studio sweep, 14833 passed, with the same 10 failures that are present on main unchanged.

One guard this PR nearly broke, and did not

test_every_composed_script_injects_the_helper_its_bodies_call caught that the composed pwsh scripts were injecting a function body that now reaches a helper they were not also injecting. PowerShell writes an error and carries on with $null, so that would have been a silent false pass. Both guards in that file follow the new indirection rather than being weakened.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 16, 2026
…h bitnesses

Two ordering defects in the candidate list, both raised on the PR.

In a 32-bit PowerShell $env:ProgramFiles is the x86 tree, so the first Program
Files rung searched was the one an old 32-bit CUDA toolkit leaves behind. That
copy is a working binary: it lists the GPU and reports its own older CUDA
version, so the two-pass CUDA preference does not rescue it. SysNative and
ProgramW6432, which reach the 64-bit locations whatever the process bitness,
now come first.

The DriverStore bound was applied to the nv* name matches rather than to the
directories that actually hold nvidia-smi. NVIDIA ships several packages whose
names start nv and contain no nvidia-smi at all, so a machine that installed
the HD audio or virtual audio driver after its display driver spent the whole
allowance of eight on directories with nothing in them and reported no
nvidia-smi found. The existence test now runs before the limit. It is a file
check, not a process spawn; the bound that costs anything is the one on the
candidates handed back, and that is unchanged.

Three checks added, each driven against a fake filesystem rather than read out
of the source, and each verified to fail when its fix is reverted.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 16, 2026
Every candidate gets its own bounded runner, and on a host with a wedged NVIDIA
driver each one waits out that bound before failing. Broadening the search made
the list longer, so what used to be two stalls can now be ten, and all of it is
spent in front of a driver-library fallback that answers in milliseconds.

One deadline of 30 seconds across the loop. The bound is on time rather than on
the number of candidates because time is the cost being controlled: a machine
where every probe answers at once still tries them all, and one where they hang
stops early. It can never skip the loop outright, so a slow machine still gets
looked at before being reported as having no GPU. Get-Date rather than a
Stopwatch, since Constrained Language Mode refuses the method calls and this
runs on hosts that enforce it.

Driven with probes that really sleep, because the thing under test is elapsed
time and a stubbed clock would only prove the arithmetic. Five checks: the loop
stops early on a wedged host, still probes at least once, still reports the GPU
it did find, stays near the deadline rather than scaling with the candidate
count, and, as a control, walks every candidate when nothing hangs.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 16, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 16, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Test-NvidiaSmiHasGpu records whether the binary it just probed timed out, and
its own comment says what matters is whether the one it settled on answered.
The two-pass loop broke that: it keeps probing after the candidate it will
settle on, so a later copy that hangs leaves the flag set for ITS path while an
earlier working binary is the one chosen.

Downstream that flag decides whether to ask the selected nvidia-smi for the GPU
name, the compute capability and the driver version. All three would have been
skipped on a perfectly good binary because a different copy elsewhere on the
machine hung, and the compute capability is the one that feeds
-DCMAKE_CUDA_ARCHITECTURES.

The state is captured beside the path and restored with it. Captured rather
than assumed false: it is false today only because a candidate becomes the
first listing when its -L probe succeeded, which is a property of the predicate
rather than of this loop.

Three checks: the working candidate is still the one selected, a later hang no
longer marks it wedged, and, as a control, a selected binary that did itself
hang is still reported wedged so the guard is not simply disabled.

Also bounded the read-only slice in that suite by the next statement instead of
a fixed 1400 characters, which stopped short the moment a comment was added and
failed for a reason unrelated to the loop.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed studio/setup.ps1 still searches only the two directories on main, so a driver that lives in the DriverStore or is reached from a 32-bit process is missed and the host gets CPU-only wheels; the two-pass CUDA preference and the wedge-flag restore both look right to me, so I will get this reviewed.

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed studio/setup.ps1 still searches only the two directories on main, so a driver that lives in the DriverStore or is reached from a 32-bit process is missed and the host gets CPU-only wheels; the two-pass CUDA preference and the wedge-flag restore both look right to me, so I will get this reviewed.

The deadline I added had one budget and a break in the failure branch, so a
single slow FAILING probe ended the whole search. A machine whose System32 copy
is broken and whose legacy NVSMI copy works lost its GPU entirely and went to
CPU-only PyTorch. That is strictly worse than the stall the deadline exists to
prevent, and the comment above the break claimed it could not happen: it looked
exactly once and then gave up.

Two budgets now, because stopping early means two different things.

The soft budget, 30 seconds, applies only once a usable nvidia-smi is already
in hand and the loop is just looking for a better CUDA banner. Giving that up
costs at most a wheel family.

The hard budget, 60 seconds, is the only thing allowed to end the search with
nothing found, because that outcome is CPU wheels on a machine with a GPU. The
expensive answer is now the one that costs the most before it is reached.

Candidate enumeration also moved out in front of both clocks. It is Test-Path
calls, but on a host with a filesystem filter driver it is not free, and
charging discovery to the probe budget is another way a slow disk becomes no
GPU.

Five checks: a slow failing first probe no longer ends the search and the
working copy behind it is still found; the hard bound still stops an unbounded
walk; it spends the hard budget rather than the soft one before giving up; and
a control that giving up empty-handed really does report no GPU, so the first
two cannot pass by the loop never terminating.
…xists

Get-WoaNvidiaSmiPath handed the first EXISTING candidate to
Test-WoaNvidiaPresent and Get-WoaDriverCudaVersion, and both treat a non-answer
as "no NVIDIA on this machine". So a broken copy at the front of the list does
not cost a retry, it declines the native ARM64 CUDA stack outright and the host
falls back to the x64 route.

That was survivable when two locations were searched. It is not survivable now
that this PR made the list longer, because every location added is another
chance that the first entry is a stale copy sitting in front of a working one.
This is the same defect the main detection loop was already fixed for, in a
function that kept the old shape.

It now returns the first candidate whose -L probe lists a GPU, and falls back
to the first that exists when nothing answers, so a host where the probe cannot
run is exactly where it was before. Memoised, because both callers probe and
the list would otherwise be walked twice with a bounded process spawn per
entry, and reset per run since under `irm | iex` the script scope is the
caller's session.

Four checks: a stale copy in front is skipped, the probe really ran rather than
the name being pattern-matched, a second call is served from the memo, and with
nothing answering the old first-existing behaviour is preserved.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 17, 2026
…two-pass

Three items, two of them consequences of the previous commit.

The deadline was only checked at the top of the loop. The listing probe that
just returned can have spent most of its own bound, and the banner probe has a
full bound of its own, so a candidate starting just inside the deadline could
add nearly twice the per-probe timeout after it. Rechecked before the banner
runs, where there is already a usable answer to fall back on.

Get-WoaNvidiaSmiPath probed without any aggregate bound, so a wedged driver
plus retained DriverStore copies held Initialize-WoaNativeCudaTorch for minutes
before the install started. It now carries the same soft and hard budgets as
the main loop, for the same reasons.

It also cached the first candidate that merely LISTED a GPU.
Get-WoaDriverCudaVersion asks that same binary for the CUDA banner, and a null
answer does not just lose a version: it skips the CUDA-major compatibility
guard, which is what stops a native wheel newer than the installed driver being
selected. It now prefers a candidate answering both, keeps a listing-only one as
the next choice, and still falls back to the first that exists.

Seven checks. Two of them replaced a pair that did NOT bite: "fewer than ten
banner probes" and "under eight seconds" both held with the fix reverted,
because at 1.8 s per candidate the top-of-loop check stops the walk one
candidate later either way. The exact banner count is what separates them, and
that is what is asserted now, mutation-tested in both directions.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 17, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The direct-binary list already probes both System32 and SysNative, with a comment saying why:
in a 32-bit PowerShell on 64-bit Windows the name System32 is redirected to SysWOW64, and
SysNative is the only spelling that reaches the real one. The DriverStore scan added in this PR
did not get the same treatment, so it looked in SysWOW64\DriverStore, which does not exist.

That misses exactly the population this change was written to recover: a host whose only
nvidia-smi.exe is inside the 64-bit driver package would still have been classified as having no
NVIDIA GPU, and would still have been handed CPU wheels.

Both spellings are now scanned, in install.ps1 and studio/setup.ps1 identically. At most one of
the two resolves in any given process, so this is not a doubled scan, and the eight-package
bound is applied to the whole DriverStore contribution rather than per root, so adding the
second spelling cannot double the number of probes even if both ever did resolve.

Tests: a host whose only nvidia-smi is under SysNative\DriverStore is found, and twelve packages
under each spelling still yield at most eight candidates. Three mutations injected, all three
caught, including the reported bug and a per-root bound.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 420d4f1777

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

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 17, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 420d4f1777

ℹ️ 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-only pass over install.ps1, studio/setup.ps1 and
tests/studio/test_nvidia_smi_discovery.ps1. No code changed.
@danielhanchen
danielhanchen merged commit 2f3cc59 into main Sep 17, 2026
7 of 48 checks passed
@danielhanchen
danielhanchen deleted the av-fp-nvsmi-discovery branch September 17, 2026 12:45
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
* Look for nvidia-smi everywhere it actually is

HasNvidiaSmi does not mean nvidia-smi exists. It means an NVIDIA GPU is
present, and the wheel index decision hangs off it: a host where nvidia-smi
is not found silently gets CPU-only PyTorch.

Two directories were searched, and there are real hosts where a real GPU sits
in neither of them:

  SysNative      From a 32-bit process, System32 is redirected to SysWOW64,
                 which has no nvidia-smi. SysNative reaches the real one.
  ProgramW6432   In that same process ProgramFiles is Program Files (x86).
  x86 tree       A machine that once had a 32-bit toolkit can carry a copy.
  DriverStore    Where the driver package itself lives, present on hosts
                 where the copy into System32 did not happen (unslothai#9255).

There were also three separate candidate lists, in install.ps1 twice and
studio/setup.ps1 once, and they disagreed. One shared
Get-NvidiaSmiCandidatePaths replaces all three, character-identical between
the two files the same way the driver-library inventory already is.

Nothing is removed. One ordering does change and is worth stating plainly:
the call sites disagreed on whether System32 or the legacy NVSMI directory
came first, and a single list cannot keep both. System32 wins, because that
is where the current driver puts its copy and a machine carrying both can
have an older binary under NVSMI reporting an older CUDA version. It affects
only a host that has both, and only in which of two working binaries answers.

The DriverStore scan is bounded on purpose: that directory holds every driver
package the machine has ever had, so it is filtered to NVIDIA's own prefix and
the newest few by write time, never walked whole. Candidates reached two ways
are probed once, because each probe is a process spawn with a wall-clock bound.

No native call and no new type, so this adds nothing to the scanned surface.

* Pick the nvidia-smi that can report a CUDA version, not just the first one found

An adversarial audit of this PR found the regression the reordering could
cause, and it was right.

Listing a GPU is not the same as being able to report a CUDA version. A
partially installed or stale utility answers -L and still prints a banner
Get-TorchIndexUrl cannot parse, and that path falls back to cu126. Taking the
first binary that merely lists a GPU could therefore hand a cu128-capable
host cu126, purely because of which directory is searched first, which is the
one thing this change alters.

The loop now makes two passes: prefer a candidate that answers both
questions, and settle for one that only lists a GPU if none does. That second
half matters as much as the first, since without it a host whose only
nvidia-smi cannot name a version would go from detected to not detected at
all.

Driven rather than read: two candidates both list a GPU, only the second
names a version, and the second must win. Reverting to the single pass fails
that check; dropping the fallback fails the one beside it.

* Search the current driver's nvidia-smi before any legacy copy, in both bitnesses

Two ordering defects in the candidate list, both raised on the PR.

In a 32-bit PowerShell $env:ProgramFiles is the x86 tree, so the first Program
Files rung searched was the one an old 32-bit CUDA toolkit leaves behind. That
copy is a working binary: it lists the GPU and reports its own older CUDA
version, so the two-pass CUDA preference does not rescue it. SysNative and
ProgramW6432, which reach the 64-bit locations whatever the process bitness,
now come first.

The DriverStore bound was applied to the nv* name matches rather than to the
directories that actually hold nvidia-smi. NVIDIA ships several packages whose
names start nv and contain no nvidia-smi at all, so a machine that installed
the HD audio or virtual audio driver after its display driver spent the whole
allowance of eight on directories with nothing in them and reported no
nvidia-smi found. The existence test now runs before the limit. It is a file
check, not a process spawn; the bound that costs anything is the one on the
candidates handed back, and that is unchanged.

Three checks added, each driven against a fake filesystem rather than read out
of the source, and each verified to fail when its fix is reverted.

* Bound the whole nvidia-smi search, not just each probe inside it

Every candidate gets its own bounded runner, and on a host with a wedged NVIDIA
driver each one waits out that bound before failing. Broadening the search made
the list longer, so what used to be two stalls can now be ten, and all of it is
spent in front of a driver-library fallback that answers in milliseconds.

One deadline of 30 seconds across the loop. The bound is on time rather than on
the number of candidates because time is the cost being controlled: a machine
where every probe answers at once still tries them all, and one where they hang
stops early. It can never skip the loop outright, so a slow machine still gets
looked at before being reported as having no GPU. Get-Date rather than a
Stopwatch, since Constrained Language Mode refuses the method calls and this
runs on hosts that enforce it.

Driven with probes that really sleep, because the thing under test is elapsed
time and a stubbed clock would only prove the arithmetic. Five checks: the loop
stops early on a wedged host, still probes at least once, still reports the GPU
it did find, stays near the deadline rather than scaling with the candidate
count, and, as a control, walks every candidate when nothing hangs.

* Keep the wedge flag describing the binary the loop actually selected

Test-NvidiaSmiHasGpu records whether the binary it just probed timed out, and
its own comment says what matters is whether the one it settled on answered.
The two-pass loop broke that: it keeps probing after the candidate it will
settle on, so a later copy that hangs leaves the flag set for ITS path while an
earlier working binary is the one chosen.

Downstream that flag decides whether to ask the selected nvidia-smi for the GPU
name, the compute capability and the driver version. All three would have been
skipped on a perfectly good binary because a different copy elsewhere on the
machine hung, and the compute capability is the one that feeds
-DCMAKE_CUDA_ARCHITECTURES.

The state is captured beside the path and restored with it. Captured rather
than assumed false: it is false today only because a candidate becomes the
first listing when its -L probe succeeded, which is a property of the predicate
rather than of this loop.

Three checks: the working candidate is still the one selected, a later hang no
longer marks it wedged, and, as a control, a selected binary that did itself
hang is still reported wedged so the guard is not simply disabled.

Also bounded the read-only slice in that suite by the next statement instead of
a fixed 1400 characters, which stopped short the moment a comment was added and
failed for a reason unrelated to the loop.

* Never let the probe budget end the search with no GPU found

The deadline I added had one budget and a break in the failure branch, so a
single slow FAILING probe ended the whole search. A machine whose System32 copy
is broken and whose legacy NVSMI copy works lost its GPU entirely and went to
CPU-only PyTorch. That is strictly worse than the stall the deadline exists to
prevent, and the comment above the break claimed it could not happen: it looked
exactly once and then gave up.

Two budgets now, because stopping early means two different things.

The soft budget, 30 seconds, applies only once a usable nvidia-smi is already
in hand and the loop is just looking for a better CUDA banner. Giving that up
costs at most a wheel family.

The hard budget, 60 seconds, is the only thing allowed to end the search with
nothing found, because that outcome is CPU wheels on a machine with a GPU. The
expensive answer is now the one that costs the most before it is reached.

Candidate enumeration also moved out in front of both clocks. It is Test-Path
calls, but on a host with a filesystem filter driver it is not free, and
charging discovery to the probe budget is another way a slow disk becomes no
GPU.

Five checks: a slow failing first probe no longer ends the search and the
working copy behind it is still found; the hard bound still stops an unbounded
walk; it spends the hard budget rather than the soft one before giving up; and
a control that giving up empty-handed really does report no GPU, so the first
two cannot pass by the loop never terminating.

* Give the ARM64 picker a binary that answers, not the first one that exists

Get-WoaNvidiaSmiPath handed the first EXISTING candidate to
Test-WoaNvidiaPresent and Get-WoaDriverCudaVersion, and both treat a non-answer
as "no NVIDIA on this machine". So a broken copy at the front of the list does
not cost a retry, it declines the native ARM64 CUDA stack outright and the host
falls back to the x64 route.

That was survivable when two locations were searched. It is not survivable now
that this PR made the list longer, because every location added is another
chance that the first entry is a stale copy sitting in front of a working one.
This is the same defect the main detection loop was already fixed for, in a
function that kept the old shape.

It now returns the first candidate whose -L probe lists a GPU, and falls back
to the first that exists when nothing answers, so a host where the probe cannot
run is exactly where it was before. Memoised, because both callers probe and
the list would otherwise be walked twice with a bounded process spawn per
entry, and reset per run since under `irm | iex` the script scope is the
caller's session.

Four checks: a stale copy in front is skipped, the probe really ran rather than
the name being pattern-matched, a second call is served from the memo, and with
nothing answering the old first-existing behaviour is preserved.

* Bound the banner probe and the ARM64 scan, and make the ARM64 picker two-pass

Three items, two of them consequences of the previous commit.

The deadline was only checked at the top of the loop. The listing probe that
just returned can have spent most of its own bound, and the banner probe has a
full bound of its own, so a candidate starting just inside the deadline could
add nearly twice the per-probe timeout after it. Rechecked before the banner
runs, where there is already a usable answer to fall back on.

Get-WoaNvidiaSmiPath probed without any aggregate bound, so a wedged driver
plus retained DriverStore copies held Initialize-WoaNativeCudaTorch for minutes
before the install started. It now carries the same soft and hard budgets as
the main loop, for the same reasons.

It also cached the first candidate that merely LISTED a GPU.
Get-WoaDriverCudaVersion asks that same binary for the CUDA banner, and a null
answer does not just lose a version: it skips the CUDA-major compatibility
guard, which is what stops a native wheel newer than the installed driver being
selected. It now prefers a candidate answering both, keeps a listing-only one as
the next choice, and still falls back to the first that exists.

Seven checks. Two of them replaced a pair that did NOT bite: "fewer than ten
banner probes" and "under eight seconds" both held with the fix reverted,
because at 1.8 s per candidate the top-of-loop check stops the walk one
candidate later either way. The exact banner count is what separates them, and
that is what is asserted now, mutation-tested in both directions.

* Reach the DriverStore through SysNative too, not only System32

The direct-binary list already probes both System32 and SysNative, with a comment saying why:
in a 32-bit PowerShell on 64-bit Windows the name System32 is redirected to SysWOW64, and
SysNative is the only spelling that reaches the real one. The DriverStore scan added in this PR
did not get the same treatment, so it looked in SysWOW64\DriverStore, which does not exist.

That misses exactly the population this change was written to recover: a host whose only
nvidia-smi.exe is inside the 64-bit driver package would still have been classified as having no
NVIDIA GPU, and would still have been handed CPU wheels.

Both spellings are now scanned, in install.ps1 and studio/setup.ps1 identically. At most one of
the two resolves in any given process, so this is not a doubled scan, and the eight-package
bound is applied to the whole DriverStore contribution rather than per root, so adding the
second spelling cannot double the number of probes even if both ever did resolve.

Tests: a host whose only nvidia-smi is under SysNative\DriverStore is found, and twelve packages
under each spelling still yield at most eight candidates. Three mutations injected, all three
caught, including the reported bug and a per-root bound.

* Tighten comments in the nvidia-smi discovery change

Comment-only pass over install.ps1, studio/setup.ps1 and
tests/studio/test_nvidia_smi_discovery.ps1. No code changed.

---------

Co-authored-by: danielhanchen <[email protected]>
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