Skip to content

Commit 1e65bcd

Browse files
committed
Enable DeepSeek2 GLM MTP target rows
1 parent 2c16014 commit 1e65bcd

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/llama-context.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,9 +1938,22 @@ int llama_context::decode(const llama_batch & batch_inp) {
19381938

19391939
const uint32_t n_embd = hparams.n_embd_out();
19401940
float * embd_nextn_out = embd_nextn.data + offset*n_embd;
1941+
const size_t n_bytes = (size_t) n_rows*n_embd*sizeof(float);
19411942

19421943
GGML_ASSERT((offset + n_rows)*n_embd <= (int64_t) embd_nextn.size);
1943-
ggml_backend_tensor_get_async(backend_h, t_h_nextn, embd_nextn_out, 0, n_rows*n_embd*sizeof(float));
1944+
if (n_bytes > ggml_nbytes(t_h_nextn)) {
1945+
LLAMA_LOG_ERROR(
1946+
"%s: nextn embedding tensor is too small: masked=%d, n_rows=%lld, offset=%lld, "
1947+
"n_embd=%u, want=%zu bytes, have=%zu bytes, ne=[%lld, %lld, %lld, %lld], "
1948+
"ubatch.n_tokens=%u, n_outputs=%d, n_outputs_prev=%lld, n_tokens_prev=%lld\n",
1949+
__func__, (int) masked, (long long) n_rows, (long long) offset,
1950+
n_embd, n_bytes, ggml_nbytes(t_h_nextn),
1951+
(long long) t_h_nextn->ne[0], (long long) t_h_nextn->ne[1],
1952+
(long long) t_h_nextn->ne[2], (long long) t_h_nextn->ne[3],
1953+
ubatch.n_tokens, n_outputs, (long long) n_outputs_prev, (long long) n_tokens_prev);
1954+
return -3;
1955+
}
1956+
ggml_backend_tensor_get_async(backend_h, t_h_nextn, embd_nextn_out, 0, n_bytes);
19441957
}
19451958
}
19461959

src/models/deepseek2.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ llama_model_deepseek2::graph::graph(const llama_model & model, const llm_graph_p
381381
Qcur, Kcur, Vcur, nullptr, nullptr, nullptr, kq_scale, il);
382382
}
383383
}
384-
if (il == n_layer - 1 && inp_out_ids) {
384+
if (il == n_layer - 1 && inp_out_ids && cparams.embeddings_nextn_masked) {
385385
cur = ggml_get_rows(ctx0, cur, inp_out_ids);
386386
inpSA = ggml_get_rows(ctx0, inpSA, inp_out_ids);
387387
}
@@ -442,6 +442,10 @@ llama_model_deepseek2::graph::graph(const llama_model & model, const llm_graph_p
442442
cb(cur, "h_nextn", -1);
443443
res->t_h_nextn = cur;
444444

445+
if (!cparams.embeddings_nextn_masked && inp_out_ids) {
446+
cur = ggml_get_rows(ctx0, cur, inp_out_ids);
447+
}
448+
445449
cur = build_norm(cur, model.output_norm, NULL, LLM_NORM_RMS, -1);
446450

447451
cb(cur, "result_norm", -1);

0 commit comments

Comments
 (0)