Repository navigation
model : build the qwen4exp shared expert before the routed experts - #1
Draft
anothergasteizone wants to merge 1 commit into
Draft
anothergasteizone wants to merge 1 commit into
anothergasteizone wants to merge 1 commit into
Conversation
build_moe_ffn expands the routed experts into the graph, so the shared expert came after the expert sum and the final moe_out + shexp add ran as its own node. Expanding the shared expert first puts that add right after the expert sum, so it joins the same add chain (one fused MULTI_ADD on Vulkan). Only the node order changes; the result is bit-identical. Assisted-by: Claude Code (Claude Opus 5.5)
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
Build the qwen4exp shared expert before the routed experts, so that the final
moe_out + shexpadd lands right after the expert sum in the graph. The add then joins the existing add chain (one fusedMULTI_ADDon Vulkan) instead of running as its own dispatch.build_moe_ffnexpands the routed experts into the graph, so the shared expert used to come after the expert sum and split the add chain. Expanding the shared expert first only changes the node order. The result is bit-identical on every backend.Additional information
Measured on an AMD Radeon AI PRO R9700 (RDNA4, 32 GB) used as an eGPU over Thunderbolt 3, where the cost per dispatch is high. Model: Qwen4-35B-A3B UD-Q4_K_XL. On its own the speedup is below the run-to-run noise here (about 2%); it adds up with other dispatch reductions.
"before" is a branch that already carries ggml-org#33710 (hc_post fusion fix) and ggml-org#33286.
It is part of a set of changes measured together with ggml-org#33710 and ggml-org#33286, and combines with ggml-org#33412 (generated epilogue fusion, R9700 eGPU numbers in ggml-org#33412 (comment)), where the shared expert is then summed in the same fused add. All together, decode goes from 80.7 to 93.4 t/s (+16%) on this setup:
qwen3next,qwen35moeandqwen2moebuild the shared expert the same way; I can follow up there if this is wanted.Setup, 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.Dispatch counts from
GGML_VK_PERF_LOGGER. KL divergence:llama-perplexity --kl-divergence, 4x512 tokens (prefill,-ub 512) and 2x512 tokens (decode,-ub 1).llama-bench: 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)