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

Method llm_build_olmo

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

Source from the content-addressed store, hash-verified

1#include "models.h"
2
3llm_build_olmo::llm_build_olmo(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 ggml_tensor * inp_out_ids = build_inp_out_ids();
20
21 for (int il = 0; il < n_layer; ++il) {
22 ggml_tensor * inpSA = inpL;
23
24 // norm
25 cur = build_norm(inpL,
26 NULL, NULL,
27 LLM_NORM, il);
28 cb(cur, "attn_norm", il);
29
30 // self-attention
31 {
32 // compute Q and K and RoPE them
33 ggml_tensor * Qcur = build_lora_mm(model.layers[il].wq, cur);
34 cb(Qcur, "Qcur", il);
35 if (hparams.f_clamp_kqv > 0.0f) {
36 Qcur = ggml_clamp(ctx0, Qcur, -hparams.f_clamp_kqv, hparams.f_clamp_kqv);
37 cb(Qcur, "Qcur", il);
38 }
39 ggml_tensor * Kcur = build_lora_mm(model.layers[il].wk, cur);
40 cb(Kcur, "Kcur", il);
41 if (hparams.f_clamp_kqv > 0.0f) {
42 Kcur = ggml_clamp(ctx0, Kcur, -hparams.f_clamp_kqv, hparams.f_clamp_kqv);
43 cb(Kcur, "Kcur", il);
44 }
45 ggml_tensor * Vcur = build_lora_mm(model.layers[il].wv, cur);
46 cb(Vcur, "Vcur", il);
47 if (hparams.f_clamp_kqv > 0.0f) {
48 Vcur = ggml_clamp(ctx0, Vcur, -hparams.f_clamp_kqv, hparams.f_clamp_kqv);
49 cb(Vcur, "Vcur", il);
50 }
51 Qcur = ggml_reshape_3d(ctx0, Qcur, n_embd_head, n_head, n_tokens);
52 Kcur = ggml_reshape_3d(ctx0, Kcur, n_embd_head, n_head_kv, n_tokens);
53 Vcur = ggml_reshape_3d(ctx0, Vcur, n_embd_head, n_head_kv, n_tokens);
54
55 Qcur = ggml_rope_ext(
56 ctx0, Qcur, inp_pos, nullptr,
57 n_rot, rope_type, n_ctx_orig, freq_base, freq_scale,
58 ext_factor, attn_factor, beta_fast, beta_slow
59 );
60

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected