[PR #5127] [Engine] DS4_PROF: a chunked prompt overflows the profile's sample array (stack smashing) #5317

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5127
Author: @R-Okauchi
Created: 11/3/2026
Status: 🔄 Open

Base: main ← Head: dsv41-prof-sample


📝 Commits (1)

  • c9cf36a DeepSeek engine: DS4_PROF's chunked prompt fits its sample array again

📊 Changes

1 file changed (+5 additions, -3 deletions)

View changed files

📝 src/dsv41/ds4_model.cu (+5 -3)

📄 Description

Problem and result

With DS4_PROF=1 and no DS4_PROF_SYNC, a prompt that takes the chunked pass aborted the DeepSeek engine on my DGX Spark:
the engine log ended with *** stack smashing detected ***: terminated and the server reported exit code -6. Shorter prompts
(the windowed path) still ran.

prof_collect() sums each event pair into a local double sample_ms[6], but the chunked prompt numbers its stages 0 to 10
(prof_mark(d, 6) .. prof_mark(d, 10): attn mHC, attention projections, compressor + indexer, q_b + rope, sparse attention,
ffn mHC + router + sort), so stages 6-10 write past the array. A chunk sample then adds only stages 0-3 to cprof_ms
(stages = chunk_sample ? 4 : 6), so where the overflow does not abort, the finer prompt table prints 0 for stages 4-10 (this
part is from reading the code; I did not see a run get that far).

This came with the collector's rewrite in 29c2d574f8 (DeepSeek --parallel from Project Maya). In v0.2.9, prof_collect()
added each sample straight into (prof_chunk ? cprof_ms : st.prof_ms)[m.stage], and cprof_ms has 16 entries.

Change

sample_ms gets cprof_ms's size (16), a mark outside it is not summed, and a chunk sample adds all of its stages to
cprof_ms, as before 29c2d574f8. A decoded token still adds its 6 stages to st.prof_ms. Only the DS4_PROF path changes;
without it nothing runs differently.

Validation

On a DGX Spark (GB10, driver 580.178.04, CUDA 13.0, Ubuntu 24.04 container), DeepSeek-V4.1-Flash-1017 GSQ-RCO IQ2_XS (ISTA-DASLab's
four-shard layout, packed with pack_gguf.py as setup does), standalone runs of strata-dsv41 --pack <pack> --ids @<ids> --n <N> --max-context 262144 --eos 1 --vision on --experts 6 --dspark none with DS4_UMA_HEADROOM_GIB=12. The prompt is a chat prompt in
DeepSeek's format (the one tools/dsv41/smoke.py builds) around 1,308 or 65,095 tokens of plain text.

Passed:

  • Built strata-dsv41 at ffa80d7313 as released and with this patch, with spark/build_engine.sh's cmake configuration
    (Release, -DSTRATA_PORTABLE=ON -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON,
    -DCMAKE_CUDA_ARCHITECTURES=121-real;121-virtual) in nvidia/cuda:13.0.2-devel-ubuntu24.04 (arm64). Both print
    strata-dsv41 0.1.56 build ffa80d731; the patched ds4_model.cu compiles with the same two warnings as the unpatched one
    (#177-D at lines 102 and 106, unrelated) and no new ones.

  • Unpatched build, DS4_PROF=1, the 1,308-token prompt, --n 16: *** stack smashing detected ***: terminated,
    Aborted (core dumped), no token. The release package (0.1.56) did the same under serve/server.py (with DS4_IO_STATS=1
    as well; the server reported exit code -6).

  • Patched build, the same command: 16 tokens, exit 0, and the prompt table has every stage:

    ds4 prompt GPU time, 1308 tokens: attention 208 ms, routing + shared expert 101 ms, experts 4414 ms (with the waits for streamed ones), between layers 0 ms
    ds4 prof  between layers                           0.1 ms   0.0%
    ds4 prof  attn rest (q_b, wo_a/b, hc_post)       207.6 ms   2.5%
    ds4 prof  shared expert                          101.4 ms   1.2%
    ds4 prof  experts (incl waits)                  4414.2 ms  53.6%
    ds4 prof  engram                                  66.0 ms   0.8%
    ds4 prof  attn mHC (mix/split/norm)              601.7 ms   7.3%
    ds4 prof  attn projections                        35.6 ms   0.4%
    ds4 prof  compressor + indexer                    73.2 ms   0.9%
    ds4 prof  q_b + rope                            1301.9 ms  15.8%
    ds4 prof  sparse attention                       658.4 ms   8.0%
    ds4 prof  ffn mHC + router + sort                777.6 ms   9.4%
    

    and the decode line after it: GPU per token (DS4_PROF): 71.29 ms - between layers 0.04, attention 30.99, routing + shared expert 12.16, experts gate/up 7.43, waiting for the CPU lane 15.67, down + post 5.00.

  • Patched build, the 65,095-token prompt with --prefill-chunk 8192, --n 16: exit 0, every stage filled (experts incl. waits
    46,545 ms, sparse attention 20,448 ms, q_b + rope 13,540 ms, ffn mHC + router + sort 11,212 ms, ...).

  • Metal: cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release with metal-cpp 26 and llama.cpp 3cf03257 (the
    pins of .github/workflows/metal-build.yml), cmake --build build-metal --target strata_ds4 on macOS 26.4 (SDK 26.5): the
    patched ds4_model.cu compiles and strata_ds4 links, no diagnostics.

  • HIP: tools/dsv41/build_hip_linux.sh strata-dsv41 with STRATA_HIP_ARCHS=gfx1151 in rocm/dev-ubuntu-24.04:7.2.4-complete,
    as released and with the patch: both link; the patched binary differs; ds4_model.cu has 616 warnings in both builds and
    none in the changed lines.

Not run:

  • The patch on AMD or Apple hardware (builds only). SYCL does not compile ds4_model.cu.

Limits

Only the profiler's collection. I did not look into why the prompt events were said to hang the driver on gfx1151 Windows
(prof_chunk = prof_on && !prof_sync_on); if that was this overflow, it would show there too.


🔄 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/5127 **Author:** [@R-Okauchi](https://github.com/R-Okauchi) **Created:** 11/3/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `dsv41-prof-sample` --- ### 📝 Commits (1) - [`c9cf36a`](https://github.com/Niko1221/Strata/commit/c9cf36a53d7787cc8ed3f42adab5c21469ca2c27) DeepSeek engine: DS4_PROF's chunked prompt fits its sample array again ### 📊 Changes **1 file changed** (+5 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/dsv41/ds4_model.cu` (+5 -3) </details> ### 📄 Description ## Problem and result With `DS4_PROF=1` and no `DS4_PROF_SYNC`, a prompt that takes the chunked pass aborted the DeepSeek engine on my DGX Spark: the engine log ended with `*** stack smashing detected ***: terminated` and the server reported exit code -6. Shorter prompts (the windowed path) still ran. `prof_collect()` sums each event pair into a local `double sample_ms[6]`, but the chunked prompt numbers its stages 0 to 10 (`prof_mark(d, 6)` .. `prof_mark(d, 10)`: attn mHC, attention projections, compressor + indexer, q_b + rope, sparse attention, ffn mHC + router + sort), so stages 6-10 write past the array. A chunk sample then adds only stages 0-3 to `cprof_ms` (`stages = chunk_sample ? 4 : 6`), so where the overflow does not abort, the finer prompt table prints 0 for stages 4-10 (this part is from reading the code; I did not see a run get that far). This came with the collector's rewrite in 29c2d574f8 (DeepSeek `--parallel` from Project Maya). In v0.2.9, `prof_collect()` added each sample straight into `(prof_chunk ? cprof_ms : st.prof_ms)[m.stage]`, and `cprof_ms` has 16 entries. ## Change `sample_ms` gets `cprof_ms`'s size (16), a mark outside it is not summed, and a chunk sample adds all of its stages to `cprof_ms`, as before 29c2d574f8. A decoded token still adds its 6 stages to `st.prof_ms`. Only the `DS4_PROF` path changes; without it nothing runs differently. ## Validation On a DGX Spark (GB10, driver 580.178.04, CUDA 13.0, Ubuntu 24.04 container), DeepSeek-V4.1-Flash-1017 GSQ-RCO IQ2_XS (ISTA-DASLab's four-shard layout, packed with `pack_gguf.py` as setup does), standalone runs of `strata-dsv41 --pack <pack> --ids @<ids> --n <N> --max-context 262144 --eos 1 --vision on --experts 6 --dspark none` with `DS4_UMA_HEADROOM_GIB=12`. The prompt is a chat prompt in DeepSeek's format (the one `tools/dsv41/smoke.py` builds) around 1,308 or 65,095 tokens of plain text. Passed: - Built `strata-dsv41` at ffa80d73133e as released and with this patch, with `spark/build_engine.sh`'s cmake configuration (Release, `-DSTRATA_PORTABLE=ON -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON`, `-DCMAKE_CUDA_ARCHITECTURES=121-real;121-virtual`) in `nvidia/cuda:13.0.2-devel-ubuntu24.04` (arm64). Both print `strata-dsv41 0.1.56 build ffa80d731`; the patched `ds4_model.cu` compiles with the same two warnings as the unpatched one (#177-D at lines 102 and 106, unrelated) and no new ones. - Unpatched build, `DS4_PROF=1`, the 1,308-token prompt, `--n 16`: `*** stack smashing detected ***: terminated`, `Aborted (core dumped)`, no token. The release package (0.1.56) did the same under `serve/server.py` (with `DS4_IO_STATS=1` as well; the server reported exit code -6). - Patched build, the same command: 16 tokens, exit 0, and the prompt table has every stage: ``` ds4 prompt GPU time, 1308 tokens: attention 208 ms, routing + shared expert 101 ms, experts 4414 ms (with the waits for streamed ones), between layers 0 ms ds4 prof between layers 0.1 ms 0.0% ds4 prof attn rest (q_b, wo_a/b, hc_post) 207.6 ms 2.5% ds4 prof shared expert 101.4 ms 1.2% ds4 prof experts (incl waits) 4414.2 ms 53.6% ds4 prof engram 66.0 ms 0.8% ds4 prof attn mHC (mix/split/norm) 601.7 ms 7.3% ds4 prof attn projections 35.6 ms 0.4% ds4 prof compressor + indexer 73.2 ms 0.9% ds4 prof q_b + rope 1301.9 ms 15.8% ds4 prof sparse attention 658.4 ms 8.0% ds4 prof ffn mHC + router + sort 777.6 ms 9.4% ``` and the decode line after it: `GPU per token (DS4_PROF): 71.29 ms - between layers 0.04, attention 30.99, routing + shared expert 12.16, experts gate/up 7.43, waiting for the CPU lane 15.67, down + post 5.00`. - Patched build, the 65,095-token prompt with `--prefill-chunk 8192`, `--n 16`: exit 0, every stage filled (experts incl. waits 46,545 ms, sparse attention 20,448 ms, q_b + rope 13,540 ms, ffn mHC + router + sort 11,212 ms, ...). - Metal: `cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release` with metal-cpp 26 and llama.cpp 3cf03257 (the pins of `.github/workflows/metal-build.yml`), `cmake --build build-metal --target strata_ds4` on macOS 26.4 (SDK 26.5): the patched `ds4_model.cu` compiles and `strata_ds4` links, no diagnostics. - HIP: `tools/dsv41/build_hip_linux.sh strata-dsv41` with `STRATA_HIP_ARCHS=gfx1151` in `rocm/dev-ubuntu-24.04:7.2.4-complete`, as released and with the patch: both link; the patched binary differs; `ds4_model.cu` has 616 warnings in both builds and none in the changed lines. Not run: - The patch on AMD or Apple hardware (builds only). SYCL does not compile `ds4_model.cu`. ## Limits Only the profiler's collection. I did not look into why the prompt events were said to hang the driver on gfx1151 Windows (`prof_chunk = prof_on && !prof_sync_on`); if that was this overflow, it would show there too. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5317
No description provided.