MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / build_persimmon

Method build_persimmon

llama.cpp:5573–5781  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5571 }
5572
5573 struct ggml_cgraph * build_persimmon() {
5574 struct ggml_cgraph * gf = ggml_new_graph_custom(ctx0, LLAMA_MAX_NODES, false);
5575
5576 const int64_t n_rot = n_embd_head / 2;
5577
5578 struct ggml_tensor * cur;
5579 struct ggml_tensor * inpL;
5580
5581 inpL = llm_build_inp_embd(ctx0, hparams, batch, model.tok_embd, cb);
5582 cb(inpL, "imp_embd", -1);
5583
5584 struct ggml_tensor * inp_pos = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_tokens);
5585 cb(inp_pos, "inp_pos", -1);
5586
5587 // KQ_scale
5588 struct ggml_tensor * KQ_scale = ggml_new_tensor_1d(ctx0, GGML_TYPE_F32, 1);
5589 cb(KQ_scale, "KQ_scale", -1);
5590
5591 struct ggml_tensor * KQ_mask = ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, n_kv, n_tokens, 1);
5592 cb(KQ_mask, "KQ_mask", -1);
5593
5594 if (do_rope_shift) {
5595 llm_build_k_shift(ctx0, hparams, cparams, kv_self, gf, LLM_ROPE_NEOX, n_ctx, n_embd_head, freq_base, freq_scale, cb);
5596 }
5597
5598 for (int il = 0; il < n_layer; ++il) {
5599 struct ggml_tensor * residual = inpL;
5600
5601 cur = llm_build_norm(ctx0, inpL, hparams,
5602 model.layers[il].attn_norm,
5603 model.layers[il].attn_norm_b,
5604 LLM_NORM, cb, il);
5605 cb(cur, "attn_norm", il);
5606
5607 // self attention
5608 {
5609 cur = ggml_mul_mat(ctx0, model.layers[il].wqkv, cur);
5610 cb(cur, "wqkv", il);
5611
5612 cur = ggml_add(ctx0, cur, model.layers[il].bqkv);
5613 cb(cur, "bqkv", il);
5614
5615 // split qkv
5616 GGML_ASSERT(n_head_kv == n_head);
5617
5618 struct ggml_tensor * tmpqkv = ggml_reshape_4d(ctx0, cur, n_embd_head, 3, n_head, n_tokens);
5619 cb(tmpqkv, "tmpqkv", il);
5620
5621 struct ggml_tensor * tmpqkv_perm = ggml_cont(ctx0, ggml_permute(ctx0, tmpqkv, 0, 3, 1, 2));
5622 cb(tmpqkv_perm, "tmpqkv", il);
5623
5624 struct ggml_tensor * tmpq = ggml_view_3d(
5625 ctx0, tmpqkv_perm, n_embd_head, n_head, n_tokens,
5626 ggml_element_size(tmpqkv_perm) * n_embd_head,
5627 ggml_element_size(tmpqkv_perm) * n_embd_head * n_head,
5628 0
5629 );
5630 cb(tmpq, "tmpq", il);

Callers 1

llama_build_graphFunction · 0.80

Calls 15

llm_build_inp_embdFunction · 0.85
cbFunction · 0.85
llm_build_k_shiftFunction · 0.85
llm_build_normFunction · 0.85
llm_build_kv_storeFunction · 0.85
llm_build_kqvFunction · 0.85
llm_build_ffnFunction · 0.85
ggml_new_graph_customFunction · 0.70
ggml_new_tensor_1dFunction · 0.70
ggml_new_tensor_3dFunction · 0.70
ggml_mul_matFunction · 0.70
ggml_addFunction · 0.70

Tested by

no test coverage detected