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

Method llm_build_smollm3

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

Source from the content-addressed store, hash-verified

1#include "models.h"
2
3llm_build_smollm3::llm_build_smollm3(const llama_model & model, const llm_graph_params & params) : llm_graph_context(params) {
4 const int64_t n_embd_head = hparams.n_embd_head_v;
5
6 GGML_ASSERT(n_embd_head == hparams.n_embd_head_k);
7 GGML_ASSERT(n_embd_head == hparams.n_rot);
8
9 ggml_tensor * cur;
10 ggml_tensor * inpL;
11
12 inpL = build_inp_embd(model.tok_embd);
13
14 // inp_pos - contains the positions
15 ggml_tensor * inp_pos = build_inp_pos();
16
17 auto * inp_attn = build_attn_inp_kv();
18
19 const float kq_scale = hparams.f_attention_scale == 0.0f ? 1.0f/sqrtf(float(n_embd_head)) : hparams.f_attention_scale;
20
21 ggml_tensor * inp_out_ids = build_inp_out_ids();
22
23 for (int il = 0; il < n_layer; ++il) {
24 ggml_tensor * inpSA = inpL;
25
26 const bool use_rope = (il + 1) % hparams.n_no_rope_layer_step != 0;
27
28 // norm
29 cur = build_norm(inpL,
30 model.layers[il].attn_norm, NULL,
31 LLM_NORM_RMS, il);
32 cb(cur, "attn_norm", il);
33
34 // self-attention
35 {
36 // compute Q and K and RoPE them
37 ggml_tensor * Qcur = build_lora_mm(model.layers[il].wq, cur);
38 cb(Qcur, "Qcur", il);
39 if (model.layers[il].bq) {
40 Qcur = ggml_add(ctx0, Qcur, model.layers[il].bq);
41 cb(Qcur, "Qcur", il);
42 }
43 ggml_tensor * Kcur = build_lora_mm(model.layers[il].wk, cur);
44 cb(Kcur, "Kcur", il);
45 if (model.layers[il].bk) {
46 Kcur = ggml_add(ctx0, Kcur, model.layers[il].bk);
47 cb(Kcur, "Kcur", il);
48 }
49 ggml_tensor * Vcur = build_lora_mm(model.layers[il].wv, cur);
50 cb(Vcur, "Vcur", il);
51 if (model.layers[il].bv) {
52 Vcur = ggml_add(ctx0, Vcur, model.layers[il].bv);
53 cb(Vcur, "Vcur", il);
54 }
55 Qcur = ggml_reshape_3d(ctx0, Qcur, n_embd_head, n_head, n_tokens);
56 Kcur = ggml_reshape_3d(ctx0, Kcur, n_embd_head, n_head_kv, n_tokens);
57 Vcur = ggml_reshape_3d(ctx0, Vcur, n_embd_head, n_head_kv, n_tokens);
58
59 if (use_rope) {
60 Qcur = ggml_rope_ext(

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected