Skip to content

server: add --no-sleep flag for GPU heartbeat on headless GPUs - #25214

Draft
johnkarlhill wants to merge 5 commits into
ggml-org:masterfrom
johnkarlhill:heartbeat-no-sleep
Draft

johnkarlhill wants to merge 5 commits into
ggml-org:masterfrom
johnkarlhill:heartbeat-no-sleep

Conversation

@johnkarlhill

Copy link
Copy Markdown
Contributor

Overview

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

Usage:
llama-server -m model.gguf --no-sleep 30 -ngl 999
Default: 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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES — Claude Code was used for code generation and iterative debugging of all three backend heartbeat mechanisms. Initial design, workflow, and changes were human-initiated and tested on real hardware.

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.
@johnkarlhill
johnkarlhill requested review from a team as code owners July 1, 2026 21:02
@github-actions github-actions Bot added Vulkan Issues specific to the Vulkan backend server ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language CUDA Related to the CUDA backend labels Jul 1, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

Hi @johnkarlhill, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.

  • Multiple backend changes in one PR: When adding support for a new model or feature, focus on CPU support only in the initial PR. Add support for other backends like CUDA in follow-up PRs. If you have a good reason to modify multiple backends in one PR, please explain it.

  • AI-generated content: This project does not accept PRs, descriptions or commit messages that are fully or predominantly AI-generated. If you have used AI to assist you in writing code, please make sure to disclose that explicitly.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@arthw arthw 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.

It's good for SYCL backend.

Thank you!

@0cc4m

0cc4m commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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.

Comment thread common/arg.cpp Outdated
// 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") {

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.

is this a joke?

@johnkarlhill johnkarlhill Jul 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Easter egg... but if the name of the flag is changing, it doesn't make sense anymore. Removed.

@ORippler

ORippler commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

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.

+1. Please lay out clearly why this is a general problem not tied to a specific OS/IHV combination

@ngxson ngxson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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]>
@johnkarlhill

Copy link
Copy Markdown
Contributor Author

@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 johnkarlhill left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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.

@johnkarlhill johnkarlhill left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I forgot to mention, thank you all for reviewing!

@0cc4m

0cc4m commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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.

@ORippler is mostly concerned with the CUDA backend and I am concerned with the Vulkan backend. We're not talking about SYCL.

@ORippler

ORippler commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

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 still reads like a driver-level problem restricted to Intel Arc GPUs (and by extension SYCL/OpenVino + potentially Vulkan backends).

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.

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.

@sockless-coding

Copy link
Copy Markdown

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
Primary GPU: Nvidia 5070
Secondary GPU: Intel B70

Verified on SYCL
Verified on Vulcan in even when split between the Nvidia and Intel card the VRAM of the Intel card gets cleared after a few seconds of idle.

Moving things around so the B70 is the Primary and running the 5070 as secondary
Running the b9911 release of CUDA 13 does not reproduce the same problem model is still loaded in to VRam after 10min of idle.
Running the b9911 release of Vulcan does not reproduce the same problem model is still loaded in to VRam after 10min of idle.

This is a Intel Windows Driver issue, but the pull request solves the issue.
Since it's an optional flag wouldn't it be enough to just add proper documentation to it?
The flag does what it says, it sends a heartbeat to the GPU keeping it alive.

@ORippler ORippler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@0cc4m

0cc4m commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

For the Vulkan side, @rillomas are you aware of this behaviour?

@sockless-coding

Copy link
Copy Markdown

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.
Just writing a small keepalive app works as well and probably a better solution since this seem to be an Windows + Intel GPU without Display issue...

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.
I did not verify that the pull request solves the issue either since I'm not using the Vulkan backend myself.

@rillomas

rillomas commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

For the Vulkan side, @rillomas are you aware of this behaviour?

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.

@johnkarlhill
johnkarlhill marked this pull request as draft July 9, 2026 22:32
@johnkarlhill

johnkarlhill commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

@utopiafallen

utopiafallen commented Jul 11, 2026 •

Copy link
Copy Markdown

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
Would love to see the Vulkan bit added back in so I can pull this PR for my local Vulkan build to workaround the issue. I believe this issue also affects headless AMD multi-GPU (and maybe even single GPU recently?) since I was coming across similar complaints in my research to figuring out this issue. Thanks for putting this together!

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?

@johnkarlhill

Copy link
Copy Markdown
Contributor Author

@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!!

@utopiafallen

Copy link
Copy Markdown

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.

@rillomas

Copy link
Copy Markdown
Contributor

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.

I was able to reproduce this so made a separate issue #25646. Will be checking internally.

@Neutralized

Neutralized commented Aug 28, 2026 •

Copy link
Copy Markdown

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

@utopiafallen

Copy link
Copy Markdown

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.

@mroark1m

Copy link
Copy Markdown

I tried a dummy plug on the card display port but it doesn't seem to fix it.

@Neutralized

Copy link
Copy Markdown

I ended up plugging second monitor to my second card and it fixed the ram eviction

This branch has not been deployed

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

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning server SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants