1. 五个名词其实分属三条轴

机制作用轴改变什么不自动改变什么
Full / Sparse / Linear attention序列轴当前 token 如何读取历史 token 或递推状态不决定 MoE expert、残差流或外部工具。
Attention Residuals深度轴当前层如何选择此前层/块的表示不等同于缩短上下文 KV。
Engram静态记忆轴用 token N-gram 的确定地址查 learned table不是会话可写 memory、RAG 或 prefix KV。
mHC / mHC-Lite残差流轴多路 residual streams 如何稳定混合不是 token 稀疏 attention。
MoE条件计算轴当前 token 激活哪些 experts不决定是否保留完整历史。

这些机制可以叠加在同一层。Engram 查询静态局部模式,sparse attention 读取长历史,MoE 完成条件计算,多流 residual matrix 再混合不同深度的信息。系统仍要为每条轴分别追踪状态与通信。

2. 统一账本:计算、状态、访问和通信

判断一个新机制能否加速 serving,至少要回答四个问题:每 token 有多少算术操作;要保留多少动态状态;每步实际从哪一级内存读取多少字节;跨 GPU/节点要传什么。

端到端时间不是 FLOPs 的同义词: T ≈ max(T_compute, T_HBM, T_network) + T_launch + T_schedule 状态也不只有 KV: state = KV / compressed KV / recurrent matrix + sparse index + residual-block cache + static memory rows + MoE routing buffers

理论复杂度下降后,不规则访问仍可能输给成熟的 dense kernel;状态即便更小,若每步都需要远端随机 lookup,收益也可能被网络延迟吃掉。2026 年的实现越来越依赖算法与 kernel/allocator 协同设计,单改复杂度公式并不足够。

3. Full attention:精确语义和成熟 dense kernel

causal full attention 让位置 i 读取所有 j ≤ i 的 K/V。Prefill 形成下三角 score matrix,decode 只有一个或少量 query,却要读取整个历史 cache。

Q = XWq, K = XWk, V = XWv A = softmax(QK^T / sqrt(d) + causal_mask) Y = AV prefill score compute/memory pattern 随 n² 增长; decode 每新 token 的 KV 读取随 n 增长。

FlashAttention 通过 tile、online softmax 和片上重用减少 HBM 读写,输出仍是精确 attention,不是稀疏近似。full attention 的优势是连续 dense GEMM、语义直接和 kernel 成熟;代价是一百万 token 时计算和 KV 读取无法只靠 IO 优化消除。

4. GQA、MLA 与量化:优化 full attention 的状态宽度

Grouped Query Attention 让多个 query heads 共享较少 KV heads,KV bytes 按 KV head 数下降。MLA 把历史状态压到 latent representation,并在 attention 路径中恢复需要的表示。KV quantization 再减少每个元素的位数。

普通 KV 容量近似: 2 × layers × tokens × kv_heads × head_dim × bytes/element GQA 减少 kv_heads;MLA 减少所存 latent width; 量化减少 bytes/element。 它们降低容量,不改变 full scan 随 history length 增长的事实。

Kimi K2.6 的官方结构使用 MLA;Qwen3.5 保留的 Gated Attention 层使用 32 Q heads、2 KV heads。二者都说明“full attention”内部也有重要状态优化,不能只按传统 MHA 公式估算。

5. Sparse attention:先选位置,再做精确局部 attention

稀疏 attention 可用固定 sliding window/global token,也可由 indexer 动态选择 blocks。通用的两阶段数据流是:轻量路径为全部或压缩历史打分,选 top-k;主路径 gather 被选 K/V,再运行 exact attention。

I_i = TopK(Index(q_i, history), k) y_i = softmax(q_i K[I_i]^T / sqrt(d)) V[I_i] 若 k 固定,主 attention FLOPs 可不随完整 n 线性增长; 但 index 扫描、top-k、gather 和 miss 风险仍存在。

固定 block 稀疏最容易形成规整 kernel;token 级动态稀疏理论 FLOPs 更少,却可能产生随机 HBM 访问和低 tensor-core 利用率。稀疏机制也常继续存储完整 K/V,只减少读取集合,因此 KV capacity 与 attention compute 必须分别测。

6. MiniMax MSA:2026 的 block-sparse + kernel 共设计

MiniMax Sparse Attention 基于 GQA。每个 query、每个 GQA group 由轻量 Index Branch 为 KV blocks 打分并独立选 top-k,local block 无论分数都包含;Main Branch 只对选中 blocks 做精确 sparse attention。训练用 KL loss 对齐 index distribution 与 group-averaged main distribution,并对 Main Branch 脱开 Index Branch 梯度。

MiniMax Sparse Attention 论文中 Index Branch、Top-K KV blocks、Main Branch 与 attention mask 的结构图
原始/官方结构图:MiniMax Sparse Attention, Figure 1。Index Branch 以 block max pooling 和 score 选择 top-k KV blocks,Main Branch 对选中 block 做精确 sparse attention,右侧给出不同 query group 的 mask;它说明 MSA 的模型与 kernel-facing 稀疏形状,不等于其他动态 sparse attention 的选择器或缓存格式。

kernel 侧使用 exp-free top-k 和 KV-outer 调度。选中的 KV block 会聚集相关 queries,拼出更饱满的 tensor-core MMA,而非让每个 query 各自随机查找 KV。block 热度高度倾斜时,预调度 chunk 与 two-phase combine 可以减少对原子更新的依赖。

论文测量:109B MoE、3T-token training budget 的实验中,MSA 在 1M 上相对 GQA 报告 28.4× attention compute reduction;配套 kernel 在 H800 报告 14.2× prefill、7.6× decode wall-clock speedup。它们不是整个 MiniMax M3 服务的无条件倍数。

7. 其他 2026 sparse 路线:压缩历史和共享索引

DeepSeek-V4 不只从原始 KV blocks 中 top-k:它组合较细粒度 c4a 压缩、128:1 的 c128a 全局压缩与 128-token local window,并共享 K/V、用 inverse RoPE 修正位置语义。因此既改变存储形状,也改变访问集合。

GLM-5.2 的 IndexShare 让每四个 sparse-attention layers 共享一个轻量 indexer,减少跨层重复索引,但各层仍使用自己的 Q/K/V 表示。共享 index buffer 需要与 prefix、position 和模型 revision 一致。

这三种路线不能只按“稀疏率”排名:MSA 重点是规整 block selection 与 kernel;V4 同时压缩 KV;IndexShare 重点是跨层摊薄索引税。它们分别改变 allocator、prefix cache 和 PD transfer。

8. Linear attention:用递推充分统计替代完整历史

kernelized linear attention 用 feature map phi 把 attention 的结合顺序重排,使历史被累积到固定形状状态,而不是保留每个 token 的显式 K/V。因果版本按 token 更新状态。

S_t = S_(t-1) + phi(k_t) v_t^T z_t = z_(t-1) + phi(k_t) y_t = phi(q_t)^T S_t / (phi(q_t)^T z_t) decode state 不随 token 数线性增长; state 大小通常随 feature/head dimensions 增长。

Delta-rule 系列会削弱或改写与当前 key 相关的旧状态,再写入新 value,gating 决定保留与更新比例。相比简单求和,这种更新更有表达力,也需要专用 recurrent/scan kernel 和精确数值处理。

9. Qwen3.5:2026 hybrid linear/full 的具体例子

Qwen3.5-397B-A17B 的 60 层按 15 组排列,每组 3 层 Gated DeltaNet + 1 层 Gated Attention。它让大多数层使用固定递推状态,同时周期性保留 full attention 读取精确 token history;因此在效率和精确检索之间做结构性折中。

这要求 runtime 维护两类 state,并在 prefix hit、abort、PD transfer 和 checkpoint restore 时保持同一 token 边界。不能只用“线性 attention 没有 KV”描述整个 Qwen3.5。

10. Full、Sparse、Linear 的选择矩阵

维度FullSparseLinear / recurrent
历史语义显式读取全部 token显式读取选中 token/block读取压缩充分统计,通常不能任意回看单 token
decode stateKV 随 n 增长常仍保存 KV;也可压缩固定形状 recurrent state
主要算子dense matmul + softmaxindex/top-k/gather + sparse matmulscan/recurrent update + matmul
硬件局部性最好,kernel 成熟依 block 规则性和热度decode 好;prefill 需高效 parallel scan
风险百万长度成本miss、选择器成本、不规则访问状态压缩的信息损失和训练难度
2026 代表Kimi K2.6 的 MLA 路线MiniMax MSA、V4、GLM IndexShareQwen3.5 Gated DeltaNet 层

