mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[PR #183] Optimize HIP ConvRot register transpose and block geometry #202
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-kitchen#202
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-kitchen/pull/183
Author: @qweqweewqe7-create
Created: 9/16/2026
Status: 🔄 Open
Base:
main← Head:optimize-hip-convrot-register-transpose📝 Commits (5)
22d7127Optimize HIP ConvRot register transpose and block geometry8b94a26Handle misaligned BF16 SwiGLU ConvRot inputsaa5258aVectorize ConvRot INT8 SiTU input loads, tune MOSS-Image widths76f5a7eAlign two v0.2.40 HIP tests with the ConvRot changesda6565eKeep the fused ConvRot INT8 producer on gfx12📊 Changes
3 files changed (+372 additions, -23 deletions)
View changed files
📝
comfy_kitchen/backends/hip/hadamard.h(+314 -22)📝
comfy_kitchen/backends/hip/ops/quantize_int8.hip(+21 -0)📝
tests/test_hip_wmma.py(+37 -1)📄 Description
Summary
Optimize the HIP INT8 ConvRot path by reducing wave-local LDS transpose traffic
and selecting block geometries that better match the dominant H3 projection
depths on RDNA4.
The optimized path:
evaluation order needed for exact quantization under
-ffast-math;Performance
Broad H3 projection sweeps over approximately M=15k through 110k:
The sweep covered QKV, attention output, MLP up, and MLP down projection
geometries rather than tuning for one fixed production M.
Correctness
Historical optimization validation:
After rebasing onto current upstream
main, the existing optimized ConvRotpaths were compared bit-for-bit against the previously validated authoritative
winner over representative BF16/FP16/FP32, GELU, SwiGLU, fused and spill-path
cases. Both gfx1200 and gfx1201 were 13 / 13 bitwise exact.
The current upstream ConvRot/input-activation tests, including the newer fused
RMSNorm path, were also re-run on both RDNA4 GPUs.
Notes
Changing block geometry changes the parallel reduction order, so a direct
bit-for-bit comparison between the optimized block sizes and the older
1024-thread upstream geometry is not used as the rebase-regression criterion.
Rebase equivalence is checked against the already validated optimized winner,
while the upstream test suite covers numerical/API correctness.
Update: rebased onto v0.2.38 (SiTU port #252), SiTU vector loads, MOSS-Image widths
Rebased onto current
main(42081bf, v0.2.38), which resolves the conflict with the HIP SiTU ConvRot port (#252). The existing two commits are unchanged in substance. One commit is added, Vectorize ConvRot INT8 SiTU input loads, tune MOSS-Image widths:[hidden | gate]SiTU row with two 8-byte loads, as SwiGLU already does, instead of eight dtype-dispatched scalar loads. The scalar and vector loaders share one SiTU formula (situ_value);K=3072uses 128-thread andK=8192256-thread blocks whenM >= 1024(MOSS-Image attention/FFN-in and SiTU FFN-down widths). Short M keeps the wide block.RX 9070 XT (gfx1201), PyTorch
2.16.0a0+rocm10.2.0a20261015, activation rotate+quant, alternating runs. "Before" is this PR's previous state.The MOSS-Image DiT forward goes from 553 to about 537 ms. The H3 widths are unchanged.
A packed four-column int8 store was also tried. It made the H3 widths 15-18% slower and K=3072 slower as well, so it is not included.
Correctness: outputs are bit-identical to the previous state, except the bf16 SiTU path, where 101 of 51.6M int8 values move by one step at rounding boundaries. That path's accuracy against an fp64 reference is the same: at the differing positions the old and new kernels match the reference 49 and 52 times. Block sizes do not change the result of the max reduction, so the new widths are bit-identical to the old ones.
Re-validation on RX 9070 XT (gfx1201) and RX 9060 XT (gfx1200),
gfx1200;gfx1201build:tests/test_int8*.py tests/test_hip_wmma.py tests/test_hip_dispatch.py tests/test_convrot_unpacked_quantization.py tests/test_hip_convrot_perf.py tests/test_w4a8_requant.py tests/test_adaln.py tests/test_rms_rope.pygive the same results as unmodifiedmain(1176 passed). The only failures, 18 triton cases andtest_int8_linear_correctness[hip], fail identically onmain.Update: rebased onto v0.2.40 (#259)
Rebased onto
main(f8b7e97, v0.2.40). One conflict, inlaunch_convrot_quant_fused_impl: it now combines this PR's single-buffer shared-memory size with #259'sTILED_QOUTkernel template. The fused kernel body already uses one buffer per group, andconvrot_fused_lds_fitsuses the same size.Two commits are added:
x. The offset-input SwiGLU test now checks two things: the binding refuses the misaligned input, and the public wrapper, which realigns, matches the aligned result.COMFY_KITCHEN_CONVROT_TRANSPOSED=1selects it on gfx12.RX 9070 XT (gfx1201) and RX 9060 XT (gfx1200), PyTorch
2.16.0a0+rocm10.3.0a20261023, HIP 7.17.26423. Timings are wall-clock medians over windows of calls, averaged over two alternating runs.int8_linearwith ConvRot, bf16 out, this PR with the transposed vs the fused producer:At every shape, the two producers give identical outputs, and both match
main.Tests on both GPUs (
test_hip_wmma,test_hip_dispatch,test_gemm_bias_contract,test_int8*,test_adaln,test_rms_rope,test_int8_attention,test_sol_attn,test_convrot_unpacked_quantization,test_w4a8_mma,test_w6a8):main's 2400 plus the offset-input test from this PR.main: 18 triton rope cases andtest_int8_linear_correctness[hip].🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.