Repository navigation
studio: select torchao version from the installed torch - #6400
Conversation
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.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
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.
| try: | ||
| major, minor = int(parts[0]), int(parts[1]) | ||
| except (IndexError, ValueError): | ||
| return _TORCHAO_DEFAULT_SPEC |
There was a problem hiding this comment.
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.
| 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 |
| 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, | ||
| ) |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| _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).
|
Thanks for the review. Addressed all three in 753feb5:
|
…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.
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.0pin, so torchao's C++ extensions load instead of being silently skipped.Why
A user reported (Windows, torch 2.10.0+cu130):
torchao then falls back to its pure-Python path (slower, no compiled kernels).
Root cause:
studio/install_python_stack.pypins CUDA torch totorch>=2.4,<2.11and its driver ladder selects thecu130wheel index on recent NVIDIA drivers, so pip resolvestorch 2.10.0.studio/backend/requirements/overrides.txthard-pinnedtorchao==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):
_select_torchao_spec(torch_version)is a small pure mapping (unit-tested). It ignores the local+cu130/+rocm/+cpusuffix and falls back to the previous0.14.0for any non-2.x major or unparseable/missing version._probe_installed_torch_version()readstorch.__version__from the venv via asys.executablesubprocess. This is cross-platform on purpose: the existingprobe_torch_wheel_env()returnsNoneoff-Linux, and the report is from Windows.pip_installcall. The flags are unchanged (--force-reinstall --no-cache-dir, plus--no-depson 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.txtnow 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
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.test_pytorch_mirror.pystill passes (no installer import regression).from torchao.quantization import Float8Tensorconfirmed importable on torchao 0.16.0 and 0.17.0.