Commit e86f02bcd for llama.cpp
commit e86f02bcd58974baba75cc1f404486c0c7c7a111
Author: Georgi Gerganov <ggerganov@gmail.com>
Date: Fri Dec 4 21:08:17 2026 +0200
models : avoid using explicit inplace ops (#33721)
diff --git a/src/models/deepseek41.cpp b/src/models/deepseek41.cpp
index 419a852f0..31ca5accc 100644
--- a/src/models/deepseek41.cpp
+++ b/src/models/deepseek41.cpp
@@ -605,11 +605,11 @@ ggml_tensor * llama_model_deepseek41::graph::build_attention41(
// add the per-block mask with broadcast, in place: no [n_comp, tokens] mask tensor
// fill a computed node, not a new leaf: a leaf stays allocated for the whole graph
ggml_tensor * bm = ggml_cont(ctx0, ggml_view_3d(ctx0, score, 1, n_blk, nc*n_stream, bs*ggml_element_size(score), score->nb[1], 0));
- bm = ggml_fill_inplace(ctx0, bm, -INFINITY);
+ bm = ggml_fill(ctx0, bm, -INFINITY);
bm = ggml_set_rows(ctx0, bm, zeros, ggml_reshape_3d(ctx0, bsel, k_b, nc*n_stream, 1));
bm = ggml_reshape_4d(ctx0, bm, 1, n_blk, nc, n_stream);
cb(bm, "cand_mask", il);
- score = ggml_add_inplace(ctx0, ggml_reshape_4d(ctx0, score, bs, n_blk, nc, n_stream), bm);
+ score = ggml_add(ctx0, ggml_reshape_4d(ctx0, score, bs, n_blk, nc, n_stream), bm);
score = ggml_reshape_4d(ctx0, score, n_comp, nc, 1, n_stream);
} else {
ggml_tensor * bm = ggml_fill(ctx0, ggml_new_tensor_4d(ctx0, GGML_TYPE_F32, 1, n_blk, nc*n_stream, 1), -INFINITY);
diff --git a/src/models/minimax-m3.cpp b/src/models/minimax-m3.cpp
index 92c7ca757..bcc3928f9 100644
--- a/src/models/minimax-m3.cpp
+++ b/src/models/minimax-m3.cpp
@@ -400,7 +400,7 @@ llama_model_minimax_m3::graph::graph(const llm_graph_params & params) : llm_grap
// the reference computes the indexer scores in F32: https://github.com/huggingface/transformers/blob/0f53828e83f2212060233d2ea552cc76617b8712/src/transformers/models/minimax_m3_vl/modeling_minimax_m3_vl.py#L562
ggml_prec_set_acc(sc, GGML_PREC_F32);
// unmapped positions come out -inf, so they can never rank into the top-k
- sc = ggml_add_inplace(ctx0, sc,
+ sc = ggml_add(ctx0, sc,
ggml_reshape_4d(ctx0, msa->pos_mask, n_ps, 1, 1, ns));
ggml_tensor * bs = ggml_pool_2d(ctx0, sc, GGML_OP_POOL_MAX, blk, 1, blk, 1, 0, 0);
cb(bs, "msa_bs", il);
@@ -483,7 +483,7 @@ llama_model_minimax_m3::graph::graph(const llm_graph_params & params) : llm_grap
ggml_prec_set_acc(sc, GGML_PREC_F32);
sc = ggml_reshape_3d(ctx0, sc, n_ps, Hd, n_tps);
// unmapped positions (holes, padding, empty cells) come out -inf
- sc = ggml_add_inplace(ctx0, sc, pm_s);
+ sc = ggml_add(ctx0, sc, pm_s);
ggml_tensor * bs = ggml_pool_2d(ctx0, sc, GGML_OP_POOL_MAX, blk, 1, blk, 1, 0, 0);
cb(bs, "msa_bs", il);
@@ -514,7 +514,7 @@ llama_model_minimax_m3::graph::graph(const llm_graph_params & params) : llm_grap
ggml_tensor * bmc = ggml_get_rows(ctx0, bm2, cb_s); // [n_tps*Hd, n_kv] F32
ggml_tensor * bmx = ggml_cont(ctx0, ggml_transpose(ctx0, bmc));
bmx = ggml_reshape_3d(ctx0, bmx, n_kv, n_tps, Hd);
- ggml_tensor * mask4 = ggml_add_inplace(ctx0, bmx, mf_s);
+ ggml_tensor * mask4 = ggml_add(ctx0, bmx, mf_s);
mask4 = ggml_cast(ctx0,
ggml_reshape_4d(ctx0, mask4, n_kv, n_tps, 1, Hd), GGML_TYPE_F16);
cb(mask4, "msa_mask4", il);
diff --git a/tools/mtmd/models/cogvlm.cpp b/tools/mtmd/models/cogvlm.cpp
index aeaa33e4f..3756e044f 100644
--- a/tools/mtmd/models/cogvlm.cpp
+++ b/tools/mtmd/models/cogvlm.cpp
@@ -73,7 +73,7 @@ ggml_cgraph * mtmd_graph_cogvlm::build() {
cur = build_norm(cur, model.mm_post_fc_norm_w, model.mm_post_fc_norm_b, NORM_TYPE_NORMAL, 1e-5, -1);
// Apply GELU
- cur = ggml_gelu_inplace(ctx0, cur);
+ cur = ggml_gelu(ctx0, cur);
// Branch 1: multiply with mm_h_to_4h_w
ggml_tensor * h_to_4h = build_mm(model.mm_h_to_4h_w, cur);
diff --git a/tools/mtmd/models/conformer.cpp b/tools/mtmd/models/conformer.cpp
index 4cd2bee53..1f6a80805 100644
--- a/tools/mtmd/models/conformer.cpp
+++ b/tools/mtmd/models/conformer.cpp
@@ -23,7 +23,7 @@ ggml_cgraph * mtmd_graph_conformer::build() {
cb(cur, "conformer.pre_encode.conv.{}", 0);
// layer.1 - relu
- cur = ggml_relu_inplace(ctx0, cur);
+ cur = ggml_relu(ctx0, cur);
// layer.2 conv2d dw
cur = ggml_conv_2d_dw_direct(ctx0, model.pre_encode_conv_X_w[2], cur, 2, 2, 1, 1, 1, 1);
@@ -36,7 +36,7 @@ ggml_cgraph * mtmd_graph_conformer::build() {
cb(cur, "conformer.pre_encode.conv.{}", 3);
// layer.4 - relu
- cur = ggml_relu_inplace(ctx0, cur);
+ cur = ggml_relu(ctx0, cur);
// layer.5 conv2d dw
cur = ggml_conv_2d_dw_direct(ctx0, model.pre_encode_conv_X_w[5], cur, 2, 2, 1, 1, 1, 1);
@@ -49,7 +49,7 @@ ggml_cgraph * mtmd_graph_conformer::build() {
cb(cur, "conformer.pre_encode.conv.{}", 6);
// layer.7 - relu
- cur = ggml_relu_inplace(ctx0, cur);
+ cur = ggml_relu(ctx0, cur);
// flatten channel and frequency axis
cur = ggml_cont(ctx0, ggml_permute(ctx0, cur, 0, 2, 1, 3));
diff --git a/tools/mtmd/models/lfm3a.cpp b/tools/mtmd/models/lfm3a.cpp
index 03128a298..d96aca934 100644
--- a/tools/mtmd/models/lfm3a.cpp
+++ b/tools/mtmd/models/lfm3a.cpp
@@ -59,17 +59,17 @@ ggml_cgraph * mtmd_graph_lfm3a::build() {
// downsampler, same layout as the lfm2a pre-encoder but with SiLU
cur = conv_down(cur, "ds0", model.pre_encode_conv_X_w[0], model.pre_encode_conv_X_b[0], false);
- cur = ggml_silu_inplace(ctx0, cur);
+ cur = ggml_silu(ctx0, cur);
cur = conv_down(cur, "ds1", model.pre_encode_conv_X_w[2], model.pre_encode_conv_X_b[2], true);
cur = ggml_conv_2d_direct(ctx0, model.pre_encode_conv_X_w[3], cur, 1, 1, 0, 0, 1, 1);
cur = ggml_add(ctx0, cur, model.pre_encode_conv_X_b[3]);
- cur = ggml_silu_inplace(ctx0, cur);
+ cur = ggml_silu(ctx0, cur);
cur = conv_down(cur, "ds2", model.pre_encode_conv_X_w[5], model.pre_encode_conv_X_b[5], true);
cur = ggml_conv_2d_direct(ctx0, model.pre_encode_conv_X_w[6], cur, 1, 1, 0, 0, 1, 1);
cur = ggml_add(ctx0, cur, model.pre_encode_conv_X_b[6]);
- cur = ggml_silu_inplace(ctx0, cur);
+ cur = ggml_silu(ctx0, cur);
cb(cur, "downsample.conv", -1);
// [n_pos, n_mel/8, n_ch] -> [n_ch * n_mel/8, n_pos]
diff --git a/tools/mtmd/models/llava.cpp b/tools/mtmd/models/llava.cpp
index 8e8c7638b..90ceee5e7 100644
--- a/tools/mtmd/models/llava.cpp
+++ b/tools/mtmd/models/llava.cpp
@@ -344,7 +344,7 @@ ggml_cgraph * mtmd_graph_llava::build() {
embeddings = build_mm(model.mm_model_mlp_0_w, embeddings);
embeddings = ggml_norm(ctx0, embeddings, eps);
embeddings = ggml_add(ctx0, ggml_mul(ctx0, embeddings, model.mm_model_ln_q_w), model.mm_model_ln_q_b);
- embeddings = ggml_gelu_inplace(ctx0, embeddings);
+ embeddings = ggml_gelu(ctx0, embeddings);
ggml_tensor * x = embeddings;
embeddings = build_mm(model.mm_model_mlp_2_w, embeddings);
x = build_mm(model.mm_model_mlp_1_w,x);