Repository navigation
hrx: chunk the plain prefill matmul above the tile's 2048-token range too - #248
Conversation
… too #244 took the *batched* matmul path above the 2048-token tile range. The plain 2-D matmuls at the same token counts are the larger class in Qwen3-VL's CLIP graph (`[1024,8464]`, `[3072,8464]`, `[4096,8464]`, `[4096,2116]`, `[2048,2116]`, `[8464,1024]`) and were refused by the same range, so chunk them as well — but only for the form where that is provably safe: the plain contraction, with no activation packing, no split-k and no fused unary, and binding the input itself. Everything else keeps today's behaviour and stays on the CPU rather than being handed a dispatch whose meaning chunking would change. Measured on HRX0 against the CPU reference: `m=1024,n=8464,k=1024,bs=[1,1]` (the shape family of the graph's refused 2-D matmuls, float weights) went from `not supported [HRX0]` to **OK**, and `-o MUL_MAT` is 567/567. Scope, measured rather than implied: the CLIP graph's own projections carry **quantized** weights, where the packed-q8 and split-k paths are exactly what this guard declines, so the graph-level refusal count barely moves yet. The test row proves the path, not the graph; chunk-aware activation packing is the larger change that would. Refs ggml-org#1467
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at b67f2662cac912d19d7af4697985c8bf1656042a
The second half of #244, scoped to the one form where chunking provably can't change meaning. Since a wrong tile is the risk here (the N % 16 lesson), I checked every place a chunk boundary could leak into the kernel's preconditions:
- The token range.
common_is_supported_prefill_token_countis1 < t ≤ 2048, with no% 16on the token dimension, so the WMMA kernel already takes arbitrary counts in that range unchunked. - No degenerate tail.
append_token_chunked_dispatchessplits evenly (chunk_count = ceil(t/2048),base = t / chunk_count, the remainder spread one token at a time), so a count just over the limit never produces a 1-token tail, which the range would refuse. For example 2049 → 1025 + 1024, 2116 → 1058 + 1058, 8464 → 5 × ~1693, and every chunk stays in(1, 2048]. Each binding's[skip, skip+length)is bounds-checked. - What is and isn't sliced. Only the activation (binding 0, stride
nb[1], which also covers the row-padded activation the matcher allows) and the output (binding 2) are sliced. The weight is shared, which is correct for a token split. - The guard.
allow_token_chunks = truewidens only the match. Every form other than the plain contraction (pack_q4,pack_q6,split_k, a staged activation, a fused unary) returnsfalsefrombuild_mul_mat_dispatchabove 2048, so it's left unclaimed and stays on the CPU, rather than going to a dispatch whose packing or split-k pass would assume the whole activation.
It merges cleanly onto 1bit/hrx-vulkan-patched. The new test_mul_mat(F32, F32, 1024, 8464, 1024, …) row is the CLIP MLP shape and is checked against the CPU reference by the harness. I didn't run the HRX arm (no device ticket); your -o MUL_MAT 567/567 is the evidence. And "this proves the path, not the graph" is the right caveat, since the quantized CLIP projections are exactly what the guard declines.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at b67f2662cac912d19d7af4697985c8bf1656042a
The plain 2-D case is the one the CLIP graph actually needs, and the guard that makes chunking safe is specific rather than cautious:
if (match.token_count > kMulMatPrefillMaxTokens) {
// only safe for the plain 2-D contraction: a chunked dispatch cannot carry the activation packing
// or the split-k path (both rewrite the whole activation), and it must bind the input itself.
if (pack_q4 || pack_q6 || split_k || activation.value != match.input->id || match.has_fused_unary)
return false;Each of the five exclusions has a mechanism behind it — packing and split-k rewrite the whole activation, so a per-chunk rebind would be wrong; a fused unary or an activation that is not the op's own input would be applied per chunk instead of once. That is the right shape for extending a chunking path: enumerate what the chunked dispatch cannot carry and fall back, rather than assume the plain case generalises.
Built and ran the shape (-o MUL_MAT, 1591 cases, Backend CPU: OK):
MUL_MAT(… m=1024,n=8464,k=1024,bs=[1,1] …): OK <- this PR: the CLIP MLP projection
MUL_MAT(… m=256, n=4096,k=256, bs=[1,2] …): OK <- #244's plain over-bound case
MUL_MAT(… m=128, n=8464,k=64, bs=[1,16] …): OK <- #244's per-plane case
so the new case is well-formed and the reference agrees, and the two earlier ones still pass — no regression in the area this touches.
Note the chunk binding differs from #244's on purpose: {{0, input_row, input_last}, {2, output_row, output_last}} rebinds dim 0 of the input and dim 2 of the output, i.e. exactly the token axis for a 2-D contraction, versus the per-plane sets the batched path needs. Same helper, different binding, and the helper is where the coverage contract lives.
Not run, and it is the part that matters: the chunked dispatch itself. build226 is GGML_HRX=OFF, so this ran against the CPU reference and the HRX path (kMulMatPrefillMaxTokens, ggml.workload.token_capacity) was never entered. The command that would cover it: an HRX build + test-backend-ops -b HRX0 -o MUL_MAT under gpu-hold — the same gap I recorded on #244, and it will stay a gap for every chunking PR until one of them is measured on the device.
What this is
The second half of the work that went into #244, split out because #244 merged (
c94b3cc97) before this commit landed.#244 chunked the batched prefill matmul above the tile's 2048-token range. The plain 2-D matmuls at the same token
counts are the larger class in Qwen3-VL's CLIP graph —
[1024,8464],[3072,8464],[4096,8464],[4096,2116],[2048,2116],[8464,1024]— and they were refused by the same range (common_is_supported_prefill_token_count, a tilerange rather than a shape or layout limit: contiguous activation, float weight, sizes all inside the matcher's bounds).
The change
Chunk them too, but only for the form where that is provably safe: the plain contraction, with no activation packing, no
split-k and no fused unary, binding the input directly. Anything else keeps today's behaviour and stays on the CPU rather
than being handed a dispatch whose meaning chunking would change.
Measured (HRX0, CPU-reference checked)
m=1024,n=8464,k=1024,bs=[1,1](the refused 2-D family, float weights)not supported [HRX0]-o MUL_MATsuiteScope, measured rather than implied
The CLIP graph's own projections carry quantized weights, where the packed-q8 and split-k paths are exactly what the guard
declines — so the graph-level refusal count barely moves yet. This test row proves the path; it does not prove the graph.
Chunk-aware activation packing is the larger change that would, and it is listed on ggml-org#1467 with the rest.
Refs 1bit-MONSTER/engine#1467