Skip to content

hrx: chunk the plain prefill matmul above the tile's 2048-token range too - #248

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/1467-chunked-plain-mm
Nov 8, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/1467-chunked-plain-mm

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

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 tile
range 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)

row before after
m=1024,n=8464,k=1024,bs=[1,1] (the refused 2-D family, float weights) not supported [HRX0] OK
-o MUL_MAT suite 566/566 567/567, no failures

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

… 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 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: 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_count is 1 < t ≤ 2048, with no % 16 on the token dimension, so the WMMA kernel already takes arbitrary counts in that range unchunked.
  • No degenerate tail. append_token_chunked_dispatches splits 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 = true widens only the match. Every form other than the plain contraction (pack_q4, pack_q6, split_k, a staged activation, a fused unary) returns false from build_mul_mat_dispatch above 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 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: 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.

@bong-water-water-bong
bong-water-water-bong merged commit b1b310c into 1bit/hrx-vulkan-patched Nov 8, 2026
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/1467-chunked-plain-mm branch November 12, 2026 21:18
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