| 1744 | } |
| 1745 | |
| 1746 | ggml_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 | |
| 1797 | static std::unique_ptr<llm_graph_input_attn_kv> build_attn_inp_kv_impl( |
| 1798 | ggml_context * ctx0, |
nothing calls this directly
no test coverage detected