Deepseek论文解读:MLA

Multihead Latent Attention (MLA)是Deepseek提出的一种新的attention机制,用于减少推理时的内存瓶颈,同时兼顾性能提升和缓存效率。本文将对MLA的原理、实现和效果进行解读。 Notations Symbol Description $d_h$ dimension of embedding per attention head $d_c$ the KV compression dimension in MLA $d_r^R$ the per-head dimension of the decoupled queries and key in MLA $n_h$ number of attention heads $l$ the transformer layer number $h_t \in \mathbb{R}^{d}$ the attention input of $t$-th token at an attention layer $u_t \in \mathbb{R}^{d}$ the output hidden of $t$-th token at an attention layer 背景 auto-regressive的LLM主要是decoder的架构,基于先前生成的tokens来预测下一个token。生成过程是顺序的,会用到历史token的KV来保证生成的连贯性,直到最大长度或者生成结束符。 每一步的output作为下次input时,需要进行tokenlizer、embedding、MLP投影生成Q,K,V,这时为了避免重复计算,会将KV做cache;但是在常用MHA中,kVcache的大小会随着token长度的增加而增加,导致内存瓶颈。 ...

February 15, 2025 · 2 min