Skip to content

fix(studio): propagate Ollama CUDA runtime to llama-server on Linux - #7563

Closed
Imagineer99 wants to merge 13 commits into
unslothai:mainfrom
Imagineer99:fix/wsl-ollama-cuda-runtime
Closed

Imagineer99 wants to merge 13 commits into
unslothai:mainfrom
Imagineer99:fix/wsl-ollama-cuda-runtime

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • propagate the Ollama-private CUDA runtime selected by the prebuilt installer into the Linux llama-server environment
  • match the installed runtime_line exactly and require both cuBLAS and CUDA runtime libraries before adding a directory
  • cover matching, mismatched, incomplete, and missing-marker cases plus launcher-environment integration

Why

The Linux/WSL installer can select a CUDA prebuilt after discovering libraries under /usr/local/lib/ollama/cuda_v*. Those private Ollama directories are not normally visible to the dynamic linker, and the launcher did not carry the selected directory into LD_LIBRARY_PATH. The CUDA backend could therefore fail to load and silently fall back to CPU after an otherwise successful install.

This is Linux-only and leaves the Windows and macOS launcher paths unchanged.

Validation

  • 278 passed — studio/backend/tests/test_llama_cpp_mtp_detection.py
  • 346 passed — unsloth_cli/tests/test_start.py
  • 389 passed — OpenAI tool-passthrough and Anthropic message suites
  • live WSL A/B with the same CUDA 13 llama.cpp binary: no propagated path reported no CUDA devices; the fixed launcher detected and selected an RTX 5070 Ti
  • fresh --no-torch WSL install plus Qwen3.5-9B action tests completed through Pi, Claude, OpenCode, and Codex without the prior CPU-fallback timeouts

@Imagineer99
Imagineer99 marked this pull request as ready for review July 28, 2026 15:26
@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f848733f90

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

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acf6ae97be

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

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: a4324a6a5d

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d2b3a35ac

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the gap: the installer counts /usr/local/lib/ollama/cuda_v* in prebuilt_core.py when picking the runtime line, but _llama_server_env_for_binary never puts that dir back on LD_LIBRARY_PATH. The branch has conflicts now, so could you rebase and I will get this reviewed.

@danielhanchen

Copy link
Copy Markdown
Member

Still confirmed against main, where the Linux branch of _llama_server_env_for_binary ends at the LD_LIBRARY_PATH join without the Ollama cuda_v* dir; the branch is still showing conflicts, so could you rebase and I will get this reviewed.

@wasimysaid wasimysaid self-assigned this Sep 21, 2026
@wasimysaid

Copy link
Copy Markdown
Collaborator

Live Studio A/B — verified from the spawned llama-server process

Head 1b376dc125 vs main 64e4d52d4. Loaded the same GGUF on both sides and read the environment of the actual spawned llama-server (/proc/<pid>/environ), not the launcher's.

  • head: LD_LIBRARY_PATH ends with /usr/local/lib/ollama/cuda_v13 → OLLAMA_DIR_ON_LD_LIBRARY_PATH=TRUE; the model loaded and served real GPU inference (119 tok/s).
  • main: no Ollama entry → OLLAMA_DIR_ON_LD_LIBRARY_PATH=FALSE.

Ordering matches the intent: the Ollama dir is appended last, so it rescues without displacing the working runtime.

Caveat, for honesty: this host has no /usr/local/lib/ollama and no root, so that directory was synthesized with symlinks to each side's real CUDA libs. The path, the env marker and the live process env are genuine; the "rescues a genuinely missing library" case could not be exercised here.

wasimysaid pushed a commit to wasimysaid/unsloth that referenced this pull request Sep 22, 2026
The Linux/WSL prebuilt installer discovers a CUDA runtime under
/usr/local/lib/ollama/cuda_v* and will select a CUDA runtime line from it,
but that directory is private to Ollama and is not on the dynamic linker's
search path. A prebuilt whose only libcudart/libcublas copy lives there
could not load its CUDA backend and silently fell back to CPU.

