Skip to content

hrx: GDN snapshot publish forms decay ratios in log space (fixes NaN after MTP rollback) - #52

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-gdn-snapshot-ratio
Oct 1, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-gdn-snapshot-ratio

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Fixes NaN logits on Qwen3.8-27B with --mtp on HRX0. The server aborts with "NaN logits at vocab index 0" a few verify steps into some prompts. Affected: Q8_0, UD-Q5_K_XL and the UD-Q6_K files; it depends on the prompt.

Cause. The snapshot publish path in gated_delta_net_f32_wmma.loom formed each prefix decay ratio c_t/c_s by dividing the two exponentials (divf %cp_t, %cp_s).

  • When a strongly forgetting head drives exp(log c_s) to 0, the later c_t is 0 as well, so the ratio is 0/0 = NaN.
  • That NaN goes into the f16 D tile and into every rollback snapshot after the first token.
  • The main recurrence already forms the same ratio as exp(log c_t - log c_s), so the step's own outputs stay finite. Only the published states go bad, and the next verify that resumes from one of them returns NaN.

Fix. At all 12 sites (both branches), read log c_t from the gate scratch (gs_flat quad+3, already written next to c_t) and use exp(log c_t - log c_s). The change is limited to the snapshot path and touches nothing in the main recurrence.

How it was found (with the peer session):

  • Narrowing down:
    • The NaN needs --mtp and the KV/recurrent state on HRX (clean with -nkvo and on Vulkan).
    • It isn't graph replay, ggml allocator aliasing, cross-dispatch ordering or the draft context.
  • Pinpointing:
    • An LD_PRELOAD decode trace in the real server pinned it to the target decode after a particular rollback sequence.
    • A one-context replay of that trace reproduced it deterministically.

Results (replay of the server's decode/rollback trace, Qwen3.8-27B-Q8_0, one HRX0 context, only libggml-hrx swapped):

build first non-finite step argmax vs CPU
fork d5048ad 10 NaN from step 10
this fix none 37/37 rows

A server-level --mtp check and a speed check (12 divides become 12 exps, on the snapshot path only) are running. Results will follow in a comment before merge.

The edit is a minimal change in an upstream kernel file, with no notice added.

🤖 Generated with Claude Code

…after MTP rollback)

The snapshot publish path in gated_delta_net_f32_wmma.loom built the prefix
decay ratio c_t/c_s by dividing the two exponentials. When a strongly
forgetting head drives exp(log c_s) to 0, the later c_t is 0 as well and the
ratio is 0/0 = NaN; it reaches the f16 D tile and every snapshot after the
first token. The main recurrence already forms the same ratio as
exp(log c_t - log c_s), so a step's own outputs stayed finite and only the
published rollback states went bad.

Qwen3.8-27B (Q8_0 and other files) with --mtp on HRX0: a verify batch after
a 3-token rollback published NaN states, and the next verify returned NaN
logits (server abort "NaN logits at vocab index 0"). Use log c_t from the
gate scratch (gs_flat quad+3) and exp(log c_t - log c_s) at all 12 sites.

Replay of the server's decode/rollback trace on one HRX0 context: first
non-finite step 10 -> none; argmax matches the CPU on 37/37 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the ggml label Oct 1, 2026
@bong-water-water-bong

Copy link
Copy Markdown
Author

Server-level results with the fix. Unchanged llama-server, only libggml-hrx swapped, balanced power mode:

  1. Qwen3.8-27B-Q8_0 with --mtp:
    • prose then code: 0 NaN, 256 tokens each, 15.7 and 20.2 tok/s, draft acceptance 0.658, coherent text;
    • prose alone: 0 NaN, 15.9 tok/s.
      Before the fix, both runs aborted with NaN.
  2. Q8_0 without MTP, the same code request twice: both OK (7.7 and 7.6 tok/s). Before the fix, the second request hit an AMDGPU MEMORY_FAULT, so that was most likely the same bug, with NaN state feeding a later index.
  3. UD-Q4_K_XL with --mtp, old build vs fixed: 19.5/15.7 vs 19.6/15.6 tok/s, same acceptance (188/200), same text. No regression.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is correct. Checked against the branch head (7912b2d):

  • What lane 3 holds. Lane 3 of each gs_flat quad is %pp15, the prefix sum of the log gates (line 859). Lane 1 is %cpv = expf(%pp15) from the same value, and the stores are followed by a workgroup barrier. So expf(lc_t - lc_s) is the same ratio as cp_t / cp_s, without the 0/0 that occurs once both exponentials underflow.
  • No overflow. For t > s the prefix log sum only decreases, so lc_t - lc_s <= 0 and the new expf stays in [0, 1].
  • Coverage. No divf on a %cp* remains anywhere in the file, including the five-token fragment path. All 12 sites in both publish branches are changed.
  • Results from the server (posted earlier as a comment):
    • Q8_0 --mtp gives no NaN, and the no-MTP double-request memory fault is gone.
    • UD-Q4_K_XL --mtp speed is unchanged: 19.6/15.6 tok/s against 19.5/15.7, with the same draft acceptance and the same text.
    • In rs_replay, the argmax matches the CPU on 37/37 rows.

Follow-up, not blocking: a check case in our own file would keep this from regressing. It needs a GDN snapshot publish whose second token has a strongly negative log gate (so exp underflows to 0), with snapshots 1..n-1 required to be finite and to match an f32 reference. The fix doesn't touch the step-4 row-1 logit gap (29.41 against 30.87 on the CPU), so it's a separate precision effect worth its own look.

Approved from my side.

🤖 Generated with Claude Code

@bong-water-water-bong
bong-water-water-bong merged commit cde002d into 1bit/hrx-vulkan-patched Oct 1, 2026
1 check passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hrx-gdn-snapshot-ratio branch November 12, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant