Skip to content

Windows x64 and Linux CUDA bundles: ship cudart/cublas so installs without PyTorch run on the GPU - #362

Open
LeoBorcherding wants to merge 2 commits into
unslothai:masterfrom
LeoBorcherding:fix/windows-x64-cuda-runtime
Open

LeoBorcherding wants to merge 2 commits into
unslothai:masterfrom
LeoBorcherding:fix/windows-x64-cuda-runtime

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 10, 2026 •

Copy link
Copy Markdown

Unsloth Studio installs without PyTorch (chat-only) on a machine with an NVIDIA GPU run llama-server on the CPU. The CUDA app bundles ship the CUDA backend (ggml-cuda.dll, libggml-cuda.so) but not the CUDA runtime it links against (cudart, cublas, cublasLt). Studio has relied on PyTorch to supply it, and the NVIDIA driver does not include it.

This PR ships the runtime in the Windows x64 and Linux CUDA bundles, and records that in the release manifest.

1. Windows x64

  • Problem: ggml-cuda.dll cannot load without cudart64_* / cublas64_* / cublasLt64_*, and llama.cpp falls back to the CPU with no error. The install still reports "installed and validated". This has been the case since Source llama.cpp prebuilts from unslothai/llama.cpp (CUDA, ROCm, macOS) unsloth#5963 moved Windows installs from upstream's llama-* bundles plus the paired cudart-llama-bin-win-cuda-*.zip to these app-* bundles: its selection code says the app bundles come "with bundled runtime libs", but only the ARM64 bundle has them (since Fix ROCm CPU performance, update the ROCm toolchain, and bundle Windows ARM64 CUDA libraries #233).
  • Fix: unsloth-prebuilt-cuda-windows.yml copies the three DLLs from the job's toolkit into src/build/bin before signing and sets BUNDLE_CUDA_RUNTIME=1 on the packaging step, as the ARM64 leg does. The step fails if a pattern does not match exactly one DLL.
  • Takes effect: With no Studio change. Studio copies every *.dll from the bundle, and Windows loads DLLs from the executable's own directory first, so installs that have PyTorch use the bundled runtime too.
  • Tested: On windows-2022 runners, with the published b12246 binaries, the real toolkit install step, and this copy step and packager unchanged: run. The published bundle fails LoadLibrary(ggml-cuda.dll) with WinError 126 and --list-devices prints (none). The bundle from this PR loads it and reaches ggml_cuda_init. The runners have no NVIDIA GPU or driver, so the cuda12 legs use a stand-in for nvcuda.dll.

2. Linux x64 and arm64

  • Problem: The Linux CUDA bundles ship no runtime either: libggml-cuda.so needs libcudart.so.N and libcublas.so.N. Studio only installs a Linux CUDA bundle after finding those on disk. On a chat-only install with only the NVIDIA driver it logs "no published CUDA bundle covers this host" and falls back to a source build, which uses CUDA only when nvcc is present. The result is the CPU.
  • Fix: unsloth-prebuilt-cuda.yml copies libcudart, libcublas and libcublasLt from the job's toolkit into src/build/bin under their sonames. The packager's NEEDED walk picks them up from there. NVIDIA's libcublas carries RUNPATH $ORIGIN, so libcublasLt resolves from the bundle directory with no LD_LIBRARY_PATH.
  • Takes effect: Only with a Studio change. Studio still skips a Linux CUDA bundle when it finds no runtime on disk. It has to accept bundles whose manifest entry has bundles_cuda_runtime: true (section 3). Until then this section changes the download size and nothing else.
  • Tested:
    • On a real GPU: the tarball built by this copy step and packager, in a clean ubuntu:22.04 container that has the NVIDIA driver and no CUDA libraries. Packaged as on master, llama-server --list-devices prints (none). Packaged with this PR it prints CUDA0: NVIDIA GeForce RTX 3090. Same result for cuda12 and cuda13.
    • On ubuntu-22.04 and ubuntu-24.04-arm runners, with the real toolkit install step: run. The step finds all three libraries on both CUDA lines and on arm64, and the bundle's libggml-cuda.so then has no unresolved library besides the driver's libcuda.so.1.

3. The manifest says which bundles carry the runtime

  • Problem: Nothing tells the installer whether a CUDA bundle is self-contained. Releases before this PR are not.
  • Fix: package_bundle.py writes bundles_cuda_runtime into UNSLOTH_PREBUILT_INFO.json (true when the bundle contains cuBLAS) and assemble_metadata.py copies it into each CUDA entry of llama-prebuilt-manifest.json. A bundle packaged before the field existed reads as false.
  • Tested: In the Linux run above, the manifest entry is false for the published bundle and true for the bundle with the runtime. Studio reads manifest entries with .get, so the extra key does not affect current installs.

Size

Every CUDA bundle grows, for installs with PyTorch as well. Measured:

