Repository navigation
corpus: select the IQ1_S prefill arm and stage both packet halves (#2832) - #428
Merged
bong-water-water-bong merged 7 commits intoNov 19, 2026
Merged
Conversation
…cher passes (ggml-org#2832) The arm added in 831ed61 was keyed on 19, but no dispatcher can pass 19: the corpus numbers weight formats with common_mul_mat_format_config_value() (dispatch-mul-mat-weight-format.h), where Q4KRow64 = 44, Q6K = 6 and IQ1_S = 26; 19 is ggml.h's type id. @ggml_kquant_grid_fill_for also only answers 21/22/24/25/26/27/28, so the 4 KiB codebook would have been staged never and read uninitialised. It also did not link: the motif calls @ggml_kquant_grid_fill_for, which is defined in ops/kquant_decode_f32.loom, but no export that compiles the motif lists that module, so every prefill launch of q4_K/q6_K dies with "LINK/MATERIALIZE: unresolved exact declaration" and a refused command (engine#2865, hw-gate 3593/3604 against 3604/3604 on the parent). - motif: 19 -> 26 in both places, and call @ggml_kquant_iq1s_grid_fill (defined by the motif's own library, motifs/kquant_iq1_s.loom) instead of the format-dispatching wrapper, so no module has to link the 11k-line decode op to resolve it. - manifest: every export that compiles motifs/mul_mat_quantized_f16_prefill.loom (22 of them) now lists motifs/kquant_iq1_s.loom in library_sources and compile_dependencies -- the corpus requires one list per primary source, and an unresolved declaration fails the Loom link even when the branch is dead. - ops: @ggml_mul_mat_iq1_s_f16_wmma_prefill_wave32, the q4_K prefill schedule with 26 baked and the weight bound as stored rows (IQ1_S has no packed row layout). - dispatch: common.mul_mat.iq1_s_prefill_wave32 at priority 294, IQ1_S, no alias, tokens 256..2048 step 256 (the kernel's own assume -- the q6_k route's 128 floor does not satisfy it), input % 256, output % 64. - tests: three rows at 9 / 64 / 512 tokens, 4096-wide output; the row helper now quantizes IQ types through ggml_quantize_chunk with a dummy importance matrix, since they have no from_float_ref.
…-org#2832) The IQ1 arm pinned the staged weight window offset to 0, so all four producers of a row wrote the same 32 values at [0,32) and the consumer's [32,64) half stayed uninitialised LDS: the prefill matmul returned NaN on the 1024-workgroup tile (n=512 passed through the arm on gfx1151).
added 5 commits
November 18, 2026 16:54
The 1024-thread tile stages four halves of 32 values into the 64-value window the mma reads, so the
store origin ran to 32*3 + 16 = 112 on a 72-wide row: the Loom verifier refused the range as
unprovable ("vector_extent is 16, view_bound is 72, and the maximum legal origin is 56 @ 18540:9")
and the arm never compiled for the shapes Qwen3.8-27B asks for (5120x6144, 5120x17408). An IQ1
packet covers [32p, 32p+32), so two halves tile that window exactly and four do not.
Qwen3.8-27B-UD-IQ1_S, gfx1151, one binary, the arm toggled by dispatch name:
pp512 11.30 +- 0.03 -> 90.15 +- 0.35 t/s (7.98x)
tg128 12.74 +- 0.01 -> 12.72 +- 0.02 t/s (unchanged)
A paired tile stages the gate rows and the up rows from two buffers, but only the q4_K native decoder ever read %up_weight: the IQ1 arm decoded both halves from the gate weight, so a swiglu tile would have published gate rows twice. The IQ1 arm now picks the buffer by %weight_is_up (the q4_K decoder's own rule), leaving the generated IQ1 motif and its regenerated bytes untouched. New kernel.def ggml_mul_mat_iq1_s_swiglu_f16_wmma_prefill_wave32 is the q4_K swiglu prefill schedule with format 26, and the matcher common.mul_mat_swiglu.iq1_s_prefill_wave32 (priority 305) claims a gate/up pair of IQ1_S weights, 256..2048 tokens in 256-token steps, input % 256, output % 64. Both layouts are pinned in the def (staged f16 input, un-packed f16 copy): the staged geometry is the only one the IQ1 publish is proven at. Device, gfx1151: the two new rows pass swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.256.4096 1806 ms swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.512.4096 1821 ms and the full suite is 267 passed, 13 failed - the same 13 flash-attention rows that engine#2870 tracks. Qwen3.8-27B UD-IQ1_S pp512 is unchanged (90.37 +- 0.36 with the arm against 90.25 +- 0.27 with it disabled): in the profile the 104 IQ1_S swiglu launches move to this kernel (692 ms) but the 16 softmax-free pairs whose two weights are different formats (IQ1_M, IQ2_XS) stay on the generic kernel and hold 2937 ms of the 12164 ms batch, so the arm's share is too small to move the model.
…window IQ1_S was the only format whose prefill staged the f16 weight tile; every other quantized matmul in a UD-IQ1 model ran the generic one-wave schedule. On Qwen3.8-27B that left 85% of the prefill matmul work there, the largest share being IQ2_XXS (34 of the 68 non-IQ1_S tensors whose output dim is 5120), then IQ2_XS and IQ1_M. All three block formats hold eight 4-value packets per 32-value group, and motifs/dequant.loom already had a 4-value packet decoder for each, so a pair helper can decode eight packets and concatenate them into the two 16-value windows an IQ1_S packet fills -- the window geometry, the row-base math and the up/gate select are the same as the IQ1_S arm. Only the block size differs: 50, 56, 66 and 74 bytes, now one select feeding the row stride. Four arms, four registrations (iq1_s 294, iq2_xxs 293, iq2_xs 292, iq1_m 291), all gated the same way as the q6_K prefill.
…hips
make_quantized_rows passed a dummy importance matrix whenever a type had no
from_float_ref; IQ1_M has none and does not require one, so the guard refused
to build the weight at all. Take the matrix only where the type asks for it.
Adds dense.iq2_xxs.{256,512}, dense.iq2_xs.512 and dense.iq1_m.512 rows at
4096 wide.
bong-water-water-bong
added a commit
that referenced
this pull request
Nov 19, 2026
#427) * corpus: an IQ1_S producer arm in the f16 prefill publish (engine#2832) The shared publish weights helper knew two weight layouts (q6 stored and q6 packed, both 210-byte blocks) and one identical layout, the q4_K native tile. IQ1_S is neither: 50-byte blocks reading a 4 KiB codebook, and a packet p owns [32p, 32p+16) and [32p+16, 32p+32) -- 16 apart, where the q6 pair is 32 apart. So the format test becomes iq1 first, the load offset is pinned to zero for that arm, k1 becomes k0+16, the 8-wide store branch is suppressed (IQ1 needs the 16-wide one), and the codebook is staged once per launch in the body, where each subgroup fills its own chunk. The block size enters only through the row stride, as the plan predicted. Every existing format takes the same path as before: the iq1 flag is false, so the select and the else arm reproduce the previous k0/k1 and store width. Verified by rebuilding the corpus (ninja ggml-hrx links). No device measurement yet, and no dispatch registration, so nothing selects format 19 into this op. * corpus: declare the IQ1 codebook module where the motif is compiled (ggml-org#2865) The arm added in 831ed61 calls @ggml_iq1s_f16_pair and @ggml_kquant_grid_fill_for, both of which live in motifs/kquant_iq1_s.loom and ops/kquant_decode_f32.loom, but no export that compiles motifs/mul_mat_quantized_f16_prefill.loom declares either module. The Loom root link resolves declarations from the recipe and does not care that the new branch is dead for format 44, so every prefill launch of q4_K and q6_K was refused: LINK/MATERIALIZE: unresolved exact declaration '@ggml_kquant_grid_fill_for' graph_compute: failed to prepare command 1 kind=Kernel ... bindings=3 That is the 11 hw_gate failures (3593/3604 against 3604/3604 on the parent), not register pressure. - motif: call @ggml_kquant_iq1s_grid_fill directly (declared in the motif, defined by motifs/kquant_iq1_s.loom) instead of the format-dispatching wrapper, so no module has to link the 11k-line decode op to resolve it. - manifest: all 22 exports that compile the motif list motifs/kquant_iq1_s.loom in library_sources and compile_dependencies. The corpus requires one list per primary source (collect_sources) and requires the two lists to be equal (generate_corpus_records). * corpus: select the IQ1_S prefill arm and stage both packet halves (ggml-org#2832) (#428) * corpus: select the IQ1_S prefill arm, and key it on the id the dispatcher passes (ggml-org#2832) The arm added in 831ed61 was keyed on 19, but no dispatcher can pass 19: the corpus numbers weight formats with common_mul_mat_format_config_value() (dispatch-mul-mat-weight-format.h), where Q4KRow64 = 44, Q6K = 6 and IQ1_S = 26; 19 is ggml.h's type id. @ggml_kquant_grid_fill_for also only answers 21/22/24/25/26/27/28, so the 4 KiB codebook would have been staged never and read uninitialised. It also did not link: the motif calls @ggml_kquant_grid_fill_for, which is defined in ops/kquant_decode_f32.loom, but no export that compiles the motif lists that module, so every prefill launch of q4_K/q6_K dies with "LINK/MATERIALIZE: unresolved exact declaration" and a refused command (engine#2865, hw-gate 3593/3604 against 3604/3604 on the parent). - motif: 19 -> 26 in both places, and call @ggml_kquant_iq1s_grid_fill (defined by the motif's own library, motifs/kquant_iq1_s.loom) instead of the format-dispatching wrapper, so no module has to link the 11k-line decode op to resolve it. - manifest: every export that compiles motifs/mul_mat_quantized_f16_prefill.loom (22 of them) now lists motifs/kquant_iq1_s.loom in library_sources and compile_dependencies -- the corpus requires one list per primary source, and an unresolved declaration fails the Loom link even when the branch is dead. - ops: @ggml_mul_mat_iq1_s_f16_wmma_prefill_wave32, the q4_K prefill schedule with 26 baked and the weight bound as stored rows (IQ1_S has no packed row layout). - dispatch: common.mul_mat.iq1_s_prefill_wave32 at priority 294, IQ1_S, no alias, tokens 256..2048 step 256 (the kernel's own assume -- the q6_k route's 128 floor does not satisfy it), input % 256, output % 64. - tests: three rows at 9 / 64 / 512 tokens, 4096-wide output; the row helper now quantizes IQ types through ggml_quantize_chunk with a dummy importance matrix, since they have no from_float_ref. * corpus: stage both IQ1 packet halves in the f16 prefill publish (ggml-org#2832) The IQ1 arm pinned the staged weight window offset to 0, so all four producers of a row wrote the same 32 values at [0,32) and the consumer's [32,64) half stayed uninitialised LDS: the prefill matmul returned NaN on the 1024-workgroup tile (n=512 passed through the arm on gfx1151). * test: cover the IQ1 prefill arm at one block and ten (ggml-org#2832) * corpus: keep the IQ1 prefill arm on the 512-thread tile (ggml-org#2832) The 1024-thread tile stages four halves of 32 values into the 64-value window the mma reads, so the store origin ran to 32*3 + 16 = 112 on a 72-wide row: the Loom verifier refused the range as unprovable ("vector_extent is 16, view_bound is 72, and the maximum legal origin is 56 @ 18540:9") and the arm never compiled for the shapes Qwen3.8-27B asks for (5120x6144, 5120x17408). An IQ1 packet covers [32p, 32p+32), so two halves tile that window exactly and four do not. Qwen3.8-27B-UD-IQ1_S, gfx1151, one binary, the arm toggled by dispatch name: pp512 11.30 +- 0.03 -> 90.15 +- 0.35 t/s (7.98x) tg128 12.74 +- 0.01 -> 12.72 +- 0.02 t/s (unchanged) * corpus: stage the IQ1_S swiglu prefill from both weights (ggml-org#2832) A paired tile stages the gate rows and the up rows from two buffers, but only the q4_K native decoder ever read %up_weight: the IQ1 arm decoded both halves from the gate weight, so a swiglu tile would have published gate rows twice. The IQ1 arm now picks the buffer by %weight_is_up (the q4_K decoder's own rule), leaving the generated IQ1 motif and its regenerated bytes untouched. New kernel.def ggml_mul_mat_iq1_s_swiglu_f16_wmma_prefill_wave32 is the q4_K swiglu prefill schedule with format 26, and the matcher common.mul_mat_swiglu.iq1_s_prefill_wave32 (priority 305) claims a gate/up pair of IQ1_S weights, 256..2048 tokens in 256-token steps, input % 256, output % 64. Both layouts are pinned in the def (staged f16 input, un-packed f16 copy): the staged geometry is the only one the IQ1 publish is proven at. Device, gfx1151: the two new rows pass swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.256.4096 1806 ms swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.512.4096 1821 ms and the full suite is 267 passed, 13 failed - the same 13 flash-attention rows that engine#2870 tracks. Qwen3.8-27B UD-IQ1_S pp512 is unchanged (90.37 +- 0.36 with the arm against 90.25 +- 0.27 with it disabled): in the profile the 104 IQ1_S swiglu launches move to this kernel (692 ms) but the 16 softmax-free pairs whose two weights are different formats (IQ1_M, IQ2_XS) stay on the generic kernel and hold 2937 ms of the 12164 ms batch, so the arm's share is too small to move the model. * corpus: stage IQ2_XXS, IQ2_XS and IQ1_M prefill from the same packet window IQ1_S was the only format whose prefill staged the f16 weight tile; every other quantized matmul in a UD-IQ1 model ran the generic one-wave schedule. On Qwen3.8-27B that left 85% of the prefill matmul work there, the largest share being IQ2_XXS (34 of the 68 non-IQ1_S tensors whose output dim is 5120), then IQ2_XS and IQ1_M. All three block formats hold eight 4-value packets per 32-value group, and motifs/dequant.loom already had a 4-value packet decoder for each, so a pair helper can decode eight packets and concatenate them into the two 16-value windows an IQ1_S packet fills -- the window geometry, the row-base math and the up/gate select are the same as the IQ1_S arm. Only the block size differs: 50, 56, 66 and 74 bytes, now one select feeding the row stride. Four arms, four registrations (iq1_s 294, iq2_xxs 293, iq2_xs 292, iq1_m 291), all gated the same way as the q6_K prefill. * test: cover the staged IQ2 and IQ1_M arms, and quantize IQ1_M as it ships make_quantized_rows passed a dummy importance matrix whenever a type had no from_float_ref; IQ1_M has none and does not require one, so the guard refused to build the weight at all. Take the matrix only where the type asks for it. Adds dense.iq2_xxs.{256,512}, dense.iq2_xs.512 and dense.iq1_m.512 rows at 4096 wide. --------- Co-authored-by: bcloud <bcloud@localhost> Co-authored-by: bong-water-water-bong <[email protected]> --------- Co-authored-by: bcloud <bcloud@localhost> Co-authored-by: bong-water-water-bong <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stage A, part 2 of ggml-org#2832: dispatch IQ1_S prefill through the f16 publish kernel.
Stacked on #427 (the IQ1_S producer arm): the base is
corpus/iq1s-prefill-producer, so this diff is only the op, the matcher, the test rows and one fix to the arm itself.What it adds
ops/mul_mat_f32_f32_wmma.loom:@ggml_mul_mat_iq1_s_f16_wmma_prefill_wave32, a clone of the q4_K prefill kernel.def with%prefill_weight_format = 26.dispatch-mul-mat.cpp:match_iq1_s_prefill_wave32_dispatch+ registry entrycommon.mul_mat.iq1_s_prefill_wave32at priority 294, below q6_K prefill (295) and above the genericcommon.mul_mat.f32_f32_wmma(80). Gated onGGML_TYPE_IQ1_S, no alias, 256 <= tokens <= 2048 step 256,input_size % 256 == 0,output_size % 64 == 0.tests/test-hrx-ops.cpp:dense.iq1_s.*rows at n = 9 and 64 (generic wmma) and n = 512 (the new arm), all 4096 wide, plus an imatrix path inmake_quantized_rowsfor types whose only reference isggml_quantize_chunk.motifs/kquant_iq1_s.loomstill regenerates byte for byte fromtools/generate_iq1_loom.py(checked withcmp: the motif output is 108649 bytes, identical; the dequant and kquant outputs are contained verbatim inmotifs/dequant.loomandops/kquant_decode_f32.loom).Baked 26, not 19.
common_mul_mat_format_config_value()givesIQ1_S = 26,motifs/dequant.loomkeys its IQ1 arm on 26, and the q4_K prefill kernel.def bakes 44 (=Q4KRow64), so the corpus uses that numbering. 19 is ggml.h's type id and is unassigned in the corpus numbering only by luck. Baking 19 would make the arm unreachable from the dispatcher while still compiling.Fixes #427's arm. The arm pinned the staged window offset to 0, so all four producers of a row wrote the same 32 values at
[0,32)and the consumer's[32,64)half read uninitialised LDS. On gfx1151 the n=512 row came back NaN before the fix. The offset is nowweight_k_base + 32 * load_halfand the codebook packet index isweight_group + load_half. #427 is inert without this matcher, so it can land as is and take the fix from here.Evidence (strixhalo, gfx1151, under
~/.local/bin/gpu-hold)dense.iq1_s.mul_mat_f32_f32_wmma.9.4096PASS,.64.4096PASS,dense.iq1_s.mul_mat_iq1_s_f16_wmma_prefill_wave32.512.4096PASS (1184 ms) - and FAIL (NaN at element 0) before the packet fix, which is what pinned the bug to the odd packets.test-hrx-opssuite in that tree: 261 passed, 13 failed, 0 known-fail, 0 unexpected-pass, 274 total, 401 s. All 13 failures are flash-attention rows (qwen_flash_attention,flash_attention.accumulator_range.128.1024.v1000,flash_attention.{64..512}.2.65.1/...wmma,flash_attention.96.2.4.1/...next_q8.320,fa_decode_split.4.513*); none is a mul_mat, prefill or kquant row, and this branch touches no flash-attention file (git diff 8c23f152..HEAD -- .../dispatch-flash-attention.cpp .../ops/flash_attention.loomis empty).They are routing assertions, not numeric mismatches:
qwen_flash_attentionfails withmissing expected kernel: loom_libs:ggml_flash_attention_decode_split_f32_f16_wmma_next_q8 / scheduled kernels: loom_libs:ggml_flash_attention_f32_f16_wmma, andfa_decode_split.4.513ontest-hrx-ops.cpp:2502: plan.dispatches.size() == query_token_count. The split path's kernels live in the privategpu-kernelsadd-on (addons/hip-hrx/qsa_attn_select.hip), which this tree does not build (GGML_HRX_HIP_ADDON_DIRempty) - the hw-gate tree does. Not established: whether those rows pass in a tree that builds the add-on; that is a flash-attention dispatch question, separate from this change.ninja test-hrx-opsclean in a tree configured-DGGML_HRX=ON -DHRX_SOURCE_DIR=<hrx-system @ 7f423692>;git diff --checkclean, no non-ASCII.Downstream. engine#2865 pinned this branch and its
hw_gatepassed: ops 3604/3604, placement PASS on all seven models, kat/kld/needle PASS. That is the only evidence the arm leaves q6_K/q4_K prefill alone, since it adds 4 KiB of LDS and a barrier to every format.Not established: a device run on gfx1201 - this tree has no HRX dispatch registry for that target (
find_dispatch_registryknows gfx1100 and gfx1151), so every graph compute fails there for any weight type.The model run (stage A, Qwen3.8-27B-UD-IQ1_S, gfx1151, one binary, arm toggled by dispatch name)
The first version of this arm did not compile at the shapes the model asks for (5120x6144, 5120x17408): it cloned the q4_K schedule's 1024-thread tile, which stages four halves of 32 values into the 64-value window
@ggml_f16_prefill_stage_mmareads (quant_group*32 + k_half), so the store origin reached 32*3 + 16 = 112 on a 72-wide row and the verifier refused it -vector_extent is 16, view_bound is 72, and the maximum legal origin is 56 @ 18540:9. An IQ1 packet covers[32p, 32p+32), so two halves tile that window exactly; the arm now stays on the 512-thread tile. Device rows:.512.5120.6144PASS 2776 ms,.512.5120.17408PASS 6860 ms, plus.512.4096{, .256, .2560}PASS.