Skip to content

HRX: Qwen3-4B --parallel 4 NaN logits on a never-used slot while another GPU job runs (CWSR off) #528

Closed

Description

@bong-water-water-bong

1bit-canonical on strixhalo aborted at 2026-10-23 07:45:12 ADT with a whole-vocabulary NaN:

367.05.963.920 E common_sampler_sample: HRX returned NaN logits: count=151936 of 151936,
                 index range [0..151935], contiguous=yes, continuing=no (engine#315)
/home/bcloud/wt/tsvchrx4/src/third_party/llama.cpp/common/sampling.cpp:620: HRX: NaN logits (engine#123)

Every one of the 151,936 logits was NaN, and the whole range was contiguous, so this is not one lane or one row of the output — it is the output of the request as a whole. The boot is CWSR off (/sys/module/amdgpu/parameters/cwsr_enable = 0), so the #315 eviction mechanism does not apply here.

What the slot was doing

07:45:09  slot get_availabl: id 3 | task -1 | selected slot by LCP similarity, f_sim_best = 0.252 (> 0.100 thold), f_keep = 0.472
07:45:09  slot launch_slot_: id 3 | task 187 | processing task, is_child = 0
07:45:11  slot print_timing: id 3 | task 187 | prompt eval 210.74 ms / 175 tokens (830.42 tok/s)
07:45:11  slot print_timing: id 3 | task 187 |        eval 1624.04 ms /  29 tokens (17.86 tok/s)
07:45:11  slot print_timing: id 3 | task 187 |    graphs reused = 190
07:45:11  slot      release: id 3 | task 187 | stop processing: n_tokens = 262
07:45:11  slot get_availabl: id 2 | task -1 | selected slot by LRU, t_last = -1
07:45:11  slot launch_slot_: id 2 | task 218 | processing task, is_child = 0
07:45:12  E common_sampler_sample: HRX returned NaN logits (above)
07:45:18  systemd: Main process exited, code=exited, status=1/FAILURE
07:45:29  systemd: Scheduled restart job, restart counter is at 1  (active again, ready on :8095)

The abort is on slot 2's first task after selected slot by LRU, t_last = -1 — a slot that had never been used in this process (6 h 07 min uptime, 18.8 s CPU) — one second after slot 3 finished a 175-token prompt / 29-token generation normally with 190 reused graphs. Backtrace (the crash handler's): common_sampler_sample <- server_context_impl::post_decode lambda <- iterate <- post_decode <- update_slots <- server_queue::start_loop <- llama_server.

Concurrent GPU work

An hw-gate run was on the same GPU for the whole window: run 39940594897 (hw-gate.yml, head f061e5df = the gpu-kernels 744bd713d968 bump, created 2026-10-23T10:39:01Z, updated 10:46:28Z → 07:39:01–07:46:28 ADT), i.e. it spans the 07:45:12 abort. GTT at the service's restart one line later: GTT 95.1 of 120.0 GiB free, MemAvailable 84.7 GiB.

Environment

  • Unit: 1bit-canonical.service + drop-in hrx.conf — 1bit serve -m ~/models/Qwen3-4B-Q4_K_M.gguf --device hrx --ctx-size 8192 --parallel 4 (serve turns qwen.attention off and passes -kvu; docs/serve.md, engine serve --parallel on HRX: shared KV cache, no qwen.attention (Qwen3-4B 4 slots 39 -> 153 tok/s) #240), ONEBIT_LLAMA_SERVER=~/.local/share/1bit-hrx-3092596/hrx/llama/bin/llama-server, HSA_USERPTR_FOR_PAGED_MEM=0, Restart=always.
  • Package: ~/.local/share/1bit-hrx-3092596 (installed 2026-10-19T22:57 ADT, own copy, never rebuilt in place): engine 309259627, llama.cpp 00f2a68de (fork Vulkan: carry ggml-org#28243 (Qwen3.8-Flash-Next MTP) on our fork branch #110), hrx-system 82804197bcbe, gpu-kernels 7562196; built with -DONEBIT_HRX=ON and the private HIP add-on (ONEBIT_GPU_PRIVATE), packed by scripts/package-linux.sh 3092596.
  • Kernel 7.3.0-rc4-1bit-perfopt, CWSR off, --parallel 4 (n_slots = 4, n_ctx_slot = 8192, kv_unified) as logged at load.
  • The service restarted itself once (NRestarts=1). coder-llm (Qwen3-Coder-30B-A3B, same package family) has 0 restarts since the 01:38 boot.

One occurrence in about 6.5 h of uptime.

Related

#433 (ZAYA1-8B NaN with a second HRX process on the GPU) was re-checked clean today: 120 fresh loads, 0 NaN, no heavy GPU neighbour. #123 is the guard that turned this into an abort instead of a silently wrong token. The hrx-gdn-* NaN family is the 27B MTP path, a different model and a different graph. --parallel on HRX is per-slot KV with unified cache and qwen.attention dispatch off (engine #240).

Next

Reproduce with 60 requests per arm on this package and on main, each request landing on a fresh/LRU slot (prompts varied so LCP similarity stays below the 0.1 threshold), with and without a GPU neighbour inside the same claim — the neighbour being any heavy job of ours, not the real hardware gate.

Activity

  1. added
    bug
    on Oct 23, 2026
  2. bong-water-water-bong commented on Oct 23, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Reproduction attempt: 0 NaN in 300 requests across five arms, so this is one occurrence that these arms do not reproduce. Data and the two conditions I could not reproduce below.

    Arms (each 60 requests, every request on a never-used or LRU slot)

    Two builds, 1bit serve -m ~/models/Qwen3-4B-Q4_K_M.gguf --device hrx --ctx-size 8192, private port and systemd-run --scope -p MemoryMax=8G, HSA_USERPTR_FOR_PAGED_MEM=0 as the unit sets it, all inside one gpu-hold -l "pi issues-a" -t 14 claim per arm pair:

    arm build --parallel GPU neighbour requests NaN OK restarts never-used slots hit requests picked by LCP similarity
    old-neighbour 3092596 package (engine 309259627, llama.cpp 00f2a68de, gpu-kernels 7562196) 4 our own Qwen3-0.6B serve, 127 requests 60 0 60 0 4 of 4 0
    old-alone same 4 none 60 0 60 0 4 of 4 0
    main-neighbour release main 7871c71d (llama.cpp 851fa6c8d8f2, hrx-system 82804197bcbe, private HIP add-on 744bd713d968, 1bit sha256 703edb65…) 4 our own Qwen3-0.6B serve 60 0 60 0 4 of 4 0
    main-alone same 4 none 60 0 60 0 4 of 4 0
    main-parallel1 same 1 none 60 0 60 0 1 of 1 0

    Method, so the arm shape can be checked: each request carried a 16-character nonce plus random words (~300 prompt tokens, max_tokens 32, temperature 0), so no two requests shared a prefix. The server's own slot log confirms it: every --parallel 4 arm filled all four slots from selected slot by LRU, t_last = -1 first, then rotated by LRU, and no request was ever selected by LCP similarity (selected slot by LCP similarity count = 0 in every arm) — i.e. no prefix reuse at all, which is the state the failing slot 2 was in. The neighbour was our own second HRX serve hammered from a thread (127 requests, 0 NaN), never the real hardware gate.

    Environment: strixhalo, kernel 7.3.0-rc4-1bit-perfopt, CWSR off, 90 W cap, PCM pad (23 Oct), Tctl 55–63 °C across the two claims, GTT 34.9 GB of 128.8 GB used and MemAvailable 74 GiB at claim start (the incident's line was GTT 95.1 of 120.0 GiB free, MemAvailable 84.7 GiB). sudo -n dmesg after each claim: no amdgpu fault, reset or ring timeout (the only amdgpu lines are the boot-time REG_WAIT/TMZ ones from 01:37).

    What this does and does not rule out

    Ruled out as a sufficient condition, on this box, in 300 requests: a never-used slot (4 hit per arm), full --parallel 4 multi-sequence serving, the 2026-10-19 package alone, the current release line alone, and a second model sharing the GPU.

    Two conditions of the incident are not in these arms:

    1. The kind of neighbour. Mine was a second serve — decode-heavy, one graph reused. The gate run 39940594897 was test-backend-ops op sweeps plus repeated model loads: many different graphs, many allocations, the kernels this path never touched. That is the closest thing to a difference in mechanism and the next thing to reproduce.
    2. Uptime. The service had been up 6 h 07 min and had served 217 tasks when the whole-vocab NaN appeared; each arm here lived about a minute.

    Next probes, in order: (1) same five arms with test-backend-ops -b HRX0 -o MUL_MAT in a loop as the neighbour instead of a second serve; (2) a long soak of the failing configuration (one --parallel 4 serve, hours, unique prompts) with GGML_HRX_NAN_CONTINUE=1 so a NaN is captured with its index range instead of aborting; (3) keep the abort behaviour in the service: the guard printed count=151936 of 151936 … contiguous=yes, which is the diagnostic that makes this class of report actionable.

    Recommendation for the orchestrator (owner decides)

    Move 1bit-canonical to the release-candidate package when the candidate exists, for currency — the running package is from 2026-10-19 (engine 309259627, llama.cpp 00f2a68de) and predates the current HRX pin, strict placement by default and the warm-up work — but not as a fix for this NaN: 0/300 here attributes nothing to those changes. Rollback stays trivial (the ~/.local/share/1bit-hrx-3092596 directory and the drop-in's ONEBIT_LLAMA_SERVER line), and no agent should touch the service; the owner restarts it.

  3. bong-water-water-bong commented on Oct 25, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Status from pi issues-c (the handover of this item) — a reproduction attempt that is still queued, and what
    the code says to look at next. No new NaN was produced; nothing here contradicts the 0/300 from the earlier
    campaign.

    What I built for it

    ~/wt/issues-c/nan528.sh, run inside one claim, shaped after the failing configuration rather than after a
    second serve:

    • llama-server -m Qwen3-4B-Q4_K_M.gguf -c 8192 --parallel 4 -kvu -ngl 99 -dev HRX0, i.e. the same unified-KV
      four-slot shape 1bit serve --device hrx --parallel passes, with GGML_HRX_DISABLE_DISPATCH=qwen.attention
      set (that is what app/serve.cpp adds, and it is the path that made per-slot answers bleed before serve --parallel on HRX: shared KV cache, no qwen.attention (Qwen3-4B 4 slots 39 -> 153 tok/s) #240);
    • HSA_USERPTR_FOR_PAGED_MEM=0 as the unit sets it, and GGML_HRX_NAN_CONTINUE=1 so a NaN is captured with its
      index range
      instead of aborting (the guard at common/sampling.cpp:608 is the diagnostic that made the report
      actionable in the first place);
    • the second job is llama-bench on Qwen3-0.6B in a loop inside the same claim, i.e. a neighbour with many
      different graphs, many allocations, and kernels this path never touches - the closest cheap analogue of the
      test-backend-ops sweep the hardware gate was running at 07:45 on 23 Oct. The earlier campaign's neighbour was
      a second serve (one graph reused), which is the one difference it named as unexplained;
    • ~170-word prompts plus a 16-character nonce and cache_prompt: false, so no request can be picked by LCP
      similarity and every request lands on a never-used or LRU slot; 60 requests per arm, two arms (neighbour on /
      neighbour off).

    Arm 1 (heavy neighbour) has now run on the pin (llama.cpp 75242f31 + hrx-system 82804197bc, our own build,
    not the 2026-10-19 package), one gpu-hold claim, label 90 W cap, PCM pad (23 Oct), sudo -n dmesg after the
    claim: no amdgpu fault, reset or ring timeout.

    arm requests NaN HTTP errors restarts slot selection
    neighbour = llama-bench Qwen3-0.6B loop 60 0 0 0 60/60 by LRU (4 never-used slots, then rotation), 0 by LCP similarity
    control, serve alone 60 0 0 0 60/60 by LRU, same shape

    Median request 0.7-0.9 s (175-token prompt + 32 generated), i.e. the shape of the incident's requests; both arms
    selected every request by LRU and none by LCP similarity, and neither produced a single NaN line with the guard's
    index-range diagnostic armed (GGML_HRX_NAN_CONTINUE=1).

    So this makes 0 NaN in 120 requests on the current pin, on top of the earlier campaign's 0/300 across five arms
    on the 2026-10-19 package and the release line
    . A 1-in-~500-request event cannot be settled by 120 requests; what
    these arms do settle is that the neighbour class the incident blamed (a second serve then, a bench loop now) is
    not a sufficient condition, and that the reproduce path is a soak, not another 60-request arm.

    What the incident shape still points at

    The abort was on slot 2's first task (selected slot by LRU, t_last = -1, one second after slot 3 finished
    cleanly with 190 reused graphs), and every one of the 151,936 logits was NaN with a contiguous range. That is not
    a wrong-value kernel: the whole output of the request is NaN, which is what an unwritten or poisoned output range
    looks like - the logits buffer was allocated, the graph ran, and what came back was not a number. Two mechanisms
    in this tree can do that and both are independent of -kvu's correctness:

    1. a transient arena range read before its write in a plan whose dispatch order the recorder did not model -
      the class engine hrx: fusion must withdraw dispatches it makes redundant (reader emitted before the fused writer, engine #533) #570 is about (a fusion that makes an already-emitted dispatch redundant leaves a reader in
      the program), except that the verifier catches those at plan time when it can see them, and a runtime plan
      chosen under a different ubatch shape is where it could slip through;
    2. fresh device memory: a transient arena or a per-slot KV allocation that the pool hands out for the first
      time in that process, read before the first write. A never-used slot is exactly the state that makes this
      visible, and a heavy neighbour changes which pool pages are fresh - which is why the neighbour matters.

    Both are testable without waiting for a second 6.5-hour occurrence: the arm above records the NaN index range and
    the slot id, GGML_HRX_LOG_TRANSIENT_REUSE=1 prints both arena sizes for every program (guarded vs stock), and
    GGML_HRX_TRANSIENT_REUSE=legacy is the A/B switch for the guarded packer. If an arm does produce a NaN, the next
    step is the same request with the stock packer and with the plan dump of that shape - that separates "arena reuse
    without a barrier" from "uninitialized fresh memory" in one run.

    Recommendation (unchanged, and now with a second reason)

    Do not move 1bit-canonical off the 2026-10-19 package for this; move it when the release candidate exists,
    and add the soak to the candidate's acceptance instead: GGML_HRX_NAN_CONTINUE=1 on one --parallel 4 serve for
    a few hours with unique prompts and a bench neighbour. 60 requests per arm cannot see a 1-in-~500 request event;
    a soak with the index-range guard on can, and it costs one claim.

  4. bong-water-water-bong commented on Oct 27, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Ran the issue's own repro plan on strixhalo. Two valid arms, four slots each, no NaN.

    arm slots requests NaN replies "NaN logits" in log GTT before → after
    none 4 of 4 60 0 0 13 365 248 → 13 402 112
    neighbour (second HRX server busy for the whole arm) 4 of 4 60 0 0 6 645 248 → 6 400 172 032

    Conditions, so this is auditable rather than a claim: package ~/.local/share/1bit-hrx-3092596
    (mtime 2026-10-19 22:57), Qwen3-4B-Q4_K_M.gguf, --parallel 4 --ctx-size 8192,
    amdgpu.cwsr_enable=0 (matches the report), 24-token greedy prompts, prompts generated from
    /dev/urandom so slot LCP similarity stays under the 0.1 reuse threshold, 4 requests in flight per
    batch (a sequential loop only ever uses one slot and cannot reach a never-used slot — my first run
    proved that by reporting slots_used=1 of 4 and is marked invalid by the harness now).
    Logs: ~/lb/528/run-20261027T215046Z-none and ~/lb/528/run-20261027T215131Z-neighbour.

    What this does not reproduce: the neighbour here is a second HRX server, not the hardware gate's
    own workload (hw-gate run 39940594897 as named in the report). If the trigger is specific to that
    workload's shape — a bench holding the GPU's queue rather than a second server sharing GTT — this arm
    does not cover it. That is the one remaining difference I can see between the report and this run.

    Harness is in the repo convention for reruns; it refuses to report a result unless at least three
    distinct slots actually launched. Verdict from me: unreproduced, not fixed — leaving the issue open
    rather than closing it on absence of evidence, and if it recurs, the useful datum is which GPU job was
    co-resident and whether GTT was still growing at the time.

  5. bong-water-water-bong commented on Oct 28, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Checked what can be checked without a GPU: the guard the trace hit is still there and the failure shape it describes is still documented in the pin —

    $ git grep -n "HRX: NaN logits" e7e5cd08 -- common/
    e7e5cd08:common/sampling.cpp:620:                    GGML_ABORT("HRX: NaN logits (engine#123)");
    

    so if it happened again it would still abort rather than emit tokens. Counter-evidence that it does not currently reproduce: docs/npu-leaderboard.md:30 records a Qwen3-4B HRX run at parallel=4, kv_unified=true, requests=60 producing decode (eval) 41.48 tok/s — the exact shape of the failing case (four slots, repeated requests) running to completion, so no slot produced whole-vocab NaN there. That is one arrangement on one boot, not proof: the record does not say whether cwsr_enable was 0, and the bug needs a never-used slot while a second GPU job runs.

    Classification: needs GPU measurement — the targeted repro, not the leaderboard shape: llama-server --parallel 4 with cwsr_enable=0, three slots kept busy and one left untouched, one concurrent GPU job on the box, then force the idle slot to take a request and read the log for HRX returned NaN logits: count=<vocab> of <vocab> / the sampling.cpp:620 abort. Related: the #315 eviction path is out of scope here by the boot's cwsr_enable=0, which is what makes this a different (and still open) mechanism.

  6. bong-water-water-bong commented on Oct 30, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The padded-KV mechanism is now confirmed on hardware (HRX0, gfx1151), on the production prefill window: q=175, n_kv=256, mask 0 over [0,175) / -INFINITY over [175,256), f16 NaN half 0x7E00 written into the masked K/V columns.

    FLASH_ATTN_EXT(...,kv=256,nb=175,pad_nan=0): OK
    [FLASH_ATTN_EXT] NaN at index 0 (HRX0=-nan CPU=-0.090690)   ... pad_nan=1): FAIL
    [FLASH_ATTN_EXT] NaN at index 0 (HRX0=-nan CPU=-0.023538)   ... pad_nan=2): FAIL
    [FLASH_ATTN_EXT] NaN at index 0 (HRX0=-nan CPU=0.039812)    ... pad_nan=3): FAIL
    

    pad_nan=1/2/3 = NaN in K+V / K only / V only: the whole output row is -nan on HRX0 while the CPU reference on the same buffers stays finite (the report's repeat of the same case printed HRX0=-nan CPU=0.028604); 3 runs, 3 random tensors, NaN at index 0 every time.

    pad_nan=0 pads with the finite 60000 and passes within the case's max_nmse_err() = 5e-4, so the mask is honoured and only non-finite padding bites — the upstream invariant confirmed at the kernel, third_party/llama.cpp/src/llama-kv-cache.cpp:292 ("allocate tensors and initialize the buffers to avoid NaNs in the padding"), where on HRX a failed clear is a log line only (ggml/src/ggml-hrx/ggml-hrx.cpp:286-300). Dispatch shows the kernel takes the padded extent, not the mask extent: common.flash_attention_f32_f16_wmma (single), dispatch-flash-attention.cpp:260 uses key_value_capacity = 256.

    Getting it to run at all took a harness fix, and that matters more than the case: the pre-allocation support gate in tests/test-backend-ops.cpp rejected it with not supported [HRX0, HRX0, HRX0] because the gate runs before ggml_backend_alloc_ctx_tensors, so the alias tensors are unplaced. Consequence: no upstream flash-attention case had ever run through test-backend-ops on HRX in that tree — every FLASH_ATTN_EXT eval case was silently unsupported, not passing. Minimal fix and verbatim outputs: E1-528-result.md and e1-528/e1-528.patch (108 insertions, tests only).

    What this does not prove: the provenance of the NaNs reported in this issue is still open — nothing above says the runtime buffer clear failed — and the original --parallel 4 arm used only one slot (docs/npu-leaderboard.md:40), so it was never a valid repro of the four-slot case.

    Next: a --parallel load generator that keeps all four slots busy and never reuses one, plus the HRX buffer-clear log line from an affected run. That is what would settle this.

  7. bong-water-water-bong commented on Oct 30, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Reproduced at the current pin and fixed in the two places the HRX flash-attention kernels actually live. strixhalo, llama.cpp 40c4ccb76 + hrx-system 82804197 + gpu-kernels 17a882640fa8, CWSR off, one gpu-hold claim per run.

    Reproduction: the mechanism holds at this pin

    test-backend-ops test -b HRX0 -o FLASH_ATTN_EXT -p pad_nan (case added in this work): q=175 over n_kv=256, hsk=hsv=128, f16 K/V, mask 0 over [0,175) and -INFINITY over [175,256), f16 0x7E00 written into the masked K/V columns after allocation.

    pad_nan=0 (finite padding): OK
    pad_nan=1 (NaN in K and V): [FLASH_ATTN_EXT] ERR = inf > 0.000500000      FAIL
    pad_nan=2 (NaN in K):       [FLASH_ATTN_EXT] ERR = inf > 0.000500000      FAIL
    pad_nan=3 (NaN in V):       [FLASH_ATTN_EXT] NaN at index 0 (HRX0=-nan CPU=0.124857)  FAIL
    

    Two extra facts the earlier comments did not have:

    1. Two kernels, and the production one is not in the fork. GGML_HRX_LOG_DISPATCH=1 shows hip.fa_prompt_f16 (fused) — the private add-on's prefill kernel. With GGML_HRX_DISABLE_DISPATCH=hip. the same graph goes to the in-fork Loom common.attention_strided_f32_f16. Both leaked; the leak is in the block that mixes valid and padded keys (NaN confined to fully padded 32-key blocks is skipped by both).
    2. No FLASH_ATTN_EXT case had ever run on HRX. The support gate in test-backend-ops asks ggml_backend_supports_op about every tensor before allocation, including the k/v alias nodes, and ggml-hrx claims only what its dispatcher executes, so a lone VIEW made every case not supported [HRX0, HRX0] — 0 cases ran, silently. Fixing that gate is what makes the case run at all.

    Fixes

    • 1bit-MONSTER/llama.cpp#155 — the in-fork Loom kernels (ggml_attention_strided_f32_f16, ggml_attention_rows_f32_f16, flash_attention_f32_f16_wmma) select on the mask instead of adding it, and skip a zero-probability key in P·V; plus the pad_nan cases and the support-gate fix.
    • 1bit-MONSTER/gpu-kernels#44 — the same in fa_prompt_f16 (prefill, the serving path) and fa_decode. A column no row of the tile attends to is never read from K or V at all.

    With both: pad_nan 4/4 OK on the add-on path and 8/8 (prefill + decode) on the default dispatch; the whole FLASH_ATTN_EXT matrix is 425 OK / 0 FAIL twice; KLD on Qwen3-0.6B is unchanged (median 0.000000, RMS Δp 0.001 %, same top-p 100.000 %); tg128 unchanged, pp512 −2..−4 % from the per-column liveness scan; Qwen3-4B --parallel 4 -kvu + a bench neighbour in the same claim, 60 unique requests: 0 NaN, 4/4 slots.

    What this does and does not settle for the abort

    It settles the class: HRX returned a NaN row where the CPU was finite whenever a masked column's K or V was non-finite, so the guard's count=151936 of 151936, contiguous=yes is what a NaN-poisoned attention output looks like downstream. The provenance of the NaN in the 23 Oct incident (a KV clear that failed and only logged, versus a range never written) is still open — the kernels now ignore those columns either way, which is the invariant the CPU already had. The soak plan from the earlier comments is still the right acceptance test for a release candidate: GGML_HRX_NAN_CONTINUE=1, one --parallel 4 serve for hours, unique prompts, a bench neighbour.

  8. bong-water-water-bong commented on Oct 30, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Decision implemented: the shipped fix is allocator-side (verify and repair the zero padding of the KV cache), the kernel-side mask select is withdrawn, and the negative control below is the end-to-end proof that this is the abort's mechanism and not only a test case.

    Fix — 1bit-MONSTER/llama.cpp#155

    src/llama-kv-zero.cpp verifies the KV padding instead of trusting ggml_backend_buffer_clear, which on HRX is best-effort (ggml-hrx.cpp buffer_clear logs a failed fill and carries on). Three 4 KiB windows are sampled out of every KV tensor; when one is not zero the buffer is filled through ggml_backend_tensor_set and verified again. Called after allocation and after every reset (llama-kv-cache.cpp, marked [1bit]). Load-time only — three reads per KV tensor and zero writes when the clear took, nothing per token.

    Negative control: the incident's condition, then the same run with the fix

    A local, uncommitted switch makes buffer_clear leave 0x7E (f16 NaN) in buffers over 64 MiB, i.e. a clear that does not take. Qwen3-4B --parallel 4 -kvu on HRX0:

    clear only, no verification:  64 x "E common_sampler_sample: HRX returned NaN logits:
                                  count=151936 of 151936, index range [0..151935], contiguous=yes"
    verification on (default):    W llama_kv_zero_fill: KV cache was not zero after the clear (HRX0,
                                  12288 bytes non-zero in 3 samples): zero-filling 1152.00 MiB and
                                  verifying again
                                  -> 0 NaN logits, 60/60 requests clean, 4/4 slots
    

    The first arm is the abort from this issue line for line — same vocabulary count, same contiguous range, same guard — which is what makes the padding the right invariant to fix. In normal runs the log says what it checked: I llama_kv_zero_fill: KV cache verified zero (HRX0, 1152.00 MiB) at load and on each reset.

    Measured

    • llama-bench Qwen3-4B, arms alternating inside one claim, 3 rounds: pp512 4062/3999/3875 (clear only) vs 3975/3858/4042 (verify), tg128 79.36/79.03/79.41 vs 79.14/79.21/79.45 — unchanged beyond the box's noise.
    • --parallel 4 -kvu serve with a bench neighbour in the same claim, 60 unique requests: 0 NaN, 4/4 slots, 60/60 LRU.
    • FLASH_ATTN_EXT matrix on the default path: 419 OK / 0 FAIL. Also fixed in that PR: the support gate counted alias nodes, and ggml-hrx claims only what its dispatcher emits, so no FLASH_ATTN_EXT case had ever run on HRX — they were all silently not supported. That is why this class was invisible to the gate.
    • The pad_nan case from the earlier comment is kept: pad_nan=0 (finite padding, the property the fix guarantees) runs always and passes on HRX0 vs CPU for q=175 over n_kv=256 and for decode; pad_nan=1..3 (NaN padding, the stricter CPU-reference property) are opt-in with GGML_TEST_FA_NAN_PAD=1.

    Withdrawn

    1bit-MONSTER/gpu-kernels#44 (the same select in the add-on's fa_prompt_f16/fa_decode) is closed. It is correct hardening — a masked column selected rather than added, a zero-probability key skipped in P·V — but it cost -2..-4 % pp512, and with the padding guaranteed zero it buys nothing on the serving path. The kernel-side diff is preserved in that PR if a future workload ever needs kernels that tolerate non-finite padding.

    Still open, and unchanged by this: the provenance of the NaN in the 23 Oct incident (which clear failed, or which range was never written). The fix makes the padding self-verifying at every allocation and reset and logs when it had to repair, so the next occurrence will say so instead of showing up as a NaN logits abort.

  9. bong-water-water-bong commented on Oct 31, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Closed by merge, with the fix reachable at the engine pin.

    The fix. 1bit-MONSTER/llama.cpp#155 — kv: verify the zero padding of the KV cache, and repair it —
    merged as b8861a9f97fd71fae01cee1c4df965bb0e1ae299 (2026-10-30T13:54:55Z). It stops trusting
    ggml_backend_buffer_clear, which on HRX is best-effort (ggml-hrx.cpp buffer_clear logs a failed fill and
    carries on), samples three 4 KiB windows out of every KV tensor, and refills + re-verifies through
    ggml_backend_tensor_set when a sample is non-zero. Load-time and on every reset only: three reads per KV
    tensor, zero writes when the clear took.

    Reachable at main. Engine #672 (merged 2026-10-31T01:09:23Z, 31d52e12c) sets
    third_party/llama.cpp = 5e6388a5a852281c6929303c1219665b2a6d4c0a, and:

    $ git -C third_party/llama.cpp merge-base --is-ancestor b8861a9f9 5e6388a5a852281c6929303c1219665b2a6d4c0a
      -> true
    

    so every build from 31d52e1 on carries the verification; no separate action is needed from the packager.

    Verified today, on this box, CPU-side (~/wt/i528/build/bin/test-kv-zero, the test the PR adds):

    llama_kv_zero_fill: test zero-filled and verified (CPU, 0.25 MiB)
    llama_kv_zero_fill: test was not zero after the clear (CPU, 12288 bytes non-zero in 3 samples):
                        zero-filling 6.00 MiB and verifying again
    test-kv-zero: all tests passed
    

    Verified by the lane on the device, in the thread above (2026-10-30 09:41 comment): the negative control
    reproduces this issue's exact abort — a deliberate clear that leaves 0x7E (f16 NaN) gives
    HRX returned NaN logits: count=151936 of 151936, index range [0..151935], contiguous=yes, 32–64 times — and
    with the verification on, 0 NaN in 60/60 requests across 4/4 slots with a bench neighbour in the same claim,
    plus one repair line naming the byte count. Perf unchanged beyond noise (pp512 3975/3858/4042 vs
    4062/3999/3875; tg128 79.14/79.21/79.45 vs 79.36/79.03/79.41, interleaved in one claim).

    What is closed and what is not. The defect this issue reports — a whole-vocabulary NaN produced by a KV
    padding that was assumed zero and was not — has a fix at the pin, an end-to-end negative control, and a test.
    The provenance of the 23 Oct NaN (which clear failed, or which range was never written) is not established
    and does not need to be: the padding is now self-verifying at every allocation and reset and logs when it had
    to repair, so a recurrence will name itself instead of appearing as a NaN logits abort. The soak the thread
    recommended (GGML_HRX_NAN_CONTINUE=1, one --parallel 4 serve for hours, unique prompts, a bench neighbour)
    is release-candidate acceptance material and is not a reason to keep this issue open.

    Also recorded while closing: FLASH_ATTN_EXT had never run on HRX in that tree (the support gate rejected every
    case on unplaced alias tensors), so this class was invisible to the gate; after the PR the matrix is 419 OK /
    0 FAIL and the tail pad_nan cases are opt-in behind GGML_TEST_FA_NAN_PAD=1. The withdrawn kernel-side fix
    (gpu-kernels#44, −2..−4 % pp512 and nothing bought once the padding is guaranteed) stays closed with its
    diff preserved there.

    Tracked on ~/briefs/TISSUES-BOARD.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions