pydata: Huiming's learning notes

Keep Looking, Don't Settle

FlashAttention:从 Online Softmax 分块计算到 FlashAttention-4

roadmap

摘要. Attention 是 Transformer 中唯一随序列长度 \(N\) 平方增长的算子。标准实现把 \(N\times N\) 的打分矩阵 \(S\) 与概率矩阵 \(P\) 写回 HBM,慢的不是计算 …

MHA和MLA的KV cache比较

KV cache 比较

Setup

  • Model: L layers, hidden dimension \(d\) = 7168, num_heads \(h\) = 128, head_dim \(d_h\) = 128 (so \(d = h × d_h\), for deepseek V3 like setting)
  • MLA latent dimension: \(d_c\) = 512 (compressed KV latent)
  • Sequence: tokens t₁, t₂, ..., t₁₀₀
  • Assume t₁ to t₉₉ are already cached (prefill done). Now we process t₁₀₀ (decode …

DeepSeek V3 MoE

MLA plot

1. Deepseek MoE 的结构

DeepSeek-V3 的 MoE 架构延续并优化了其特有的 DeepSeekMoE 设计,并引入了 无辅助损失的负载均衡(Auxiliary-loss-free Load Balancing 策略。

1. 整体结构公式 …