MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / llm_build_plm

Method llm_build_plm

subprojects/llama.cpp/src/models/plm.cpp:3–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "models.h"
2
3llm_build_plm::llm_build_plm(const llama_model & model, const llm_graph_params & params) : llm_graph_context(params) {
4 const float kq_scale = 1.0f/sqrtf(float(hparams.n_embd_head_k));
5
6 const uint32_t n_embd_head_qk_rope = hparams.n_rot;
7 const uint32_t n_embd_head_qk_nope = hparams.n_embd_head_k - hparams.n_rot;
8
9 const uint32_t kv_lora_rank = hparams.n_lora_kv;
10
11 ggml_tensor * cur;
12 ggml_tensor * inpL;
13
14 // {n_embd, n_tokens}
15 inpL = build_inp_embd(model.tok_embd);
16
17 // inp_pos - contains the positions
18 ggml_tensor * inp_pos = build_inp_pos();
19
20 auto * inp_attn = build_attn_inp_kv();
21
22 ggml_tensor * inp_out_ids = build_inp_out_ids();
23
24 for (int il = 0; il < n_layer; ++il) {
25 ggml_tensor * inpSA = inpL;
26
27 // norm
28 cur = build_norm(inpL,
29 model.layers[il].attn_norm, NULL,
30 LLM_NORM_RMS, il);
31 cb(cur, "attn_norm", il);
32
33 // self_attention
34 {
35 ggml_tensor * q = NULL;
36 q = ggml_mul_mat(ctx0, model.layers[il].wq, cur);
37 cb(q, "q", il);
38
39 // split into {n_head * n_embd_head_qk_nope, n_tokens}
40 ggml_tensor * q_nope = ggml_view_3d(ctx0, q, n_embd_head_qk_nope, n_head, n_tokens,
41 ggml_row_size(q->type, hparams.n_embd_head_k),
42 ggml_row_size(q->type, hparams.n_embd_head_k * n_head),
43 0);
44 cb(q_nope, "q_nope", il);
45
46 // and {n_head * n_embd_head_qk_rope, n_tokens}
47 ggml_tensor * q_pe = ggml_view_3d(ctx0, q, n_embd_head_qk_rope, n_head, n_tokens,
48 ggml_row_size(q->type, hparams.n_embd_head_k),
49 ggml_row_size(q->type, hparams.n_embd_head_k * n_head),
50 ggml_row_size(q->type, n_embd_head_qk_nope));
51 cb(q_pe, "q_pe", il);
52
53 // {n_embd, kv_lora_rank + n_embd_head_qk_rope} * {n_embd, n_tokens} -> {kv_lora_rank + n_embd_head_qk_rope, n_tokens}
54 ggml_tensor * kv_pe_compresseed = ggml_mul_mat(ctx0, model.layers[il].wkv_a_mqa, cur);
55 cb(kv_pe_compresseed, "kv_pe_compresseed", il);
56
57 // split into {kv_lora_rank, n_tokens}
58 ggml_tensor * kv_compressed = ggml_view_2d(ctx0, kv_pe_compresseed, kv_lora_rank, n_tokens,
59 kv_pe_compresseed->nb[1],
60 0);

Callers

nothing calls this directly

Calls 11

ggml_mul_matFunction · 0.85
ggml_view_3dFunction · 0.85
ggml_row_sizeFunction · 0.85
ggml_view_2dFunction · 0.85
ggml_contFunction · 0.85
ggml_rope_extFunction · 0.85
ggml_concatFunction · 0.85
ggml_repeatFunction · 0.85
ggml_get_rowsFunction · 0.85
ggml_addFunction · 0.85

Tested by

no test coverage detected