From e574a17b062be51b98e239ccd3d3743e3d902333 Mon Sep 17 00:00:00 2001 From: Tarek Dakhran Date: Sun, 15 Nov 2026 01:05:20 +0100 Subject: [PATCH] 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 --- src/models/lfm3.cpp | 4 ++-- tests/fusion/MTL.csv | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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::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::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