Skip to content

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

Closed

Description

@mithulaartigala

a few days ago I made an issue talking about how unsloth keeps randomly using my CPU for infeence even tho i have a pretty decent GPU.

it seems like yall actually did soomething even tho it doesn;t properly work.

I made codex doa check for me and it always fixes it. this is what it came up with this.


On Windows native, Studio can regress to a CPU-only llama-server even when CUDA training works and a CUDA-capable llama.cpp build exists locally.

What I observed locally:

  • Training used the GPU normally on an RTX 5070.
  • Studio inference logs showed:
warning: no usable GPU found, --gpu-layers option will be ignored
warning: one possible reason is that llama.cpp was compiled without GPU support
  • Studio was resolving LLAMA_SERVER_PATH to:
C:\Users\artig\.unsloth\llama_cpp_fixed_b9016\build\bin\Release\llama-server.exe

which was the CPU-only build.

  • A separate CUDA build at:
C:\Users\artig\.unsloth\llama_cpp_fixed_b9016\build-cuda\bin\Release\llama-server.exe

worked correctly and reported:

CUDA0: NVIDIA GeForce RTX 5070

Probable bug:

  • A Studio update/installer rewrote the backend bootstrap and restored the default path logic.
  • On startup, Studio preferred a stale CPU-only llama-server path instead of the valid CUDA build.
  • Result: training works, but GGUF inference falls back to CPU forever.

Suggested fix for Unsloth:

  1. Prefer a verified CUDA-capable binary when multiple local llama-server.exe builds exist.
  2. On Windows, during startup, probe candidate binaries with --list-devices and reject ones that return no CUDA devices when NVIDIA/CUDA is present.
  3. Do not silently bind to:
...\build\bin\Release\llama-server.exe

if a working CUDA build exists elsewhere in the same tree.
4. Persist the chosen backend path across Studio updates instead of resetting to default bootstrap logic.
5. If Studio detects NVIDIA + CUDA training support but inference binary is CPU-only, show a hard warning in UI instead of silently using CPU.

