]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
Qwen2 : assume tied weights if lm_head/output weights is missing (#6738)
authorRen Xuancheng <redacted>
Thu, 18 Apr 2024 11:38:04 +0000 (19:38 +0800)
committerGitHub <redacted>
Thu, 18 Apr 2024 11:38:04 +0000 (14:38 +0300)
llama.cpp

index 8c1446296fe35d63d63bb9c7c5777009d8e8d8a4..05094fec197d62cfdd7344f17da4d245502dae62 100644 (file)
--- a/llama.cpp
+++ b/llama.cpp
@@ -5184,7 +5184,13 @@ static bool llm_load_tensors(
                     // output
                     {
                         model.output_norm = ml.create_tensor(ctx_output,       tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd});
-                        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);
+                        }
                     }
 
                     for (int i = 0; i < n_layer; ++i) {