Repository navigation
qwen4exp: enable rms_norm + mul fusion - #28896
Merged
Merged
Conversation
CISC
approved these changes
Sep 14, 2026
ggerganov
reviewed
Sep 14, 2026
| ggml_tensor * xn = ggml_rms_norm(ctx0, x, hparams.f_norm_rms_eps); | ||
| // the gamma view enters the graph first, so rms_norm and mul stay adjacent for backend fusion | ||
| ggml_tensor * w_norm_hc = ggml_reshape_2d(ctx0, w_norm, n_embd, hc); | ||
| ggml_build_forward_expand(gf, w_norm_hc); |
Member
There was a problem hiding this comment.
Is the ggml_build_forward_expand(gf, w_norm_hc) call actually needed?
Edit: nvm, it's needed
ggerganov
reviewed
Sep 14, 2026
| // the converter folded each gamma to (1 + w) | ||
| ggml_tensor * xn = ggml_rms_norm(ctx0, x, hparams.f_norm_rms_eps); | ||
| // the gamma view enters the graph first, so rms_norm and mul stay adjacent for backend fusion | ||
| ggml_tensor * w_norm_hc = ggml_reshape_2d(ctx0, w_norm, n_embd, hc); |
Member
There was a problem hiding this comment.
You should be able to avoid both of these ggml_reshape_2d calls by loading the weight directly as a 2D tensor via the TENSOR_ALLOW_RESHAPE flag. See how we do it here:
llama.cpp/src/models/deepseek4.cpp
Lines 120 to 122 in 97e4ca7
Member
There was a problem hiding this comment.
I already forgot about this feature. :)
ggerganov
approved these changes
Sep 14, 2026
Member
|
Fusion table needs to be updated: |
meh
pushed a commit
to meh/llama.cpp
that referenced
this pull request
Sep 15, 2026
* qwen4exp: enable rms_norm + mul fusion * use TENSOR_ALLOW_RESHAPE
liquidspikes
added a commit
to liquidspikes/llama.cpp
that referenced
this pull request
Sep 16, 2026
quimmedes
pushed a commit
to quimmedes/cafe-llama.cpp
that referenced
this pull request
Sep 16, 2026
* qwen4exp: enable rms_norm + mul fusion * use TENSOR_ALLOW_RESHAPE
adderek
pushed a commit
to adderek/llama.cpp
that referenced
this pull request
Sep 20, 2026
* qwen4exp: enable rms_norm + mul fusion * use TENSOR_ALLOW_RESHAPE (cherry picked from commit 41abbfd)
adderek
pushed a commit
to adderek/llama.cpp
that referenced
this pull request
Sep 20, 2026
Cherry-picked from unslothai/llama.cpp topic branches onto d0e7ec2, then merged here. The case for taking these is CORRECTNESS, not speed — the two performance commits in the set touch the GPU path and nothing in the verification below measured throughput. 82b4198 fix llm_graph_input_ple reuse e339f5d model: qwen4exp: reduce number of graph splits (ggml-org#27880) 6f06845 qwen4exp: fix QSA correctness defects and harden metadata loading f46d73a qwen4exp: trim comments 4594877 qwen4exp: enable rms_norm + mul fusion (ggml-org#28896) Three conflicts were resolved by hand and are worth knowing about: llama-memory-hybrid-idx.cpp BOTH sides kept. Upstream adds hparams_idx.rope_type = LLAMA_ROPE_TYPE_NONE (cached indexer keys are raw; rotation happens after pooling at read time, so a K-shift must not rotate them). Our no_turbo() guard stays: the indexer keys are read back with GET_ROWS, TurboQuant stores them WHT-rotated and has no get_rows, so that one cache falls back to f16. Independent fixes at the same spot, not alternatives. qwen4exp.cpp metadata guards took upstream. GGML_ASSERT(dsv4_hc_mult > 0) becomes a throw with a readable message plus a > 1 check — transformers, vLLM and SGLang all reject hc_count <= 1. build_ple -> build_inp_ple took the upstream refactor. Our GGML_UNUSED(inp) was dropped: inp is genuinely used in the new build_ple, via build_conv_state_at. Verified on this box, 2026-09-20: - compiles and links, zero warnings under -Wall -Wextra -Wpedantic - loads Qwen3.8-Flash-Next UD-IQ4_XS (88 GB, the only qwen4exp weights here) CPU-only and generates correctly - byte-identical output against the pre-merge build (d0e7ec2) at temp 0 seed 42, on a short prompt AND on a ~2515-token prompt split into ~5 ubatches, which is where the PLE predecessor history can actually diverge - needle recall intact in the long run (a broken n-gram hash fails retrieval first, so this is the check that matters) NOT verified: anything on a GPU. No HIP build was made, so the two perf commits are unmeasured and the preserved no_turbo() guard ran with f16 KV, where it had nothing to convert. Its real test is --cache-type-k turbo4 on a card. Deliberately not taken: dbac7c4 (superseded one day later by b356fa2 / ggml-org#28040, which replaces the whole hash-map rebuild with a logarithmic lookup and carries a measured +4.9% tg at 71k ctx) and ca14269 (the tip of a 7-commit NextN/MTP chain that also needs draft weights we do not have). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
roverdrubber
added a commit
to roverdrubber/llama.cpp
that referenced
this pull request
Oct 15, 2026
The branch is far behind upstream master and the parts that a card other than this one needs had drifted. This ports the non-backend half of that sync, content-matched against upstream rather than replayed by hash: the parser and JSON schema chain (ggml-org#27764, ggml-org#28736, ggml-org#28742, which adds common/parsers/, common/json-schema.* and tests/test-json-schema.cpp and retires the three example scripts it replaces), the chat, grammar, jinja and server fixes (ggml-org#28302, ggml-org#28469, ggml-org#26885, ggml-org#28279, ggml-org#28511, ggml-org#28620, ggml-org#28817, ggml-org#28749), the qwen4exp RMSNorm and multiply fusion (ggml-org#28896, hand-ported because the norm tensors here load with a different shape), the GDN q/k l2 norm as flash-linear-attention defines it (ggml-org#28068), the ggml_prec_set_acc API that replaces ggml_mul_mat_set_prec and ggml_flash_attn_ext_set_prec at every call site, and the scheduler fixes for zero-sized expert ids (ggml-org#28739) and split inputs (ggml-org#28387). The GPU backend half of the same sync lands in the following two commits; this one alone does not build the CUDA or HIP backend, because their call sites move to the new precision API there. test-chat, test-json-schema, test-json-schema-to-grammar, test-grammar-integration and test-grammar-parser pass. Assisted-by: Claude Opus 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
refactor the graph to enable rms_norm + mul fusion. I see about +3% PP because of this.
Additional information
Requirements