Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Core: pip extras and auto-install support for torch 2.13 and 2.14 (#12151)

Daniel Han0eb7837f28ea
diff --git a/pyproject.toml b/pyproject.toml
index bb7a2943d5d..a4288d11546 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -632,6 +632,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",
+ "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",
@@ -875,6 +904,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]",
]
@@ -1212,6 +1261,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'",
diff --git a/tests/test_torch2110_cuda_extras.py b/tests/test_torch2110_cuda_extras.py
index 15072439bc2..c60534e39bb 100644
--- a/tests/test_torch2110_cuda_extras.py
+++ b/tests/test_torch2110_cuda_extras.py
@@ -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.
@@ -41,10 +41,12 @@ REPO = Path(__file__).resolve().parents[1]
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")
@@ -175,6 +177,73 @@ 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
+
+
+ "torch_version, series",
+ [
+ ("2.12.0+cu130", "torch2120"),
+ ("2.12.1", "torch2121"),
+ ("2.13.0+cu126", "torch2130"),
+ ("2.14.0+cu130", "torch2140"),
+ ],
+)
[email protected]("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
+
+
+ "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)
+
+
+ "torch_version",
+ ["2.13.0rc1", "2.13.0a0+git1234", "2.14.0rc2+cu130", "2.13.0+git1234", "2.14.0+cu130.custom"],
+)
+def test_auto_install_rejects_nonstable_torch213_plus(torch_version: str, capsys):
+ with pytest.raises(RuntimeError, match = "pre-release or custom build"):
+ _run_auto_install(torch_version, "13.0", capsys)
+
+
[email protected]("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"))
diff --git a/unsloth/_auto_install.py b/unsloth/_auto_install.py
index 8e385687e35..3b7f49a318f 100644
--- a/unsloth/_auto_install.py
+++ b/unsloth/_auto_install.py
@@ -38,12 +38,18 @@ elif v < V('2.11.1'): x = 'cu{}{}-torch2110'
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!")
+# torch2130 / torch2140 pin the stable release, so a pre-release, source or custom build would be replaced.
+elif re.fullmatch(r"[0-9\.]{3,}(?:\+cu[0-9]+)?", torch.__version__) is None: raise RuntimeError(f"Torch = {torch.__version__} is a pre-release or custom build; install a stable torch!")
+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'
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}')
\ No newline at end of file