The launchers now read the build's install marker and put the matching
Ollama CUDA directory last on the child loader path, so it only rescues
hosts with no other copy and never displaces the runtime that qualified
the build. The whisper-server sidecar does the same, including slim
bundles whose CUDA module is hardlinked from a paired llama.cpp install.

Rebuilt from unslothai#7563 by Imagineer99, adapted onto current
main.
wasimysaid pushed a commit to wasimysaid/unsloth that referenced this pull request Sep 23, 2026
The Linux/WSL prebuilt installer discovers a CUDA runtime under
/usr/local/lib/ollama/cuda_v* and will select a CUDA runtime line from it,
but that directory is private to Ollama and is not on the dynamic linker's
search path. A prebuilt whose only libcudart/libcublas copy lives there
could not load its CUDA backend and silently fell back to CPU.

The launchers now read the build's install marker and put the matching
Ollama CUDA directory last on the child loader path, so it only rescues
hosts with no other copy and never displaces the runtime that qualified
the build. The whisper-server sidecar does the same, including slim
bundles whose CUDA module is hardlinked from a paired llama.cpp install.

Rebuilt from unslothai#7563 by Imagineer99, adapted onto current
main.
danielhanchen pushed a commit to danielhanchen/unsloth-staging-review that referenced this pull request Sep 25, 2026
The Linux/WSL prebuilt installer discovers a CUDA runtime under
/usr/local/lib/ollama/cuda_v* and will select a CUDA runtime line from it,
but that directory is private to Ollama and is not on the dynamic linker's
search path. A prebuilt whose only libcudart/libcublas copy lives there
could not load its CUDA backend and silently fell back to CPU.

The launchers now read the build's install marker and put the matching
Ollama CUDA directory last on the child loader path, so it only rescues
hosts with no other copy and never displaces the runtime that qualified
the build. The whisper-server sidecar does the same, including slim
bundles whose CUDA module is hardlinked from a paired llama.cpp install.

Rebuilt from unslothai/unsloth#7563 by Imagineer99, adapted onto current
main.
danielhanchen added a commit that referenced this pull request Sep 25, 2026
…t for #7563) (#11666)

* fix(studio): propagate Ollama CUDA runtime to llama-server

The Linux/WSL prebuilt installer discovers a CUDA runtime under
/usr/local/lib/ollama/cuda_v* and will select a CUDA runtime line from it,
but that directory is private to Ollama and is not on the dynamic linker's
search path. A prebuilt whose only libcudart/libcublas copy lives there
could not load its CUDA backend and silently fell back to CPU.

The launchers now read the build's install marker and put the matching
Ollama CUDA directory last on the child loader path, so it only rescues
hosts with no other copy and never displaces the runtime that qualified
the build. The whisper-server sidecar does the same, including slim
bundles whose CUDA module is hardlinked from a paired llama.cpp install.

Rebuilt from #7563 by Imagineer99, adapted onto current
main.

* fix(studio): never let the Ollama runtime displace a loader-resolved CUDA

The vendored dir joins LD_LIBRARY_PATH, which precedes the loader's cache and
its default dirs however late the entry sits, so appending it last was not
enough: where ldconfig already answers libcudart/libcublas for that major, the
private copy would still take precedence over the runtime that qualified the
build. Yield the dir only while the loader cannot find both, falling back to
the default dirs when no ldconfig can be read.

The rescue direction is unchanged: with neither the cache nor the defaults
providing the pair, the dir is still added.

* fix(studio): count the multiarch dirs when ldconfig cannot be read

The no-ldconfig fallback probed only the generic loader defaults, but Debian
and Ubuntu glibc searches the architecture-specific /lib/<triple> and
/usr/lib/<triple> built in -- `ld.so --list-diagnostics` lists them ahead of
/lib and /usr/lib -- and the installer counts them too. A distro CUDA runtime
sitting in one of those was therefore reported missing, the Ollama dir joined
LD_LIBRARY_PATH, and it displaced that runtime despite the loader probe.