Bundle Before After Delta
windows-x64-cuda12-legacy 38 MiB 589 MiB +552 MiB
windows-x64-cuda12-newer 244 MiB 796 MiB +552 MiB
windows-x64-cuda13-newer 242 MiB 615 MiB +374 MiB
linux-x64-cuda12-newer 248 MiB 814 MiB +566 MiB
linux-x64-cuda13-newer 246 MiB 634 MiB +388 MiB
linux-arm64-cuda13-portable 204 MiB 695 MiB +491 MiB

The other bundles grow by the same amount per platform and CUDA line. Over the 15 CUDA bundles a release grows by about 7 GiB.

Report

Reported in the Discord help thread: RTX 5070 Ti, Windows, chat-only Unsloth Desktop install, LFM2.5-24B-A2B UD-Q3_K_XL. 10 tok/s in Unsloth Studio against about 140 in LM Studio on the same model, with the GPU at 0% and the CPU at 75%.

Install log:

[TAURI:DIAG] ... skip_torch=true ... gpu_branch=no_torch
gpu            NVIDIA GeForce RTX 5070 Ti (sm_120)
               Driver: 591.86
llama.cpp      prebuilt installed and validated
               installed release: unslothai/llama.cpp@b11985-mix-c116c32 (tag b11985) -- cuda backend

llama-server log at 50k context:

common_params_print_info: build 11985 (6f4cc4d72) with MSVC 19.44.35229.0 for Windows AMD64 (Compiled by the Unsloth team)
device_info:
  - CPU     : 12th Gen Intel(R) Core(TM) i5-12600K (32559 MiB, 18282 MiB free)
load_tensors: offloaded 41/41 layers to GPU
load_tensors:          CPU model buffer size = 10432.10 MiB
llama_kv_cache:        CPU KV buffer size =   528.59 MiB
print_timing: eval time = 6128.80 ms / 64 tokens ( 97.28 ms per token, 10.28 tokens per second)

llama-server.exe --list-devices:

Available devices: (none)

build\bin\Release has ggml-cuda.dll (257 MB), and dir cu*.dll finds nothing. nvidia-smi shows driver 591.86 / CUDA 13.1, which is new enough for both the cuda12 and cuda13 bundles. Reinstalling reproduces it, and so does pointing Studio at LM Studio's llama.cpp folder (LM Studio keeps its CUDA runtime elsewhere).

Companion changes in unslothai/unsloth

  • Linux: select a CUDA bundle on a host with no CUDA runtime on disk when its manifest entry has bundles_cuda_runtime: true.
  • Windows: require the three DLLs for a windows-cuda install whose manifest entry has bundles_cuda_runtime: true. Keying on the field keeps installs of older releases healthy.

Not tested

  • A full release build. The tests repackage the published binaries, so the new steps have not run inside a compile leg.
  • Signing. The CUDA 12.8 Windows DLLs are unsigned (the 13.x ones are NVIDIA-signed), so the cuda12 legs will sign them with our certificate, including the 660 MiB cublasLt64_12.dll. The ARM64 leg never did that.
  • A real NVIDIA GPU on Windows, and Linux arm64 on real hardware.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T02:41:18.378731Z 8efcd3f 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.

@oobabooga

Copy link
Copy Markdown
Member

I ran your copy step and packager on the published b12246 binaries on two windows-2022 runners (CUDA 12.8, CUDA 13.3). The master bundle fails to load ggml-cuda.dll (WinError 126); yours loads it and reaches ggml_cuda_init. The runners have no NVIDIA GPU, so the test stops at the loader.

The size cost is larger than the ARM64 comparison in the description suggests:

Bundle Before After Delta
cuda12-legacy 37 MiB 589 MiB +552 MiB
cuda12-newer 244 MiB 796 MiB +552 MiB
cuda13-newer 242 MiB 615 MiB +373 MiB

The other four bundles grow by the same amount per CUDA line.

One path I did not exercise: the CUDA 12.8 redist DLLs are unsigned (the 13.x ones are NVIDIA-signed), so the cuda12 legs will sign them with our certificate, including the 660 MiB cublasLt64_12.dll. If that fails, that night's release does not publish, and this is a clean revert.

Linux has the same gap, which this PR does not cover: its CUDA bundles ship no runtime either, so a --no-torch install with only the NVIDIA driver runs on the CPU. The difference is that the installer logs it there. I read that from the installer code and did not run such an install.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 24a7ce78bd

ℹ️ 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".

@oobabooga oobabooga changed the title Windows x64 CUDA bundles: ship cudart/cublas so installs without PyTorch run on the GPU Windows x64 and Linux CUDA bundles: ship cudart/cublas so installs without PyTorch run on the GPU Nov 11, 2026
@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 8efcd3f293

ℹ️ 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".

@LeoBorcherding

LeoBorcherding commented Nov 11, 2026 •

Copy link
Copy Markdown
Author

Thanks for running it, converging Codex, and adding the Linux side. The size cost is the bigger problem, though (+373 to +552 MiB per bundle, now on Linux too), so I'd rather not ship the runtime in the bundles at all.

