mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
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#4548
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/3287
Author: @catalinb13
Created: 10/19/2026
Status: 🔄 Open
Base:
main← Head:metal-nan-sentinel-pick-guard📝 Commits (1)
eba6f3d[Engine] Metal: catch the argmax sentinel where the device row check cannot run📊 Changes
4 files changed (+86 additions, -13 deletions)
View changed files
📝
include/strata/core/verify.hpp(+6 -2)📝
serve/server.py(+3 -0)📝
serve/test_server.py(+59 -0)📝
src/core/verify.cpp(+18 -11)📄 Description
Problem and result
On the Metal engine a non-finite logits row (#879) reaches the user as a crash instead of a recovery. The #879 guard reads per-window flags that
logits_nonfinite_rowsraises on the device beside the greedy pick, but the Metal port has no kernel of that name — it is a trap stub (metal/src/engine/stubs.cpp) — so the flags stay zero andnonfinite_hitreports a clean window. What a row that is all NaN leaves behind is Metal's sampler sentinel:metal/kernels/sample.metalseeds the argmax atbi = 0x7fffffffand skips NaN elements, so the row keeps the sentinel,pl_finishcopies it out, and the engine printsT 2147483647. The serve loop then dies twice: the detokenizer raises a rawIndexError: token id 2147483647 is outside the vocabulary (248320)and kills the request thread, and the engine feeds the sentinel into the drafter and the embedding and segfaults (exit -11) shortly after.Measured on an M1 Max (macOS, engine built from
mainate88ee39d, Qwen3.8 vocabulary 248320), reproduced when the machine is under enough memory pressure for a row to go NaN.After this change the sentinel takes the existing #879 recovery, on both sides:
DONE … nonfinite— the cached state is dropped before the sentinel can reach the drafter, so the follow-on segfault goes away;EngineNonFiniteif a sentinel id appears in the token stream anyway (an engine binary without this fix), so the request gets the normal path: retried once when nothing went out yet, ends as"length"mid-reply, a clean error after a second pass — never a traceback.Approach
Verifier::note_nonfinitetakes the picks that were just read beside it and marks the row of any pick holdingINT32_MAX. That reading is true on every platform: the id is past every vocabulary, so a pick that holds it is exactly the fact #879 records. All five pick-read sites pass their buffer (run,run_slot_rows,run_slots,batch_poll,pl_finish). Where the device check already runs, the scan can only agree with it; on Metal it is the whole guard.The server's arm is one test in
_runbefore the detokenizer, raising the sameEngineNonFinitetheDONE … nonfiniteline raises, so it needs no new recovery code.Validation
Passed:
python3 -m unittest serve.test_server.NonFiniteLogits serve.test_server.SentinelToken— 7/7 on this branch offmain(d986ecbc). Two new mock tests: a sentinel before the first token is retried once and answers normally; a sentinel mid-reply ends the reply as"length"with the text up to it. The five existing #879 tests still pass.ctest2/2 (runtime_hello,window_cells_test) on the M1 Max.Not run:
STRATA_NAN_INJECTreports the row through the flags, beside this path). The engine-side arm is therefore compile-and-static evidence; the server-side arm is proven by the tests and by this machine's own crash tracebacks.Failed: none.
Limits
INT32_MAX, which on those platforms the device check already reports.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.