mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4688] [CLOSED] [Engine] fix: sanitize non-finite/implausible PLE table rows at decode #5137
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5137
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
dcddc65fix: sanitize non-finite/implausible PLE table rows at decode (#3602, #879)afee533test: 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_embadded and removed across the per-layer loop) traced the first non-finite/huge value back tom.ple_emb, before any GPU kernel had touched that chunk - i.e. the corruption was already present in the output ofPleTable::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 whatcheck_row's own comment says a real PLE value should reach ("orders smaller" than1e5). 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
#879family, since it is clearly multi-causal and I do not want to overstate what this PR covers:STRATA_PLE_CHECKevidence 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.native_ple_postops_batch, called from thel == 1 && ple_on && ple_batchblock inprefill.cpp) but with a different symptom (silent wrong answers, ~1/8 engine starts, no NaN) and a differentSTRATA_PLE_BATCH=0workaround. 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 with0.0, reusing the exact thresholdcheck_rowalready 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 throughPleTable::Impl::decode, and this is plain host C++ (std::isfinite/std::fabson afloat*) - no CUDA/HIP/SYCL-specific code is touched, andngram.cppis 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:
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.ctx2k: 2048 tokens - 107.8 tok/s prefill, 40.8 tok/s decode, no errorctx19k: 19456 tokens - 140.3 tok/s prefill, 48.7 tok/s decode, no errorctx64k: 65536 tokens - 143.6 tok/s prefill, 46.5 tok/s decode, no errorHTTP 503 non-finite logits (#879)before this change)--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 withmain; the PR itself is this same single commit cherry-picked cleanly onto currentmain.STRATA_PLE_CHECKconfirmation: file bytes match).Failed: none observed with this change in place.
Not run:
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-sideSTRATA_PLE_COMPACT=1/ple_iq4nl_dequantpath 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 addedsrc/kernels/ple_sanitize_test.cpp: a host-only unit test (no GPU, no model, no file on disk) covering anuntouched normal row, the
1e5boundary on both sides, a literal NaN, +-Inf, the exact magnitudesSTRATA_PLE_CHECKreported from real rows during this investigation, and two independently-bad values in onerow. Registered under
STRATA_BUILD_TESTS, linked againststrata_kernelslike the other kernel tests.decode()'s behavior is unchanged by the extraction - verified by rebuilding the fullstratatargetafterward.
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.