Skip to content

ggml-hrx: ROPE above 2048 tokens as token chunks (Qwen3-4B runs -ub 4096) - #122

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-rope-ubatch
Oct 21, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-rope-ubatch

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

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

  • positions: rows [first, first+count) of 4 bytes: first4 + count4 <= T*4.
  • input (strided): offset firststride24, 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 firstHhs4, length countHhs4 <= THhs*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.

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

…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
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
@bong-water-water-bong
bong-water-water-bong merged commit abb23be into 1bit/hrx-vulkan-patched Oct 21, 2026
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hrx-rope-ubatch branch November 12, 2026 21:15
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