[PR #5044] [CLOSED] [Engine] fix refused batch accounting, engine output decoding and q36 OOM messages #5297

Closed
opened 2026-11-07 16:34:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5044
Author: @bahooo22
Created: 11/3/2026
Status: ❌ Closed

Base: main ← Head: upstream-patches


📝 Commits (3)

  • 1bbdb32 serve: refused batch admissions are errors, not completed requests (#3040)
  • 5d2fb57 serve: decode the engine output with errors="replace"
  • 0c4ba48 q36: report need/free MiB on expert-buffer and staging OOM

📊 Changes

3 files changed (+65 additions, -28 deletions)

View changed files

📝 serve/server.py (+31 -20)
📝 serve/test_parallel.py (+9 -1)
📝 src/qwen35/q36_engine.cu (+25 -7)

📄 Description

Problem and result

Three independent defects on the Windows/CUDA engine side.

  1. Refused batch admissions counted as completed requests (#3040). A request admitted to
    no BGEN slot returned 503, but its history row was recorded as length with non-zero
    prompt_tokens, and the totals, latencies and last_timings included it. After the change
    such a request is an error row with prompt_tokens=0; the monitor keeps the row, while
    completion and latency totals stay unchanged. The next admitted request counts normally.
  2. The reader thread died on non-UTF-8 engine output. On Windows the engine can write
    non-UTF-8 bytes (e.g. 0x8e) to stdout; _readerthread raised
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e and the server lost the engine
    output. After the change both engine and vision-encoder Popen calls use
    errors="replace"; an undecodable byte becomes U+FFFD in diagnostic text only, protocol
    lines stay ASCII.
  3. cudaMalloc failures said only "out of memory" (#4252, #4215). The q36 engine printed
    the failing line number but not how much it needed or had free, so a user could not tell
    whether to shrink the context, MTP, slots or the quant. alloc_vram now covers the expert
    slots (L.blobs, the all-in-VRAM case included), the slot table, the expert scratch and
    the prompt staging, and reports need/free MiB with ctx, chunk, top_k and n_embd. Successful
    loads are unchanged.

Approach

Three small, independent commits; none changes a successful path. The accounting fix mirrors
the approach discussed in #3040/#3336: a local admission_rejected flag set only when
GpuBusy arrives before any segment and with zero tokens. The decoding fix is limited to the
two Popen calls that read the engine's stdout. The q36 patch moves the existing helper above
the expert-placement loop and routes the three remaining cudaMalloc calls through it; the
return codes and err strings keep their shape ("out of memory: needs N MiB, M MiB
free").

Validation

Passed:

  • python -m py_compile serve/server.py serve/test_parallel.py on ffa80d73 + the three
    commits — OK.
  • python -m unittest serve.test_parallel.ParallelService.test_bgen_refused_for_good_is_a_retryable_503_and_frees_the_slots -v
    on ffa80d73 + the three commits — 1/1 OK (4.6 s): 503, an error row with zero tokens and
    prompt_read=None, totals 1, and 2 after an admitted request.
  • The same q36 block builds in our tree with build-verify.bat — 25/25; the OOM message was
    observed on a real 8 GiB RTX 3060 Ti run of KAT Q5 80k:
    prompt staging (E.stage[1]) allocation failed: need 528.0 MiB, free 1260.0 MiB (ctx 81920, chunk 512, top_k 8, n_embd 2048). With --vram-reserve-mib 1200 the engine
    starts (9 slots, 1.03 GiB staging).
  • Windows native run: before the decoding fix the reader thread raised
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e; with it the reader continues.

Failed:

  • none observed.

Not run:

  • CUDA build of the rebased branch itself (the tree built is our fork, not ffa80d73 +
    these three commits; the q36 hunk applies cleanly, but a fresh upstream build was not made).
  • Real-model run on the rebased branch.
  • HIP, Metal, SYCL; AMD/Mac hardware was not available.

Limits

  • Commit 1bbdb329 duplicates the open PR #3336; drop it if that one is merged first.
  • The decoding change replaces an undecodable byte with U+FFFD in diagnostic lines; it does
    not attempt to guess the original encoding.
  • The q36 change is diagnostics only: it does not retry an allocation or fall back to a
    smaller chunk/reserve.
  • The OOM message was observed on a hybrid (VRAM+CPU experts) 8 GiB card; other placements
    report the same fields.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5044 **Author:** [@bahooo22](https://github.com/bahooo22) **Created:** 11/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `upstream-patches` --- ### 📝 Commits (3) - [`1bbdb32`](https://github.com/Niko1221/Strata/commit/1bbdb3291e7b8541496178dabf8221fbc483827d) serve: refused batch admissions are errors, not completed requests (#3040) - [`5d2fb57`](https://github.com/Niko1221/Strata/commit/5d2fb577d29b4645aaf6566a32105449ad09b65b) serve: decode the engine output with errors="replace" - [`0c4ba48`](https://github.com/Niko1221/Strata/commit/0c4ba485cf1ce13c4bce6c3e905958836bafe0b1) q36: report need/free MiB on expert-buffer and staging OOM ### 📊 Changes **3 files changed** (+65 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+31 -20) 📝 `serve/test_parallel.py` (+9 -1) 📝 `src/qwen35/q36_engine.cu` (+25 -7) </details> ### 📄 Description ## Problem and result Three independent defects on the Windows/CUDA engine side. 1. **Refused batch admissions counted as completed requests (#3040).** A request admitted to no BGEN slot returned 503, but its history row was recorded as `length` with non-zero `prompt_tokens`, and the totals, latencies and `last_timings` included it. After the change such a request is an `error` row with `prompt_tokens=0`; the monitor keeps the row, while completion and latency totals stay unchanged. The next admitted request counts normally. 2. **The reader thread died on non-UTF-8 engine output.** On Windows the engine can write non-UTF-8 bytes (e.g. 0x8e) to stdout; `_readerthread` raised `UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e` and the server lost the engine output. After the change both engine and vision-encoder `Popen` calls use `errors="replace"`; an undecodable byte becomes U+FFFD in diagnostic text only, protocol lines stay ASCII. 3. **cudaMalloc failures said only "out of memory" (#4252, #4215).** The q36 engine printed the failing line number but not how much it needed or had free, so a user could not tell whether to shrink the context, MTP, slots or the quant. `alloc_vram` now covers the expert slots (`L.blobs`, the all-in-VRAM case included), the slot table, the expert scratch and the prompt staging, and reports need/free MiB with ctx, chunk, top_k and n_embd. Successful loads are unchanged. ## Related discussion - #3040: https://github.com/Niko1221/Strata/issues/3040 — the same behavior as the open PR #3336; if that PR lands first, drop commit `1bbdb329`. - #4252: https://github.com/Niko1221/Strata/issues/4252 and #4215: https://github.com/Niko1221/Strata/issues/4215 — OOM tail diagnostics. - The decoding fix has no issue; it was found by running the native q36 engine on Windows. ## Approach Three small, independent commits; none changes a successful path. The accounting fix mirrors the approach discussed in #3040/#3336: a local `admission_rejected` flag set only when `GpuBusy` arrives before any segment and with zero tokens. The decoding fix is limited to the two `Popen` calls that read the engine's stdout. The q36 patch moves the existing helper above the expert-placement loop and routes the three remaining `cudaMalloc` calls through it; the return codes and `err` strings keep their shape ("out of memory: <what> needs N MiB, M MiB free"). ## Validation **Passed:** - `python -m py_compile serve/server.py serve/test_parallel.py` on `ffa80d73` + the three commits — OK. - `python -m unittest serve.test_parallel.ParallelService.test_bgen_refused_for_good_is_a_retryable_503_and_frees_the_slots -v` on `ffa80d73` + the three commits — 1/1 OK (4.6 s): 503, an error row with zero tokens and `prompt_read=None`, totals 1, and 2 after an admitted request. - The same q36 block builds in our tree with `build-verify.bat` — 25/25; the OOM message was observed on a real 8 GiB RTX 3060 Ti run of KAT Q5 80k: `prompt staging (E.stage[1]) allocation failed: need 528.0 MiB, free 1260.0 MiB (ctx 81920, chunk 512, top_k 8, n_embd 2048)`. With `--vram-reserve-mib 1200` the engine starts (9 slots, 1.03 GiB staging). - Windows native run: before the decoding fix the reader thread raised `UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e`; with it the reader continues. **Failed:** - none observed. **Not run:** - CUDA build of the rebased branch itself (the tree built is our fork, not `ffa80d73` + these three commits; the q36 hunk applies cleanly, but a fresh upstream build was not made). - Real-model run on the rebased branch. - HIP, Metal, SYCL; AMD/Mac hardware was not available. ## Limits - Commit `1bbdb329` duplicates the open PR #3336; drop it if that one is merged first. - The decoding change replaces an undecodable byte with U+FFFD in diagnostic lines; it does not attempt to guess the original encoding. - The q36 change is diagnostics only: it does not retry an allocation or fall back to a smaller chunk/reserve. - The OOM message was observed on a hybrid (VRAM+CPU experts) 8 GiB card; other placements report the same fields. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:34:10 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5297
No description provided.