Repository navigation
cuda: fuse the Gemma 4 MoE layer tail (GGML_CUDA_TAIL_FUSION, off by default) - #414
Merged
Merged
Conversation
…=4096 on Hopper (GGML_CUDA_MMVQ_TALL_EXT) Extend the 8-rows-per-CTA one-column mat-vec geometry, previously used for PQ2_0 only, to Q8_0, Q4_0, Q2_0, Q4_K and Q6_K when the matrix has at least 4096 rows (a multiple of 8) on Hopper. The K partition and reduction order per row are unchanged, so every output row is bit-identical to the default geometry. GGML_CUDA_MMVQ_TALL_EXT=0 restores the PQ2_0-only behavior (default: enabled).
Every folded Gemma 4 weight (attention q/k/v/o, shared FFN, routed experts) goes through build_lora_mm / build_lora_mm_id, which apply the activation transform.
…_FUSION=1) Fuse the three RMS_NORM+MUL(+ADD) groups and the layer-scalar MUL at the end of the Gemma 4 MoE layer into a single launch (one block per row, ncols <= 3072). The kernel uses the same per-thread partial sums, reductions and expression forms as the unfused kernels, so the result is bit-identical. Add an "ffn_res" node name in gemma4.cpp so the group can be matched. GGML_CUDA_TAIL_FUSION=1 enables it (default 0: off). GGML_CUDA_TAIL_VERIFY=1 additionally runs the unfused nodes and compares the outputs bit-for-bit, printing TAILVERIFY lines on mismatch (default 0: off).
…tail kernel (GGML_CUDA_TAIL_FUSION=2/3) Level 2: the next layer's attn_norm (RMS_NORM+MUL) joins the same launch. Level 3: the kernel also writes the q8_1 rows of the normalized activation that the mat-vecs of the next attention block would otherwise quantize (all consumers are plain MUL_MATs with the AOS layout), using the same expressions as quantize_q8_1. GGML_CUDA_TAIL_FUSION=0/1/2/3 selects the level (default 0: off). With GGML_CUDA_TAIL_VERIFY=1 the level-2/3 outputs are compared bit-for-bit against the unfused nodes as well.
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.
Depends on #413 (stacked on
gemma/tall-ext; the diff here includes its two commits until it merges).What
GGML_CUDA_TAIL_FUSION=0/1/2/3selects the level (default 0, off).GGML_CUDA_TAIL_VERIFY=1also runs the unfused nodes and compares the outputs bit-for-bit. It is a debug mode and keeps a 128 MB scratch while enabled.Why
How
ffn_resnode name in gemma4.cpp so the pattern can be matched.Testing (H200, this branch)