Repository navigation
Studio: scale the token count timeout so long chats can compact - #15900
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Reached Codex review convergence at oobabooga#431. |
…che builds in the background (#16013) ## Summary `studio/backend/tests/test_rag_store.py::test_dense_packs_float32_rows_without_struct_and_the_query_once` (from #15859) fails now and then since #15961, on PRs that do not touch RAG (seen on the `(Python 3.13, g-r)` shard for #15900): ``` tests/test_rag_store.py:619: in test_dense_packs_float32_rows_without_struct_and_the_query_once assert ranked == as_list and ranked[0][1] > 0.99 E At index 4 diff: ('d1:2', 0.7071067988872528) != ('d1:2', 0.7071067690849304) ``` The test runs `search_dense` twice (numpy query, then the same query as a list) and expects identical results. Since #15961 the first search finds no in-memory matrix for the scope and queues a build on the `rag-vec-cache` background thread. If that build lands before the second search, the second answer comes from the numpy matrix instead of vec0, and the two backends' cosine scores differ in the last few ulps. Reproduced on main by pausing 1 s between the two calls: it fails every time. What the test is about (the query is packed once, numpy and list inputs answer alike) does not depend on the cache. ## What changed The test sets `RAG_VEC_CACHE=0` through `monkeypatch`, so both searches go through vec0 regardless of timing. ## Verification - Main with a 1 s pause between the two searches: fails with the diff above. Same pause with this change: passes. - `tests/test_rag_store.py` and `tests/test_rag_vec_cache.py`: 45 passed. - With `_search_dense` packing the query per scope instead of once, the test fails with `assert 4 == 1`, so the guard it was written for still bites.
|
Review record for #15900, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#587. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
Merge the two approaches for unslothai#15800: 1. Byte-count guard (our original fix): when the UTF-8 content exceeds n_ctx * 4 bytes, return an estimate (bytes // 3) without calling /apply-template. This bypasses the 2-3 minute wait on multi-million-token transcripts. The fit loop drops messages and re-counts; by then the list is below the threshold. 2. Scaled read timeout (from unslothai#15900): the httpx read timeout is now 10 s + 1 s per 100k characters of the serialized payload, so a slow CPU can finish an exact count that would have hit the old fixed 10 s ceiling. Connect, write, and pool timeouts stay at 10 s. 3. Timeout error reporting: a ReadTimeout during a count is now reported as 'llama-server timed out counting the prompt' instead of being swallowed as a template refusal. The fit loop's first count is the estimate (fast, no HTTP); subsequent counts are exact (scaled timeout). No changes to fit_rolling_context, fit_checkpoint_context, or any caller. Fixes unslothai#15800
Fixes #15800.
Problem
Once a GGUF chat's stored transcript is several million tokens long, it stops compacting. Automatic compaction and "Compact conversation" both fail. Each send runs for about two minutes and then shows "Message too long", so the thread cannot be continued. The reporter's log:
Root cause
fit_checkpoint_contextandfit_rolling_contextboth start with an exact count of the whole transcript (/apply-template, then/tokenize).count_chat_tokensgives each request a fixed 10 s timeout. llama-server renders and tokenizes on one thread, so past a CPU-dependent size the count times out._render_countswallows theReadTimeoutand reports it as a template failure. Both fits fail, and the preflight sends the transcript unfitted.The reporter's Xeon E5-4669 v4 took 11.1 s just to tokenize their 1.68M-token prompt. The reload in the report is incidental: the thread had grown past the threshold.
/compactruns through the same fit, so it fails the same way.Fix
count_chat_tokenssizes its read timeout to the prompt: 10 s plus 1 s per 100,000 characters of messages, system prompt and tools. That is a sixth of the reporter's measured rate, so a slow CPU can finish a long count while a stuck server still times out. Connect, write and pool timeouts stay at 10 s.llama-server timed out counting the promptinstead of blaming the template.The fits and their counts are otherwise unchanged and stay exact.
Behavior boundaries
Verification
Live A/B with
unsloth/Qwen3.5-4B-MTP-GGUFUD-Q4_K_XL at a 16,384-token context. Each request was a 12.2M-token transcript followed by "What is 2+2?", withcontext_overflow: truncate_oldest:compact_contextOn main, the checkpoint runs logged the reporter's exact sequence. With this PR, no warnings or errors were logged,
prompt_tokens_beforewas llama-server's exact 12,203,714, and 1-, 10- and 40-turn chats behaved as before.New
tests/test_count_chat_tokens_timeout.pydrives the rolling fit, the checkpoint fit and/compactthroughcount_chat_tokens, against a llama-server stand-in that renders at the reporter's measured speed and times out when the client's timeout is too short. With main's fixed 10 s, those tests fail. It also checks the timeout floor for short prompts and the timeout message. The 71 existing test files that exercise these fits orcount_chat_tokenspassed before the timeout was narrowed to reads, and the fit and count tests among them pass after it.