Skip to content

server: fix token counting API crash on sleep - #29309

Merged
ngxson merged 3 commits into
ggml-org:masterfrom
willweimike:master
Sep 23, 2026
Merged

ngxson merged 3 commits into
ggml-org:masterfrom
willweimike:master

Conversation

@willweimike

Copy link
Copy Markdown
Contributor

Overview

Fixed #29188

Fixed that if the server was in a sleeping state, the token counting endpoint read ctx_server.vocab without waking up correctly.

Additional information

Add test_sleep.py to ensure that the endpoint can successfully wake up a server that is in sleep mode.

Requirements

@willweimike
willweimike requested a review from a team as a code owner September 23, 2026 10:45
@ServeurpersoCom

Copy link
Copy Markdown
Contributor

Hello, reproduced the crash on master, a SIGSEGV on the first count request after sleep with and without mmproj, and the new test fails there too. With the fix, /chat/completions/input_tokens, /v1/chat/completions/input_tokens, /responses/input_tokens, /v1/responses/input_tokens and /v1/messages/count_tokens all wake the server and return the right count, and test_sleep.py passes.

Nit: the three local aliases are not needed, reading ctx_server.vocab, ctx_server.mctx and ctx_server.init_opt inline after create_response() would keep it shorter.

@willweimike
willweimike marked this pull request as draft September 23, 2026 12:09
@willweimike
willweimike marked this pull request as ready for review September 23, 2026 12:10
@willweimike

Copy link
Copy Markdown
Contributor Author

@ServeurpersoCom Thank you for your kind suggestion! I have refined it.

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

LGTM, re-tested the updated version: every count route wakes the server without crashing and test_sleep.py passes.

@ServeurpersoCom

Copy link
Copy Markdown
Contributor

cc @ngxson

@ngxson ngxson changed the title server: wake up sleeping server correctly server: fix token counting API crash on sleep Sep 23, 2026
@ngxson
ngxson merged commit 42916d8 into ggml-org:master Sep 23, 2026
14 of 17 checks passed
despc added a commit to despc/llama.cpp that referenced this pull request Sep 26, 2026
Conflicts resolved by hand, keeping the fork's functionality:
- allreduce.cu: our mixed-runtime collective kept; upstream's HIP enablement
  and CUDA_CHECK cleanup applied, #else stub comment taken from upstream.
- llama-context.cpp/.h: upstream's per-graph-type gf_res_prev and
  gf_res_prev_active (ggml-org#28549, CUDA graph for MTP draft) around our ubatch
  phase profiler; expert heatmap/hotstore members kept.
- server-context.cpp/.h: upstream's handle_count_tokens signature (ggml-org#29309)
  with our reject_unknown_model guard.
- fattn-common.cuh: our GGML_CUDA_FATTN_LAUNCH_PROFILE log kept.
qwen4exp.cpp auto-merged: our MTP head kept, upstream hc ops and sparse FA in
(PR ggml-org#28243 still unmerged upstream, so MTP stays ours).

Validation (greedy, temp 0 / top_k 1 / seed 42, hash of reasoning+content):
- Qwen3.8-27B 4-GPU MTP: byte-identical to the old build on all prompts.
- Qwen3.8-Flash 4-GPU MTP: 1 of 3 identical, 2 diverge late. Cause is the
  fused hc_pre_gated/hc_post ops from ggml-org#28901 (different rounding order);
  still diverges with GGML_CUDA_DISABLE_FUSION=1. test-backend-ops passes
  DSV4_HC_PRE/POST on CUDA0, CUDA1, V100_CUDA0, V100_CUDA1. Perplexity
  (docs corpus, 24x1024): 5.4967 +/- 0.127 old, 5.4707 +/- 0.126 new.
Generation speed unchanged on both models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wizard815 pushed a commit to Wizard815/mx-llama.cpp-Rocm10 that referenced this pull request Sep 29, 2026
* server: wake up sleeping server correctly

* server: wake up sleeping server correctly (local aliases removed)

(cherry picked from commit 42916d8)
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
* server: wake up sleeping server correctly

* server: wake up sleeping server correctly (local aliases removed)
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 7, 2026
* server: wake up sleeping server correctly

* server: wake up sleeping server correctly (local aliases removed)

(cherry picked from commit 42916d8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eval bug: SIGSEGV in token-counting routes when the request arrives while the server is sleeping (stale vocab/mctx captured before the wake barrier)

3 participants