summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDon Mahurin <dmahurin@users.noreply.github.com>2024-03-08 02:41:50 -0800
committerGitHub <noreply@github.com>2024-03-08 12:41:50 +0200
commite457fb3540e0aaec47cfde0abf784c213f9216ee (patch)
treefaa76ac6cc30fa61742b93db107c2a25602c13a6
parentaf37fd8b30e37ccbffdd82e6f48559e2fb7ce7dd (diff)
llama : assume tied weights if lm_head/output weights is missing (#5824)
This is to support model configurations with "tie_word_embeddings" set to true. Co-authored-by: Don Mahurin <2797413+dmahurin@users.noreply.github.com>
-rw-r--r--llama.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llama.cpp b/llama.cpp
index 4225f955..458382b2 100644
--- a/llama.cpp
+++ b/llama.cpp
@@ -3888,7 +3888,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);
+ }
}
}