Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Core extras and auto-install support for torch 2.13 and 2.14
  • Loading branch information
danielhanchen committed Sep 27, 2026
commit 1d3b743338e071ebf2a12be7841b30758f615046
69 changes: 69 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,35 @@ cu130onlytorch2121 = [
"xformers @ https://download.pytorch.org/whl/cu130/xformers-0.0.35-py39-none-manylinux_2_28_x86_64.whl ; ('linux' in sys_platform) and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
"xformers @ https://download.pytorch.org/whl/cu130/xformers-0.0.35-py39-none-win_amd64.whl ; (sys_platform == 'win32') and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
]
# torch 2.13 / 2.14 also ship on cu126/cu130 only; torchaudio stops at 2.11.0.
cu126onlytorch2130 = [
"torch==2.13.0+cu126",
"torchvision==0.28.0+cu126",
"torchaudio==2.11.0+cu126",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Drop the incompatible torchaudio 2.11 pins

Every new torch 2.13/2.14 leaf pins torchaudio 2.11 even though torchaudio's native extension must match the torch release line; the repository's own install.ps1::Test-WoaWheelPairsWithTorch therefore explicitly rejects the 2.14/2.11 pairing. Because 2.11 no longer constrains torch in its metadata, dependency resolution succeeds but leaves audio operations with an ABI-mismatched extension, so these new extras should omit torchaudio unless a matching compatible build is available.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Checked on real wheels: torchaudio 2.11.0+cu130 ships abi3 (stable ABI) libraries, and on torch 2.13.0+cu130 and 2.14.0+cu130 its extension loads and forced_align, rnnt_loss and lfilter run on CPU and CUDA. The install.ps1 check is for the custom Windows on ARM builds, which are not abi3.

"xformers @ https://download.pytorch.org/whl/cu126/xformers-0.0.35-py39-none-manylinux_2_28_x86_64.whl ; ('linux' in sys_platform) and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
"xformers @ https://download.pytorch.org/whl/cu126/xformers-0.0.35-py39-none-win_amd64.whl ; (sys_platform == 'win32') and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
]
cu130onlytorch2130 = [
"torch==2.13.0+cu130",
"torchvision==0.28.0+cu130",
"torchaudio==2.11.0+cu130",
"xformers @ https://download.pytorch.org/whl/cu130/xformers-0.0.35-py39-none-manylinux_2_28_x86_64.whl ; ('linux' in sys_platform) and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
"xformers @ https://download.pytorch.org/whl/cu130/xformers-0.0.35-py39-none-win_amd64.whl ; (sys_platform == 'win32') and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
]
cu126onlytorch2140 = [
"torch==2.14.0+cu126",
"torchvision==0.29.0+cu126",
"torchaudio==2.11.0+cu126",
"xformers @ https://download.pytorch.org/whl/cu126/xformers-0.0.35-py39-none-manylinux_2_28_x86_64.whl ; ('linux' in sys_platform) and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
"xformers @ https://download.pytorch.org/whl/cu126/xformers-0.0.35-py39-none-win_amd64.whl ; (sys_platform == 'win32') and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
]
cu130onlytorch2140 = [
"torch==2.14.0+cu130",
"torchvision==0.29.0+cu130",
"torchaudio==2.11.0+cu130",
"xformers @ https://download.pytorch.org/whl/cu130/xformers-0.0.35-py39-none-manylinux_2_28_x86_64.whl ; ('linux' in sys_platform) and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
"xformers @ https://download.pytorch.org/whl/cu130/xformers-0.0.35-py39-none-win_amd64.whl ; (sys_platform == 'win32') and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",
]
cu118 = [
"unsloth[huggingface]",
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
Expand Down Expand Up @@ -870,6 +899,26 @@ cu130-torch2121 = [
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu130onlytorch2121]",
]
cu126-torch2130 = [
"unsloth[huggingface]",
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu126onlytorch2130]",
]
cu130-torch2130 = [
"unsloth[huggingface]",
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu130onlytorch2130]",
]
cu126-torch2140 = [
"unsloth[huggingface]",
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu126onlytorch2140]",
]
cu130-torch2140 = [
"unsloth[huggingface]",
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu130onlytorch2140]",
]
kaggle = [
"unsloth[huggingface]",
]
Expand Down Expand Up @@ -1207,6 +1256,26 @@ cu130-ampere-torch2121 = [
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu130onlytorch2121]",
]
cu126-ampere-torch2130 = [
"unsloth[huggingface]",
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu126onlytorch2130]",
]
cu130-ampere-torch2130 = [
"unsloth[huggingface]",
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu130onlytorch2130]",
]
cu126-ampere-torch2140 = [
"unsloth[huggingface]",
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu126onlytorch2140]",
]
cu130-ampere-torch2140 = [
"unsloth[huggingface]",
"bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0",
"unsloth[cu130onlytorch2140]",
]
flashattentiontorch260abiFALSEcu12x = [
"flash-attn @ https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.4.post1/flash_attn-2.7.4.post1+cu12torch2.6cxx11abiFALSE-cp39-cp39-linux_x86_64.whl ; ('linux' in sys_platform) and python_version == '3.9'",
"flash-attn @ https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.4.post1/flash_attn-2.7.4.post1+cu12torch2.6cxx11abiFALSE-cp310-cp310-linux_x86_64.whl ; ('linux' in sys_platform) and python_version == '3.10'",
Expand Down
64 changes: 62 additions & 2 deletions tests/test_torch2110_cuda_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""Regression guard: the CUDA torch2110 / torch212x extras must pin the torch trio to the
"""Regression guard: the CUDA torch2110 / torch212x / torch2130 / torch2140 extras must pin the torch trio to the
matching +cuXXX local build (xformers 0.0.35 does not pin torch), else resolution walks
torch up to a release the xformers wheel was not built for. Parses files only, no network.

Expand All @@ -41,10 +41,12 @@
PYPROJECT = REPO / "pyproject.toml"
AUTO_INSTALL = REPO / "unsloth" / "_auto_install.py"
_TORCH_TRIO = ("torch", "torchvision", "torchaudio")
# torchaudio has no 2.12 release, so the 2.12 leaves keep 2.11.0.
# torchaudio stops at 2.11.0 (stable ABI), so the 2.12+ leaves keep it.
_TORCH212_TRIO = {
"torch2120": {"torch": "2.12.0", "torchvision": "0.27.0", "torchaudio": "2.11.0"},
"torch2121": {"torch": "2.12.1", "torchvision": "0.27.1", "torchaudio": "2.11.0"},
"torch2130": {"torch": "2.13.0", "torchvision": "0.28.0", "torchaudio": "2.11.0"},
"torch2140": {"torch": "2.14.0", "torchvision": "0.29.0", "torchaudio": "2.11.0"},
}
_TORCH212_CUDA = ("cu126", "cu130")

Expand Down Expand Up @@ -175,6 +177,64 @@ def test_auto_install_rejects_cuda128_on_torch212():
assert 'if v >= V(\'2.12.0\') and cuda not in ("12.6", "13.0")' in source


def _run_auto_install(torch_version: str, cuda: str, capsys) -> str:
import sys
import types

fake = types.ModuleType("torch")
fake.__version__ = torch_version
fake.version = types.SimpleNamespace(cuda = cuda)
fake.cuda = types.SimpleNamespace(get_device_capability = lambda: (9, 0))
fake._C = types.SimpleNamespace(_GLIBCXX_USE_CXX11_ABI = True)
saved = sys.modules.get("torch")
sys.modules["torch"] = fake
try:
exec(compile(AUTO_INSTALL.read_text(encoding = "utf-8"), str(AUTO_INSTALL), "exec"), {})
finally:
if saved is None:
sys.modules.pop("torch", None)
else:
sys.modules["torch"] = saved
return capsys.readouterr().out


@pytest.mark.parametrize(
"torch_version, series",
[
("2.12.0+cu130", "torch2120"),
("2.12.1", "torch2121"),
("2.13.0+cu126", "torch2130"),
("2.14.0+cu130", "torch2140"),
],
)
@pytest.mark.parametrize("cuda", ["12.6", "13.0"])
def test_auto_install_selects_series(torch_version: str, series: str, cuda: str, capsys):
out = _run_auto_install(torch_version, cuda, capsys)
tag = cuda.replace(".", "")
assert f'"unsloth[cu{tag}-{series}] @' in out
assert f"--extra-index-url https://download.pytorch.org/whl/cu{tag}" in out


@pytest.mark.parametrize(
"torch_version, message",
[
("2.12.2", "not supported"),
("2.13.1", "not supported"),
("2.14.1", "too new"),
("2.15.0", "too new"),
],
)
def test_auto_install_rejects_unpinned_versions(torch_version: str, message: str, capsys):
with pytest.raises(RuntimeError, match = message):
_run_auto_install(torch_version, "13.0", capsys)


@pytest.mark.parametrize("torch_version", ["2.13.0", "2.14.0"])
def test_auto_install_rejects_cuda128_on_torch213_plus(torch_version: str, capsys):
with pytest.raises(RuntimeError, match = "requires CUDA 12.6 or 13.0"):
_run_auto_install(torch_version, "12.8", capsys)


@pytest.mark.parametrize("cuda", ["cu126", "cu128", "cu130"])
def test_cuda12_torch2100_keeps_torch_pinned_off_x86(cuda: str):
reqs = _reqs(_extra(f"{cuda}onlytorch2100"))
Expand Down
8 changes: 6 additions & 2 deletions unsloth/_auto_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@
elif v < V('2.12.0'): raise RuntimeError(f"Torch = {v} not supported!")
elif v < V('2.12.1'): x = 'cu{}{}-torch2120'
elif v < V('2.12.2'): x = 'cu{}{}-torch2121'
elif v < V('2.13.0'): raise RuntimeError(f"Torch = {v} not supported!")
elif v < V('2.13.1'): x = 'cu{}{}-torch2130'
elif v < V('2.14.0'): raise RuntimeError(f"Torch = {v} not supported!")
elif v < V('2.14.1'): x = 'cu{}{}-torch2140'
Comment on lines +44 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject cu126 builds on Blackwell before selecting the new extras

When torch 2.13/2.14 is installed from cu126 on an SM100/SM120 GPU, these branches now emit an install command even though the adjacent comment documents that cu126 stops at SM90 and Blackwell requires CUDA 13. The script already reads torch.cuda.get_device_capability() but never applies it, so the generated environment can install successfully and then fail when CUDA kernels run; reject this combination or require cuda == "13.0" when the capability is at least 10.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this here: the script only prints the extra matching the torch that is already installed, and torch 2.12 on main behaves the same way. A cu126 torch on a Blackwell card is already unusable before this runs, and the extra reinstalls that same build.

Comment on lines +44 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject prereleases before selecting stable extras

When an installed build reports a version such as 2.13.0rc1+cu130 or 2.13.0a0+cu130, the regex above truncates it to 2.13.0, so this new branch selects torch2130; the resulting extra exact-pins the stable torch==2.13.0+cu130 trio and replaces the prerelease/source build rather than refusing it. The same problem affects the new 2.14 branch, so inspect the full parsed version for prerelease/dev markers before mapping these stable-only extras.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same mapping every branch in this script uses: a 2.12.0rc1 build maps to torch2120 on main today. Prerelease handling would be a separate change across all the branches, not something these two lines introduce.

else: raise RuntimeError(f"Torch = {v} too new!")
if v > V('2.6.9') and cuda not in ("11.8", "12.6", "12.8", "13.0"): raise RuntimeError(f"CUDA = {cuda} not supported!")
if v >= V('2.10.0') and cuda not in ("12.6", "12.8", "13.0"): raise RuntimeError(f"Torch = {v} requires CUDA 12.6, 12.8, or 13.0! Got CUDA = {cuda}")
# torch 2.12 ships on cu126/cu130 only, and cu126 builds stop at sm_90, so Blackwell needs CUDA 13.
# torch 2.12+ ships on cu126/cu130 only, and cu126 builds stop at sm_90, so Blackwell needs CUDA 13.
if v >= V('2.12.0') and cuda not in ("12.6", "13.0"): raise RuntimeError(f"Torch = {v} requires CUDA 12.6 or 13.0! Got CUDA = {cuda}")
x = x.format(cuda.replace(".", ""), "-ampere" if False else "") # is_ampere is broken due to flash-attn
# torch2110+ extras pin +cuNNN builds, which resolve only from the matching index.
extra_index = f' --extra-index-url https://download.pytorch.org/whl/cu{cuda.replace(".", "")}' if (x.endswith(('-torch2110', '-torch2120', '-torch2121')) and cuda in ("12.6", "12.8", "13.0")) else ''
extra_index = f' --extra-index-url https://download.pytorch.org/whl/cu{cuda.replace(".", "")}' if (x.endswith(('-torch2110', '-torch2120', '-torch2121', '-torch2130', '-torch2140')) and cuda in ("12.6", "12.8", "13.0")) else ''
print(f'pip install --upgrade pip setuptools wheel && pip install --no-deps git+https://github.com/unslothai/unsloth-zoo.git && pip install "unsloth[{x}] @ git+https://github.com/unslothai/unsloth.git" --no-build-isolation{extra_index}')
Loading