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

Method llm_build_minicpm3

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

Source from the content-addressed store, hash-verified

1#include "models.h"
2
3llm_build_minicpm3::llm_build_minicpm3(const llama_model & model, const llm_graph_params & params) : llm_graph_context(params) {
4 //TODO: if the model varies, these parameters need to be read from the model
5 const int64_t n_embd_base = 256;
6 const float scale_embd = 12.0f;
7 const float scale_depth = 1.4f;
8 const float kq_scale = 1.0f / sqrtf(float(hparams.n_embd_head_k));
9
10 const uint32_t n_embd_head_qk_rope = hparams.n_rot;
11 const uint32_t n_embd_head_qk_nope = hparams.n_embd_head_k - hparams.n_rot;
12
13 const uint32_t kv_lora_rank = hparams.n_lora_kv;
14
15 ggml_tensor * cur;
16 ggml_tensor * inpL;
17
18 inpL = build_inp_embd(model.tok_embd);
19
20 // scale the input embeddings
21 inpL = ggml_scale(ctx0, inpL, scale_embd);
22 cb(inpL, "inp_scaled", -1);
23
24 // inp_pos - contains the positions
25 ggml_tensor * inp_pos = build_inp_pos();
26
27 auto * inp_attn = build_attn_inp_kv();
28
29 ggml_tensor * inp_out_ids = build_inp_out_ids();
30
31 for (int il = 0; il < n_layer; ++il) {
32 ggml_tensor * inpSA = inpL;
33
34 ggml_tensor * rope_factors = model.get_rope_factors(cparams, il);
35
36 // norm
37 cur = build_norm(inpL,
38 model.layers[il].attn_norm, NULL,
39 LLM_NORM_RMS, il);
40 cb(cur, "attn_norm", il);
41
42 // self_attention
43 {
44 ggml_tensor * q = NULL;
45 // {n_embd, q_lora_rank} * {n_embd, n_tokens} -> {q_lora_rank, n_tokens}
46 q = ggml_mul_mat(ctx0, model.layers[il].wq_a, cur);
47 cb(q, "q", il);
48
49 q = build_norm(q,
50 model.layers[il].attn_q_a_norm, NULL,
51 LLM_NORM_RMS, il);
52 cb(q, "q", il);
53
54 // {q_lora_rank, n_head * hparams.n_embd_head_k} * {q_lora_rank, n_tokens} -> {n_head * hparams.n_embd_head_k, n_tokens}
55 q = ggml_mul_mat(ctx0, model.layers[il].wq_b, q);
56 cb(q, "q", il);
57
58 // split into {n_head * n_embd_head_qk_nope, n_tokens}
59 ggml_tensor * q_nope = ggml_view_3d(ctx0, q, n_embd_head_qk_nope, n_head, n_tokens,
60 ggml_row_size(q->type, hparams.n_embd_head_k),

Callers

nothing calls this directly

Calls 13

ggml_scaleFunction · 0.85
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