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

Method llm_build_plamo3

subprojects/llama.cpp/src/models/plamo3.cpp:4–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2
3template <bool iswa>
4llm_build_plamo3<iswa>::llm_build_plamo3(const llama_model & model, const llm_graph_params & params) :
5 llm_graph_context(params) {
6 const int64_t head_dim_q = hparams.n_embd_head_k;
7 const int64_t head_dim_v = hparams.n_embd_head_v;
8
9 ggml_tensor * cur;
10 ggml_tensor * inpL = build_inp_embd(model.tok_embd);
11 ggml_tensor * inp_pos = build_inp_pos();
12
13 using inp_attn_type = std::conditional_t<iswa, llm_graph_input_attn_kv_iswa, llm_graph_input_attn_kv>;
14 inp_attn_type * inp_attn = nullptr;
15
16 if constexpr (iswa) {
17 inp_attn = build_attn_inp_kv_iswa();
18 } else {
19 inp_attn = build_attn_inp_kv();
20 }
21
22 ggml_tensor * inp_out_ids = build_inp_out_ids();
23
24 for (int il = 0; il < n_layer; ++il) {
25 ggml_tensor * residual = inpL;
26
27 float freq_base_l = 0.0f;
28 float freq_scale_l = 0.0f;
29 if constexpr (iswa) {
30 freq_base_l = model.get_rope_freq_base (cparams, il);
31 freq_scale_l = model.get_rope_freq_scale(cparams, il);
32 } else {
33 freq_base_l = freq_base;
34 freq_scale_l = freq_scale;
35 }
36
37 cur = build_norm(inpL, model.layers[il].attn_norm, NULL, LLM_NORM_RMS, il);
38 cb(cur, "attn_norm", il);
39
40 ggml_tensor * qkv = build_lora_mm(model.layers[il].wqkv, cur);
41 cb(cur, "wqkv", il);
42
43 const int32_t n_head = hparams.n_head(il);
44 const int32_t n_head_kv = hparams.n_head_kv(il);
45
46 const int64_t q_offset = 0;
47 const int64_t k_offset = head_dim_q * n_head;
48 const int64_t v_offset = k_offset + head_dim_q * n_head_kv;
49
50 ggml_tensor * Qcur = ggml_view_3d(ctx0, qkv, head_dim_q, n_head, n_tokens,
51 head_dim_q * sizeof(float), qkv->nb[1], q_offset * ggml_element_size(qkv));
52 ggml_tensor * Kcur = ggml_view_3d(ctx0, qkv, head_dim_q, n_head_kv, n_tokens,
53 head_dim_q * sizeof(float), qkv->nb[1], k_offset * ggml_element_size(qkv));
54 ggml_tensor * Vcur = ggml_view_3d(ctx0, qkv, head_dim_v, n_head_kv, n_tokens,
55 head_dim_v * sizeof(float), qkv->nb[1], v_offset * ggml_element_size(qkv));
56
57 cb(Qcur, "Qcur", il);
58 cb(Kcur, "Kcur", il);
59 cb(Vcur, "Vcur", il);
60
61 Qcur = build_norm(Qcur, model.layers[il].attn_q_norm, NULL, LLM_NORM_RMS, il);

Callers

nothing calls this directly

Calls 10

ggml_view_3dFunction · 0.85
ggml_element_sizeFunction · 0.85
ggml_rope_extFunction · 0.85
ggml_get_rowsFunction · 0.85
ggml_addFunction · 0.85
get_rope_freq_baseMethod · 0.80
get_rope_freq_scaleMethod · 0.80
n_headMethod · 0.80
n_head_kvMethod · 0.80

Tested by

no test coverage detected