Skip to content

ggml-hrx: run prompt batches above 512 tokens (engine #389) - #101

Merged
bong-water-water-bong merged 5 commits into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-ub389
Oct 12, 2026
Merged

bong-water-water-bong merged 5 commits into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-ub389

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

ggml-hrx: run prompt batches above 512 tokens (engine #389)

Fixes #389.

Every -ub above 512 failed the first prompt batch of a Qwen3.5/3.6 (qwen35)
model with GGML_STATUS_FAILED (llama_decode ret -3).

Root cause

fused-context-claim.h claimed L2_NORM / SOFTPLUS / GATED_DELTA_NET for HRX
at any token count, but the gated-delta-net matchers only took
token_count <= 512. The claim decides placement, so the scheduler placed a node
that no matcher could execute, and the whole graph failed:

graph_compute: unsupported HRX node 2: L2_NORM output=3:f32[128,16,1024,1]<-L2_NORM \
  inputs=[2:f32[128,16,1024,1]<-VIEW] consumers=[16:GATED_DELTA_NET]
graph_compute: ggml_backend_sched_graph_compute_async failed with error -1
process_ubatch: failed to compute graph, compute status: -1
llama_decode: failed to decode, ret = -3

SSM_CONV above 512 tokens had no HRX path either: its rollback/generic Loom
kernels declare n_t <= 512, so it went to the CPU — 97 graph splits per
ubatch
.

The log line naming the cause was invisible without -v, because
llama-bench's null log callback discarded every line, including errors.
That is fixed here too.

A second, independent face of the same defect appeared at -ub 4096: the 27B
qkv projection went to the CPU (the prefill matmul matchers stop at 2048 tokens),
and the claimed SSM_CONV failed the graph. A claim cannot see its consumers, so
a claim must also require the producers its matcher looks at to stay on this
backend.

Changes

  • ggml/src/ggml-hrx/ubatch-token-limits.h (new): shared token-count bounds,
    so the claim and the matchers cannot disagree again. kSsmConvRollbackMaxTokens = 512,
    kSetRowsKernelMaxTokens = 2048, kUbatchMaxTokens = 65536.
  • dispatch-ssm-conv-chunked.{h,cpp} (new): a conv prefill above 512 tokens
    runs as a chain of at most 512-token dispatches per sequence, each passing its
    final 3-row conv history to the next through a ping-pong transient; the last
    chunk writes the real cache.
  • dispatch-row-chunks.{h,cpp} (new): a KV-cache write cannot leave HRX (the
    cache lives there), so SET_ROWS above its 2048-token kernel range runs as
    several dispatches.
  • fused-context-claim.h: the GDN claim is bounded by kUbatchMaxTokens; the
    SSM_CONV claim keys on the delta-net conv tensors' names (conv_input,
    conv_output_raw) so other conv layouts (Mamba's conv bias before SILU) keep the
    standalone test and fall back to the CPU as before; and a second overload
    fused_context_claim(op, supported) also requires the producers the matcher
    looks at to stay on this backend.
  • llama-bench.cpp: the null log callback keeps GGML_LOG_LEVEL_ERROR and its
    continuation lines without -v, so a failed decode says why.

No kernel change.

Verification (Strix Halo, 2026-10-12)

check result
Qwen3-0.6B greedy text, ub 512 / 1024 / 2048 bit-identical across all three
Qwen3.8-27B PPL, ub 512 / 1024 / 2048 5.7532 ± 0.16114 on all three
Qwen3.8-27B multi-seq PPL, b1024/ub512 vs b1024/ub1024 7.1431 ± 0.27993 on both
Qwen3.8-27B ub 1024 runs to completion (4097 tokens, 19.4 s)
-ub 4096, Qwen3.8-27B addressed by the producer-stays-on-HRX claim; not yet run-verified

ub 4096 remains unverified by a run — the verification batch was aborted. This
PR touches numerics, so it should carry the hw-gate label before merge.

bong-water-water-bong and others added 5 commits October 12, 2026 07:42
Every -ub above 512 failed the first prompt batch of a Qwen3.5/3.6 (qwen35)
model with GGML_STATUS_FAILED (llama_decode ret -3). The HRX log line that
names the cause, "graph_compute: unsupported HRX node 2: L2_NORM
output=f32[128,16,1024,1] ... consumers=[GATED_DELTA_NET]", was hidden
because llama-bench drops every log line without -v.

Root cause: fused-context-claim.h claims L2_NORM / SOFTPLUS /
GATED_DELTA_NET for HRX at any token count, but the gated-delta-net
matchers only took token_count <= 512, so the scheduler placed a node that
no matcher could execute and the whole graph failed. SSM_CONV above 512
tokens had no HRX path either (its rollback/generic Loom kernels declare
n_t <= 512), so it went to the CPU: 97 graph splits per ubatch.

- ubatch-token-limits.h (new): shared bounds. The GDN WMMA kernels walk
  16-token chunks with fixed LDS (token_count range up to 1048576), so the
  GDN matchers now take up to 65536 tokens.
- dispatch-ssm-conv-chunked.{h,cpp} (new): a conv prefill above 512 tokens
  runs as a chain of <= 512-token llm_ssm_conv_dconv4_silu_rollback_f32
  dispatches per sequence; each passes its final 3-row conv history to the
  next through a ping-pong transient, the last writes the cache slots. No
  kernel change.
- fused-context-claim.h: the GDN claims carry the same bound; SSM_CONV fed
  by CONCAT(state, x^T) is claimed up to it, so the graph stays on HRX
  (27B ub 1024: 97 -> 1 graph split).
- graph-executor.cpp / ggml-hrx.cpp: the two early returns that could fail
  without a message now log one, and an empty status prints a fallback.
- llama-bench: without -v, error-level log lines still reach stderr.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The SSM_CONV claim from the previous commit keyed on "fed by CONCAT", which
Mamba/Mamba2 (Zamba2, Jamba, Granite-hybrid, Nemotron-H) graphs also build;
they add a conv bias before SILU, which the CONCAT prefill matcher does not
take, so above 512 tokens those nodes would be claimed with no matcher and
fail the graph. A claim cannot see consumers, so it now also requires the
names the delta-net conv builder gives these tensors (conv_input-N,
conv_output_raw-N: qwen3next, qwen35, qwen35moe). Other conv layouts keep
the standalone test and fall back to the CPU above 512 tokens, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n HRX

At -ub 4096 the 27B prefill matmuls go to the CPU (the prefill matmul
matchers stop at 2048 tokens: 712 graph splits), so the qkv projection
that the conv window transposes became a split input, the CONCAT matcher
no longer saw TRANSPOSE(x), and the claimed SSM_CONV failed the graph
("unsupported HRX node 11: SSM_CONV output=f32[10240,4096,1,1]").

fused_context_claim(op, supported) now also asks the backend's own
supports_op about the conv's x producer; the per-op claim in
device_supports_op passes it in. When x leaves HRX the conv falls back to
the CPU with it instead of failing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
At -ub 4096 the next failure after the conv was the KV-cache SET_ROWS
(rows f32 [1024, 4096] into the f16 cache): the cache lives in HRX memory,
so the node cannot fall back to another backend, and the set_rows matcher
rejects token_count > 2048 (ggml.set_rows.token_capacity range [1, 2048]):
"SET_ROWS matcher rejected node: shape or rows layout is unsupported".

dispatch-row-chunks.{h,cpp} (new) splits a row-wise dispatch into equal
chunks of at most N rows over offset row/index bindings; the plain
SET_ROWS matcher takes up to kUbatchMaxTokens rows and uses it above 2048.
The fused ROPE+SET_ROWS matcher keeps its 2048 bound. The shared bound in
ubatch-token-limits.h is renamed kUbatchMaxTokens, as it now covers more
than the linear-attention matchers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…unks

A conv prefill of one sequence with one cache slot, 8192..10240 channels
and a multiple of 512 tokens now runs AMD's 512-token pair per chunk
(llm_ssm_conv_snapshot_window_tail_f32 + llm_ssm_conv_dconv4_silu_prefill
_512_wg1024) instead of the token-serial rollback kernel. The snapshot
kernel already writes the chunk's last 3 x rows as the conv history, so
the chain passes it to the next chunk through a ping-pong transient and
the last chunk writes the real cache. Partial ubatches and multi-sequence
batches keep the rollback chain. No kernel change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Author

Note on the hw-gate line in the description: the hw-gate label and workflow live in this engine repo (PR #403, docs/hw-gate.md, .github/workflows/hw-gate.yml), not on 1bit-MONSTER/llama.cpp, which has no such label. Nothing here needs labelling; the point of that line is only that these changes touch the claim/dispatch paths that determine numerics, so they should not land on inference-equivalence evidence alone. PR #403 is still open, so the gate is not yet enforced anywhere.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Sharper statement of the one unverified line, after checking every recorded -ub 4096 run against the builds that produced it.

The description says -ub 4096 is "addressed by the producer-stays-on-HRX claim" (2345d88cc). That is true but incomplete. Per its own commit message, 2345d88cc withdraws the claim when the qkv projection leaves HRX, so the conv falls back to the CPU with it instead of failing. It makes ub4096 stop failing; it does not keep the conv on HRX. 66a6d1c07 (11:50) is the commit that keeps a >512-token conv on HRX, by chaining 512-token dispatches, and the ub4096 line does not mention it.

Why nothing was caught: every recorded ub4096 failure used bin-final, whose libggml-hrx.so is the 10:07 build.

run time build result
c_ppl_fix_ub4096 08:18 bin-final failed, SSM_CONV [4099,10240,1,1]
dbg4096 09:35 bin-final failed, same node
dbg4096b 10:05 bin-final failed, same node
dbg4096c 10:43 bin-final rc=143, killed by the 90 C heat guard

dbg4096b at 10:05 predates even the 10:07 build, so no run has exercised the fallback. 66a6d1c07 was built at 11:50 into build/bin and bin-fast; neither has been run at ub4096. batch3.log, the batch written to settle this, is 0 bytes.

One caution for anyone reading batch1.log: it records ppl_fix_ub4096 rc=0, but that is the systemd scope's exit code, not the run's. The same block then prints the SSM_CONV error and perplexity : failed to decode, and there is no Final estimate. ub4096 failed there.

So the accurate version of that row is: -ub 4096 has not been run on any build containing either 2345d88cc (built 10:07) or 66a6d1c07 (built 11:50) -- still inferred, not measured. The hardware note in the description stands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant