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/节点要传什么。
理论复杂度下降后,不规则访问仍可能输给成熟的 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。
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 再减少每个元素的位数。
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。
固定 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 梯度。
kernel 侧使用 exp-free top-k 和 KV-outer 调度。选中的 KV block 会聚集相关 queries,拼出更饱满的 tensor-core MMA,而非让每个 query 各自随机查找 KV。block 热度高度倾斜时,预调度 chunk 与 two-phase combine 可以减少对原子更新的依赖。
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 更新状态。
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 的选择矩阵
| 维度 | Full | Sparse | Linear / recurrent |
|---|---|---|---|
| 历史语义 | 显式读取全部 token | 显式读取选中 token/block | 读取压缩充分统计,通常不能任意回看单 token |
| decode state | KV 随 n 增长 | 常仍保存 KV;也可压缩 | 固定形状 recurrent state |
| 主要算子 | dense matmul + softmax | index/top-k/gather + sparse matmul | scan/recurrent update + matmul |
| 硬件局部性 | 最好,kernel 成熟 | 依 block 规则性和热度 | decode 好;prefill 需高效 parallel scan |
| 风险 | 百万长度成本 | miss、选择器成本、不规则访问 | 状态压缩的信息损失和训练难度 |
| 2026 代表 | Kimi K2.6 的 MLA 路线 | MiniMax MSA、V4、GLM IndexShare | Qwen3.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 parallel | Q/K/V blocks、softmax 统计或 partial outputs | 序列越长,collective/环形 attention 越重。 |
| Dynamic sparse | index results、远端 selected KV blocks、partial outputs | 热门 block 倾斜、随机远端 gather、负载不均。 |
| Linear/recurrent | prefix state、scan partial state | 状态较小,但 prefill parallel scan 有顺序/合并依赖。 |
| Hybrid | KV + 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 权重。
所以 AttnRes 不直接减少上下文 KV,也不取代 token attention。它改变每个 token 在网络深度上的信息路径,可与 full、sparse 或 linear token attention 组合。
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。
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 融合,并可在多个分支/层插入。
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 的 KV | runtime cache,可淘汰 | 不是模型参数 |
| RAG | 外部文档索引 | 数据库/索引独立更新 | 可以按系统权限更新 |
| Engram | 训练得到的 N-gram embedding table | checkpoint 静态参数 | 推理时不是通用写接口 |
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 的凸组合:
实现可以用 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 会成为参数化限制。
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 请求的数据路径
- scheduler 识别 prefix hit,并为 KV pages、compressed cache 或 recurrent state 建立 session。
- tokenizer 产生 N-gram 地址;若模型含 Engram,异步从 host 预取将来层需要的 rows。
- full layers 读取全部/压缩 KV;sparse layers 运行 index/top-k 后 gather;linear layers更新 recurrent state。
- MoE 通过 expert parallel all-to-all 发送 token;attention/context-parallel 网络流量可能同时争用链路。
- 若使用 AttnRes,pipeline stages 还要缓存/传递 block summaries;mHC-Lite 则在本层混合 residual streams。
- 工具调用暂停 decode。KV/recurrent/index state 必须作为同一 session 原子迁移或回收;Engram table 不随用户 session 复制。
新算法若要进入生产,还需给出 state format、kernel、scheduler hook 和 distributed protocol。模型公式本身无法覆盖这些实现条件。
22. 最小复现与系统验证
- Full/sparse/linear 在相同模型宽度、context、precision、batch 和硬件下比较,分开记录 FLOPs 与 HBM bytes。
- Sparse attention 记录 index/top-k/gather/main-kernel 时间、selected-block 热度和 recall/质量。
- Linear attention 记录 recurrent state bytes、prefill scan、decode update 和 prefix restore 正确性。
- AttnRes 分别测 full/block 版本的 activation memory、pipeline bytes、两阶段计算开销和质量。
- Engram 测 host/HBM table placement、prefetch hit、随机 lookup latency、冲突与 gate,不只测 table 参数量。
- mHC-Lite 检查每个 token 的 row/column sums、gradient norm、native-op throughput,并保留小规模证据边界。
- 组合模型额外测网络争用、abort/retry、prefix hit 和跨 worker state migration。
23. 一手来源
| 来源 | 本页使用内容 |
|---|---|
| FlashAttention | IO-aware exact full-attention kernel 的基础参照。 |
| Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention | kernel feature map、递推 state 与 linear attention 基础公式。 |
| Qwen3.5 官方模型卡 | 2026 Gated DeltaNet/Gated Attention hybrid layout、KV heads 和上下文。 |
| MiniMax Sparse Attention;官方 kernel | Index/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 Lookup;DeepSeek 官方 Engram 仓库 | N-gram lookup、27B memory、指标、host prefetch 与 demo 边界。 |
| mHC-Lite;作者代码 | permutation convex combination、SK 限制、实验规模与吞吐边界。 |
| 相关文章索引 | 只提供原文标题和入口;本页未复制其正文。 |