]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
llama : assume tied weights if lm_head/output weights is missing (#5824)
authorDon Mahurin <redacted>
Fri, 8 Mar 2024 10:41:50 +0000 (02:41 -0800)
committerGitHub <redacted>
Fri, 8 Mar 2024 10:41:50 +0000 (12:41 +0200)
This is to support model configurations with "tie_word_embeddings" set to true.

Co-authored-by: Don Mahurin <redacted>
llama.cpp

index 4225f955590dd0c925ff63a3467be1806c3b84a1..458382b21057c23b7daa56325051a9b8e6e455d8 100644 (file)
--- 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);
+                            }
                         }
                     }