From a1ca428c90e6a0d8e5a94be7806f3319ab2cc680 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Sat, 24 Jan 2026 17:48:09 -0800 Subject: [PATCH] glm4moelite: fix attention scale calculation (#13893) Use the original key dimension (qkNopeHeadDim + qkRopeHeadDim = 256) for the attention scale instead of the MLA absorbed dimension (kvLoraRank + qkRopeHeadDim = 576). MLA absorption is a mathematically equivalent reorganization of the attention computation - it should not change the effective attention scale. The scale should match training, which uses 1/sqrt(256). This improves tool calling and model looping issues. --- model/models/glm4moelite/model.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/model/models/glm4moelite/model.go b/model/models/glm4moelite/model.go index 4dfbab17..4d1e54aa 100644 --- a/model/models/glm4moelite/model.go +++ b/model/models/glm4moelite/model.go @@ -223,12 +223,7 @@ func New(c fs.Config) (model.Model, error) { keyLength := int(c.Uint("attention.key_length")) valueLength := int(c.Uint("attention.value_length")) - kvLoraRank := int(c.Uint("attention.kv_lora_rank")) - qkRopeHeadDim := int(c.Uint("rope.dimension_count")) - - // For MLA absorption, the effective key dimension is kvLoraRank + qkRopeHeadDim - mlaKeyLength := kvLoraRank + qkRopeHeadDim - kqScale := 1.0 / math.Sqrt(float64(mlaKeyLength)) + kqScale := 1.0 / math.Sqrt(float64(keyLength)) var pre []string switch c.String("tokenizer.ggml.pre") {