You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Windows Native GGUF Inference: GPU/CUDA Hang on Cancel & High CPU Spinlock Overhead #5692
Description: We identified two critical performance and resource-leak issues when running GGUF models on Windows Native environment using the llama-server backend. We have successfully resolved these locally with the following patches.
Issue 1: GPU/CUDA Hang on Stream Cancellation (Socket Leak)
Symptom: When a user stops/cancels a chat completion streaming midway (e.g., stopping the generation or closing the tab), llama-server continues decoding in the background. The GPU utilization stays at 100%, and the fans keep spinning indefinitely.
Root Cause: In
inference.py
, the httpx.AsyncClient proxies completions using HTTP Keep-Alive. When the client disconnects, llama-server is never notified of the closed connection.
Fix: Disable Keep-Alive with Connection: close header and max_keepalive_connections=0. Add a background cancel_watcher task checking request.is_disconnected() to actively trigger resp.aclose() to drop the connection:
python
In backend/routes/inference.py
async def cancel_watcher():
try:
while True:
if await request.is_disconnected():
await resp.aclose()
break
await asyncio.sleep(0.1)
except asyncio.CancelledError:
pass
Issue 2: High CPU Spinlock & KV Cache Backup Bottleneck on Windows
Symptom: During GGUF inference (especially with MTP/speculative decoding), CPU usage spikes to 100% causing heavy thermal throttling and loud noise, even when fully offloaded to the GPU (ngl -1).
Root Causes:
OpenMP Spinlock: The default OpenMP behavior in Windows spawns threads up to the logical core count to await GPU completion, wasting CPU cycles in a spinlock.
KV Cache Sync: llama-server copies prompt cache checkpoints to system RAM by default, causing massive WDDM driver and PCI-E bandwidth overheads on Windows.
Fix: Apply Windows-specific optimizations in
llama_cpp.py
:
Limit CPU threads to 2 when fully offloaded to GPU on Windows.
Force OMP_WAIT_POLICY=PASSIVE and OMP_NUM_THREADS=2 in the subprocess environment.
Disable context RAM checkpoints explicitly by adding --cache-ram 0, --ctx-checkpoints 0, --no-cache-prompt, and --checkpoint-every-n-tokens -1 to the server command on Windows.
Environment:
OS: Windows 11 (Native)
CUDA Version: 12.x
Unsloth Studio Version: Latest (Windows prebuilts)
Activity
rgseguridadbrk-hue commentedon Jun 1, 2026
cuando activo mtp el procesador se va al 100%
fix(studio): Windows GGUF cancel hang + CPU spinlock overhead (unslot…
Studio (Windows): keep prompt caching on full GPU offload (#7260)
Charge a tool loop for the catalogue it injects, and bound the wait f…
Charge a re-cost for everything the reservation charged
Let tool chats decode in parallel instead of one at a time (#10046)
Studio: keep the llama-server prompt cache on a shared-memory GPU (#1…
Merge origin/main into planner-cost-gate