[PR #143] [CLOSED] GLM NaN guard on top of #146: a head-logit check that feeds #146's recovery (port of Strata #1892) #361

Closed
opened 2026-10-29 21:24:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/143
Author: @boxwrench
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: fix/glm-nan-guard


📝 Commits (1)

  • b21f610 GLM NaN guard on top of #146: head-logit check that feeds #146's recovery

📊 Changes

11 files changed (+235 additions, -0 deletions)

View changed files

📝 docs/SETTINGS.md (+1 -0)
📝 include/strata/core/glm_model.hpp (+28 -0)
📝 include/strata/kernels/glm_fast.hpp (+6 -0)
📝 src/core/glm_dflash.cu (+1 -0)
📝 src/core/glm_fast_path.cu (+144 -0)
📝 src/core/glm_fast_state.hpp (+2 -0)
📝 src/core/glm_model.cu (+3 -0)
📝 src/core/glm_mtp.cu (+5 -0)
📝 src/core/glm_window.cu (+4 -0)
📝 src/kernels/cuda/glm_fast.cu (+23 -0)
📝 src/program/generate.cpp (+18 -0)

📄 Description

Refs Niko1221/Strata#879 and Niko1221/Strata#1815. Ported from Niko1221/Strata#1892 by lask3802, which fixed the same failure
there: rarely a window's logits become NaN and the reply degenerates into token 0 repeated, and the poison
sits in the conversation's K/V and recurrent state, so a cached continuation stays poisoned.

What it changes

  • Every GLM decode window checks its head logits on the GPU beside the argmax: one small kernel
    (glmfast::logits_nonfinite_rows) tests the exponent bits of every row and writes one flag a slice into
    mapped memory, read after the window's own sync - no extra sync. Covered: the token path (fast_token),
    the NextN/MTP verify head (spec_tail), and the DFlash window (window, win_pipe_part).
  • A flagged window emits none of its tokens and the request ends with an engine error naming "non-finite".
    That hands it to #146's recovery: drop_if_poisoned drops the snapshot, the checkpoints and the slots that
    may carry the poison, and the server's retry reads a request that had written nothing yet again from token 0;
    a reply that had started ends as "length". This PR adds no recovery of its own.
  • Why on top of #146: #146 fires when routing sees a non-finite score (route_ok). This check reads the head
    logits, so it also catches a NaN that appears after the last layer's routing (final norm, head) or only in
    the MTP / DFlash window.
  • On by default, as a fix; STRATA_GLM_NAN_GUARD=0 turns it off (no kernel is recorded).
    STRATA_GLM_NAN_INJECT=<n>[,<n>...] (debug) reports the n-th checked window of the process as
    non-finite, to exercise the path without a real fire.

What it leaves alone

  • Answers without a NaN (byte for byte; see below).
  • The router's existing checks (route_ok) and the DFlash drafter's own picks.

Measured

R9700 (gfx1201), Maya-S v2 IQ2_XXS, greedy, one GPU, NO_SPEC, this branch's build.

  • Answers, guard on vs off, 3 prompts x 256 tokens, with the expert placement and the prompt path pinned
    on both (STRATA_GLM_PROMOTE=0 STRATA_GLM_PROMOTE_FILL=0 STRATA_GLM_PREFILL_CPU=0 STRATA_GLM_PRESTAGE=0 STRATA_GLM_PCIE_SHARE=0 STRATA_GLM_NO_REUSE=1, one fixed usage profile): byte-identical in 3 of 3.
    Without pinning, greedy text can differ between two launches of the same config on this box (the timing
    based prefill split and the background promotion choose a different CPU/GPU expert set), so the guard
    cannot be blamed for that; pinned, the only difference between the arms is the check kernel.
  • Cost, STRATA_GLM_PROF=1: logits_nonfinite 0.017 ms/token of 60.43 ms/token of GPU stream time =
    0.028%, well inside 0.3% (a decode-rate A/B over the same arms cannot resolve a difference that small).
  • STRATA_GLM_NAN_INJECT=1: the first request's first window was flagged -> the engine logged
    non-finite logits (#879) at position 52, emitted none of the window's tokens, dropped the live session
    and the checkpoint, and the server sent the request again from token 0 once (measured on the earlier standalone version; the add-on repeats it through #146's path, see below); the client saw one normal
    answer, byte for byte the unpoisoned one.
  • MTP: on one R9700 the engine does not select the NextN/DFlash verify path (spec_ready() needs a
    layer split, dflash_ready() a drafter), so a forced STRATA_GLM_MTP_DRAFT=3 run stays token by token;
    guard on/off is still byte-identical there, and the guard is present at the MTP/DFlash head too.

Credit

The mechanism is Niko1221/Strata#1892 by lask3802; this is its port to Maya's GLM-5.3 engine.

Build and tests

Rebased on main (a709524, after #146, #145, #154 and #86); 9 files, +174/-0. HIP build (build-multi: HIP on, CUDA off, MMQ, native experts, gfx1100;gfx1201, ROCm 7.2.1): no errors. serve.test_server: 86 tests OK. HIP ctest sampler_parity, glm_model_test, glm_layer_parity: pass. On this base (RX 7900 XT, Maya-S): STRATA_GLM_NAN_INJECT=3 (after the first token) ends the reply as length with the state dropped; STRATA_GLM_NAN_INJECT=1 (before it) is retried by #146's path and answers; a 64-token greedy request is byte-identical with the guard on and off. The CUDA-side lines are the shared ones (logits_nonfinite_kernel and its launcher, a mapped cudaHostAlloc + cudaHostGetDevicePointer pair, cudaFreeHost). They use nothing HIP-only, but this branch has not been compiled with nvcc here.

Not covered: the several-conversations scheduler (STRATA_GLM_SEQS>1). There, one window can interleave conversations, so a per-sequence flag would be the follow-up.


🔄 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/mw00/project-maya/pull/143 **Author:** [@boxwrench](https://github.com/boxwrench) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/glm-nan-guard` --- ### 📝 Commits (1) - [`b21f610`](https://github.com/mw00/project-maya/commit/b21f610c1d82147bcd4b946eafbe772cca1a3ccf) GLM NaN guard on top of #146: head-logit check that feeds #146's recovery ### 📊 Changes **11 files changed** (+235 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+1 -0) 📝 `include/strata/core/glm_model.hpp` (+28 -0) 📝 `include/strata/kernels/glm_fast.hpp` (+6 -0) 📝 `src/core/glm_dflash.cu` (+1 -0) 📝 `src/core/glm_fast_path.cu` (+144 -0) 📝 `src/core/glm_fast_state.hpp` (+2 -0) 📝 `src/core/glm_model.cu` (+3 -0) 📝 `src/core/glm_mtp.cu` (+5 -0) 📝 `src/core/glm_window.cu` (+4 -0) 📝 `src/kernels/cuda/glm_fast.cu` (+23 -0) 📝 `src/program/generate.cpp` (+18 -0) </details> ### 📄 Description Refs Niko1221/Strata#879 and Niko1221/Strata#1815. Ported from Niko1221/Strata#1892 by lask3802, which fixed the same failure there: rarely a window's logits become NaN and the reply degenerates into token 0 repeated, and the poison sits in the conversation's K/V and recurrent state, so a cached continuation stays poisoned. ## What it changes - Every GLM decode window checks its head logits on the GPU beside the argmax: one small kernel (`glmfast::logits_nonfinite_rows`) tests the exponent bits of every row and writes one flag a slice into mapped memory, read after the window's own sync - no extra sync. Covered: the token path (`fast_token`), the NextN/MTP verify head (`spec_tail`), and the DFlash window (`window`, `win_pipe_part`). - A flagged window emits none of its tokens and the request ends with an engine error naming "non-finite". That hands it to #146's recovery: `drop_if_poisoned` drops the snapshot, the checkpoints and the slots that may carry the poison, and the server's retry reads a request that had written nothing yet again from token 0; a reply that had started ends as `"length"`. This PR adds no recovery of its own. - Why on top of #146: #146 fires when routing sees a non-finite score (`route_ok`). This check reads the head logits, so it also catches a NaN that appears after the last layer's routing (final norm, head) or only in the MTP / DFlash window. - On by default, as a fix; `STRATA_GLM_NAN_GUARD=0` turns it off (no kernel is recorded). `STRATA_GLM_NAN_INJECT=<n>[,<n>...]` (debug) reports the n-th checked window of the process as non-finite, to exercise the path without a real fire. ## What it leaves alone - Answers without a NaN (byte for byte; see below). - The router's existing checks (`route_ok`) and the DFlash drafter's own picks. ## Measured R9700 (gfx1201), Maya-S v2 IQ2_XXS, greedy, one GPU, NO_SPEC, this branch's build. - **Answers**, guard on vs off, 3 prompts x 256 tokens, with the expert placement and the prompt path pinned on both (`STRATA_GLM_PROMOTE=0 STRATA_GLM_PROMOTE_FILL=0 STRATA_GLM_PREFILL_CPU=0 STRATA_GLM_PRESTAGE=0 STRATA_GLM_PCIE_SHARE=0 STRATA_GLM_NO_REUSE=1`, one fixed usage profile): byte-identical in 3 of 3. Without pinning, greedy text can differ between two launches of the *same* config on this box (the timing based prefill split and the background promotion choose a different CPU/GPU expert set), so the guard cannot be blamed for that; pinned, the only difference between the arms is the check kernel. - **Cost**, `STRATA_GLM_PROF=1`: `logits_nonfinite` 0.017 ms/token of 60.43 ms/token of GPU stream time = **0.028%**, well inside 0.3% (a decode-rate A/B over the same arms cannot resolve a difference that small). - **`STRATA_GLM_NAN_INJECT=1`**: the first request's first window was flagged -> the engine logged `non-finite logits (#879)` at position 52, emitted none of the window's tokens, dropped the live session and the checkpoint, and the server sent the request again from token 0 once (measured on the earlier standalone version; the add-on repeats it through #146's path, see below); the client saw one normal answer, byte for byte the unpoisoned one. - **MTP**: on one R9700 the engine does not select the NextN/DFlash verify path (`spec_ready()` needs a layer split, `dflash_ready()` a drafter), so a forced `STRATA_GLM_MTP_DRAFT=3` run stays token by token; guard on/off is still byte-identical there, and the guard is present at the MTP/DFlash head too. ## Credit The mechanism is Niko1221/Strata#1892 by lask3802; this is its port to Maya's GLM-5.3 engine. ## Build and tests Rebased on main (a709524, after #146, #145, #154 and #86); 9 files, +174/-0. HIP build (`build-multi`: HIP on, CUDA off, MMQ, native experts, gfx1100;gfx1201, ROCm 7.2.1): no errors. `serve.test_server`: 86 tests OK. HIP ctest `sampler_parity`, `glm_model_test`, `glm_layer_parity`: pass. On this base (RX 7900 XT, Maya-S): `STRATA_GLM_NAN_INJECT=3` (after the first token) ends the reply as `length` with the state dropped; `STRATA_GLM_NAN_INJECT=1` (before it) is retried by #146's path and answers; a 64-token greedy request is byte-identical with the guard on and off. The CUDA-side lines are the shared ones (`logits_nonfinite_kernel` and its launcher, a mapped `cudaHostAlloc` + `cudaHostGetDevicePointer` pair, `cudaFreeHost`). They use nothing HIP-only, but this branch has not been compiled with nvcc here. Not covered: the several-conversations scheduler (`STRATA_GLM_SEQS>1`). There, one window can interleave conversations, so a per-sequence flag would be the follow-up. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:24:39 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#361
No description provided.