Skip to content

hrx: fuse ZAYA residual scale into one dispatch per side - #35

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-res-scale-fuse
Sep 29, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-res-scale-fuse

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

ZAYA scales both residual branches twice per layer, (x + bx)·sx + (r + br)·sr. At decode that is up to nine ADD / MUL dispatches per layer, each about 1.3 µs of work plus a 1.8 µs gap. This is part of RFC 1bit-MONSTER/engine#213 gate 1: HRX decode vs Vulkan on ZAYA1-8B.

How it works. The graph computes the r side long before x exists, so one dispatch cannot cover both sides. Each side becomes (a + b)·s where it starts. The side that comes last also takes the final ADD, reading the other side's result as an addend. The matcher is in our own files:

  • ops/res_scale_pair_f32.loom
  • dispatch-res-scale-pair.{h,cpp}

Hookups are minimal: the manifest entry, 2 lines in dispatch-common.cpp, and 2 in CMake. A bias ADD already taken by the output projection's bias fusion stays there. Every removed intermediate has exactly one consumer. The output may reuse an input's storage only exactly in place.

Checked on strixhalo (gfx1151), ZAYA1-8B Q4_K_M, HRX0:

  • Dispatches per token: 3,366 -> 3,165.
  • Bit-exact: the kernel keeps the add, mul, add order of the nodes it replaces. Greedy 6 prompts × 48 tokens, fused vs GGML_HRX_DISABLE_DISPATCH=res_scale_pair: 288/288 tokens identical, max |Δlogprob| 0.0000.
  • Decode (llama-bench tg128 ×3, interleaved, temperature-guarded): plain 67.06 / 66.94 / 67.00, fused 69.93 / 68.57 / 70.20 tok/s (about +4%).
  • Prefill pp512: 2,109 -> 2,183 tok/s.
  • Qwen3 does not match the pattern: output unchanged, no matches in the dispatch log.

Not covered: test-backend-ops cannot express this fused pattern. Correctness rests on the bit-exact A/B above.

🤖 Generated with Claude Code

ZAYA scales both residual branches, (x + bx) * sx + (r + br) * sr, twice per
layer: up to nine ADD / MUL dispatches per layer at decode, each ~1.3 us of
work plus a ~1.8 us gap. The graph computes the r side long before x exists,
so each side becomes (a + b) * s where it starts, and the later side also takes
the final ADD with the other side as an addend (ops/res_scale_pair_f32.loom,
dispatch-res-scale-pair.cpp; hookups: manifest, dispatch-common, CMake).

Same add, mul, add order per element: bitwise the same output.
ZAYA1-8B Q4_K_M, HRX0 (gfx1151): 3,366 -> 3,165 dispatches per token;
greedy 6 prompts x 48 tokens identical, max |dlogprob| 0.0000; decode
67.0 -> 68.6-70.2 tok/s (+4%, 3 interleaved rounds); pp512 2109 -> 2183.
Qwen3 does not match the pattern.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the ggml label Sep 29, 2026
@bong-water-water-bong
bong-water-water-bong merged commit 45c1770 into 1bit/hrx-vulkan-patched Sep 29, 2026
10 of 24 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hrx-res-scale-fuse 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant