Repository navigation
server: add --no-sleep flag for GPU heartbeat on headless GPUs - #25214
johnkarlhill wants to merge 5 commits into
Conversation
Prevents driver/OS VRAM eviction on secondary GPUs by periodically submitting a trivial GPU operation through each backend's synchronize path. When --no-sleep is set, the idle sleep timer is disabled (no-sleep wins if both flags are present). Backend heartbeat mechanisms: - SYCL: stream->single_task(no-op kernel) - CUDA: empty __global__ kernel launch - Vulkan: vkCmdFillBuffer on staging buffer Default: 0 (disabled). No behavior change for existing users.
|
Hi @johnkarlhill, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
arthw
left a comment
There was a problem hiding this comment.
It's good for SYCL backend.
Thank you!
|
It's not okay to make the synchronize call heavier. Additionally, this seems like a lot of code for what is basically just a workaround for bad driver behaviour. Can you describe the problem you are trying to solve and what hardware you see it on? If it really isn't solvable outside of llama.cpp, IMO it should just be handled within the affected backend, not in the llama.cpp core or server code. |
| // No Sleep Till Brooklyn - Beastie Boys - 246s | ||
| std::string v = value; | ||
| for (auto & c : v) { c = (char)::tolower((unsigned char)c); } | ||
| if (v == "brooklyn" || v == "nosleeptillbrooklyn" || v == "nosleeptilbrooklyn") { |
There was a problem hiding this comment.
Easter egg... but if the name of the flag is changing, it doesn't make sense anymore. Removed.
+1. Please lay out clearly why this is a general problem not tied to a specific OS/IHV combination |
ngxson
left a comment
There was a problem hiding this comment.
UX-wise, this flag is just too confusing, obviously the OS evicting VRAM is not considered as "sleep"
The --no-sleep name was confusing — GPU VRAM eviction is not "sleep." --gpu-heartbeat better describes what the flag actually does: periodic GPU synchronization to prevent driver VRAM eviction on headless GPUs. Drop the Beastie Boys easter egg (--no-sleep brooklyn). It doesn't belong in production code targeting ggml-org/llama.cpp. Co-Authored-By: Claude Code using DeepSeek-V4-Pro <[email protected]>
|
@ngxson renamed --no-sleep to --gpu-heartbeat based on your feedback — you're right, VRAM eviction isn't "sleep." The new name describes what it actually does: submit a periodic GPU synchronization operation. Removed the easter egg as well. |
johnkarlhill
left a comment
There was a problem hiding this comment.
@ORippler The heartbeat doesn't make heavier — it uses a dedicated private SYCL queue completely independent of the inference stream. The server-level synchronize was the original approach, but we moved the heartbeat to a separate function with its own queue precisely to avoid interfering with inference.
The problem: on Windows with Intel Arc GPUs, the driver aggressively evicts VRAM from secondary/"headless" GPUs after periods of GPU inactivity. When the server wakes up from idle and tries to use the model, the device buffers are gone — the driver has to page everything back from system RAM, causing multi-second hangs or crashes on memory-constrained machines.
This is reproducible on Arc Pro B70 + B50 dual-GPU setups. The Vulkan backend has the same mechanism for the same reason (AMD/NVIDIA headless cards have similar driver behavior).
On moving it into the backend: that's a reasonable architectural option. But the heartbeat needs to fire on a timer while the server is idle — the server's idle loop is the natural place to drive it. The backend just provides the mechanism (); the server decides when to call it.
@ngxson The driver behavior has been confirmed on Windows 11 with Intel Arc (Level Zero) and Vulkan backends, on both Arc Pro B70 and B50 GPUs. Happy to provide reproduction steps if anyone wants to verify.
@ORippler is mostly concerned with the CUDA backend and I am concerned with the Vulkan backend. We're not talking about SYCL. |
This still reads like a driver-level problem restricted to Intel Arc GPUs (and by extension SYCL/OpenVino + potentially Vulkan backends).
What prevents you from spawning a thread in the SYCL backend that issues these calls? Unless people have actually reported this issue for CUDA and there is a clean reproducer I would object such a change. |
|
I can verify this problem, and a very annoying one. The model gets unloaded after a few seconds of idle, and if you don't have the next prompt ready you might have to wait for a very long time for the model to unload and reload. OS: Windows 11 Pro Verified on SYCL Moving things around so the B70 is the Primary and running the 5070 as secondary This is a Intel Windows Driver issue, but the pull request solves the issue. |
ORippler
left a comment
There was a problem hiding this comment.
This is a Intel Windows Driver issue, but the pull request solves the issue.
Thanks for confirming it's an Intel Driver issue, and thus something to be fixed in the driver (or intel-exclusive backends). Blocking as long as it still affects non-intel-exclusive backends such as CUDA/VULKAN
|
For the Vulkan side, @rillomas are you aware of this behaviour? |
|
I ran some tests, this does not need to be implemented in llama-server to prevent the vram from being evicted when it comes to SYCL. SYCL Keepalive PoC #include <sycl/sycl.hpp>
#include <chrono>
#include <thread>
#include <iostream>
int main() {
sycl::queue q{ sycl::gpu_selector_v };
std::cout << "Running SYCL keep-alive on: "
<< q.get_device().get_info<sycl::info::device::name>()
<< "\n";
while (true) {
q.submit([&](sycl::handler& h) {
h.single_task([=]() {
// no-op kernel
});
});
q.wait();
std::this_thread::sleep_for(std::chrono::seconds(10));
}
}When it comes to Vulkan I didn't manage to get it to prevent the unloading with an external program but that might be my lack of Vulkan knowledge or that I have 3 Vulkan devices in my system. |
No I haven't heard of this, though we haven't tested much on multi GPU (multi dGPU?) scenarios. I'll see if I can reproduce this. |
|
All, I'm pulling this into draft and removing the Vulkan and CUDA code. Those Intel folks that need it can still pull it into their builds if they wish. I can certainly add Vulkan back in but there was some pushback, so I pulled it. |
|
FWIW, I can confirm this happens on Vulkan backend as well with Intel multi-GPU headless (running 2xB70). In addition to being super annoying having to wait for the model to page back to VRAM, TG performance craters after the reload (in my case, ~29t/s -> ~6t/s on Qwen3.6 36B Q8_K_XL) hinting that the driver has somehow fragmented memory during the restore? @johnkarlhill EDIT: Manually restored the Vulkan changes and in my testing, it only keeps one GPU from unloading its VRAM, the second GPU still unloads. Is that something you could address? |
|
@utopiafallen You asked for and you got it :-) And yes... watching my second GPU happily offload a model to system RAM is annoying AF. I'm glad it will be of use to you!! |
|
Thanks. Are you seeing the heartbeat keep both GPUs awake in a multi-GPU headless set-up? I'm still seeing VRAM unload on the 2nd GPU, but your heartbeat keeps the 1st one awake successfully. I'm running layer split between 2 vulkan devices with a single server. |
I was able to reproduce this so made a separate issue #25646. Will be checking internally. |
|
I have exactly same problem on AMD dual GPU setup using vulkan, i find it very bad behaviour, because it takes almost all of my system RAM and delays every new prompt. Its happening on my second GPU which doesnt have monitor connected. Setup is RX 9070XT as main, RX 9060XT as second |
|
Yup, I now roll my own llama.cpp builds because I need this workaround in place to have my inferencing setup work at all. It's actually trivial to repro on most consumer machines - just plug the display into the motherboard display ports so display is routed to the iGPU and then watch your dGPU evict its VRAM within 2 minutes of idling, and possibly crashing your system in the process. Given the cross-vendor nature of the behavior, I suspect this is a WDDM thing that was added to one of the recent Windows 11 releases and NVIDIA doesn't exhibit the issue because it's probably not implementing or honoring whatever eviction request Windows is issuing. And given the pushback from the llama.cpp maintainers, I don't expect this workaround will ever be merged. If you decide to make your own builds with this PR applied, be aware that the Vulkan path needs to be extended to issue the dummy work across every device context in a multi-GPU setup or else you'll have your secondary GPUs still evicting their VRAM. It's a straightforward change that your coding agent can do for you. |
|
I tried a dummy plug on the card display port but it doesn't seem to fix it. |
|
I ended up plugging second monitor to my second card and it fixed the ram eviction |
Overview
Prevents driver/OS VRAM eviction on secondary GPUs by periodically submitting a trivial GPU operation through each backend's synchronize path. When
--no-sleepis set, the idle sleep timer is disabled (--no-sleepwins if both flags are present).Backend heartbeat mechanisms:
stream->single_task(no-op kernel)__global__kernel launchvkCmdFillBufferon staging bufferUsage:
llama-server -m model.gguf --no-sleep 30 -ngl 999Default: 0 (disabled). No behavior change for existing users.
Additional information
Designed for headless/secondary GPU setups where the OS or GPU driver aggressively reclaims VRAM after periods of GPU inactivity. When the GPU is evicted, model weights spill from VRAM into system RAM — causing system hangs on memory-constrained machines.
Tested and confirmed working on Intel Arc (SYCL) and Vulkan backends with two-GPU configurations.
Requirements