Skip to content

Commit d199ca7

Browse files
authored
mpt : implement backwards compatiblity with duped output tensor (#6139)
1 parent 104f5e0 commit d199ca7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

llama.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ static const std::map<llm_arch, std::map<llm_tensor, std::string>> LLM_TENSOR_NA
540540
{
541541
{ LLM_TENSOR_TOKEN_EMBD, "token_embd" },
542542
{ LLM_TENSOR_OUTPUT_NORM, "output_norm" },
543+
{ LLM_TENSOR_OUTPUT, "output"},
543544
{ LLM_TENSOR_ATTN_NORM, "blk.%d.attn_norm" },
544545
{ LLM_TENSOR_FFN_NORM, "blk.%d.ffn_norm" },
545546
{ LLM_TENSOR_ATTN_QKV, "blk.%d.attn_qkv" },
@@ -4300,9 +4301,9 @@ static bool llm_load_tensors(
43004301
{
43014302
model.output_norm = ml.create_tensor(ctx_output, tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd});
43024303
model.output_norm_b = ml.create_tensor(ctx_output, tn(LLM_TENSOR_OUTPUT_NORM, "bias"), {n_embd});
4303-
if (gguf_find_tensor(ml.ctx_gguf, tn(LLM_TENSOR_OUTPUT, "weight").c_str()) >= 0) {
4304-
model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab});
4305-
} else {
4304+
4305+
model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}, false);
4306+
if (!model.output) {
43064307
model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}); // needs to be on GPU
43074308
ml.n_created--; // artificial tensor
43084309
ml.size_data += ggml_nbytes(model.output);
@@ -4507,10 +4508,12 @@ static bool llm_load_tensors(
45074508
model.output_norm = ml.create_tensor(ctx_output, tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd});
45084509
model.output_norm_b = ml.create_tensor(ctx_output, tn(LLM_TENSOR_OUTPUT_NORM, "bias"), {n_embd}, false);
45094510

4510-
// same as tok_embd, duplicated to allow offloading
4511-
model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab});
4512-
ml.n_created--; // artificial tensor
4513-
ml.size_data += ggml_nbytes(model.output);
4511+
model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}, false);
4512+
if (!model.output) {
4513+
model.output = ml.create_tensor(ctx_output_split, tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}); // needs to be on GPU
4514+
ml.n_created--; // artificial tensor
4515+
ml.size_data += ggml_nbytes(model.output);
4516+
}
45144517
}
45154518

45164519
for (int i = 0; i < n_layer; ++i) {

0 commit comments

Comments
 (0)