Skip to content

Commit 7da3e10

Browse files
deepseek4: testing ggml_sum_rows_ext
1 parent 5f76c8a commit 7da3e10

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

‎src/models/deepseek4.cpp‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,12 @@ ggml_tensor * llama_model_deepseek4::graph::build_hca_compressed_kv_from_state(
491491
score = ggml_reshape_3d(ctx0, score, n_embd_head, DSV4_HCA_RATIO, n_blocks);
492492
cb(score, name, il);
493493

494-
ggml_tensor * values = ggml_cont(ctx0, ggml_permute(ctx0, kv, 1, 0, 2, 3));
495494
ggml_tensor * scores = ggml_cont(ctx0, ggml_permute(ctx0, score, 1, 0, 2, 3));
496495

497496
ggml_tensor * weights = ggml_soft_max(ctx0, scores);
498-
ggml_tensor * comp = ggml_mul(ctx0, values, weights);
499-
comp = ggml_sum_rows(ctx0, comp);
500-
comp = ggml_cont(ctx0, ggml_permute(ctx0, comp, 1, 0, 2, 3));
497+
weights = ggml_permute(ctx0, weights, 1, 0, 2, 3);
498+
ggml_tensor * comp = ggml_mul(ctx0, kv, weights);
499+
comp = ggml_sum_rows_ext(ctx0, comp, 1);
501500
cb(comp, name, il);
502501

503502
comp = build_norm(comp, norm, nullptr, LLM_NORM_RMS, il);
@@ -564,13 +563,12 @@ ggml_tensor * llama_model_deepseek4::graph::build_overlap_compressed_kv_from_sta
564563
ggml_tensor * values = ggml_concat(ctx0, kv_prev, kv_cur, 1);
565564
ggml_tensor * scores = ggml_concat(ctx0, score_prev, score_cur, 1);
566565

567-
values = ggml_cont(ctx0, ggml_permute(ctx0, values, 1, 0, 2, 3));
568566
scores = ggml_cont(ctx0, ggml_permute(ctx0, scores, 1, 0, 2, 3));
569567

570568
ggml_tensor * weights = ggml_soft_max(ctx0, scores);
569+
weights = ggml_permute(ctx0, weights, 1, 0, 2, 3);
571570
ggml_tensor * comp = ggml_mul(ctx0, values, weights);
572-
comp = ggml_sum_rows(ctx0, comp);
573-
comp = ggml_cont(ctx0, ggml_permute(ctx0, comp, 1, 0, 2, 3));
571+
comp = ggml_sum_rows_ext(ctx0, comp, 1);
574572
cb(comp, name, il);
575573

576574
comp = build_norm(comp, norm, nullptr, LLM_NORM_RMS, il);

0 commit comments

Comments
 (0)