Skip to content

vulkan : fuse qwen4exp's SIGMOID -> SCALE -> hc_post chain again - #33710

Open
anothergasteizone wants to merge 1 commit into
ggml-org:masterfrom
anothergasteizone:vk-qwen4exp-hc-post-sigmoid-gate
Open

anothergasteizone wants to merge 1 commit into
ggml-org:masterfrom
anothergasteizone:vk-qwen4exp-hc-post-sigmoid-gate

Conversation

@anothergasteizone

@anothergasteizone anothergasteizone commented Dec 4, 2026 •

Copy link
Copy Markdown

Overview

Fixes #33711. Since #31028 the Vulkan HC_POST_GATE fusion no longer matches qwen4exp, because the graph now builds the hc_post weights as 2*sigmoid(inject) without the 1/hc input scale. This adds a pattern for the new 3-node chain SIGMOID -> SCALE -> DSV4_HC_POST and reuses the existing fused hc_post path with an input scale of 1.

The fix stands on its own on master and does not depend on any other PR. The old 4-node pattern is kept. New test-backend-ops cases build the current chain (gate_prescaled = false), including the Qwen4-35B-A3B shapes. They check the results, not that the fusion happens, so they also pass on master; the dispatch counts below show the fusion.

Additional information

Measured on an AMD Radeon AI PRO R9700 (RDNA4, 32 GB) used as an eGPU over Thunderbolt 3. On this kind of setup the cost per dispatch is high, so removing small dispatches matters more than on a GPU in a PCIe slot. Model: Qwen4-35B-A3B UD-Q4_K_XL.

Qwen4-35B-A3B, R9700 eGPU master this PR
Dispatches per decode token 2087 1927 (-160)
tg128 @ d0 (t/s) 80.6 83.1 (+3.1%)
tg128 @ d8192 (t/s) 77.3 78.2 (+1.2%)
KL divergence vs master (prefill / decode) - 0.000000 / 0.000000
Same top p vs master - 100%
temp 0 output - byte-identical

It also combines well with #33412 (generated epilogue fusion), which gives the largest gain on this setup; I posted R9700 eGPU numbers for it in #33412 (comment). Together with this fix, a shared-expert ordering change for qwen4exp (separate PR to follow) and #33286, decode goes from 80.7 to 93.4 t/s (+16%):

Qwen4-35B-A3B, R9700 eGPU (t/s) tg128 @ d0 tg128 @ d8192 pp2048
master 80.7 76.5 3365
this PR + qwen4exp change + #33286 83.2 (+3.1%) 78.8 (+3.0%) 3455
master + #33412 90.8 (+12.5%) 88.3 (+15.4%) 3522
all of the above + #33412 93.4 (+15.7%) 89.7 (+17.3%) 3690

Note that #33412 currently takes precedence over the hand-written hc_post fusion; if it lands first, I will add a small exception here so the full chain stays fused.

Setup, tests, commands and measurement notes

Hardware: AMD Radeon AI PRO R9700 (RDNA4, GFX1201, 32 GB) as an eGPU over Thunderbolt 3, RADV (Mesa 26.3.1), Ryzen 7 7840HS, Ubuntu 26.04. Model: Qwen4-35B-A3B UD-Q4_K_XL (unsloth), -ngl 99 -ot per_layer_token_embd=CPU -fa 1 -ctk q8_0 -ctv q8_0 -ub 1024 -b 4096.

test-backend-ops -o DSV4_HC_POST -b Vulkan1: 23/23 passed (4 new cases with gate_prescaled=0). DSV4_HC_PRE: 6/6.

Dispatch counts from GGML_VK_PERF_LOGGER on master a274a3948:

master:  DSV4_HC_POST: 720 x 7.252 us   (plus separate SIGMOID and SCALE)
this PR: HC_POST_SIGMOID_GATE SIGMOID: 720 x 10.243 us

KL divergence: llama-perplexity --kl-divergence vs master, 4x512 tokens (prefill, -ub 512) and 2x512 tokens (decode, -ub 1).

First table: llama-bench, this PR alone on master 78ab1ed22, 3 alternating rounds x 3 reps. Second table: 5 rounds x 3 reps per row; the first two rows and the last two were measured in separate sessions, with about 2% drift between sessions. Run-to-run noise is about 2% for tg and about 5% for pp2048, so the prefill column is not conclusive.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES. Claude Code helped find the regression from profiling, write the patch and the tests, run the validation and write this description. I reviewed the change and the results.

Written with Claude Code (Claude Opus 5.5)

Since ggml-org#31028 qwen4exp builds the hc_post weights as 2*sigmoid(inject),
with the 1/hc scale moved into the inject matmul. The existing
HC_POST_GATE pattern expects SCALE -> UNARY -> SCALE -> DSV4_HC_POST,
so it no longer matched and the three ops ran as separate dispatches.

Add a SIGMOID -> SCALE -> DSV4_HC_POST pattern that reuses the hc_post
gate path with an input scale of 1, keep it together in graph_optimize,
and add test-backend-ops cases for the new chain.

Assisted-by: Claude Code (Claude Opus 5.5)
@github-actions github-actions Bot added testing Everything test related Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Dec 4, 2026
@anothergasteizone
anothergasteizone marked this pull request as ready for review December 4, 2026 16:08
@anothergasteizone
anothergasteizone requested review from a team and ggerganov as code owners December 4, 2026 16:08

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning testing Everything test related Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eval bug: Vulkan HC_POST_GATE fusion no longer applies to qwen4exp since #31028

2 participants