Repository navigation
ggml-hrx: ROPE above 2048 tokens as token chunks (Qwen3-4B runs -ub 4096) - #122
Merged
bong-water-water-bong merged 1 commit intoOct 21, 2026
Merged
Conversation
…096)
The Loom rope kernel (ggml_rope_f32) takes at most 2048 tokens (config range), so the ROPE
matcher refused larger batches and Qwen3-4B at -ub 4096 failed the whole graph ("unsupported HRX
node: ROPE f32[128,32,4096]"). The matcher now admits up to kUbatchMaxTokens and the standalone
ROPE runs as ceil(T / 2048) equal chunks; the fused rope+set_rows path keeps its 2048 limit.
New files dispatch-token-chunks.{h,cpp} (ours): chunk rows [first, first+count) bind
offset + first*row_bytes, length (count-1)*row_bytes + last_row_bytes, and each chunk sets its
own token_count / token_capacity / input_span. GGML_HRX_QUERY_CHUNK_TOKENS forces smaller chunks
(test switch, shared with the query chunks).
Bounds proof (per chunk, against the bindings the matcher already proves for the whole node):
- positions: rows [first, first+count) of 4 bytes: first*4 + count*4 <= T*4.
- input (strided): offset first*stride2*4, length ((count-1)*stride2 + (H-1)*stride1 + hs)*4;
end = ((first+count-1)*stride2 + (H-1)*stride1 + hs)*4 <= ((T-1)*stride2 + (H-1)*stride1 + hs)*4
<= the input span (is_supported_rope_input_layout); the chunk input_span config is that length.
- output (packed): offset first*H*hs*4, length count*H*hs*4 <= T*H*hs*4.
- each chunk token_count = token_capacity <= 2048, inside the kernel range.
The helper refuses (status line) any chunk whose extent would leave its binding.
Measured on strixhalo gfx1151, performance mode (with gpu-kernels 08bb2241):
- test-backend-ops -o ROPE -b HRX0: 46/46 default, 46/46 x2 with GGML_HRX_QUERY_CHUNK_TOKENS=7.
- Qwen3-4B Q5_K_M -c 4096 -ub 4096 KLD vs the -ub 512 base: 0.000002 (same top 100%);
llama-bench pp4096: -ub 4096 3088 vs -ub 2048 3144 tok/s (medians of 3); before this the
-ub 4096 graph failed.
- Qwen3.8-27B -ub 4096 KLD vs the query-chunk build: 0.000000.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
bong-water-water-bong
changed the base branch from
1bit/fa-prompt-query-chunks-v2
to
1bit/hrx-vulkan-patched
October 21, 2026 16:54
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.
Stacked on #120 (uses its GGML_HRX_QUERY_CHUNK_TOKENS test switch); retarget to 1bit/hrx-vulkan-patched after #120 lands.
The Loom rope kernel (ggml_rope_f32) takes at most 2048 tokens (config range), so the ROPE
matcher refused larger batches and Qwen3-4B at -ub 4096 failed the whole graph ("unsupported HRX
node: ROPE f32[128,32,4096]"). The matcher now admits up to kUbatchMaxTokens and the standalone
ROPE runs as ceil(T / 2048) equal chunks; the fused rope+set_rows path keeps its 2048 limit.
New files dispatch-token-chunks.{h,cpp} (ours): chunk rows [first, first+count) bind
offset + first*row_bytes, length (count-1)*row_bytes + last_row_bytes, and each chunk sets its
own token_count / token_capacity / input_span. GGML_HRX_QUERY_CHUNK_TOKENS forces smaller chunks
(test switch, shared with the query chunks).
Bounds proof (per chunk, against the bindings the matcher already proves for the whole node):
end = ((first+count-1)*stride2 + (H-1)*stride1 + hs)*4 <= ((T-1)*stride2 + (H-1)*stride1 + hs)*4
<= the input span (is_supported_rope_input_layout); the chunk input_span config is that length.
The helper refuses (status line) any chunk whose extent would leave its binding.
Measured on strixhalo gfx1151, performance mode (with gpu-kernels 08bb2241):
llama-bench pp4096: -ub 4096 3088 vs -ub 2048 3144 tok/s (medians of 3); before this the
-ub 4096 graph failed.
The qwen attention postprocess fusion still declines above 2048 tokens; with ROPE chunked the unfused ops cover it (4B -ub 4096 KLD 0.000002), so its cap does not need lifting for correctness.
🤖 Generated with Claude Code