Commit 9f694ab
* fix(studio): Windows GGUF cancel hang + CPU spinlock overhead (#5692)
Two fixes for Windows-native GGUF inference via llama-server:
**Issue 1 — GPU/CUDA Hang on Stream Cancellation:**
- Add `Connection: close` header to all httpx requests proxying to
llama-server, preventing Keep-Alive from masking downstream socket
closure.
- Introduce `_await_disconnect_then_close` background watcher that
polls `request.is_disconnected()` every 100ms and calls
`resp.aclose()` immediately when the client disconnects. This runs
alongside the existing cancel-POST watcher and covers client aborts
that never reach the /cancel endpoint (tab close, proxy aborts,
Colab, mobile navigation, etc.).
- Change all StreamingResponse `Connection: keep-alive` headers to
`Connection: close`.
**Issue 2 — High CPU Spinlock & KV Cache Backup Overhead:**
- Set OMP_WAIT_POLICY=PASSIVE and OMP_NUM_THREADS=2 in the
llama-server subprocess environment on Windows to prevent OpenMP
from spin-waiting on all logical cores while the GPU decodes.
- Limit `--threads` to 2 on Windows when the model is fully
GPU-offloaded (`-ngl -1`). Auto-detect otherwise.
- Pass `--cache-ram 0 --ctx-checkpoints 0 --no-cache-prompt
--checkpoint-every-n-tokens -1` on Windows to disable prompt-cache
snapshots that copy KV cache to system RAM over the WDDM/PCI-E bus.
Closes #5692.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix: use local import to avoid ruff F823 (sys used before assignment)
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* review: address gemini review feedback
- Simplify _fully_gpu_offloaded init: default to False, only set True
in the gpu_indices branch, drop redundant else.
- Log exceptions in _await_disconnect_then_close at debug level instead
of silent pass, per review suggestion.
* Adjust review feedback for PR #5749
- _await_disconnect_then_close: set cancel_event before resp.aclose() so
the streamer's RemoteProtocolError handler treats the watcher-driven
close as cancellation, not an upstream error. Both call sites pass
cancel_event through.
- Windows --cache-ram / --no-cache-prompt / --ctx-checkpoints block: gate
on _fully_gpu_offloaded so CPU and partial-offload Windows runs keep
prompt-cache reuse across turns.
- Windows OMP_WAIT_POLICY / OMP_NUM_THREADS env: same gate so CPU and
partial-offload Windows runs keep default OpenMP parallelism.
* Shorten code comments touched by PR #5749
* Clean up local imports and rename underscore locals in PR #5749
- Drop the function-local `import sys as _sys` introduced as an F823
workaround; remove the redundant in-function `import os`/`import sys`
block so module-level imports resolve sys/os instead. F823 no longer
triggers because no shadowing import remains inside load_model.
- Rename `_fully_gpu_offloaded` and `_t` to `fully_gpu_offloaded` and
`threads_arg`. Underscore-prefixed names usually mean private/module-
level; plain locals match Python style for in-function temporaries.
No behavior change. ruff clean, py_compile clean, 35 studio cancel-
infra tests + 13 launch-gating AST locks + 6 disconnect-watcher locks
+ 4 spoof live-import tests all pass.
* Fix Windows GGUF follow-ups for PR #5749
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix cache flag gating for PR #5749
* Fix Python 3.9 annotations for PR #5749
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: Anmol Mishra <anmolx.work@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <danielhanchen@gmail.com>
Co-authored-by: wasimysaid <wasimysdev@gmail.com>
Co-authored-by: Lee Jackson <130007945+Imagineer99@users.noreply.github.com>
1 parent 4176448 commit 9f694ab
4 files changed
Lines changed: 303 additions & 43 deletions
File tree
- studio/backend
- core/inference
- routes
- tests
- tests/studio
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
570 | 586 | | |
571 | 587 | | |
572 | 588 | | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
| 589 | + | |
| 590 | + | |
578 | 591 | | |
579 | 592 | | |
580 | 593 | | |
| |||
1217 | 1230 | | |
1218 | 1231 | | |
1219 | 1232 | | |
1220 | | - | |
| 1233 | + | |
1221 | 1234 | | |
1222 | 1235 | | |
1223 | 1236 | | |
| |||
1242 | 1255 | | |
1243 | 1256 | | |
1244 | 1257 | | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
1245 | 1261 | | |
1246 | 1262 | | |
1247 | 1263 | | |
| |||
1257 | 1273 | | |
1258 | 1274 | | |
1259 | 1275 | | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
1260 | 1279 | | |
1261 | 1280 | | |
1262 | 1281 | | |
| |||
1347 | 1366 | | |
1348 | 1367 | | |
1349 | 1368 | | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
1350 | 1372 | | |
1351 | 1373 | | |
1352 | 1374 | | |
| |||
1359 | 1381 | | |
1360 | 1382 | | |
1361 | 1383 | | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
1362 | 1387 | | |
1363 | 1388 | | |
1364 | 1389 | | |
| |||
3924 | 3949 | | |
3925 | 3950 | | |
3926 | 3951 | | |
| 3952 | + | |
3927 | 3953 | | |
3928 | 3954 | | |
3929 | 3955 | | |
3930 | 3956 | | |
3931 | 3957 | | |
| 3958 | + | |
3932 | 3959 | | |
| 3960 | + | |
3933 | 3961 | | |
3934 | 3962 | | |
3935 | 3963 | | |
3936 | 3964 | | |
3937 | 3965 | | |
3938 | 3966 | | |
3939 | | - | |
| 3967 | + | |
3940 | 3968 | | |
3941 | 3969 | | |
| 3970 | + | |
| 3971 | + | |
| 3972 | + | |
| 3973 | + | |
| 3974 | + | |
3942 | 3975 | | |
3943 | | - | |
3944 | | - | |
3945 | | - | |
3946 | | - | |
3947 | | - | |
| 3976 | + | |
| 3977 | + | |
| 3978 | + | |
| 3979 | + | |
| 3980 | + | |
| 3981 | + | |
| 3982 | + | |
| 3983 | + | |
| 3984 | + | |
| 3985 | + | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
3948 | 3989 | | |
3949 | 3990 | | |
3950 | 3991 | | |
| |||
4086 | 4127 | | |
4087 | 4128 | | |
4088 | 4129 | | |
| 4130 | + | |
| 4131 | + | |
| 4132 | + | |
| 4133 | + | |
| 4134 | + | |
| 4135 | + | |
| 4136 | + | |
| 4137 | + | |
| 4138 | + | |
| 4139 | + | |
| 4140 | + | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
| 4150 | + | |
| 4151 | + | |
4089 | 4152 | | |
4090 | 4153 | | |
4091 | 4154 | | |
| |||
4101 | 4164 | | |
4102 | 4165 | | |
4103 | 4166 | | |
4104 | | - | |
4105 | | - | |
4106 | | - | |
4107 | 4167 | | |
4108 | 4168 | | |
4109 | 4169 | | |
| |||
4131 | 4191 | | |
4132 | 4192 | | |
4133 | 4193 | | |
| 4194 | + | |
| 4195 | + | |
| 4196 | + | |
| 4197 | + | |
| 4198 | + | |
| 4199 | + | |
| 4200 | + | |
| 4201 | + | |
4134 | 4202 | | |
4135 | 4203 | | |
4136 | 4204 | | |
| |||
5512 | 5580 | | |
5513 | 5581 | | |
5514 | 5582 | | |
5515 | | - | |
| 5583 | + | |
5516 | 5584 | | |
5517 | 5585 | | |
5518 | 5586 | | |
| |||
0 commit comments