From b59615fa42414cb9160f65d46404070734125a3a Mon Sep 17 00:00:00 2001 From: Don Mahurin <2797413+dmahurin@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:49:53 -0800 Subject: [PATCH] Assume tied weights if lm_head/output weights is missing. This is to support model configurations with "tie_word_embeddings" set to true. --- llama.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/llama.cpp b/llama.cpp index b1db5b1797dc5..df5b27e4382dc 100644 --- a/llama.cpp +++ b/llama.cpp @@ -3855,7 +3855,13 @@ static bool llm_load_tensors( { model.output_norm = ml.create_tensor(ctx_output, tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd}); if (model.arch != LLM_ARCH_MINICPM){ - model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}); + model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}, false); + // if output is NULL, init from the input tok embed + if (model.output == NULL) { + model.output = ml.create_tensor(ctx_output, tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}); + ml.n_created--; // artificial tensor + ml.size_data += ggml_nbytes(model.output); + } } }