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

Method llm_build_qwen2vl

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

ggml_addFunction · 0.85
ggml_reshape_3dFunction · 0.85
ggml_rope_multiFunction · 0.85
ggml_get_rowsFunction · 0.85

Tested by

no test coverage detected