Repository navigation
Studio: propagate the Ollama CUDA runtime to llama-server (replacement for #7563) - #11666
danielhanchen merged 21 commits into
Conversation
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.
…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.
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.
|
Review record for #11666, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#92. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1 — reviewed mirror
|
…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]>
Summary
The Unsloth prebuilt installer can select an Ollama-vendored CUDA runtime from
/usr/local/lib/ollama/cuda_v*, but the private directory is not automatically available to the dynamic loader. If the selected CUDA runtime is not otherwise loader-resolvable,llama-serverorwhisper-servercan fail to load its CUDA backend.This replacement for unslothai/unsloth#7563 propagates the matching Ollama directory to both launchers as a last-resort search path. It does not prepend that path or override a runtime already found through the loader cache or native default directories.
Changes
ldconfigis unavailable.LD_LIBRARY_PATHassertion.Verification
b1fa74a424ada8918406321bb8e621ff74f0268b./proc/<pid>/environon baselineae3077a09f2dcc7970721f7d06c6022de49ced1f./proc/<pid>/environ;LD_DEBUG=libsconfirmed the injected directory was searched only in rescue cases.The Ollama tree and no-
ldconfigloader variants were fixtures because this host has no Ollama installation. This validates launch environment and loader search behavior, not CUDA inference.Credit
Replacement of Imagineer99's original work in #7563; source and analysis credit remains with @Imagineer99 (Lee Jackson).
Verification update — head is now
29595023021c, and the loader behaviour is shown liveThe head referenced in the description (
b1fa74a424) is superseded. Current head:29595023021c1f1d6bc6b1e75307301a34bd0cd6— 21 commits, 19 files,+1746 / -79; fork PR #210.Main-versus-head dynamic-loader evidence
Full writeup: https://raw.githubusercontent.com/wasimysaid/unsloth/08fe681340a721da23d7bc4e35e7da2887bc2e41/acceptance/210-29595023021c/live-loader.md
Machine-readable result (41 891 bytes, sha256
bebc2a2e057f28b6ecd6b7425b8f233d143f9a11fa59ea5124b97ca150cadaca):https://raw.githubusercontent.com/wasimysaid/unsloth/08fe681340a721da23d7bc4e35e7da2887bc2e41/acceptance/210-29595023021c/runtime-result.json
Pinned base
ae3077a09f2dcc7970721f7d06c6022de49ced1fversus pinned head29595023021c1f1d6bc6b1e75307301a34bd0cd6; statuspassed, outcomereproduced. Ten arms were run for each launcher (llama-server,whisper-server) against both revisions. In every arm the product's own child-env builder produced the environment, a real process was spawned with it and its environment was read back from that child's/proc/<pid>/environ, and CUDA resolution was performed by the real glibc loader/lib64/ld-linux-x86-64.so.2running a compiled ELF whoseNEEDEDentries are exactlylibcudart.so.13andlibcublas.so.13; each arm's resolved object path was read back from the loader child's own/proc/<pid>/maps./usr/local/cuda-13.1payloads (rc 0).RLIMIT_NPROC = 0makes everyexecfail in the kernel —BlockingIOError: [Errno 11] … '/sbin/ldconfig'): both launchers appended the vendored directory last and the loader mapped both CUDA objects from it (rc 0); the same binary with the appended directory removed failed rc 127, so the resolution is attributable.Independent checks
runtime-result.jsonis byte-identical to the local result.Credit
Replacement of Imagineer99's original work in #7563; source and analysis credit remains with @Imagineer99 (Lee Jackson).
Limitations
/usr/local/lib/ollamatree, so the vendored tree was synthesized inside the arm workspace and reached through the module's documented roots override. The bytes placed in it are the host's real CUDA 13 payloads (sha256-identical to/usr/local/cuda/targets/x86_64-linux/lib), not stubs./lib/x86_64-linux-gnuand/usr/lib/x86_64-linux-gnudirectories were only detected and reported, never modified.RLIMIT_NPROC = 0to makeexecgenuinely fail; that is a real kernel-enforced failure, but it is not a disk image with ldconfig removed.unslothai/unslothmain(34 commits at audit time, 35 a few minutes later; merge baseae3077a0, the pinned base —mainis still moving, so re-check before rebasing). The two failing CI jobs on this head —Repo tests (CPU, studio)andRepo tests (CPU, rest)— are pre-existing unrelated failures, not caused by this change: the failingtests/studio/test_model_picker_catalog_first_paint.pyand thepickers.tsxit reads are byte-identical between the pinned base and this head, and the test also fails on the pinned base tree here. Upstreammainhas since updated both files. Rebasing brings them along.