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

Method build_attn

subprojects/llama.cpp/src/llama-graph.cpp:1746–1795  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1744}
1745
1746ggml_tensor * llm_graph_context::build_attn(
1747 llm_graph_input_attn_no_cache * inp,
1748 ggml_tensor * wo,
1749 ggml_tensor * wo_b,
1750 ggml_tensor * q_cur,
1751 ggml_tensor * k_cur,
1752 ggml_tensor * v_cur,
1753 ggml_tensor * kq_b,
1754 ggml_tensor * sinks,
1755 ggml_tensor * v_mla,
1756 float kq_scale,
1757 int il) const {
1758 GGML_UNUSED(n_tokens);
1759
1760 // these nodes are added to the graph together so that they are not reordered
1761 // by doing so, the number of splits in the graph is reduced
1762 ggml_build_forward_expand(gf, q_cur);
1763 ggml_build_forward_expand(gf, k_cur);
1764 ggml_build_forward_expand(gf, v_cur);
1765
1766 const bool is_swa = hparams.is_swa(il);
1767
1768 const auto & kq_mask = is_swa ? inp->get_kq_mask_swa() : inp->get_kq_mask();
1769
1770 // [TAG_NO_CACHE_PAD]
1771 // TODO: if ubatch.equal_seqs() == true, we can split the three tensors below into ubatch.n_seqs_unq streams
1772 // but it might not be worth it: https://github.com/ggml-org/llama.cpp/pull/15636
1773 //assert(!ubatch.equal_seqs() || (k_cur->ne[3] == 1 && k_cur->ne[3] == ubatch.n_seqs_unq));
1774
1775 ggml_tensor * q = q_cur;
1776 ggml_tensor * k = k_cur;
1777 ggml_tensor * v = v_cur;
1778
1779 ggml_tensor * cur = build_attn_mha(q, k, v, kq_b, kq_mask, sinks, v_mla, kq_scale, il);
1780 cb(cur, "kqv_out", il);
1781
1782 if (wo) {
1783 cur = build_lora_mm(wo, cur);
1784 }
1785
1786 if (wo_b) {
1787 //cb(cur, "kqv_wo", il);
1788 }
1789
1790 if (wo_b) {
1791 cur = ggml_add(ctx0, cur, wo_b);
1792 }
1793
1794 return cur;
1795}
1796
1797static std::unique_ptr<llm_graph_input_attn_kv> build_attn_inp_kv_impl(
1798 ggml_context * ctx0,

Callers

nothing calls this directly

Calls 15

ggml_addFunction · 0.85
ggml_mul_mat_set_precFunction · 0.85
ggml_view_4dFunction · 0.85
is_swaMethod · 0.80
cpy_kMethod · 0.80
cpy_vMethod · 0.80
get_kMethod · 0.80
get_vMethod · 0.80
get_swaMethod · 0.80
get_k_idxs_swaMethod · 0.80
get_v_idxs_swaMethod · 0.80

Tested by

no test coverage detected