Skip to content

fix auto-install mapping torch 2.7.1 to torch271 extra - #18348

Merged
danielhanchen merged 2 commits into
unslothai:mainfrom
DimitriChrysafis:fix-torch271-auto-install
Nov 23, 2026
Merged

danielhanchen merged 2 commits into
unslothai:mainfrom
DimitriChrysafis:fix-torch271-auto-install

Conversation

@DimitriChrysafis

Copy link
Copy Markdown
Contributor

The auto-install script currently prints a torch270 extra for PyTorch 2.7.1. The project defines a separate torch271 extra with a different xFormers version.

Move the cutoff from 2.7.9 to 2.7.1 so 2.7.0 keeps torch270 and 2.7.1 selects torch271. The matrix tests cover cu118, cu126, and cu128 and check that the selected extras exist. All 73 installer tests passed locally.

@LeoBorcherding LeoBorcherding left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tested at 36acd07d against base f95a5b1 on a Colab T4 (Python 3.12). Each row is a clean venv with torch==X from the cu126 index, then the printed command run as-is. That command installs unsloth from main, which is fine here because the PR only changes _auto_install.py, the script that picks the extra.

torch before side extra torch after xformers
2.7.0 both (same extra, installed once) cu126-torch270 2.7.0, kept 0.0.30, works
2.7.1 base cu126-torch270 2.7.0, downgraded (uninstalls 2.7.1, pulls 865 MB of torch 2.7.0) 0.0.30
2.7.1 this PR cu126-torch271 2.7.1, kept 0.0.31.post1, works, 10-step SFT 2.99 to 0.39
2.8.0 both (same extra, installed once) cu126-torch280 2.8.0, kept 0.0.32.post2, works

On base, the torch271 line could never be reached, because no torch release falls between 2.7.9 and 2.8.0 (_auto_install.py:30). The new test fails 4 of 9 cases against base's script (all four are 2.7.1) and passes 9 of 9 here. For every released torch version, the extra the script prints exists in pyproject.toml.

Outside this PR: cu126onlytorch280 points at the cu128 xformers wheel (pyproject.toml:455-457). It still ran fine on the T4.

Not tested: cu118/cu128 installs (same path, different tag; unit tests only), Windows, and Pythons other than 3.12.

@LeoBorcherding LeoBorcherding left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-checked at d8f257b8 on a MacBook Pro M5 (macOS 26, Python 3.12). This is a logic test: _auto_install.py runs against a stand-in torch module and nothing gets installed. The real installs on the Colab T4 are in the first review.

I ran it for every torch and CUDA pair on download.pytorch.org from 2.1.0 on: 75 pairs, each with and without the +cuNNN tag, so 150 runs. Against base f95a5b1f, only the six 2.7.1 runs (cu118, cu126, cu128) change, from torch270 to torch271, and every extra the script prints exists in pyproject.toml. Pairs the script doesn't support (cu129, cu132, cu134, torch 2.14.1 and 2.15.0) raise the same error on base and here.

run base f95a5b1f script this PR
test_torch2110_cuda_extras.py -k torch27 (9 cases) 4 failed (all 2.7.1), 5 passed 9 passed
all of test_torch2110_cuda_extras.py 73 passed

Pushed d8f257b8 to this branch. The torch260 boundary row used 2.6.1+cu124, but torch 2.6.1 was never released, so it's now 2.6.0+cu124. _auto_install.py is unchanged. Codex on our mirror found no issues at this head.

The real cu128 install is done too: a Colab T4 (Python 3.12), one VM, a clean venv per side with torch==2.7.1 from the cu128 index, then _auto_install.py from base f95a5b1f and from d8f257b8, and the printed command run as-is. The command installs unsloth from main, which is fine because this PR only changes _auto_install.py.

base f95a5b1f this PR d8f257b8
extra it prints cu128-torch270 cu128-torch271
torch after install 2.7.0+cu126: uninstalls 2.7.1+cu128 and torchvision, and drops to CUDA 12.6 2.7.1+cu128, kept
xformers 0.0.30 0.0.31.post1
memory_efficient_attention on the T4 works works
10-step LoRA SFT, SmolLM2-135M loss 0.708 to 0.598 loss 0.708 to 0.598

So on cu128, base doesn't just downgrade torch, it also swaps the CUDA 12.8 build for the default PyPI CUDA 12.6 one, because the xformers 0.0.30 wheel in the torch270 extra pulls plain torch==2.7.0. This PR keeps the user's torch and CUDA build. Nothing else is outstanding from my side.

danielhanchen added a commit that referenced this pull request Nov 19, 2026
…treaming without diffusers (#18535)

## Summary

`(Python 3.13, diffusion)` fails on `main` for every PR (seen on #18526
and #18348, neither of which touches diffusion). Four tests, from two
recent merges:

```
FAILED tests/test_diffusion_backend.py::test_apply_loras_quant_unbaked_requires_reload
FAILED tests/test_diffusion_backend.py::test_apply_loras_quant_baked_matrix
    Expected regex: 'Reload the model with the adapter selection'
    Actual message: 'This INT8 build was loaded without LoRA adapters, ... Reload the model with the LoRA selection: on the Images page click Reapply ...'
FAILED tests/test_diffusion_te_residency.py::test_release_streams_and_restore_unhooks_with_identical_outputs
    assert 0 == 4   (release('test') == r.mib)
FAILED tests/test_diffusion_te_residency.py::test_a_restore_that_runs_out_of_memory_keeps_streaming
    assert True is False
```

## Root causes

**LoRA reload refusal (#18420).** #18420 turned this refusal into
`LoraReloadRequiredError` and rewrote its message to name the remedy
(Reapply on the Images page, or `loras` in `/images/load`). The routes
key on the type (`X-Unsloth-Refusal: lora-reload`, `error.code =
"lora_reload_required"`). The two tests still matched the old wording.
The behaviour is intended; the tests pinned prose.

**Encoder residency streaming (#18424).** `EncoderResidency.release()`
streams the text encoders through diffusers' group offloading. The
`(Python 3.13, diffusion)` lane does not install diffusers (the same log
shows `No module named 'diffusers'` skips), so the stream fails,
`release()` correctly keeps the encoders resident and returns 0, and the
two tests that need a real stream fail. The module is right to refuse;
the tests needed diffusers and did not say so.

## Changes

- `test_diffusion_backend.py`: both tests assert
`pytest.raises(LoraReloadRequiredError, match = "Reload the model with
the LoRA selection")`, the typed refusal plus the remedy phrase both
messages share.
- `test_diffusion_te_residency.py`: the two streaming tests are marked
to skip when `importlib.util.find_spec("diffusers") is None`. Only the
absence of diffusers skips: with diffusers installed, a regression in
Unsloth's streaming still fails them. The tests that do not stream (host
RAM refusal, a failed stream putting the encoders back) keep running
everywhere.

Test-only change.

## Testing

- With diffusers 0.43.0 (current release) on a CPU host: `pytest
tests/test_diffusion_te_residency.py tests/test_diffusion_backend.py`:
733 passed, the two streaming tests included.
- Sabotage: raising a plain `LoraSelectionError` instead of
`LoraReloadRequiredError` fails both LoRA tests.
- The no-diffusers lane is the `(Python 3.13, diffusion)` job on this
PR.
@danielhanchen danielhanchen self-assigned this Nov 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T10:39:20.183283Z d8f257b 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

Copy link
Copy Markdown

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

Reviewed commit: d8f257b8f3

ℹ️ 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 da27704 into unslothai:main Nov 23, 2026
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.

3 participants