Skip to content

fix(studio): prefer CUDA llama-server build over CPU build on Windows - #5969

Closed
LeoBorcherding wants to merge 6 commits into
unslothai:mainfrom
LeoBorcherding:fix/llama-cpp-prefer-cuda-binary-windows
Closed

LeoBorcherding wants to merge 6 commits into
unslothai:mainfrom
LeoBorcherding:fix/llama-cpp-prefer-cuda-binary-windows

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Fixes #5941

Problem

On Windows, when both a CPU-only cmake build (build/bin/Release/llama-server.exe) and a CUDA cmake build (build-cuda/bin/Release/llama-server.exe) exist under the same install root, _find_llama_server_binary() always picks the CPU build because build/ appears first in the fixed search order. On machines with an NVIDIA GPU this causes GGUF inference to silently fall back to CPU even when a working CUDA binary is present.

Fix

  • Added _nvidia_available() static method — runs nvidia-smi -L with a 5s timeout
  • All three Windows cmake sections in _find_llama_server_binary() now check build-cuda/bin/Release/ before build/bin/Release/ when NVIDIA is detected
  • Logs an INFO message when the CUDA build is selected so the choice is visible in Studio logs
  • No change on Linux, non-NVIDIA Windows, or single-build setups

Test plan

  • On NVIDIA Windows with both build/ and build-cuda/ present: Studio should pick the CUDA build and log "Preferring CUDA llama-server build"
  • On CPU-only Windows: behaviour unchanged, build/bin/Release/ still used
  • On Linux: no change

When both build/bin/Release/llama-server.exe (CPU-only cmake build) and
build-cuda/bin/Release/llama-server.exe (CUDA cmake build) exist under
the same install root on Windows, _find_llama_server_binary() would
always pick the CPU build because build/ sorts before build-cuda/ in
the fixed search order. On machines with an NVIDIA GPU this causes GGUF
inference to silently fall back to CPU even when a working CUDA binary
is present alongside it.

Fix: add a _nvidia_available() helper that runs 'nvidia-smi -L' and
check build-cuda/bin/Release/ before build/bin/Release/ on Windows when
NVIDIA is detected. The check is applied in all three cmake Windows
sections: UNSLOTH_LLAMA_CPP_PATH, standard ~/.unsloth/llama.cpp search,
and legacy in-tree build. Each section logs an INFO message when the
CUDA build is selected so the choice is visible in Studio logs.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to prefer the CUDA build of llama-server over the CPU build on Windows when an NVIDIA GPU is detected via nvidia-smi. However, the implementation incorrectly references LlamaCppServer._nvidia_available() instead of LlamaCppBackend._nvidia_available(), which will result in a NameError at runtime in multiple locations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@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: ac5fd93263

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

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Tested on Windows with RTX 5060 Ti:

Manually reproduced the bug and verified the fix by importing LlamaCppBackend._find_llama_server_binary() directly from each branch against a live two-build setup (build + build-cuda both present under ~/.unsloth/llama.cpp).
On main (bug):

main picks: C:\Users\BlueberryDev\.unsloth\llama.cpp\build\bin\Release\llama-server.exe

Silently picks the CPU path with no log output, despite NVIDIA GPU being present.
On fix/llama-cpp-prefer-cuda-binary-windows (fixed):

2026-06-03 17:11:20 [info     ] Preferring CUDA llama-server build over CPU build: C:\Users\BlueberryDev\.unsloth\llama.cpp\build-cuda\bin\Release\llama-server.exe
fix picks: C:\Users\BlueberryDev\.unsloth\llama.cpp\build-cuda\bin\Release\llama-server.exe

Correctly prefers the CUDA build and logs the decision visibly.

Test plan item 1 confirmed - NVIDIA Windows with both builds present picks CUDA and logs Preferring CUDA llama-server build

Covers _find_llama_server_binary preferring the build-cuda cmake build over
the CPU build/bin/Release build when NVIDIA is present (UNSLOTH_LLAMA_CPP_PATH
and ~/.unsloth/llama.cpp paths), CPU fallback when no GPU is detected, a
CUDA-only install not being selected without NVIDIA, Linux discovery being
unchanged with the nvidia probe never running, and the _nvidia_available
return values across nvidia-smi success, non-zero exit, missing GPU token,
timeout, and missing binary.
@danielhanchen
danielhanchen self-requested a review as a code owner June 4, 2026 05:16

@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: c61188327e

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

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.

Unsloth keeps using my CPU for inference. and I found the reason and solution!

2 participants