Discover the dirs by glob rather than by machine name, so a multilib host, a
second architecture, or a container holding only one of the pair is covered.

The pair of arms pins it: the new discovery rule, and the real list checked
against the interpreter's own MULTIARCH triple, which is what the previous
draft asserted with a condition that could not hold.

* fix(studio): handle loader cache ABI and symlink markers

* fix(studio): restore cache probe dependency

* fix(studio): ignore stale CUDA cache entries

* fix(studio): handle CUDA loader edge cases

* fix(studio): normalize loader cache ABI labels

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(studio): reject unreadable loader defaults

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(studio): check loader cache without ldconfig

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(studio): require CUDA runtime soname links

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(studio): probe loader after cache query failure

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Trim comments in vendored CUDA runtime rescue

* Guard os.geteuid in vendored CUDA runtime tests for Windows collection

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: imagineer99 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
@Imagineer99

Copy link
Copy Markdown
Member Author

Closing this since the replacement #11666 has merged and the Ollama runtime fix is now on main. Thanks for carrying it across!

shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…t for unslothai#7563) (unslothai#11666)

* fix(studio): propagate Ollama CUDA runtime to llama-server

The Linux/WSL prebuilt installer discovers a CUDA runtime under
/usr/local/lib/ollama/cuda_v* and will select a CUDA runtime line from it,
but that directory is private to Ollama and is not on the dynamic linker's
search path. A prebuilt whose only libcudart/libcublas copy lives there
could not load its CUDA backend and silently fell back to CPU.

The launchers now read the build's install marker and put the matching
Ollama CUDA directory last on the child loader path, so it only rescues
hosts with no other copy and never displaces the runtime that qualified
the build. The whisper-server sidecar does the same, including slim
bundles whose CUDA module is hardlinked from a paired llama.cpp install.

Rebuilt from unslothai#7563 by Imagineer99, adapted onto current
main.

* fix(studio): never let the Ollama runtime displace a loader-resolved CUDA

The vendored dir joins LD_LIBRARY_PATH, which precedes the loader's cache and
its default dirs however late the entry sits, so appending it last was not
enough: where ldconfig already answers libcudart/libcublas for that major, the
private copy would still take precedence over the runtime that qualified the
build. Yield the dir only while the loader cannot find both, falling back to
the default dirs when no ldconfig can be read.

The rescue direction is unchanged: with neither the cache nor the defaults
providing the pair, the dir is still added.

* fix(studio): count the multiarch dirs when ldconfig cannot be read

The no-ldconfig fallback probed only the generic loader defaults, but Debian
and Ubuntu glibc searches the architecture-specific /lib/<triple> and
/usr/lib/<triple> built in -- `ld.so --list-diagnostics` lists them ahead of
/lib and /usr/lib -- and the installer counts them too. A distro CUDA runtime
sitting in one of those was therefore reported missing, the Ollama dir joined
LD_LIBRARY_PATH, and it displaced that runtime despite the loader probe.

Discover the dirs by glob rather than by machine name, so a multilib host, a
second architecture, or a container holding only one of the pair is covered.

The pair of arms pins it: the new discovery rule, and the real list checked
against the interpreter's own MULTIARCH triple, which is what the previous
draft asserted with a condition that could not hold.

* fix(studio): handle loader cache ABI and symlink markers

* fix(studio): restore cache probe dependency

* fix(studio): ignore stale CUDA cache entries

* fix(studio): handle CUDA loader edge cases

* fix(studio): normalize loader cache ABI labels

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(studio): reject unreadable loader defaults

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(studio): check loader cache without ldconfig

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(studio): require CUDA runtime soname links

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(studio): probe loader after cache query failure

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Trim comments in vendored CUDA runtime rescue

* Guard os.geteuid in vendored CUDA runtime tests for Windows collection

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: imagineer99 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
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.

4 participants