Proposal: let the installer supply the runtime, and only for installs that lack it. When there's no torch and an NVIDIA GPU, Unsloth Studio would uv pip install NVIDIA's own wheels into its env and add their bin/lib folder to the DLL search path on Windows and LD_LIBRARY_PATH on Linux:

CUDA line wheels platforms on PyPI
12.x nvidia-cuda-runtime-cu12, nvidia-cublas-cu12 (pinned to 12.9.2.10, the last cublas with a win_amd64 wheel) win_amd64, linux x86_64/aarch64
13.x nvidia-cuda-runtime, nvidia-cublas win_amd64, win_arm64, linux x86_64/aarch64

What that gets us:

  • Full installs download nothing extra. They keep using torch\lib as they do today.
  • Chat-only installs still pay the cublas size, but once per CUDA line, not on every llama.cpp update.
  • Linux gets fixed by the same change.
  • We never re-sign NVIDIA's DLLs, so the unsigned 12.8 redist can't block a release.

That change lives in unslothai/unsloth (install_llama_prebuilt.py plus the path setup in llama_cpp.py), not in this repo, so I'm closing this PR and opening a new one there.

LeoBorcherding added a commit to unslothai/unsloth that referenced this pull request Nov 12, 2026
…ause the CUDA bundles ship no cudart/cublas (#17463)

Chat-only (no-torch) installs with an NVIDIA GPU run llama.cpp on the
CPU. Reported in the Discord help thread: a 5070 Ti on Windows (driver
591.86) got ~20 tok/s where LM Studio gets ~140, `llama-server
--list-devices` printed `(none)`, and the log showed `n_threads = 2` on
the CPU.

## Why

The `app-*` CUDA bundles Unsloth Studio installs since #5963 ship
`ggml-cuda.dll` but no `cudart`/`cublas`. A full install doesn't need
them: PyTorch already carries the CUDA runtime, and Unsloth Studio puts
it on llama-server's search path, which saves ~400-550 MB per bundle. A
chat-only install skips PyTorch, so there is nothing to borrow,
`ggml-cuda.dll` fails to load, and llama.cpp quietly falls back to the
CPU.

```
.unsloth/
├ llama.cpp/…/Release/          same in every case: ggml-cuda.dll, no cudart
└ studio/unsloth_studio/…/site-packages/
   ├ torch/lib/                 full install: cudart64_12.dll, cublas64_12.dll   → GPU
   ├ (nothing)                  chat-only today                                  → CPU
   └ nvidia/cu13/bin/           chat-only with this PR: cudart64_13.dll, …        → GPU
```

On Windows torch ships these DLLs inside its own wheel (`torch\lib`). On
Linux torch pulls NVIDIA's `nvidia-cuda-runtime` / `nvidia-cublas`
wheels into `site-packages/nvidia/`, which are the same wheels this PR
installs.

## Change

- **Linux, before bundle selection.** Selection only takes a CUDA bundle
whose runtime line is already on disk, so a driver-only host would skip
CUDA and fall back to a source build. On an x64 NVIDIA host with an
`auto`/`cuda` request and no runtime the driver can use, the installer
now installs the wheels for the newest line the driver runs first, then
selects. Pre-Turing GPUs get CUDA 12, and a CUDA 13 runtime already on
disk does not count for them.
- **After install, both OSes.** The install kind and CUDA major come
from the asset name, since the install marker records no install kind.
If the runtime is missing (Linux: `detected_linux_runtime_lines()`, the
same scan selection uses; Windows: `cudart`, `cublas` and `cublasLt` of
that major, each found in the bundle, `torch/lib`, the env's `nvidia/`
wheels, `CUDA_PATH` or the loader's own DLL dirs from
`windows_runtime_dirs()`, checked flat), it installs NVIDIA's wheels:
`nvidia-cuda-runtime` + `nvidia-cublas`, or the `-cu12` names with
cublas pinned to 12.9.2.10 on Windows, the last one with a `win_amd64`
wheel.
- **Repair.** `--check-installed` reports such an install as not ready,
so setup and update reinstall it and fill the gap on machines that are
already broken.
- `llama_cpp.py` already puts the env's `nvidia/*` wheel dirs on `PATH`
/ `LD_LIBRARY_PATH`, so it needs no change.

Full installs and machines with the CUDA toolkit download nothing new.
ARM64 bundles already ship the runtime and are untouched. This replaces
unslothai/llama.cpp#362, which put the runtime in every bundle (+373 to
+552 MiB each).

## Tests

`tests/studio/install/test_no_torch_cuda_runtime_wheels.py`, 30 passed
on macOS at `907e50f558` (code-level, the filesystem, loader and host
are faked). Not run yet on a real Windows or Linux NVIDIA machine with a
chat-only install.

---------

Co-authored-by: oobabooga <[email protected]>

This branch has not been deployed

No deployments
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.

2 participants