llama.cpp
5fdfa628 - models : fix GDN normalization from `max` to `rsqrt` (#28068)

Commit
7 days ago
models : fix GDN normalization from `max` to `rsqrt` (#28068) * models: use flash-linear-attention's l2norm for gated delta net q/k The GDN q/k normalization is defined by flash-linear-attention as l2norm(x) = x * rsqrt(sum(x*x) + eps) with eps inside the root. Every GDN call site in the tree uses ggml_l2_norm instead, which is x / max(sqrt(sum(x*x)), eps), i.e. torch.nn.functional.normalize - its CUDA kernel cites that page. The clamp never engages at these magnitudes, so in practice llama.cpp normalizes with no epsilon at all where the reference has one inside the root. transformers made the same substitution when it first added Qwen3-Next and corrected it three days later in huggingface/transformers#40842, 'Fix the misalignment between the l2norm in GDN of Qwen3-Next and the implementation in the FLA library'. vLLM and SGLang vendor FLA rather than reimplementing it, so neither ever had the clamp. eps keeps coming from the checkpoint, exactly as every call site already passed it. The references hardcode 1e-6 for this norm; that is a separate question and the two agree on every GDN checkpoint in the wild. ggml_l2_norm itself is correct and unchanged, as is rwkv7-base, its original caller, which passes normalize's own default eps of 1e-12. No new ggml op: rms_norm already carries eps inside the root, so rms_norm(x, eps/n) * (1/sqrt(n)) is exactly x * rsqrt(sum(x*x) + eps). * Update src/models/models.h Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Author
Parents
Loading