[PR #4688] [CLOSED] [Engine] fix: sanitize non-finite/implausible PLE table rows at decode #5137

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4688
Author: @tomasuz
Created: 10/30/2026
Status: ❌ Closed

Base: main ← Head: fix/ple-decode-sanitize


📝 Commits (2)

  • dcddc65 fix: sanitize non-finite/implausible PLE table rows at decode (#3602, #879)
  • afee533 test: cover ple_sanitize_row with a host-only unit test (#3602/#879)

📊 Changes

4 files changed (+141 additions, -1 deletions)

View changed files

📝 CMakeLists.txt (+5 -0)
📝 include/strata/kernels/ngram.hpp (+7 -0)
📝 src/kernels/ngram.cpp (+10 -1)
➕ src/kernels/ple_sanitize_test.cpp (+119 -0)

📄 Description

Problem and result

Long prompts intermittently end with non-finite logits (#879) and a 503, reproducible at exact token-count boundaries (2048 / 19456 / 65536 tokens tested) on an AMD RX 9060 XT (gfx1200, RDNA4). The request fails even after the existing retry-via-batched-path mitigation (#3465) runs out of fallback.

Layer-by-layer instrumentation (temporary, not part of this PR - checks of m.R/m.mixed/m.bo/m.ple_emb added and removed across the per-layer loop) traced the first non-finite/huge value back to m.ple_emb, before any GPU kernel had touched that chunk - i.e. the corruption was already present in the output of PleTable::decode(), the CPU-side n-gram/PLE table lookup that runs once per chunk at layer 1.

Turning on STRATA_PLE_CHECK=1 - the engine's own existing diagnostic, written for #3602 - on every row it flagged, confirmed: "the delivered bytes ARE the file's bytes". One flagged row decodes to a literal NaN straight from the file's own bytes; others decode to values from the hundreds of thousands up to several million (e.g. -4.13008e+06, 688860, nan), far past what check_row's own comment says a real PLE value should reach ("orders smaller" than 1e5). This is a data-level defect in the on-disk PLE (n-gram lookup) table itself, not a read/transfer bug.

After the fix, the same three boundary lengths complete cleanly (prefill/decode numbers below).

I want to be precise about how this relates to the existing #879 family, since it is clearly multi-causal and I do not want to overstate what this PR covers:

  • #3602 ("Deterministic all-logits NaN (#879), IQ3_S, CUDA, Windows") looked similar at first glance, but its root cause and fix (0.2.7: "a failed read no longer leaves the next ticket waiting for ever") are a read-ticket/hang bug, not a data defect. My STRATA_PLE_CHECK evidence is the opposite of a failed read: the read succeeded and returned exactly what is on disk. This PR does not touch that code path.
  • #879 itself (the master issue) traces most of its CUDA fires to the routed-expert output rows, with "PLE history ... clean in every fire" on that hardware/workload. My evidence is specific to the PLE table's own decoded content, which their CUDA repros did not implicate - this looks like a distinct, previously-undocumented mechanism in the same symptom family, not a duplicate.
  • #2519 (gfx1201/HIP, "GDN state overflow") found a ROCm-userspace-version-correlated fire rate (9/941 on ROCm 7.2.4 vs 0/1183 on ROCm 10.0.0) - a different mechanism again, and still open in effect (closed only in the 0.2.0-beta tracker reset).
  • #3431 (Windows HIP gfx1100, "batched PLE block silently misreads prompts") touches the exact same function (native_ple_postops_batch, called from the l == 1 && ple_on && ple_batch block in prefill.cpp) but with a different symptom (silent wrong answers, ~1/8 engine starts, no NaN) and a different STRATA_PLE_BATCH=0 workaround. I did not reproduce that symptom here; my repro was 100% deterministic across every engine restart (same bad row, same decoded value), which doesn't fit a per-start-probabilistic bug. I'm linking it because the overlap in code location seemed worth flagging to whoever looks at this next, not because I believe it's the same bug.

I have not opened a new issue for this, since it's a small, self-contained fix (CONTRIBUTING.md: "Focused fixes ... can go straight to a PR"). Happy to split this into an issue first if a maintainer would rather track it that way given the #879 history above.

Approach

Sanitize at the one chokepoint every PLE table format's decode() already routes through: replace a non-finite or implausible (|x| > 1e5) decoded value with 0.0, reusing the exact threshold check_row already uses to flag a bad row (so this introduces no new policy, just enforces the existing one on the hot path instead of only in the opt-in diagnostic). Format-independent: IQ4_NL, Q5_0, F8_E4M3, Q5_1, Q8_0, Q4_0, BF16 and NVFP4 all funnel through PleTable::Impl::decode, and this is plain host C++ (std::isfinite/std::fabs on a float*) - no CUDA/HIP/SYCL-specific code is touched, and ngram.cpp is already built as a normal (non-device) translation unit in this target.

No default or behavior changes outside the bad-row case: a well-formed PLE table row round-trips identically through decode() before and after this change.

Validation

Passed:

  • Build: cmake -S . -B build-hip -DCMAKE_HIP_COMPILER=... -DGPU_TARGETS=gfx1200 -DCMAKE_HIP_ARCHITECTURES=gfx1200 -DSTRATA_ENABLE_HIP=ON && ninja -C build-hip strata - clean build, no new warnings from the changed file.
  • Isolation check: reset the branch to its base commit, applied only this one change (no other candidate fix), rebuilt, and ran the full boundary suite directly against that binary:
    • ctx2k: 2048 tokens - 107.8 tok/s prefill, 40.8 tok/s decode, no error
    • ctx19k: 19456 tokens - 140.3 tok/s prefill, 48.7 tok/s decode, no error
    • ctx64k: 65536 tokens - 143.6 tok/s prefill, 46.5 tok/s decode, no error
    • (same model/quant/prompt, same binary, same three lengths all returned HTTP 503 non-finite logits (#879) before this change)
  • Environment: AMD Radeon RX 9060 XT (gfx1200/RDNA4, Navi 44), 16 GB VRAM, ROCm 7.14.1 (Debian 13 trixie backport, kernel 7.2.11), Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS, --max-context 131072 --kv int8 --spec 4 --spec-min-p 0.5 --mtp rt. Base commit for the isolation rebuild: a point one commit ahead of this PR's merge-base with main; the PR itself is this same single commit cherry-picked cleanly onto current main.
  • Also reproduced and fixed on the same hardware with Qwen3.8-Flash-Next GSQ-RCO IQ3_S (same symptom, different quant, same STRATA_PLE_CHECK confirmation: file bytes match).

Failed: none observed with this change in place.

Not run:

  • CUDA and SYCL builds - I don't have that hardware. The changed function is plain host C++ with no backend-specific branches nearby in the file, but I have not compiled or run it on either backend; please treat that as unverified.
  • Other GPUs/vendors, other quants (Q8_0/BF16/NVFP4/etc. table formats), long-running/soak testing, and the Windows/CUDA environments where #3602/#879/#2519/#3431 were originally reported.
  • No PLE-table-content validator/repair tool exists yet; this PR is a runtime guard, not a fix to whatever produced the bad table rows in the first place (packing tool, training, or something else - out of scope here, I have no visibility into how this table was built).

Limits

This masks a bad row by zeroing it rather than explaining why the on-disk PLE table has NaN/implausible rows in the first place (likely untrained or rarely-trained hash-collision buckets in the n-gram lookup, but I did not chase that further). It also only guards the CPU-side decode() path; if a build takes the GPU-side STRATA_PLE_COMPACT=1/ple_iq4nl_dequant path instead, that path is untouched by this PR and would need the same guard if it turns out to see the same kind of row.

Update: added test coverage

Extracted the sanitize step into a small, header-declared free function (ple_sanitize_row) and added
src/kernels/ple_sanitize_test.cpp: a host-only unit test (no GPU, no model, no file on disk) covering an
untouched normal row, the 1e5 boundary on both sides, a literal NaN, +-Inf, the exact magnitudes
STRATA_PLE_CHECK reported from real rows during this investigation, and two independently-bad values in one
row. Registered under STRATA_BUILD_TESTS, linked against strata_kernels like the other kernel tests.
decode()'s behavior is unchanged by the extraction - verified by rebuilding the full strata target
afterward.

Also ran a throwaway (not included here, deployment-specific) read-only scanner over the real production
IQ3_XXS PLE table to size this before shipping: 407,943 of 320,001,536 rows (0.127%) decode to a non-finite or
implausible value; 2,725,344 individual NaN values; one finite magnitude up to 8.3e6. At 16 row lookups per
token, roughly 1 in 50 tokens touches at least one bad row - not a rare corner case. Before this fix each such
token fed garbage (not just zero) into the residual stream; after it, that token's PLE contribution is zero
(no information) instead of garbage or a 503.


🔄 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/4688 **Author:** [@tomasuz](https://github.com/tomasuz) **Created:** 10/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/ple-decode-sanitize` --- ### 📝 Commits (2) - [`dcddc65`](https://github.com/Niko1221/Strata/commit/dcddc6566b0573fff93aa3c780c2e43cef430b24) fix: sanitize non-finite/implausible PLE table rows at decode (#3602, #879) - [`afee533`](https://github.com/Niko1221/Strata/commit/afee533fa247c2aa0535a645dbae538a3ff4fed3) test: cover ple_sanitize_row with a host-only unit test (#3602/#879) ### 📊 Changes **4 files changed** (+141 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+5 -0) 📝 `include/strata/kernels/ngram.hpp` (+7 -0) 📝 `src/kernels/ngram.cpp` (+10 -1) ➕ `src/kernels/ple_sanitize_test.cpp` (+119 -0) </details> ### 📄 Description ## Problem and result Long prompts intermittently end with `non-finite logits (#879)` and a 503, reproducible at exact token-count boundaries (2048 / 19456 / 65536 tokens tested) on an AMD RX 9060 XT (gfx1200, RDNA4). The request fails even after the existing retry-via-batched-path mitigation (#3465) runs out of fallback. Layer-by-layer instrumentation (temporary, not part of this PR - checks of `m.R`/`m.mixed`/`m.bo`/`m.ple_emb` added and removed across the per-layer loop) traced the first non-finite/huge value back to `m.ple_emb`, **before any GPU kernel had touched that chunk** - i.e. the corruption was already present in the output of `PleTable::decode()`, the CPU-side n-gram/PLE table lookup that runs once per chunk at layer 1. Turning on `STRATA_PLE_CHECK=1` - the engine's own existing diagnostic, written for #3602 - on every row it flagged, confirmed: **"the delivered bytes ARE the file's bytes"**. One flagged row decodes to a literal NaN straight from the file's own bytes; others decode to values from the hundreds of thousands up to several million (e.g. `-4.13008e+06`, `688860`, `nan`), far past what `check_row`'s own comment says a real PLE value should reach ("orders smaller" than `1e5`). This is a data-level defect in the on-disk PLE (n-gram lookup) table itself, not a read/transfer bug. After the fix, the same three boundary lengths complete cleanly (prefill/decode numbers below). ## Related discussion I want to be precise about how this relates to the existing `#879` family, since it is clearly multi-causal and I do not want to overstate what this PR covers: - **#3602** ("Deterministic all-logits NaN (#879), IQ3_S, CUDA, Windows") looked similar at first glance, but its root cause and fix (0.2.7: "a failed read no longer leaves the next ticket waiting for ever") are a **read-ticket/hang bug**, not a data defect. My `STRATA_PLE_CHECK` evidence is the opposite of a failed read: the read succeeded and returned exactly what is on disk. This PR does not touch that code path. - **#879** itself (the master issue) traces most of its CUDA fires to the routed-expert output rows, with "PLE history ... clean in every fire" on that hardware/workload. My evidence is specific to the PLE table's own decoded content, which their CUDA repros did not implicate - this looks like a distinct, previously-undocumented mechanism in the same symptom family, not a duplicate. - **#2519** (gfx1201/HIP, "GDN state overflow") found a ROCm-userspace-version-correlated fire rate (9/941 on ROCm 7.2.4 vs 0/1183 on ROCm 10.0.0) - a different mechanism again, and still open in effect (closed only in the 0.2.0-beta tracker reset). - **#3431** (Windows HIP gfx1100, "batched PLE block silently misreads prompts") touches the exact same function (`native_ple_postops_batch`, called from the `l == 1 && ple_on && ple_batch` block in `prefill.cpp`) but with a different symptom (silent wrong answers, ~1/8 engine starts, no NaN) and a different `STRATA_PLE_BATCH=0` workaround. I did not reproduce that symptom here; my repro was 100% deterministic across every engine restart (same bad row, same decoded value), which doesn't fit a per-start-probabilistic bug. I'm linking it because the overlap in code location seemed worth flagging to whoever looks at this next, not because I believe it's the same bug. I have not opened a new issue for this, since it's a small, self-contained fix (CONTRIBUTING.md: "Focused fixes ... can go straight to a PR"). Happy to split this into an issue first if a maintainer would rather track it that way given the #879 history above. ## Approach Sanitize at the one chokepoint every PLE table format's `decode()` already routes through: replace a non-finite or implausible (`|x| > 1e5`) decoded value with `0.0`, reusing the exact threshold `check_row` already uses to flag a bad row (so this introduces no new policy, just enforces the existing one on the hot path instead of only in the opt-in diagnostic). Format-independent: IQ4_NL, Q5_0, F8_E4M3, Q5_1, Q8_0, Q4_0, BF16 and NVFP4 all funnel through `PleTable::Impl::decode`, and this is plain host C++ (`std::isfinite`/`std::fabs` on a `float*`) - no CUDA/HIP/SYCL-specific code is touched, and `ngram.cpp` is already built as a normal (non-device) translation unit in this target. No default or behavior changes outside the bad-row case: a well-formed PLE table row round-trips identically through `decode()` before and after this change. ## Validation **Passed:** - Build: `cmake -S . -B build-hip -DCMAKE_HIP_COMPILER=... -DGPU_TARGETS=gfx1200 -DCMAKE_HIP_ARCHITECTURES=gfx1200 -DSTRATA_ENABLE_HIP=ON && ninja -C build-hip strata` - clean build, no new warnings from the changed file. - Isolation check: reset the branch to its base commit, applied **only** this one change (no other candidate fix), rebuilt, and ran the full boundary suite directly against that binary: - `ctx2k`: 2048 tokens - 107.8 tok/s prefill, 40.8 tok/s decode, no error - `ctx19k`: 19456 tokens - 140.3 tok/s prefill, 48.7 tok/s decode, no error - `ctx64k`: 65536 tokens - 143.6 tok/s prefill, 46.5 tok/s decode, no error - (same model/quant/prompt, same binary, same three lengths all returned `HTTP 503 non-finite logits (#879)` before this change) - Environment: AMD Radeon RX 9060 XT (gfx1200/RDNA4, Navi 44), 16 GB VRAM, ROCm 7.14.1 (Debian 13 trixie backport, kernel 7.2.11), Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS, `--max-context 131072 --kv int8 --spec 4 --spec-min-p 0.5 --mtp rt`. Base commit for the isolation rebuild: a point one commit ahead of this PR's merge-base with `main`; the PR itself is this same single commit cherry-picked cleanly onto current `main`. - Also reproduced and fixed on the same hardware with Qwen3.8-Flash-Next GSQ-RCO **IQ3_S** (same symptom, different quant, same `STRATA_PLE_CHECK` confirmation: file bytes match). **Failed:** none observed with this change in place. **Not run:** - CUDA and SYCL builds - I don't have that hardware. The changed function is plain host C++ with no backend-specific branches nearby in the file, but I have not compiled or run it on either backend; please treat that as unverified. - Other GPUs/vendors, other quants (Q8_0/BF16/NVFP4/etc. table formats), long-running/soak testing, and the Windows/CUDA environments where #3602/#879/#2519/#3431 were originally reported. - No PLE-table-content validator/repair tool exists yet; this PR is a runtime guard, not a fix to whatever produced the bad table rows in the first place (packing tool, training, or something else - out of scope here, I have no visibility into how this table was built). ## Limits This masks a bad row by zeroing it rather than explaining why the on-disk PLE table has NaN/implausible rows in the first place (likely untrained or rarely-trained hash-collision buckets in the n-gram lookup, but I did not chase that further). It also only guards the CPU-side `decode()` path; if a build takes the GPU-side `STRATA_PLE_COMPACT=1`/`ple_iq4nl_dequant` path instead, that path is untouched by this PR and would need the same guard if it turns out to see the same kind of row. ## Update: added test coverage Extracted the sanitize step into a small, header-declared free function (`ple_sanitize_row`) and added `src/kernels/ple_sanitize_test.cpp`: a host-only unit test (no GPU, no model, no file on disk) covering an untouched normal row, the `1e5` boundary on both sides, a literal NaN, +-Inf, the exact magnitudes `STRATA_PLE_CHECK` reported from real rows during this investigation, and two independently-bad values in one row. Registered under `STRATA_BUILD_TESTS`, linked against `strata_kernels` like the other kernel tests. `decode()`'s behavior is unchanged by the extraction - verified by rebuilding the full `strata` target afterward. Also ran a throwaway (not included here, deployment-specific) read-only scanner over the real production IQ3_XXS PLE table to size this before shipping: 407,943 of 320,001,536 rows (0.127%) decode to a non-finite or implausible value; 2,725,344 individual NaN values; one finite magnitude up to 8.3e6. At 16 row lookups per token, roughly 1 in 50 tokens touches at least one bad row - not a rare corner case. Before this fix each such token fed garbage (not just zero) into the residual stream; after it, that token's PLE contribution is zero (no information) instead of garbage or a 503. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:33:00 +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#5137
No description provided.