实际前沿模型越来越多采用混合结构:full 提供精确纠偏,sparse 提供长程检索,linear 提供固定状态。选择单位应是“层组合 + runtime”,不是单个 attention 名称。

11. KV cache、prefix reuse 与可编辑性

full/sparse attention 的 KV 可以按 token page 分配,prefix cache 通过共享相同 token prefix 的 pages 复用。压缩 attention 还要保存 compressor boundary 和 index state。linear attention 只需保存 prefix 结束时的 recurrent state,但这个 state 是此前所有 token 的聚合;修改中间 token 后通常需要从修改点重算,不能像数据库记录一样局部替换。

prefix key 不能只包含文本字符串,还应绑定 tokenizer/model revision、position scheme、模态 processor 和 state format。混合模型的一次 prefix hit 必须同时命中 KV pages 与 recurrent states,否则会产生难以检测的语义错配。

12. 通信:三种 attention 把流量放到不同地方

结构典型跨设备数据通信风险
Full + context parallelQ/K/V blocks、softmax 统计或 partial outputs序列越长,collective/环形 attention 越重。
Dynamic sparseindex results、远端 selected KV blocks、partial outputs热门 block 倾斜、随机远端 gather、负载不均。
Linear/recurrentprefix state、scan partial state状态较小,但 prefill parallel scan 有顺序/合并依赖。
HybridKV + recurrent state 一起迁移PD protocol、版本与 token boundary 更复杂。

MoE all-to-all 与 attention 通信还会叠加。若 sparse gather 和 expert dispatch 同时占用网络,单独 benchmark 两个 kernel 都快,端到端仍可能争用 NVLink/IB。调度器应按实际 bytes 和拓扑放置 KV blocks 与 experts。

13. Kimi Attention Residuals:这是深度 attention

PreNorm residual 通常让每层输出以固定系数 1 累加,深度增加后 hidden magnitude 可能增长,较早层贡献被统一累积稀释。Attention Residuals(AttnRes)让当前层根据输入内容,对此前层输出学习 softmax 权重。

标准 residual 的抽象: x_l = x_0 + sum from j<l of F_j(x_j) Full AttnRes 的抽象: alpha_(l,j) = softmax_j(score(q_l, k_j)) x_l = sum from j<l of alpha_(l,j) v_j j 是 layer/depth index,不是 token position。

所以 AttnRes 不直接减少上下文 KV,也不取代 token attention。它改变每个 token 在网络深度上的信息路径,可与 full、sparse 或 linear token attention 组合。

Attention Residuals 论文中标准 residual、Full AttnRes 与 Block AttnRes 的对比结构图
原始/官方结构图:Attention Residuals, Figure 1(官方 实现仓库的 overview 原图)。左、中、右依次对比固定加法 residual、跨前序 sublayer 的 Full AttnRes,以及按 block 汇总后再做深度路由的 Block AttnRes;它描述模型深度上的信息聚合,不是 token-level sparse attention,也不是已公开的 Kimi K2.6 checkpoint 图。

14. Block AttnRes:为何必须和 pipeline 通信一起设计

Full AttnRes 需要保留并访问所有此前层输出,论文指出会引入训练 memory 与 pipeline communication overhead。Block AttnRes 把层分组,只对 block-level representations 做深度 attention,把 memory footprint 从与层数 L 对应的 O(Ld) 降到与 block 数 N 对应的 O(Nd)

论文结合 cache-based pipeline communication 和 two-phase computation,避免每层都跨 stage 重发完整历史。系统含义是 pipeline stage 边界必须传/缓存 block summaries;模型并行 planner 不能再假设每个 stage 只接收前一 stage 的单个 activation。

已证实实验:论文把 AttnRes 集成到 Kimi Linear 48B total / 3B active,并预训练 1.4T tokens,报告所有评测任务均有改善。未证实:这不证明 Kimi K2.6 checkpoint 使用 AttnRes;K2.6 当前模型卡写的是 MLA 架构。

15. DeepSeek Engram:N-gram 的 O(1) 条件查表

Engram 把 local token N-gram 视作静态记忆 key。经过 tokenizer compression 后,用 multi-head hashing 得到多个 table addresses,读取 learned embeddings,再通过 contextualized gating 与当前动态 hidden state 融合,并可在多个分支/层插入。

Conditional Memory 论文中 Deep Sparse Embedding 模块、N-gram hash lookup 与 gate 的结构图
原始/官方结构图:Conditional Memory via Scalable Lookup, Figure 1。Engram 可插入 Transformer block,从压缩后的 suffix N-gram 经多头 hash 查询 embedding table,再通过 concat、线性层与 attention/gate 融入 hidden state。它属于训练得到的条件记忆模块,与 runtime KV cache、RAG 索引和用户可写的会话记忆用途不同。
第 h 个 hash head 的抽象地址: idx_h = Hash_h(token_(t-n+1:t)) mod M_h m_t = Concat_h(Table_h[idx_h]) g_t = sigmoid(W_g [x_t ; m_t]) x'_t = x_t + g_t * Project(m_t) 具体压缩、hash 和多分支定义以论文/官方 demo 为准。

lookup 对 table size 是 O(1),但不是“零成本”:需要计算地址、随机 gather、投影和 gate。哈希冲突由训练和 multi-head 结构吸收,静态 table 存储会随 memory parameters 增长。

16. Engram 不是 KV、RAG 或可写会话记忆

机制key/value 来源生命周期用户能否直接写入
KV cache当前请求每层 activations请求/session 动态增长通过改变 prompt 间接产生
Prefix cache共享 token prefix 的 KVruntime cache,可淘汰不是模型参数
RAG外部文档索引数据库/索引独立更新可以按系统权限更新
Engram训练得到的 N-gram embedding tablecheckpoint 静态参数推理时不是通用写接口

Engram 的 deterministic addressing 让 runtime 在计算到插入层之前预测要读取哪些 rows,因而可从 host memory prefetch,并缓存热门 rows。论文声称在其设置中 offload massive embedding tables 只有可忽略 inference overhead;这依赖地址可提前计算、PCIe/内存带宽、命中率与 pipeline slack,不应外推到所有服务器。

17. Engram 的实验结论和产品边界

论文在 iso-parameter、iso-FLOPs 条件下把 Engram 扩到 27B memory parameters,并报告相对 MoE baseline:MMLU +3.4、CMMLU +4.0、BBH +5.0、ARC-Challenge +3.7、HumanEval +3.0、MATH +2.4;Multi-Query NIAH 从 84.2 提升到 97.0。作者的机制解释是:lookup 承担静态局部重建,让早期层和 attention 更专注全局推理。

这些结果来自论文实验,无法据此断言 DeepSeek-V4、GLM 或 Kimi 产品包含 Engram,也不能推出 27B table 在任意网络上都没有开销。官方仓库只提供核心数据流 demo,并明确使用 mock Attention/MoE/mHC 等标准组件,不是完整 frontier checkpoint 的训练或部署代码。

18. mHC-Lite:从迭代投影改成精确参数化

Hyper-Connections 用动态 residual matrices 混合多路 residual streams;无约束矩阵可能造成深层训练不稳定。mHC 用 20 次左右 Sinkhorn-Knopp row/column normalization,把非负矩阵近似投影到 Birkhoff polytope,也就是 doubly stochastic matrices 集合。

mHC-Lite 根据 Birkhoff-von Neumann theorem,把 doubly stochastic matrix 直接写成 permutation matrices 的凸组合:

w = softmax(a), w_r ≥ 0, sum_r w_r = 1 H_res = sum from r=1 to n! of w_r P_r 每个 P_r 都是 permutation matrix; 因此 H_res 的每行和每列严格为 1,无需 SK 迭代。

实现可以用 native softmax/matrix operations,不需要 20 轮 normalization kernel。它优化的是多 residual streams 的稳定混合,不改变 token attention 或 KV 结构。

19. mHC-Lite 的算子收益与证据限制

有限 SK 迭代既产生 kernel launch/同步,也未必在 ill-conditioned input 上收敛。论文测到约 27.9% 的 SK inputs 有 1/nu ≥ 10^13,并观察到 24 层网络中跨层 residual-matrix product 的列和可偏离 1 达 220%。mHC-Lite 由构造保证 exact doubly stochasticity。

