Skip to content

Commit b59615f

Browse files
committed
Assume tied weights if lm_head/output weights is missing.
This is to support model configurations with "tie_word_embeddings" set to true.
1 parent c29af7e commit b59615f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llama.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3855,7 +3855,13 @@ static bool llm_load_tensors(
38553855
{
38563856
model.output_norm = ml.create_tensor(ctx_output, tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd});
38573857
if (model.arch != LLM_ARCH_MINICPM){
3858-
model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab});
3858+
model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}, false);
3859+
// if output is NULL, init from the input tok embed
3860+
if (model.output == NULL) {
3861+
model.output = ml.create_tensor(ctx_output, tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab});
3862+
ml.n_created--; // artificial tensor
3863+
ml.size_data += ggml_nbytes(model.output);
3864+
}
38593865
}
38603866
}
38613867

0 commit comments

Comments
 (0)