From a4c3f9a0bed49af742e45e73aef696904ac1a3c2 Mon Sep 17 00:00:00 2001 From: Dr Sujit Vasanth Date: Mon, 11 May 2026 01:39:01 +0100 Subject: [PATCH] llama: prefix MTP assistant tensors with 'mtp.' on load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the Gemma 4 assistant GGUF is loaded via llama_model_load_mtp_from_file, its block tensors (blk.0-3.*), token_embd, output_norm and rope_freqs share identical names with the target model's tensors. This makes it impossible to uniquely target MTP assistant tensors via -ot rules for GPU placement. Fix: after loading the assistant into aux, rename all tensors not already prefixed with 'mtp.' to 'mtp.'. This is done purely in-memory on the tensors_by_name vector and the ggml_tensor name field — the GGUF file and published arch names are unchanged. After this change, all MTP assistant tensors are addressable as mtp.blk.N.*, mtp.token_embd.weight, mtp.output_norm.weight etc, and can be pinned with: -ot 'mtp\..*=CUDA0' --- src/llama.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/llama.cpp b/src/llama.cpp index eb6bb6715234..972b629b6392 100644 --- a/src/llama.cpp +++ b/src/llama.cpp @@ -1212,7 +1212,17 @@ int llama_model_load_mtp_from_file(struct llama_model * model, const char * path llama_model_free(aux); return -7; } - + // Rename all MTP assistant tensors with "mtp." prefix so they can be + // uniquely targeted by -ot rules without colliding with the main model's + // tensors. Tensors already prefixed with "mtp." (pre_projection, + // post_projection, centroids, token_ordering) are left unchanged. + for (auto & kv : aux->tensors_by_name) { + if (kv.first.substr(0, 4) != "mtp.") { + std::string new_name = "mtp." + kv.first; + ggml_set_name(kv.second, new_name.c_str()); + kv.first = new_name; + } + } tgt->mtp_assistant.reset(aux); return 0; }