[GH-ISSUE #4708] [Engine] Qwen3.6 warmup writes past KV cache at context=prompt chunk=2048 #2156

Closed
opened 2026-11-04 01:57:06 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @rrp1696 on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4708

Problem and result

The Qwen3.6 engine (strata-q36, engine build 0.1.54) reproducibly fails during startup warmup on a Colab Tesla T4 with --context 2048 and a 2048-token prompt chunk. The surfaced error is cudaMemcpyAsync(...): an illegal memory access was encountered (original q36_engine.cu:2288), but Compute Sanitizer traces the first invalid global write to k_attn_prep, called during Engine::warmup().

Reproduced on real hardware. A two-change source patch bounded the initial warmup input by the configured context and reset the sequence position before the smaller GEMM/decode/speculative probes. On the same T4 and original model/settings, the patched engine started with warmup enabled, completed 3/3 identical Japanese inference requests, and finished a separate startup/warmup Compute Sanitizer test with zero errors. This is a locally tested patch, not a claim about an official release.

Environment

  • Strata application 0.2.8, Qwen3.6 engine build 0.1.54; source commit: 870aedd9e1ebe1c91f94da93b59af17729f6c5c0.
  • Colab Linux x86_64, Tesla T4 (SM 7.5, 15,360 MiB total VRAM), High-RAM (50.990 GiB total RAM); CUDA toolkit 13.0, NVIDIA driver 580.82.07.
  • Qwen3.6-35B-A3B, Unsloth UD-Q4_K_XL, GGUF 22,853,663,008 bytes; context 2048; 2048-token prompt chunk; vision off; prefill auto; MTP 2 configured; MMQ enabled. CPU/GPU expert placement was not changed by the fix.

Minimal reproduction and workaround

With the specified model installed, run on the T4/High-RAM environment:

strata launch --family qwen36 --model ud-q4_k_xl --context 2048 --vision off --tune skip --no-tui --yes --access local --port 18130 --output json

Observed, unmodified release: startup fails with an illegal CUDA memory access. CUDA_LAUNCH_BLOCKING=1 moves the reported failure earlier into the attention/GEMM path, but does not by itself identify the first bad kernel.

Control with the same model and settings: append --set no-warmup=on to the command. The unmodified engine then started and answered 3/3 requests correctly. That is a diagnostic workaround, not the proposed permanent fix.

Root cause

In src/qwen35/q36_engine.cu, Engine::warmup(), the first process() takes tmax tokens. With ctx = tmax = 2048, this fills KV positions 0–2047. The subsequent process(..., kGemmT + 1, ...) adds nine tokens without resetting the position. The first added positions are 2048–2056, outside the allocated context.

Under Compute Sanitizer, the first reported invalid write is in k_attn_prep, not in the later cudaMemcpyAsync that first surfaced the asynchronous CUDA failure. The reported address was 7,425 bytes after the last valid byte of a 4,194,304-byte KV allocation; this matches the model's attention dimensions and the offending position/head/thread index.

Focused proposed source change

--- a/src/qwen35/q36_engine.cu
+++ b/src/qwen35/q36_engine.cu
@@ -2759,8 +2759,11 @@
         const auto t0 = Clock::now();
         warming = true;
         const int32_t filler = 198;   // a newline: any token works
-        std::vector<int32_t> toks((size_t) tmax, filler);
+        // The prompt chunk may equal or exceed the configured context.  Warm only cells that exist, then
+        // start the small-prompt/decode/speculative probes in a fresh sequence instead of appending past ctx.
+        std::vector<int32_t> toks((size_t) std::min(tmax, ctx), filler);
         process(toks.data(), (int64_t) toks.size(), [](int64_t) {});
+        reset();
         if (tmax > kGemmT + 1) process(toks.data(), kGemmT + 1, [](int64_t) {});   // the smallest GEMM chunk too
         process(&filler, 1, [](int64_t) {});
         if (mtp_d > 0) {

The essential change for ctx == tmax == 2048 is the reset() between the initial full prompt and the subsequent warmup probes; limiting the initial token count alone does not resolve the observed overflow. The patch does not modify MMQ, expert routing/copies, model weights, or request-time context handling.

Real-hardware validation

Trial Result
Original 0.1.54, warmup on FAIL: CUDA illegal memory access during startup
Original with CUDA_LAUNCH_BLOCKING=1 FAIL: reported error moves to attention scores GEMM
Original with only --set no-warmup=on PASS: starts; Japanese question 3/3; no CUDA error log during requests
Original under compute-sanitizer --tool memcheck FAIL: 1,186 memory-error reports; first invalid global write in k_attn_prep; exit 99
Patched source, CUDA 13 / SM75 Release build PASS
Patched engine, warmup on, same model/settings PASS: loaded; all 3 answer bodies exactly 25; normal-run CUDA error logs 0
Patched startup/warmup under Compute Sanitizer PASS: ERROR SUMMARY: 0 errors; exit 0 (separate from three-question test)

All three regular inference requests used 5の二乗はいくつですか。数字だけで答えてください。 with temperature 0, and ended with finish_reason=stop. The patched engine's measured native decode rates were 35.1, 51.4 and 51.5 tokens/s (short-question test only); peak observed GPU use was 14,359 MiB. These timings are not a controlled claim of a general performance improvement.

Reproduction status and limits

  • Reproduced locally on one Colab T4 High-RAM instance with the fixed source revision above. Original and patched results were obtained on real hardware; the reported CUDA error is not a static-only inference.
  • Sanitizer's zero-error result covers the patched startup/warmup and its internal prompt/decode/speculative probes, not the three API requests, which passed in a separate normal run.
  • This does not establish long-context, sustained/multi-conversation, non-T4, or low-RAM compatibility; no claim about the earlier ~13 GB RAM failure.
  • The current public source at the checked commit contains the same warmup sequence. This local fix has not been independently built and tested against a later upstream commit, if one appears.

The patch and minimal, sanitized evidence summary are available for maintainer review; I can provide the relevant raw diagnostic excerpts after reviewing them for secrets/private paths. No private application data is needed to reproduce this defect.

Originally created by @rrp1696 on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4708 ## Problem and result The Qwen3.6 engine (`strata-q36`, engine build 0.1.54) reproducibly fails during startup warmup on a Colab Tesla T4 with `--context 2048` and a 2048-token prompt chunk. The surfaced error is `cudaMemcpyAsync(...): an illegal memory access was encountered` (original `q36_engine.cu:2288`), but Compute Sanitizer traces the first invalid global write to `k_attn_prep`, called during `Engine::warmup()`. **Reproduced on real hardware.** A two-change source patch bounded the initial warmup input by the configured context and reset the sequence position before the smaller GEMM/decode/speculative probes. On the same T4 and original model/settings, the patched engine started with warmup **enabled**, completed 3/3 identical Japanese inference requests, and finished a separate *startup/warmup* Compute Sanitizer test with zero errors. This is a locally tested patch, not a claim about an official release. ## Environment - Strata application 0.2.8, Qwen3.6 engine build 0.1.54; source commit: [`870aedd9e1ebe1c91f94da93b59af17729f6c5c0`](https://github.com/Niko1221/Strata/commit/870aedd9e1ebe1c91f94da93b59af17729f6c5c0). - Colab Linux x86_64, Tesla T4 (SM 7.5, 15,360 MiB total VRAM), High-RAM (50.990 GiB total RAM); CUDA toolkit 13.0, NVIDIA driver 580.82.07. - Qwen3.6-35B-A3B, Unsloth UD-Q4_K_XL, GGUF 22,853,663,008 bytes; context 2048; 2048-token prompt chunk; vision off; prefill auto; MTP 2 configured; MMQ enabled. CPU/GPU expert placement was not changed by the fix. ## Minimal reproduction and workaround With the specified model installed, run on the T4/High-RAM environment: ```sh strata launch --family qwen36 --model ud-q4_k_xl --context 2048 --vision off --tune skip --no-tui --yes --access local --port 18130 --output json ``` **Observed, unmodified release:** startup fails with an illegal CUDA memory access. `CUDA_LAUNCH_BLOCKING=1` moves the reported failure earlier into the attention/GEMM path, but does not by itself identify the first bad kernel. **Control with the same model and settings:** append `--set no-warmup=on` to the command. The unmodified engine then started and answered 3/3 requests correctly. That is a diagnostic workaround, not the proposed permanent fix. ## Root cause In [`src/qwen35/q36_engine.cu`, `Engine::warmup()`](https://github.com/Niko1221/Strata/blob/870aedd9e1ebe1c91f94da93b59af17729f6c5c0/src/qwen35/q36_engine.cu#L2758-L2780), the first `process()` takes `tmax` tokens. With `ctx = tmax = 2048`, this fills KV positions 0–2047. The subsequent `process(..., kGemmT + 1, ...)` adds nine tokens *without resetting the position*. The first added positions are 2048–2056, outside the allocated context. Under Compute Sanitizer, the first reported invalid write is in `k_attn_prep`, not in the later `cudaMemcpyAsync` that first surfaced the asynchronous CUDA failure. The reported address was **7,425 bytes after the last valid byte** of a **4,194,304-byte** KV allocation; this matches the model's attention dimensions and the offending position/head/thread index. ## Focused proposed source change ```diff --- a/src/qwen35/q36_engine.cu +++ b/src/qwen35/q36_engine.cu @@ -2759,8 +2759,11 @@ const auto t0 = Clock::now(); warming = true; const int32_t filler = 198; // a newline: any token works - std::vector<int32_t> toks((size_t) tmax, filler); + // The prompt chunk may equal or exceed the configured context. Warm only cells that exist, then + // start the small-prompt/decode/speculative probes in a fresh sequence instead of appending past ctx. + std::vector<int32_t> toks((size_t) std::min(tmax, ctx), filler); process(toks.data(), (int64_t) toks.size(), [](int64_t) {}); + reset(); if (tmax > kGemmT + 1) process(toks.data(), kGemmT + 1, [](int64_t) {}); // the smallest GEMM chunk too process(&filler, 1, [](int64_t) {}); if (mtp_d > 0) { ``` The essential change for `ctx == tmax == 2048` is the `reset()` **between** the initial full prompt and the subsequent warmup probes; limiting the initial token count alone does not resolve the observed overflow. The patch does not modify MMQ, expert routing/copies, model weights, or request-time context handling. ## Real-hardware validation | Trial | Result | | --- | --- | | Original 0.1.54, warmup on | FAIL: CUDA illegal memory access during startup | | Original with `CUDA_LAUNCH_BLOCKING=1` | FAIL: reported error moves to attention scores GEMM | | Original with only `--set no-warmup=on` | PASS: starts; Japanese question 3/3; no CUDA error log during requests | | Original under `compute-sanitizer --tool memcheck` | FAIL: 1,186 memory-error reports; first invalid global write in `k_attn_prep`; exit 99 | | Patched source, CUDA 13 / SM75 Release build | PASS | | Patched engine, warmup on, same model/settings | PASS: loaded; all 3 answer bodies exactly `25`; normal-run CUDA error logs 0 | | Patched **startup/warmup** under Compute Sanitizer | PASS: `ERROR SUMMARY: 0 errors`; exit 0 (separate from three-question test) | All three regular inference requests used `5の二乗はいくつですか。数字だけで答えてください。` with temperature 0, and ended with `finish_reason=stop`. The patched engine's measured native decode rates were 35.1, 51.4 and 51.5 tokens/s (short-question test only); peak observed GPU use was 14,359 MiB. These timings are **not** a controlled claim of a general performance improvement. ## Reproduction status and limits - **Reproduced locally** on one Colab T4 High-RAM instance with the fixed source revision above. Original and patched results were obtained on real hardware; the reported CUDA error is not a static-only inference. - Sanitizer's zero-error result covers the patched **startup/warmup and its internal prompt/decode/speculative probes**, *not* the three API requests, which passed in a separate normal run. - This does not establish long-context, sustained/multi-conversation, non-T4, or low-RAM compatibility; no claim about the earlier ~13 GB RAM failure. - The current public source at the checked commit contains the same warmup sequence. This local fix has **not** been independently built and tested against a later upstream commit, if one appears. The patch and minimal, sanitized evidence summary are available for maintainer review; I can provide the relevant raw diagnostic excerpts after reviewing them for secrets/private paths. No private application data is needed to reproduce this defect.
Author
Owner

@Niko1221 commented on GitHub (Oct 31, 2026):

Fixed in 0.2.9. Your analysis was right: the warm-up now only fills the cells that exist and starts its later steps from a clean state. We ran your case (context 2048, chunk 2048) on an RTX A4000 with a Qwen3.6-35B-A3B file. The 0.2.8 engine crashed at start; the new one starts and answers, and three test answers match 0.2.8 word for word. We couldn't run it on a T4, so please comment here if yours still has trouble.

<!-- gh-comment-id:6541131474 --> @Niko1221 commented on GitHub (Oct 31, 2026): Fixed in [0.2.9](https://github.com/Niko1221/Strata/releases/tag/v0.2.9). Your analysis was right: the warm-up now only fills the cells that exist and starts its later steps from a clean state. We ran your case (context 2048, chunk 2048) on an RTX A4000 with a Qwen3.6-35B-A3B file. The 0.2.8 engine crashed at start; the new one starts and answers, and three test answers match 0.2.8 word for word. We couldn't run it on a T4, so please comment here if yours still has trouble.
Author
Owner

@rrp1696 commented on GitHub (Oct 31, 2026):

Thank you for the quick fix and for confirming the root cause on the RTX A4000. It's great to see the fix included in 0.2.9!

For clarity, my locally patched engine passed on a Colab T4 with context 2048 / chunk 2048: all three test requests returned the expected answer, and a separate Compute Sanitizer startup/warmup run reported 0 errors.

I haven't tested the official 0.2.9 build on the T4 yet, so I can't confirm that release on T4. If I encounter any issues with it, I'll report them here.

Thanks again for addressing this so quickly!

<!-- gh-comment-id:6546223301 --> @rrp1696 commented on GitHub (Oct 31, 2026): Thank you for the quick fix and for confirming the root cause on the RTX A4000. It's great to see the fix included in 0.2.9! For clarity, my **locally patched** engine passed on a Colab T4 with context 2048 / chunk 2048: all three test requests returned the expected answer, and a separate Compute Sanitizer startup/warmup run reported **0 errors**. I haven't tested the **official 0.2.9 build** on the T4 yet, so I can't confirm that release on T4. If I encounter any issues with it, I'll report them here. Thanks again for addressing this so quickly!
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#2156
No description provided.