| 1 | #include "models.h" |
| 2 | |
| 3 | llm_build_qwen3vl::llm_build_qwen3vl(const llama_model & model, const llm_graph_params & params) : llm_graph_context(params) { |
| 4 | const size_t n_deepstack_layers = hparams.n_deepstack_layers; |
| 5 | |
| 6 | const int64_t n_embd = hparams.n_embd; |
| 7 | const int64_t n_embd_head = hparams.n_embd_head_v; |
| 8 | |
| 9 | GGML_ASSERT(n_embd_head == hparams.n_embd_head_k); |
| 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 | int sections[4]; |
| 18 | std::copy(std::begin(hparams.rope_sections), std::begin(hparams.rope_sections) + 4, sections); |
| 19 | |
| 20 | // inp_pos - contains the positions |
| 21 | ggml_tensor * inp_pos = build_inp_pos(); |
| 22 | |
| 23 | auto * inp_attn = build_attn_inp_kv(); |
| 24 | |
| 25 | ggml_tensor * inp_out_ids = build_inp_out_ids(); |
| 26 | |
| 27 | for (int il = 0; il < n_layer; ++il) { |
| 28 | ggml_tensor * inpSA = inpL; |
| 29 | |
| 30 | // norm |
| 31 | cur = build_norm(inpL, |
| 32 | model.layers[il].attn_norm, NULL, |
| 33 | LLM_NORM_RMS, il); |
| 34 | cb(cur, "attn_norm", il); |
| 35 | |
| 36 | // self-attention |
| 37 | { |
| 38 | // compute Q and K and RoPE them |
| 39 | ggml_tensor * Qcur = build_lora_mm(model.layers[il].wq, cur); |
| 40 | cb(Qcur, "Qcur", il); |
| 41 | |
| 42 | ggml_tensor * Kcur = build_lora_mm(model.layers[il].wk, cur); |
| 43 | cb(Kcur, "Kcur", il); |
| 44 | |
| 45 | ggml_tensor * Vcur = build_lora_mm(model.layers[il].wv, cur); |
| 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 = build_norm(Qcur, model.layers[il].attn_q_norm, NULL, LLM_NORM_RMS, il); |
| 53 | cb(Qcur, "Qcur_normed", il); |
| 54 | |
| 55 | Qcur = ggml_rope_multi( |
| 56 | ctx0, Qcur, inp_pos, nullptr, |
| 57 | n_rot, sections, rope_type, n_ctx_orig, freq_base, freq_scale, |
| 58 | ext_factor, attn_factor, beta_fast, beta_slow |
| 59 | ); |
| 60 |
nothing calls this directly
no test coverage detected