Skip to content

Studio Linux update: torch repair and the source build read the NVIDIA driver library, a CPU wheel recorded as CUDA is repaired, a satisfied pin keeps the GPU prebuilt - #11008

Merged
danielhanchen merged 12 commits into
mainfrom
torch-repair-uses-inventory
Sep 15, 2026
Merged

danielhanchen merged 12 commits into
mainfrom
torch-repair-uses-inventory

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Three Linux gaps left after #10975 and #10985, all on the update path a Desktop or unsloth studio update run takes.

What was wrong

  • The pre-Turing torch repair was blind without nvidia-smi. _ensure_cuda_torch reads the host's compute capabilities from nvidia-smi only, so on a host where it is absent or stale the check that swaps a kernel-less cu128/cu130 wheel for cu126 returned early. Studio: read the NVIDIA inventory from NVML or the CUDA driver when nvidia-smi cannot answer #10985 taught the index selector to read the driver library; the repair beside it still did not.
  • A CPU wheel on a GPU host was never repaired on Linux. A dependency step that resolves torch from PyPI leaves +cpu behind, and an install that ran while the GPU was not detected records cpu automatically. Windows has the flavour invariant for this; Linux resolves the expected flavour and only records it, and _ensure_cuda_torch treated any CPU wheel without a CUDA pin as deliberate.
  • The source build turned CUDA off without nvidia-smi. setup.sh reads --query-gpu=compute_cap to choose CMAKE_CUDA_ARCHITECTURES, and an empty list means a CPU build (studio/setup.sh: validate source-built llama.cpp and guard empty CUDA arch detection #5854). The probe module beside it lists the same capabilities.
  • A version pin the old install already satisfied still refused to keep it. _gpu_prebuilt_to_keep_over_cpu_build treats any UNSLOTH_LLAMA_TAG / UNSLOTH_LLAMA_RELEASE_TAG pin as "not this install", so an update that failed to fetch the pinned release replaced the working GPU prebuilt of that very version with a CPU source build.

The change

  • _host_compute_sms() reads nvidia-smi first and the driver library second; _ensure_cuda_torch uses it, and _inventory_compute_sms is shared with _detect_cuda_torch_index_url (one unreadable row still voids the answer, as with nvidia-smi).
  • A CPU wheel on an NVIDIA host is repaired unless someone chose it: an explicit CPU index pin, UNSLOTH_TORCH_BACKEND=cpu, or a manifest that recorded cpu as named rather than automatically selected (the distinction recorded_torch_flavor_was_pinned exists for). A hidden GPU still leaves it alone. The message names the recorded CUDA family when there is one, so the next update after a CPU wheel slipped in puts CUDA torch back.
  • setup.sh's source build reads the capabilities from nvidia_probe.py when nvidia-smi gives none; UNSLOTH_NVIDIA_LIBRARY_PROBE=0 turns that off as everywhere else.
  • The keep guard compares a pin with the marker's tag / release_tag through _installed_prebuilt_ref_matches: an exact match, or the installer's own refs_match (branch aliases and commit prefixes, so a short commit pin matches the recorded full one), keeping the install when they match and replacing it otherwise.

Tests

  • tests/studio/install/test_cuda_repair.py: the inventory supplies the SMs when nvidia-smi cannot and a cu130 wheel on a Volta card is moved to cu126; no inventory stays blind; an unreadable row is not evidence; nvidia-smi still wins when it answers; a recorded cu128, no record, and an automatic cpu record each bring CUDA torch back over a CPU wheel; a named cpu record, an explicit CPU pin, UNSLOTH_TORCH_BACKEND=cpu, no GPU and a hidden GPU each leave it alone.
  • tests/studio/install/test_setup_keeps_gpu_prebuilt_over_cpu_source_fallback.py: a pin the old install satisfies keeps it and a different one replaces it, for both variables; the source-build fallback to the probe is present between the nvidia-smi read and the arch resolution.
  • Existing: the full CUDA repair suite, the keep-guard suite, test_gpu_detection_followups.py, test_nvidia_library_probe.py (407 passed) and tests/sh/test_resolve_cuda_archs.sh.

…PU wheel the install recorded as CUDA is repaired; a satisfied version pin keeps the GPU prebuilt
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 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-15T15:08:13.355587Z c7b5cc8 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.

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

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

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

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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

This comment was marked as resolved.

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

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: c7038336b6

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

Copy link
Copy Markdown
Member Author

From a CI sweep: your pre-commit.ci - pr failure is one wrapped condition.

--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -3933,7 +3933,9 @@ def _ensure_cuda_torch() -> None:
         and not _deliberate_cpu_torch()
-        and _is_cuda_family_leaf(_torch_index_leaf(_detect_cuda_torch_index_url(known_only = True) or ""))
+        and _is_cuda_family_leaf(
+            _torch_index_leaf(_detect_cuda_torch_index_url(known_only = True) or "")
+        )
     ):

Reproduced against c7038336b with the pinned ruff 0.6.9 over every file the hook selects: exactly one file, that hunk.

The reason it did not autofix itself is not yours. main is currently unformatted relative to its own hook, in three files from #10989 and #7536, so the autofix patch is computed over your merge tree and then will not apply to your head. Your run says so: a conflict occurred when applying fixes to the pr. #11019 formats main; once that lands, an empty push should let pre-commit.ci fix this one for you.

Not touching the branch, since you have it in flight.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: c7b5cc84a9

ℹ️ 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
danielhanchen merged commit 1ee14f0 into main Sep 15, 2026
55 of 59 checks passed
@danielhanchen
danielhanchen deleted the torch-repair-uses-inventory branch September 15, 2026 15:33
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…A driver library, a CPU wheel recorded as CUDA is repaired, a satisfied pin keeps the GPU prebuilt (unslothai#11008)

* Torch repair and the source build read the NVIDIA driver library; a CPU wheel the install recorded as CUDA is repaired; a satisfied version pin keeps the GPU prebuilt

* Match pinned refs the installer's way and fall back to the driver library after unparseable capabilities for PR unslothai#11008

* Register the installer module before importing it in the keep guard

* Exact match first for fork release tags; test the commit-prefix pin

* Repair any CPU torch nobody chose on an NVIDIA host at the next update

* Probe capabilities are all or nothing for the source build, for PR unslothai#11008

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

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

* Repair a CPU wheel only where the driver runs a CUDA wheel; compare published release pins exactly, for PR unslothai#11008

* A CUDA family named this run outranks the pinned cpu record, for PR unslothai#11008

* Match a commit pin against the marker's source ref fields too, for PR unslothai#11008

* Repair a CPU wheel only when the driver's CUDA family is known, for PR unslothai#11008

* Apply the repository kwarg spacing, for PR unslothai#11008

---------

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants