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

Method llm_build_mpt

subprojects/llama.cpp/src/models/mpt.cpp:5–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4
5llm_build_mpt::llm_build_mpt(const llama_model & model, const llm_graph_params & params) : llm_graph_context(params) {
6 const int64_t n_embd_head = hparams.n_embd_head_v;
7 const int64_t n_embd_gqa = hparams.n_embd_v_gqa();
8
9 GGML_ASSERT(n_embd_head == hparams.n_embd_head_k);
10
11 ggml_tensor * cur;
12 ggml_tensor * pos;
13 ggml_tensor * inpL;
14
15 inpL = build_inp_embd(model.tok_embd);
16
17 auto * inp_attn = build_attn_inp_kv();
18
19 if (model.pos_embd) {
20 // inp_pos - contains the positions
21 ggml_tensor * inp_pos = build_inp_pos();
22 pos = ggml_get_rows(ctx0, model.pos_embd, inp_pos);
23 cb(pos, "pos_embd", -1);
24
25 inpL = ggml_add(ctx0, inpL, pos);
26 cb(inpL, "inpL", -1);
27 }
28
29 ggml_tensor * inp_out_ids = build_inp_out_ids();
30
31 for (int il = 0; il < n_layer; ++il) {
32 ggml_tensor * attn_norm;
33
34 attn_norm = build_norm(inpL, model.layers[il].attn_norm, model.layers[il].attn_norm_b, LLM_NORM, il);
35 cb(attn_norm, "attn_norm", il);
36
37 // self-attention
38 {
39 cur = attn_norm;
40
41 cur = build_lora_mm(model.layers[il].wqkv, cur);
42 cb(cur, "wqkv", il);
43
44 if (model.layers[il].bqkv) {
45 cur = ggml_add(ctx0, cur, model.layers[il].bqkv);
46 cb(cur, "bqkv", il);
47 }
48
49 if (hparams.f_clamp_kqv > 0.0f) {
50 cur = ggml_clamp(ctx0, cur, -hparams.f_clamp_kqv, hparams.f_clamp_kqv);
51 cb(cur, "wqkv_clamped", il);
52 }
53
54 ggml_tensor * Qcur = ggml_view_3d(ctx0, cur, n_embd_head, n_head, n_tokens, n_embd_head * sizeof(float),
55 cur->nb[1], 0 * sizeof(float) * (n_embd));
56 ggml_tensor * Kcur = ggml_view_3d(ctx0, cur, n_embd_head, n_head_kv, n_tokens, n_embd_head * sizeof(float),
57 cur->nb[1], 1 * sizeof(float) * (n_embd));
58 ggml_tensor * Vcur = ggml_view_3d(ctx0, cur, n_embd_head, n_head_kv, n_tokens, n_embd_head * sizeof(float),
59 cur->nb[1], 1 * sizeof(float) * (n_embd + n_embd_gqa));
60
61 // Q/K Layernorm
62 if (model.layers[il].attn_q_norm) {

Callers

nothing calls this directly

Calls 8

ggml_get_rowsFunction · 0.85
ggml_addFunction · 0.85
ggml_clampFunction · 0.85
ggml_view_3dFunction · 0.85
ggml_reshape_2dFunction · 0.85
ggml_reshape_3dFunction · 0.85
n_embd_v_gqaMethod · 0.80

Tested by

no test coverage detected