Skip to content

qwen4exp: the fused top-k mask's zero base row is one host input, not a FILL per QSA layer (engine#679) - #483

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-i679/kpool-keep-input
Nov 22, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-i679/kpool-keep-input

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Overview

The fused top-k mask of Qwen3.8-Flash-Next (qwen4exp) built its all-zero base row with ggml_fill(f16 [n_kv], 0) in every QSA layer. HRX has no f16 FILL, so each of those 12 nodes ran on the CPU and cut the decode graph at every QSA layer. The row is now one input of llm_graph_input_kpool, zeroed on the host in set_input and shared by all QSA layers. The values are the same, so the mask and the output do not change; only the FILL nodes and their splits go away (engine#679).

Measured

strixhalo (gfx1151), rc-2026-11-22-c35 package llama-server with only libllama.so.0 swapped (base = 7737fa3, this = 7737fa3 + this commit, both built the same way; the ggml symbol imports are identical to the package's libllama). Qwen3.8-Flash-Next UD-IQ3_XXS, -ngl 99 -c 32768 -np 1 -ub 2048 --cache-reuse 256, GGML_HRX_GRAPH_PROGRAM_CACHE=128, GGML_HRX_STRICT=0, GGML_HRX_IQ3S_TABLE_DECODE=0 (both arms; see below), power mode balanced, one box-hold gpu ticket, MES failures 0 -> 0, amdgpu error lines 0 -> 0.

  • graph placement (GGML_HRX_STRICT=1 refusal line): base 17 of 6556 nodes off HRX (DUP x 1, GET_ROWS x 3, SET_ROWS x 1, FILL x 12), 26 splits -> this 5 of 6544 nodes off HRX (DUP x 1, GET_ROWS x 3, SET_ROWS x 1), 2 splits
  • greedy, 512 tokens: all 8 runs per prompt token-identical across both arms, max |logprob difference| 0.0, no NaN
  • interleaved A/B, order base, this, this, base; 2 requests per prompt per load, 4 per arm; decode tok/s:
prompt tokens base this
211 17.88-18.12 (median 18.01) 18.58-20.55 (19.17)
4,101 17.92-18.16 (18.14) 18.42-20.13 (18.64)
8,191 17.82-18.08 (17.90) 18.36-20.08 (18.49)
18,781 17.41-17.74 (17.53) 18.16-20.12 (18.68)

Ranges are disjoint at every length. Prefill at 18,781 tokens: 495-510 -> 547-585 tok/s.

  • test-llama-archs (CPU, ryzen): all 172 architectures pass, qwen4exp included.

The ggml-org#679 bar is 20.0 tok/s at 18.8k; the median is not there yet (one run 20.12).

Additional information

GGML_HRX_IQ3S_TABLE_DECODE=0 was needed in both arms because the shipped default fails on this GGUF: kernel loom_libs:ggml_mul_mat_id_swiglu_f32_f32_wmma_iq3s_table has 7 bindings but its ABI requires 6. That is a separate fix (separate PR, once it is verified on a device build).

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES. Claude Code (Claude Opus 5.5) found the cause in the scheduler log, wrote the change and ran the measurements; the numbers above are from the box.

🤖 Generated with Claude Code

… a FILL per QSA layer (engine#679)

The fused TOP_K_MASK path built its base row with ggml_fill(f16 [n_kv], 0) in
every QSA layer. HRX has no f16 FILL, so each of those nodes ran on the CPU and
split the decode graph once per QSA layer (12 CPU splits per Flash-Next decode
step in the 11-21 scheduler log, ~0.8 ms of host round trip each).

The row is now one input of llm_graph_input_kpool, zeroed on the host in
set_input and shared by every QSA layer. Same values, so the mask and the
output are unchanged; only the FILL nodes and their splits go away.

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

@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.

Verdict: APPROVE (review by lane cl-kernel).

  • Correctness: ggml_top_k_mask allocates its own result (ggml.c, ggml_new_tensor_4d) and GGML_OP_TOP_K_MASK is not in ggml_op_can_inplace (ggml-alloc.c). So no QSA layer can write into the shared zero row, and the allocator cannot reuse its buffer even when the last consumer has the same layout (decode, n_tokens=1). The new assert pins type and length to what build_qsa_sel expects: type_mask uses the same flash_attn ? F16 : F32 rule. set_input zeroes the row on every ubatch, including reused graphs, and can_reuse already keys on n_kv, which is the row's length. The host-buffer assert is consistent with how the scheduler places inputs.
  • Measurements: they support the change. The FILL nodes come off the CPU (17 -> 5 nodes off HRX, 26 -> 2 splits). Greedy output is token-identical across 8 runs per prompt with 0.0 logprob difference. Decode tok/s ranges don't overlap at every length (18.8k: 17.41-17.74 -> 18.16-20.12). test-llama-archs passes all 172 architectures. The PR states plainly that the ggml-org#679 20.0 bar is not reached yet.
  • Merge order: independent of the others (merges cleanly with each); fine to land second. Needs an engine pin bump afterwards, as noted in the CL-I679 STATE file.

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