Skip to content

studio: select torchao version from the installed torch - #6400

Merged
danielhanchen merged 3 commits into
mainfrom
studio-torchao-version-match
Jun 17, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-torchao-version-match

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What

Studio's GGUF installer now picks the torchao version from the torch actually installed in the venv, instead of a fixed torchao==0.14.0 pin, so torchao's C++ extensions load instead of being silently skipped.

Why

A user reported (Windows, torch 2.10.0+cu130):

Skipping import of cpp extensions due to incompatible torch version 2.10.0+cu130 for torchao version 0.14.0

torchao then falls back to its pure-Python path (slower, no compiled kernels).

Root cause: studio/install_python_stack.py pins CUDA torch to torch>=2.4,<2.11 and its driver ladder selects the cu130 wheel index on recent NVIDIA drivers, so pip resolves torch 2.10.0. studio/backend/requirements/overrides.txt hard-pinned torchao==0.14.0, whose C++ extensions are built against torch 2.9.0. torch 2.10.0 is outside that build, so the cpp kernels are skipped. Every CUDA index (cu126/cu128/cu130) now tops out at torch 2.10.0, so this affects most modern installs, not just cu130. The torch pin and the torchao pin drifted apart as PyTorch shipped 2.10.

Fix

Select the torchao version matching the installed torch, per the official torchao compatibility table (pytorch/ao#2919):

installed torch torchao
2.10.x 0.16.0
2.11.x 0.17.0
<= 2.9 (and unknown/older) 0.14.0 (unchanged)
  • _select_torchao_spec(torch_version) is a small pure mapping (unit-tested). It ignores the local +cu130/+rocm/+cpu suffix and falls back to the previous 0.14.0 for any non-2.x major or unparseable/missing version.
  • _probe_installed_torch_version() reads torch.__version__ from the venv via a sys.executable subprocess. This is cross-platform on purpose: the existing probe_torch_wheel_env() returns None off-Linux, and the report is from Windows.
  • The override step passes the computed spec positionally to the same force-reinstall pip_install call. The flags are unchanged (--force-reinstall --no-cache-dir, plus --no-deps on Windows ROCm), so torch resolution behaves exactly as before; only the torchao version differs, and only for torch >= 2.10. torch <= 2.9 is byte-identical to today.
  • overrides.txt now documents that torchao is selected dynamically.

Backwards-compatible: torch <= 2.9 still gets torchao==0.14.0 (already the correct match for 2.9.0), so existing installs are unchanged.

Notes

Unsloth only consumes torchao's Python API (from torchao.quantization import Float8Tensor, unsloth/kernels/utils.py), which already tolerates torchao >= 0.15.0 and imports cleanly on 0.16.0 and 0.17.0 (verified against torch 2.9.1). So the change is safe for the Float8 path regardless of whether the cpp extensions load.

Tests

  • New studio/backend/tests/test_torchao_select.py (18 cases): the torch -> torchao mapping, local version suffixes ignored, patch levels, and unparseable/missing/non-2.x fall back to the default.
  • Existing test_pytorch_mirror.py still passes (no installer import regression).
  • from torchao.quantization import Float8Tensor confirmed importable on torchao 0.16.0 and 0.17.0.

The Studio installer pins CUDA torch to torch>=2.4,<2.11 and its driver
ladder selects the cu130 wheel index on recent NVIDIA drivers, so pip
resolves torch 2.10.0. overrides.txt hard-pinned torchao==0.14.0, whose
C++ extensions are built against torch 2.9.0, so torchao skipped its cpp
kernels ("Skipping import of cpp extensions due to incompatible torch
version 2.10.0+cu130 for torchao version 0.14.0") and fell back to the
slow Python path. Every CUDA index now tops out at torch 2.10.0, so this
hit most modern installs, not just cu130.

Pick the torchao version matching the torch actually installed in the
venv (table: pytorch/ao#2919): torch 2.10.x -> torchao 0.16.0, 2.11.x ->
torchao 0.17.0, otherwise the previous 0.14.0 (so torch <=2.9 is
unchanged). The installer reads torch.__version__ from the venv via a
cross-platform sys.executable probe (probe_torch_wheel_env is Linux-only)
and passes the computed spec positionally to the existing force-reinstall
override step; overrides.txt becomes a pointer to that logic. torchao's
Python API (Float8Tensor, used by unsloth/kernels/utils.py) imports
cleanly on 0.16.0/0.17.0, verified against torch 2.9.1.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the static torchao version pin in overrides.txt with a dynamic version selection mechanism in install_python_stack.py. It probes the installed PyTorch version in the virtual environment and installs the matching torchao version to ensure its C++ extensions are compatible and loaded correctly. Additionally, a new test suite is introduced to verify this mapping. Feedback on the changes includes making PyTorch version parsing more robust against pre-release or custom version strings, using _windows_hidden_subprocess_kwargs() when probing the PyTorch version to prevent console window flashing on Windows, and using _safe_print instead of print to avoid console encoding issues on Windows.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +131 to +134
try:
major, minor = int(parts[0]), int(parts[1])
except (IndexError, ValueError):
return _TORCHAO_DEFAULT_SPEC

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To make the version parsing robust against pre-release or custom PyTorch versions (e.g., 2.10b1 or 2.10rc1 where the minor version string contains non-numeric characters), we should strip any non-digit suffixes from the minor version string before converting it to an integer. This matches the pattern used in wheel_utils.py.

Suggested change
try:
major, minor = int(parts[0]), int(parts[1])
except (IndexError, ValueError):
return _TORCHAO_DEFAULT_SPEC
try:
minor_clean = re.sub(r"[^0-9].*", "", parts[1]) if len(parts) > 1 else ""
major, minor = int(parts[0]), int(minor_clean)
except (IndexError, ValueError):
return _TORCHAO_DEFAULT_SPEC

Comment on lines +148 to +158
probe = subprocess.run(
[
sys.executable,
"-c",
"import torch, sys; sys.stdout.write(getattr(torch, '__version__', ''))",
],
stdout = subprocess.PIPE,
stderr = subprocess.DEVNULL,
text = True,
timeout = 90,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

On Windows, spawning a subprocess without suppressing the console window can cause a brief console window flash/popup, which degrades the user experience. Since install_python_stack.py defines _windows_hidden_subprocess_kwargs() specifically to prevent this, we should pass it to subprocess.run here.

Suggested change
probe = subprocess.run(
[
sys.executable,
"-c",
"import torch, sys; sys.stdout.write(getattr(torch, '__version__', ''))",
],
stdout = subprocess.PIPE,
stderr = subprocess.DEVNULL,
text = True,
timeout = 90,
)
probe = subprocess.run(
[
sys.executable,
"-c",
"import torch, sys; sys.stdout.write(getattr(torch, '__version__', ''))",
],
stdout = subprocess.PIPE,
stderr = subprocess.DEVNULL,
text = True,
timeout = 90,
**_windows_hidden_subprocess_kwargs(),
)

else:
_progress("dependency overrides")
_torch_ver = _probe_installed_torch_version()
_torchao_spec = _select_torchao_spec(_torch_ver)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency and to prevent potential console encoding issues on Windows (especially when stdout is redirected), we should use _safe_print instead of the raw print function. _safe_print is defined in this file specifically to handle non-UTF-8 consoles safely.

Suggested change
_torchao_spec = _select_torchao_spec(_torch_ver)
_safe_print(f" torch {_torch_ver or 'unknown'} detected -- installing {_torchao_spec}")

- Clean the torch minor of pre-release/dev suffixes before parsing
  (e.g. '2.10rc1' -> minor 10), matching wheel_utils.probe_torch_wheel_env.
- Pass _windows_hidden_subprocess_kwargs() to the torch-version probe so
  it does not flash a console window on Windows (no-op elsewhere).
- Use _safe_print for the selection log line, consistent with the file's
  other status output (safe on non-UTF-8 consoles).
@danielhanchen

Copy link
Copy Markdown
Member Author

Thanks for the review. Addressed all three in 753feb5:

  • Strip any pre-release/dev suffix from the torch minor before parsing (e.g. 2.10rc1 -> minor 10), matching the re.sub(r"[^0-9].*", "", ...) pattern in wheel_utils.probe_torch_wheel_env. Added test cases for 2.10.0rc1, 2.10.0.dev...+cu130, and 2.10rc1.
  • Pass _windows_hidden_subprocess_kwargs() to the torch-version probe so it does not flash a console window on Windows (no-op on Linux/macOS).
  • Use _safe_print for the selection log line, consistent with the rest of the file.

@danielhanchen
danielhanchen merged commit f5f9e21 into main Jun 17, 2026
39 of 42 checks passed
@danielhanchen
danielhanchen deleted the studio-torchao-version-match branch June 17, 2026 11:09
danielhanchen added a commit that referenced this pull request Jun 18, 2026
…errides, UI re-login) (#6419)

* studio: set _stats_logger in kill-process test backend

#6377 added a self._stats_logger cleanup step to _kill_process's finally block.
test_kill_process_records_timestamp_on_actual_kill (added in #6400) builds the
backend via __new__, which bypasses __init__ where _stats_logger is set, so once
both landed on main the test raised AttributeError: 'LlamaCppBackend' object has
no attribute '_stats_logger'. Set _stats_logger on the hand-built backend,
mirroring __init__, so the kill path's finally has the attribute it expects.

* test: assert torchao override step on normal Linux, not overrides.txt

#6400 moved the torchao dependency override from a fixed pin in overrides.txt to
a torch-matched spec installed via --force-reinstall (_select_torchao_spec), and
turned overrides.txt into a comment-only pointer. It updated the Windows variant
(test_windows_only_includes_overrides) to check for --reinstall, but left
test_normal_linux_includes_overrides asserting overrides.txt is installed, which
no longer happens. Check for the override step (--reinstall) instead, matching
the Windows test.

* test(ui): tolerate ERR_ABORTED on /login re-login in shutdown step

The Shutdown step re-logs in after a CLI password rotation that revoked the prior
token. The SPA auth guard can client-side-redirect mid-navigation against the
stale token, aborting page.goto("/login") with net::ERR_ABORTED. It is a race
(passes on main most of the time). Resolve on domcontentloaded and tolerate the
abort, relying on the password-field wait that follows to confirm we reached
/login, matching the wait_until used by the other navigations in this file.
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.

1 participant