Skip to content

Commit

Permalink
更新文章
Browse files Browse the repository at this point in the history
  • Loading branch information
ProphetHJK committed Feb 14, 2025
1 parent 95eb2e7 commit 23efead
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 1 deletion.
6 changes: 5 additions & 1 deletion _posts/2025-02-03-deepseek.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ categories: [技术]
tags: [AI, transformer]
---

## 架构

![alt text](/assets/img/2025-02-03-deepseek/image-3.png)

## Multi-Head Latent Attention

主要作用是加速推理。
Expand Down Expand Up @@ -77,7 +81,7 @@ $$
v^{𝐶}_𝑡 =𝑊^{𝑈V}c^{𝐾𝑉}_𝑡,
$$

这里的(1)是将 MHA 的映射和压缩进行了整合,归结为将$h_t$(也就是非 muti-head 的 attention 中的 $k_t$ 或 $v_t$)使用 $𝑊^{𝐷𝐾𝑉}$ 矩阵进行映射+压缩(就是降维,D 就是 down 降维)得到 $c_t$ ($c$ 表示 cache),计算权重时,原表达式中的每个维度中的 $k_t$ 和 $v_t$ 都可以使用每个维度对应的解压参数($𝑊^{𝑈𝐾}$ 和 $𝑊^{𝑈V}$) 和 $c_t$ 运算得到(而且 $c_t$ 是 key 和 value 共用的,cache 的占用空间非常小,如上图所示,就是 1/16)。
这里的(1)是将 MHA 的映射和压缩进行了整合,也就是将$h_t$(也就是非 muti-head 的 attention 中的 $k_t$ 或 $v_t$)使用 $𝑊^{𝐷𝐾𝑉}$ 矩阵进行映射+压缩(就是降维,D 就是 down 降维)得到 $c_t$ ($c$ 表示 cache),计算权重时,原表达式中的每个 head(维度)中的 $k_t$ 和 $v_t$ 都可以使用每个 head 对应的解压参数($𝑊^{𝑈𝐾}$ 和 $𝑊^{𝑈V}$) 和 $c_t$ 运算得到(而且 $c_t$ 是 key 和 value 共用的,cache 的占用空间非常小,如上图所示,就是 1/16)。

我们先不考虑 Positional Encoding,在 cache 命中的情况下可以这样计算:

Expand Down
Loading

0 comments on commit 23efead

Please sign in to comment.