但它的实验规模必须保留:6/12/24 层、约 45M/120M/360M 参数,训练约 1.3B tokens;吞吐实验在单节点 8×A100 80GB 上进行,且 mHC 对照是作者的 PyTorch 重实现,可能低估专用 kernel。n=4 residual streams 时有 24 个 permutation matrices;若 n 增大,n! basis 会成为参数化限制。

产品归属:mHC-Lite 论文作者和代码仓库独立于 DeepSeek 官方 V4 发布。DeepSeek-V4 技术报告明确的是 mHC;没有一手证据时,不能写“V4 已用 mHC-Lite”。

20. 把四种机制放进同一个 Transformer block

这张图说明状态分层:Engram table 是静态模型参数,可 host prefetch;KV/recurrent state 属于 session;MoE dispatch buffer 属于当前 batch;AttnRes block cache 属于一次 forward/backward 的深度表示;mHC-Lite 的小矩阵是 token/层级 residual routing。它们需要不同 allocator、失效策略和通信协议。

21. 一个百万 token Agent 请求的数据路径

  1. scheduler 识别 prefix hit,并为 KV pages、compressed cache 或 recurrent state 建立 session。
  2. tokenizer 产生 N-gram 地址;若模型含 Engram,异步从 host 预取将来层需要的 rows。
  3. full layers 读取全部/压缩 KV;sparse layers 运行 index/top-k 后 gather;linear layers更新 recurrent state。
  4. MoE 通过 expert parallel all-to-all 发送 token;attention/context-parallel 网络流量可能同时争用链路。
  5. 若使用 AttnRes,pipeline stages 还要缓存/传递 block summaries;mHC-Lite 则在本层混合 residual streams。
  6. 工具调用暂停 decode。KV/recurrent/index state 必须作为同一 session 原子迁移或回收;Engram table 不随用户 session 复制。

新算法若要进入生产,还需给出 state format、kernel、scheduler hook 和 distributed protocol。模型公式本身无法覆盖这些实现条件。

22. 最小复现与系统验证

  1. Full/sparse/linear 在相同模型宽度、context、precision、batch 和硬件下比较,分开记录 FLOPs 与 HBM bytes。
  2. Sparse attention 记录 index/top-k/gather/main-kernel 时间、selected-block 热度和 recall/质量。
  3. Linear attention 记录 recurrent state bytes、prefill scan、decode update 和 prefix restore 正确性。
  4. AttnRes 分别测 full/block 版本的 activation memory、pipeline bytes、两阶段计算开销和质量。
  5. Engram 测 host/HBM table placement、prefetch hit、随机 lookup latency、冲突与 gate,不只测 table 参数量。
  6. mHC-Lite 检查每个 token 的 row/column sums、gradient norm、native-op throughput,并保留小规模证据边界。
  7. 组合模型额外测网络争用、abort/retry、prefix hit 和跨 worker state migration。
不可接受的验证:只算理论复杂度、只跑短序列、或只复现论文小模型,都不能证明百万 context、跨节点 Agent serving 的端到端收益。

23. 一手来源

来源本页使用内容
FlashAttentionIO-aware exact full-attention kernel 的基础参照。
Transformers are RNNs: Fast Autoregressive Transformers with Linear Attentionkernel feature map、递推 state 与 linear attention 基础公式。
Qwen3.5 官方模型卡2026 Gated DeltaNet/Gated Attention hybrid layout、KV heads 和上下文。
MiniMax Sparse Attention官方 kernelIndex/Main Branch、KL、KV-outer、two-phase combine 与 H800 实验。
DeepSeek-V4 Technical Report压缩/稀疏/局部 attention 与 mHC 的当前产品证据。
GLM-5.2 官方发布IndexShare 与 1M 的 2026 实现背景。
Kimi Team:Attention Residuals官方仓库Full/Block AttnRes、pipeline 方案、48B/3B 与 1.4T-token 实验。
Conditional Memory via Scalable LookupDeepSeek 官方 Engram 仓库N-gram lookup、27B memory、指标、host prefetch 与 demo 边界。
mHC-Lite作者代码permutation convex combination、SK 限制、实验规模与吞吐边界。
相关文章索引只提供原文标题和入口;本页未复制其正文。