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

Method llm_build_exaone4

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

Source from the content-addressed store, hash-verified

3
4template <bool iswa>
5llm_build_exaone4<iswa>::llm_build_exaone4(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_k;
8
9 GGML_ASSERT(n_embd_head == hparams.n_embd_head_v);
10 GGML_ASSERT(n_embd_head == hparams.n_rot);
11
12 ggml_tensor * cur;
13 ggml_tensor * inpL;
14
15 inpL = build_inp_embd(model.tok_embd);
16
17 // inp_pos - contains the positions
18 ggml_tensor * inp_pos = build_inp_pos();
19
20 using inp_attn_type = std::conditional_t<iswa, llm_graph_input_attn_kv_iswa, llm_graph_input_attn_kv>;
21 inp_attn_type * inp_attn = nullptr;
22
23 if constexpr (iswa) {
24 inp_attn = build_attn_inp_kv_iswa();
25 } else {
26 inp_attn = build_attn_inp_kv();
27 }
28 ggml_tensor * inp_out_ids = build_inp_out_ids();
29
30 for (int il = 0; il < n_layer; ++il) {
31 ggml_tensor * inpSA = inpL;
32
33 // use RoPE for SWA layers or non-SWA models
34 const bool use_rope = hparams.is_swa(il) || hparams.swa_type == LLAMA_SWA_TYPE_NONE;
35
36 cur = inpL;
37
38 // self-attention
39 {
40 ggml_tensor * rope_factors = model.get_rope_factors(cparams, il);
41
42 ggml_tensor * Qcur = build_lora_mm(model.layers[il].wq, cur);
43 cb(Qcur, "Qcur", il);
44
45 ggml_tensor * Kcur = build_lora_mm(model.layers[il].wk, cur);
46 cb(Kcur, "Kcur", il);
47
48 ggml_tensor * Vcur = build_lora_mm(model.layers[il].wv, cur);
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 = build_norm(Qcur, model.layers[il].attn_q_norm, NULL, LLM_NORM_RMS, il);
56 Kcur = build_norm(Kcur, model.layers[il].attn_k_norm, NULL, LLM_NORM_RMS, il);
57 cb(Qcur, "Qcur_normed", il);
58 cb(Kcur, "Kcur_normed", il);
59
60 if (use_rope) {
61 Qcur = ggml_rope_ext(ctx0, Qcur, inp_pos, rope_factors, n_rot, rope_type, n_ctx_orig, freq_base,
62 freq_scale, ext_factor, attn_factor, beta_fast, beta_slow);

Callers

nothing calls this directly

Calls 7

ggml_reshape_3dFunction · 0.85
ggml_rope_extFunction · 0.85
ggml_get_rowsFunction · 0.85
ggml_addFunction · 0.85
is_swaMethod · 0.80
get_rope_factorsMethod · 0.80

Tested by

no test coverage detected