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

Method llm_build_grovemoe

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

Source from the content-addressed store, hash-verified

3
4
5llm_build_grovemoe::llm_build_grovemoe(const llama_model & model, const llm_graph_params & params) :
6 llm_graph_context(params) {
7 const int64_t n_embd_head = hparams.n_embd_head_v;
8 const int64_t n_chunk_expert = n_expert / hparams.n_group_experts;
9
10 GGML_ASSERT(n_embd_head == hparams.n_embd_head_k);
11 GGML_ASSERT(n_embd_head == hparams.n_rot);
12
13 ggml_tensor * cur;
14 ggml_tensor * inpL;
15
16 inpL = build_inp_embd(model.tok_embd);
17
18 // inp_pos - contains the positions
19 ggml_tensor * inp_pos = build_inp_pos();
20
21 auto * inp_attn = build_attn_inp_kv();
22
23 ggml_tensor * inp_out_ids = build_inp_out_ids();
24
25 for (int il = 0; il < n_layer; ++il) {
26 ggml_tensor * inpSA = inpL;
27
28 // norm
29 cur = build_norm(inpL, model.layers[il].attn_norm, NULL, LLM_NORM_RMS, il);
30 cb(cur, "attn_norm", il);
31
32 // self_attention
33 {
34 // compute Q and K and RoPE them
35 ggml_tensor * Qcur = build_lora_mm(model.layers[il].wq, cur);
36 cb(Qcur, "Qcur", il);
37
38 ggml_tensor * Kcur = build_lora_mm(model.layers[il].wk, cur);
39 cb(Kcur, "Kcur", il);
40
41 ggml_tensor * Vcur = build_lora_mm(model.layers[il].wv, cur);
42 cb(Vcur, "Vcur", il);
43
44 Qcur = ggml_reshape_3d(ctx0, Qcur, n_embd_head, n_head, n_tokens);
45 Kcur = ggml_reshape_3d(ctx0, Kcur, n_embd_head, n_head_kv, n_tokens);
46 Vcur = ggml_reshape_3d(ctx0, Vcur, n_embd_head, n_head_kv, n_tokens);
47
48 Qcur = build_norm(Qcur, model.layers[il].attn_q_norm, NULL, LLM_NORM_RMS, il);
49 cb(Qcur, "Qcur_normed", il);
50
51 Qcur = ggml_rope_ext(ctx0, Qcur, inp_pos, nullptr, n_rot, rope_type, n_ctx_orig, freq_base, freq_scale,
52 ext_factor, attn_factor, beta_fast, beta_slow);
53
54 Kcur = build_norm(Kcur, model.layers[il].attn_k_norm, NULL, LLM_NORM_RMS, il);
55 cb(Kcur, "Kcur_normed", il);
56
57 Kcur = ggml_rope_ext(ctx0, Kcur, inp_pos, nullptr, n_rot, rope_type, n_ctx_orig, freq_base, freq_scale,
58 ext_factor, attn_factor, beta_fast, beta_slow);
59
60 cb(Qcur, "Qcur", il);
61 cb(Kcur, "Kcur", il);
62 cb(Vcur, "Vcur", il);

Callers

nothing calls this directly

Calls 6

ggml_reshape_3dFunction · 0.85
ggml_rope_extFunction · 0.85
ggml_get_rowsFunction · 0.85
ggml_addFunction · 0.85
ggml_scaleFunction · 0.85

Tested by

no test coverage detected