GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Vulkan: RMS norm for short rows (per-head Q/K norm 2.4-2.7x faster, bit-identical) by danielhanchen · Pull Request #37 · unslothai/stable-diffusion.cpp Conversation
|
| shape | RADV master | RADV with 0015 | Windows AMD master | Windows AMD with 0015 |
|---|---|---|---|---|
| [64, 32, 4096] | 1104.8 | 299.9 | 1720.5 | 324.2 |
| [64, 24, 1024] | 149.0 | 37.4 | 237.5 | 46.7 |
| [128, 32, 4096] | 965.2 | 568.4 | 1603.2 | 566.9 |
| [128, 24, 1024] | 144.5 | 40.0 | 232.6 | 47.6 |
| [3072, 4096] | 498.3 | 498.1 | 484.1 | 484.2 |
#54 alone matches master in every row. RMS_NORM 53/53 on both drivers; Z-Image Q4_K_M on RADV renders the same pixels as master.
Based on master (ggml 135ce1e0, merged in on Nov 7). Adds scripts/unsloth/ggml-patches/0015-ggml-vulkan-rms-norm-short-rows.patch.
ggml 135ce1e0 (e995244, "fuse attention normalization and layout conversion") adds rms_norm_128.comp, a subgroup-shuffle RMS norm for rows of exactly 128, created only on devices with full 32-wide subgroups. The old patch no longer applied, so it was ported:
ggml_vk_op_get_pipeline tries upstream's rms_norm_128 first (rows of 128, subgroup size 32), then this patch's 128-thread rms_norm_small for every other row of at most 128 elements, and for rows of 128 on devices without the subgroup path (for example wave64-only AMD GCN, or drivers that cannot require full subgroups).The timings below were measured before upstream's kernel existed. On devices that create rms_norm_128, head size 128 (Z-Image, FLUX.2 klein) now takes upstream's kernel on master already, so the win measured below only remains for head sizes under 128 and for devices without full 32-wide subgroups. Not re-timed on a real GPU after the port (no GPU on the CI runners; lavapipe only checks correctness).
AMD Ryzen AI MAX+ 395 (Radeon 8060S, gfx1151), Mesa 25.2.8 RADV, Vulkan 1.4.318, warp size 64; master ba6ac30 vs this branch 725579a, built with the prebuilt Vulkan leg flags, 3 interleaved repeats, same job.
| test-backend-ops RMS_NORM perf | master | this PR | speedup |
|---|---|---|---|
| ne=[64,32,4096] | 1093.9 us | 299.8 us | 3.65x |
| ne=[64,24,1024] | 148.7 us | 37.3 us | 3.99x |
| ne=[128,32,4096] | 965.4 us | 568.5 us | 1.70x |
| ne=[128,24,1024] | 144.2 us | 41.3 us | 3.49x |
| ne=[3072,4096] | 497.4 us | 497.7 us | 1.00x |
RADV reports warp size 64, so master's new 128-column kernel does not take the 128-wide rows there and this kernel does. test-backend-ops RMS_NORM 53/53, RMS_NORM_MUL_ADD 37/37, RMS_NORM_MUL_ROPE 224/224 on both arms. End to end: Z-Image-Turbo Q4_K_M 512x512 8 steps sampling 8.07 s [8.30, 8.05, 8.07] -> 7.96 s [7.95, 7.97, 7.96], pixel-identical; SD1.5 (no RMS norm) unchanged and pixel-identical.
ggml-vulkan's RMS norm runs one 512-thread workgroup per row. The DiTs Studio runs on sd.cpp normalise Q and K per head, so the rows are 128 elements long and there are many of them: Z-Image at 1024x1024 has 30 heads x 4128 tokens = 123,840 rows per call. Three quarters of every workgroup only adds zeros and waits on barriers.
Per-op GPU time (GGML_VK_PERF_LOGGER=1, B200, Vulkan, one steady denoise step of Z-Image Turbo Q4_K_M at 1024x1024, 1198 ms in total):
| Op | Shape | Calls | Time |
|---|---|---|---|
RMS_NORM_MUL |
(128, 30, 4128) | 60 | 173.5 ms (2.89 ms each) |
RMS_NORM_MUL |
(3840, 4128), same number of bytes | 120 | 5.5 ms (0.046 ms each) |
The per-head norm was 15% of the step, behind only the quantised matmuls (48%) and flash attention (18%).
A second build of rms_norm.comp with BLOCK_SIZE = 128 (rms_norm_small_f32, plus the fused-multiply variant through the same specialisation constant as today). ggml_vk_op_get_pipeline picks it for GGML_OP_RMS_NORM when ne00 <= 128 and the add-partials path is not in use. Everything else keeps the 512-thread pipelines.
The result is bit-identical by construction. With at most 128 columns, thread t holds x[t]^2 (or 0) in both versions, and the 512-thread tree only adds exact zeros in its first two halving steps (strides 256 and 128) before running the same strides 64 down to 1 as the 128-thread tree. The scale and the multiply loop are unchanged.
B200 (Vulkan, NV_coopmat2), base = sync-upstream-fd21ecf, head = this branch, same build flags (the prebuilt Vulkan leg's). Studio's Vulkan argv (--diffusion-fa, with --conv-direct on here because the perf logger aborts in ggml-vulkan on the im2col VAE graph at 1024). The card is shared with other jobs, so totals move between runs; base and head ran back to back, interleaved. Medians over the steady denoise steps, two runs per arm:
| Model, size | RMS_NORM GPU time per step, base |
head | ratio |
|---|---|---|---|
| Z-Image Turbo Q4_K_M, 1024, 8 steps | 74.5 / 49.9 ms | 28.1 / 18.4 ms | 2.65x / 2.71x |
| FLUX.2 klein 4B Q4_K_M, 1024, 4 steps | 31.8 / 31.9 ms | 14.9 / 12.8 ms | 2.13x / 2.49x |
| Z-Image Turbo Q4_K_M, 512, 8 steps | 13.1 / 33.0 ms (second run on a busier card) | 5.4 / 5.4 ms | 2.4x / - |
At Z-Image 1024 that is about 30 to 55 ms of a 390 to 570 ms step in these runs, roughly 8%. Wall-clock sampling did not resolve it on this host (host load moves Vulkan wall time by tens of percent between identical runs), and the exclusive-card timing was not run, so the end-to-end win is the GPU-time estimate above, not a measured wall-clock number.
Reproduce: scripts/sdcpp_speed/vk_bench.py --cases zimage1024,klein1024,zimage512 --arms base=<base sd-cli>,rms=<head sd-cli> --variants studio_cd_on,studio_cd_on+perf --env studio_cd_on+perf:GGML_VK_PERF_LOGGER=1 --reps 2, then scripts/sdcpp_speed/vk_perf_parse.py <log>.
test-backend-ops test -o RMS_NORM -b Vulkan0 on the head: 55/55 OK (includes 64-column rows, which take the new pipeline).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@codex review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…subgroup kernel ggml 135ce1e0 (e995244) adds rms_norm_128 for rows of exactly 128 on devices with full 32-wide subgroups. Keep that kernel first; the 128-thread variant here now serves every other row of at most 128 elements, and rows of 128 on devices without the subgroup path.
💡 Codex Reviewstable-diffusion.cpp/include/stable-diffusion.h Lines 556 to 558 in 725579a
For applications or language bindings built against the previous public API, retaining the exported AGENTS.md reference: AGENTS.md:L74-L76 stable-diffusion.cpp/examples/server/routes_openai.cpp Lines 207 to 209 in 725579a
For ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@codex review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@codex review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.