Skip to content

Commit d237d7b

Browse files
committed
Fix Gemma4 MTP
1 parent f9aaf84 commit d237d7b

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/graphs/build_gemma4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ ggml_cgraph * llm_build_context::build_gemma4_mtp() {
663663
// not required for correct inference — the full-vocab matmul against the tied output
664664
// weight still yields valid per-token logits.
665665
{
666-
logits = build_output(lctx, ctx0, cur, model.output, model.output_norm, cb);
666+
logits = build_output(lctx, ctx0, cur, model.output, model.output_norm, cb, false);
667667
cb(logits, "result_output", -1);
668668
}
669669
ggml_build_forward_expand(gf, logits);

src/llama-build-context.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,7 @@ ggml_tensor * llm_build_context::build_output(llama_context & lctx, ggml_context
20482048
}
20492049

20502050
ggml_tensor * llm_build_context::build_output(llama_context & lctx, ggml_context * ctx, ggml_tensor * cur,
2051-
ggml_tensor * output, ggml_tensor * output_norm, const llm_build_cb & cb) {
2051+
ggml_tensor * output, ggml_tensor * output_norm, const llm_build_cb & cb, bool add_normed_name) {
20522052
// lm_head
20532053
if (output->extra) {
20542054
auto split_output = (ggml_split_tensor_t *)output->extra;
@@ -2069,7 +2069,7 @@ ggml_tensor * llm_build_context::build_output(llama_context & lctx, ggml_context
20692069
o.push_back(llm_build_context::llm_build_lora_mm(lctx, ctx, split, cur));
20702070
}
20712071
cb(o.back(), "output", id);
2072-
if (last_norm) {
2072+
if (add_normed_name && last_norm) {
20732073
cb(last_norm, "result_norm", -1);
20742074
}
20752075
}
@@ -2095,7 +2095,9 @@ ggml_tensor * llm_build_context::build_output(llama_context & lctx, ggml_context
20952095
}
20962096
if (output_norm) {
20972097
cur = llm_build_context::llm_build_norm(ctx, cur, lctx.model.hparams, output_norm, NULL, LLM_NORM_RMS, cb, -1);
2098-
cb(cur, "result_norm", -1);
2098+
if (add_normed_name) {
2099+
cb(cur, "result_norm", -1);
2100+
}
20992101
}
21002102
cur = llm_build_context::llm_build_lora_mm(lctx, ctx, output, cur);
21012103
}

src/llama-build-context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ llm_expert_gating_func_type gating_op,
448448
static ggml_tensor * build_output(llama_context & lctx, ggml_context * ctx, ggml_tensor * cur, ggml_tensor * output, const llm_build_cb & cb);
449449

450450
static ggml_tensor * build_output(llama_context & lctx, ggml_context * ctx, ggml_tensor * cur,
451-
ggml_tensor * output, ggml_tensor * output_norm, const llm_build_cb & cb);
451+
ggml_tensor * output, ggml_tensor * output_norm, const llm_build_cb & cb, bool add_normed_name = true);
452452

453453
static ggml_tensor * do_split_norm(ggml_context * ctx, ggml_tensor * cur, ggml_tensor * the_norm, const llama_hparams & hparams,
454454
const llm_build_cb & cb, int id, int il_cb, bool is_norm);

0 commit comments

Comments
 (0)