Commit e574a17b0 for llama.cpp
commit e574a17b062be51b98e239ccd3d3743e3d902333
Author: Tarek Dakhran <tarek@liquid.ai>
Date: Sun Nov 15 01:05:20 2026 +0100
model : metal : workaround fusion for LFM3 (#32296)
* lfm3 : put the normed tensor first in residual adds to enable norm fusion
Assisted-by: Claude Opus 5.5
* tests : update Metal fusion baseline for lfm3
Assisted-by: Claude Opus 5.5
diff --git a/src/models/lfm3.cpp b/src/models/lfm3.cpp
index 0746394ce..a820d9b97 100644
--- a/src/models/lfm3.cpp
+++ b/src/models/lfm3.cpp
@@ -179,7 +179,7 @@ llama_model_lfm3::graph<decision>::graph(const llm_graph_params & params) :
prev_cur = ggml_get_rows(ctx0, prev_cur, inp_out_ids);
}
- cur = ggml_add(ctx0, prev_cur, cur);
+ cur = ggml_add(ctx0, cur, prev_cur);
auto * ffn_norm_out = build_norm(cur, model.layers[il].ffn_norm, NULL, LLM_NORM_RMS, il);
cb(ffn_norm_out, "model.layers.{}.ffn_norm", il);
@@ -191,7 +191,7 @@ llama_model_lfm3::graph<decision>::graph(const llm_graph_params & params) :
cb(ffn_out, "model.layers.{}.post_ffn_norm", il);
}
- cur = ggml_add(ctx0, cur, ffn_out);
+ cur = ggml_add(ctx0, ffn_out, cur);
cur = build_cvec(cur, il);
cb(cur, "l_out", il);
diff --git a/tests/fusion/MTL.csv b/tests/fusion/MTL.csv
index 401df6930..89cafb247 100644
--- a/tests/fusion/MTL.csv
+++ b/tests/fusion/MTL.csv
@@ -194,7 +194,8 @@ lfm2 ,0 ,any ,RMS_NORM+MUL , 7
lfm2moe ,1 ,any ,MUL+ADD , 2
lfm2moe ,1 ,any ,RMS_NORM+MUL , 7
lfm2moe ,1 ,any ,UNARY+ADD+ARGSORT+GET_ROWS+SUM_ROWS+CLAMP+DIV, 1
-lfm3 ,0 ,any ,RMS_NORM+MUL , 17
+lfm3 ,0 ,any ,RMS_NORM+MUL , 12
+lfm3 ,0 ,any ,RMS_NORM+MUL+ADD , 5
llada ,0 ,any ,RMS_NORM+MUL , 5
llada-moe ,1 ,any ,MUL+ADD , 4
llada-moe ,1 ,any ,RMS_NORM+MUL , 9