Activity

  1. LeoBorcherding commented on Jun 5, 2026

    @LeoBorcherding
    Collaborator

    hi @MightyXdash i made a fix in #5969 if you could try pulling the branch and seeing if it fixes your issue and commenting the results that would be great

  2. LeoBorcherding commented on Jun 12, 2026

    @LeoBorcherding
    Collaborator

    The underlying problem here (Windows + NVIDIA resolving to the CPU llama-server build) has been fixed in main, just through a different approach than the one originally proposed.

    Two PRs cover it:

    Could you update to the latest main and confirm inference picks up your RTX 5070 now? A fresh install is best so the new prebuilt selection runs. If you still see the "no usable GPU found" warning on inference, drop the install/selection log here and we'll reopen.

    Thanks for the detailed writeup, it lined up exactly with what got fixed.

  3. Pavlogal commented on Jun 13, 2026

    @Pavlogal

    Last week I was meddling with the same issue, trying to run Gemma 4 12B but always having the inference land on the CPU. Then I rebuilt llama.cpp manually with CUDA and the same thing was happening. So I tried running literally the same build directly with different arguments (explicitly stating gpu layers and batch size) and it worked, getting full GPU utilization:

    C:\Users\pavle\.unsloth\llama.cpp\build\bin\Release\llama-server.exe -m C:\Users\pavle\.cache\huggingface\hub\models--unsloth--gemma-4-12b-it-GGUF\snapshots\3f09de26549e6d7ea54f1b83755149f840fcd333\gemma-4-12b-it-UD-Q4_K_XL.gguf --port 1627 -c 10000 --parallel 1 --flash-attn on --no-context-shift --fit on --threads -1 --gpu-layers 999 --batch-size 512 --jinja --spec-default --chat-template-kwargs '{\"enable_thinking\":true}' --mmproj C:\Users\pavle\.cache\huggingface\hub\models--unsloth--gemma-4-12b-it-GGUF\snapshots\3f09de26549e6d7ea54f1b83755149f840fcd333\mmproj-F16.gguf

    Today I completely reinstalled unsloth studio to see if it's gonna work on its own now and nope, most of the inference still gets thrown on the CPU. GPU utilization hanging around 30-40%. Running on CUDA toolkit 13.3, RTX 2070 Super Max Q. It built llama.cpp from source during install and no errors were found there.

    I think it's genuinely just the default llama-server arguments when running through unsloth that are causing the issue now, maybe it's because gpu layers aren't mentioned at all? These are the parameters it runs with through unsloth:
    {"timestamp": "2026-06-13T11:37:16.707939Z", "level": "info", "event": "Starting llama-server: C:\\Users\\pavle\\.unsloth\\llama.cpp\\build\\bin\\Release\\llama-server.exe -m C:\\Users\\pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-12b-it-GGUF\\snapshots\\3249fa54d5efa384afc552cc6700ad091efd5c39\\gemma-4-12b-it-UD-Q4_K_XL.gguf --port 4763 -c 4096 --parallel 1 --flash-attn on --no-context-shift --fit on --threads -1 --jinja --model-draft C:\\Users\\pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-12b-it-GGUF\\snapshots\\3249fa54d5efa384afc552cc6700ad091efd5c39\\mtp-gemma-4-12b-it.gguf --spec-type draft-mtp --spec-draft-n-max 2 --chat-template-file C:\\Users\\pavle\\AppData\\Local\\Temp\\unsloth_chat_template_vnjbl4j4.jinja --chat-template-kwargs {\"enable_thinking\": true, \"preserve_thinking\": false} --mmproj C:\\Users\\pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-12b-it-GGUF\\snapshots\\3249fa54d5efa384afc552cc6700ad091efd5c39\\mmproj-F16.gguf"}

    Edit: I reran the automatically built llama-server again, with the custom command above and once again got full GPU utilization.

  4. mithulaartigala commented on Jun 16, 2026

    @mithulaartigala
    Author

    Last week I was meddling with the same issue, trying to run Gemma 4 12B but always having the inference land on the CPU. Then I rebuilt llama.cpp manually with CUDA and the same thing was happening. So I tried running literally the same build directly with different arguments (explicitly stating gpu layers and batch size) and it worked, getting full GPU utilization:

    C:\Users\pavle\.unsloth\llama.cpp\build\bin\Release\llama-server.exe -m C:\Users\pavle\.cache\huggingface\hub\models--unsloth--gemma-4-12b-it-GGUF\snapshots\3f09de26549e6d7ea54f1b83755149f840fcd333\gemma-4-12b-it-UD-Q4_K_XL.gguf --port 1627 -c 10000 --parallel 1 --flash-attn on --no-context-shift --fit on --threads -1 --gpu-layers 999 --batch-size 512 --jinja --spec-default --chat-template-kwargs '{\"enable_thinking\":true}' --mmproj C:\Users\pavle\.cache\huggingface\hub\models--unsloth--gemma-4-12b-it-GGUF\snapshots\3f09de26549e6d7ea54f1b83755149f840fcd333\mmproj-F16.gguf

    Today I completely reinstalled unsloth studio to see if it's gonna work on its own now and nope, most of the inference still gets thrown on the CPU. GPU utilization hanging around 30-40%. Running on CUDA toolkit 13.3, RTX 2070 Super Max Q. It built llama.cpp from source during install and no errors were found there.

    I think it's genuinely just the default llama-server arguments when running through unsloth that are causing the issue now, maybe it's because gpu layers aren't mentioned at all? These are the parameters it runs with through unsloth: {"timestamp": "2026-06-13T11:37:16.707939Z", "level": "info", "event": "Starting llama-server: C:\\Users\\pavle\\.unsloth\\llama.cpp\\build\\bin\\Release\\llama-server.exe -m C:\\Users\\pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-12b-it-GGUF\\snapshots\\3249fa54d5efa384afc552cc6700ad091efd5c39\\gemma-4-12b-it-UD-Q4_K_XL.gguf --port 4763 -c 4096 --parallel 1 --flash-attn on --no-context-shift --fit on --threads -1 --jinja --model-draft C:\\Users\\pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-12b-it-GGUF\\snapshots\\3249fa54d5efa384afc552cc6700ad091efd5c39\\mtp-gemma-4-12b-it.gguf --spec-type draft-mtp --spec-draft-n-max 2 --chat-template-file C:\\Users\\pavle\\AppData\\Local\\Temp\\unsloth_chat_template_vnjbl4j4.jinja --chat-template-kwargs {\"enable_thinking\": true, \"preserve_thinking\": false} --mmproj C:\\Users\\pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-12b-it-GGUF\\snapshots\\3249fa54d5efa384afc552cc6700ad091efd5c39\\mmproj-F16.gguf"}

    Edit: I reran the automatically built llama-server again, with the custom command above and once again got full GPU utilization.

    I had the same issue btw (AGAIN!!)

  5. mithulaartigala commented on Jun 16, 2026

    @mithulaartigala
    Author

    i didnt mean to close it

  6. mr-pepe69 commented on Jun 22, 2026

    @mr-pepe69

    I am experiencing this in the Docker version in fedora 44 with a rtx 3050. training uses the GPU just fine, but it refuses to do inference with the GPU.

  7. Pavlogal commented on Jul 5, 2026

    @Pavlogal

    Alright so I clean installed the latest version of unsloth once again, this time on my RTX 2080 Super machine. The build for llama.cpp was correct, it definitely had CUDA support. I once again tried running gemma4 12B, and once again my GPU utilization was low. So I figured I'd try with a much smaller model, like gemma4 2B, which hovered around 66% GPU utilization.

    12B logs:

    {"timestamp": "2026-07-05T15:47:20.703743Z", "level": "info", "event": "Starting llama-server: C:\\Users\\Pavle\\.unsloth\\llama.cpp\\build\\bin\\Release\\llama-server.exe -m C:\\Users\\Pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-12B-it-qat-GGUF\\snapshots\\7102bdea62863acff919c945405ef29973113d66\\gemma-4-12B-it-qat-UD-Q4_K_XL.gguf --port 49964 -c 4096 --parallel 1 --flash-attn on --no-context-shift --fit on --metrics --jinja --model-draft C:\\Users\\Pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-12B-it-qat-GGUF\\snapshots\\7102bdea62863acff919c945405ef29973113d66\\mtp-gemma-4-12B-it.gguf --spec-type draft-mtp --spec-draft-n-max 2 --chat-template-file C:\\Users\\Pavle\\AppData\\Local\\Temp\\unsloth_chat_template_h7jt9emz.jinja --chat-template-kwargs {\"enable_thinking\": true, \"preserve_thinking\": false} --mmproj C:\\Users\\Pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-12B-it-qat-GGUF\\snapshots\\7102bdea62863acff919c945405ef29973113d66\\mmproj-F16.gguf"}
    

    2B logs:

    {"timestamp": "2026-07-05T15:58:00.773844Z", "level": "info", "event": "Starting llama-server: C:\\Users\\Pavle\\.unsloth\\llama.cpp\\build\\bin\\Release\\llama-server.exe -m C:\\Users\\Pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-E2B-it-GGUF\\snapshots\\ecc8b33b2c50598815e4b0f7cea6088e3ae7adb8\\gemma-4-E2B-it-UD-Q4_K_XL.gguf --port 50532 -c 131072 --parallel 1 --flash-attn on --no-context-shift -ngl -1 --metrics --threads 2 --jinja --model-draft C:\\Users\\Pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-E2B-it-GGUF\\snapshots\\ecc8b33b2c50598815e4b0f7cea6088e3ae7adb8\\mtp-gemma-4-E2B-it.gguf --spec-type draft-mtp --spec-draft-n-max 2 --chat-template-file C:\\Users\\Pavle\\AppData\\Local\\Temp\\unsloth_chat_template_qacm1a4n.jinja --chat-template-kwargs {\"enable_thinking\": true, \"preserve_thinking\": false} --mmproj C:\\Users\\Pavle\\.cache\\huggingface\\hub\\models--unsloth--gemma-4-E2B-it-GGUF\\snapshots\\ecc8b33b2c50598815e4b0f7cea6088e3ae7adb8\\mmproj-F16.gguf --cache-ram 0 --ctx-checkpoints 0 --no-cache-prompt"}
    

    Comparing the logs, it's clear that the main difference is that when running the 2B model, the -ngl -1 parameter is added, offloading all layers to the GPU, meanwhile for the 12B model it's completely absent. Realistically, it could offload at least something but it completely gives up instead. So I tried forcing the -ngl -1 parameter with unsloth studio run --model unsloth/gemma-4-12B-it-qat-GGUF -ngl -1 and got the same behavior. Then I tried the same with -ngl 999 and finally got 100% GPU utilization, and performance ~20 tok/s.

    So really I think unsloth is just being too conservative in estimating what can and cannot fit on the GPU when calculating gpu layers. It's true that gemma4 12B on an 8GB card is a tight fit, but the problem here is not that it's not loading into memory (it is, with no problems at all), it's that inference is not running on the GPU at all. I don't know how unsloth chooses these parameters, but it would either have to be tweaked to be a little more lenient, or even better I wish we had some interface that would allow us to manually set the desired parameters (similarly to how we can change the context window in the sidebar). I don't know, maybe I'm too ambitious trying to run this model in the first place, but such a feature would surely come in handy when fine tuning and tinkering.

    As for the builds of llama.cpp, it's been a while since I've had issues with them. The last few times I got the correct CUDA build instead of the CPU-only one.

  8. danielhanchen commented on Oct 11, 2026

    @danielhanchen
    Member

    Fixed! Sorry on the delay. When a llama.cpp folder had a CPU-only build next to a CUDA build-cuda, Studio always took the first one it found, so inference ran on the CPU while training used the GPU. Since #11005 Studio checks which builds actually ship a GPU backend and prefers the one your GPU can run, and since #8812 it warns in the UI when a model loads with no layers (or only some) on the GPU. If you set LLAMA_SERVER_PATH yourself, that exact binary is still used as-is, so point it at the CUDA build or remove it.

    @Pavlogal what you saw is a different thing: a 12B with the vision projector and MTP draft does not fit in 8 GB, so llama.cpp's own fitter keeps only part of the model on the GPU. Since #6414 you can override that in the model settings under Advanced > GPU Memory > Manual, then set GPU Layers (the same as --gpu-layers). On Windows a value above what fits can still run because the NVIDIA driver spills to system RAM.

    @mr-pepe69 if Docker still runs inference on the CPU after updating, please open a new issue with the Starting llama-server line and the llama-server startup log.

    To update: Unsloth Desktop will have an update banner. For Studio, use unsloth studio update. For Docker, use docker exec <container> unsloth-studio-update. Reopen if it still happens.

  9. mithulaartigala commented on Oct 11, 2026

    @mithulaartigala
    Author

    NICEE!!! TYSM!!!

    Unsloth Studio the goat!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions