Repository navigation
vulkan : fuse qwen4exp's SIGMOID -> SCALE -> hc_post chain again - #33710
Open
anothergasteizone wants to merge 1 commit into
Open
anothergasteizone wants to merge 1 commit into
anothergasteizone wants to merge 1 commit into
Conversation
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)
anothergasteizone
marked this pull request as ready for review
December 4, 2026 16:08
jeffbolznv
approved these changes
Dec 4, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Fixes #33711. Since #31028 the Vulkan
HC_POST_GATEfusion no longer matches qwen4exp, because the graph now builds the hc_post weights as2*sigmoid(inject)without the1/hcinput scale. This adds a pattern for the new 3-node chainSIGMOID -> SCALE -> DSV4_HC_POSTand 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-opscases 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.
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%):
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 withgate_prescaled=0).DSV4_HC_PRE: 6/6.Dispatch counts from
GGML_VK_PERF_LOGGERon mastera274a3948:KL divergence:
llama-perplexity --kl-divergencevs 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
Written with Claude Code (Claude Opus 5.5)