Files
llm-atlas/research/K3_ATTNRES_SPIKE_PROTOCOL.md

407 lines
14 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# K3 Attention Residuals 局部梯度尖峰与归约敏感性协议
协议 ID:`llm-atlas-k3-attnres-spike-path-v1`
冻结日期:2026-07-30
协议状态:**结果前预注册**
父协议:`llm-atlas-k3-attnres-gradient-scale-v1`
## 0. 研究身份
本轮是 Round 05 的**定向机制追踪**,不是盲发现:
- 已知 depth-32 / Block 的三 seed 平均 layer 21–25 normalized post-MLP
activation-gradient RMS 较高;
- 已知 observationally,MLP mixer latest-source mass 与该梯度谱相关;
- 未知尖峰最早在哪个 block position 出现;
- 未知 mixer 的 softmax/key derivative path 与 learned value coefficients 分别贡献多少;
- 未知更换 raw gradient tensor 的公开 reduction 后,layer 21–25 是否仍构成稳定局部峰。
前置已知结果和相关分析固定在
`research/K3_ATTNRES_SPIKE_SCOPING.md`。任何 Round 06 输出不得被倒写成“事前未知”。
## 1. 允许回答的问题
1. 在同一个缩小 Block AttnRes 模型里,layer 21–25 的相对高值在哪些
attention / MLP 位置已经可见?
2. 在前向完全相同的条件下,对**全部 mixer** 切断 weight / key 导数路径是否降低尖峰?
3. 在前向完全相同的条件下,把**全部 mixer** 的 source value 反向系数改为均匀权重,
是否降低尖峰?
4. element RMS、token-RMS mean / median / p95 是否给出一致的 spike 结论?
5. Round 06 的新增观测是否保持 Round 05 训练状态、BPC 和 post-MLP global RMS exact?
## 2. 明确不回答的问题
- 论文 Figure 5(c) 的未公开 telemetry 定义;
- Kimi K3 2.8T checkpoint 的真实梯度;
- learned mixer 对大模型最终能力的因果收益;
- 改写 backward rule 后重新训练会发生什么;
- 哪个 source 具有可命名的语义;
- 三个 seed 之外的总体显著性或置信区间;
- 同 FLOPs、wall time 或参数量公平性。
## 3. 冻结训练合同
Round 06 不创建新训练任务分布,完整复用 Round 05:
| 字段 | 固定值 |
|---|---|
| architecture | Block AttnRes |
| Transformer depth | 32 |
| aggregation groups | 8 |
| blocks / group | 4 |
| width / heads / FFN | 192 / 6 / 768 |
| context / vocabulary | 256 / byte-256 |
| formal seeds | 2026073001 / 2026073002 / 2026073003 |
| steps / batch | 8,000 / 32 |
| target bytes / formal cell | 65,536,000 |
| optimizer | AdamW |
| peak / min LR | 3e-4 / 3e-5 |
| warmup | 400 |
| weight decay | 0.1 for ndim ≥ 2 |
| betas / epsilon | 0.9, 0.95 / 1e-8 |
| clip | global norm 1.0 |
| forward | CUDA BF16 autocast |
| residual accumulation | explicit FP32 |
| diagnostic CE | fixed 16 × 256 token-mean FP32 CE |
| diagnostic steps | 0 / 100 / 500 / 2,000 / 4,000 / 8,000 |
数据 bytes、training schedule、validation tensor 和 diagnostic tensor hashes 必须与父协议
manifest exact。训练窗口仍由父协议 ID 派生;Round 06 ID 只标识新增 telemetry,不能改变
任一 optimizer input。
## 4. 正式网格与 replay
正式运行:
```text
depth-32 / block / seed-2026073001
depth-32 / block / seed-2026073002
depth-32 / block / seed-2026073003
```
另从初始化完整重跑:
```text
replay / depth-32 / block / seed-2026073001
```
正式三格共处理 196,608,000 target bytes;含 replay 共 262,144,000 bytes。
每格都必须在全新 Python 进程中运行。可并行两个进程,但不能共享 model、optimizer、RNG
或 CUDA graph。性能计时不进入数值复现合同。
## 5. 六个 activation 位置
对每个 Transformer block `l` 捕获:
1. `pre_attention_input`:attention RMSNorm 的输入;Block 中是 attention mixer 输出;
2. `attention_branch_output`:attention projection 输出;
3. `post_attention_state`:attention branch 加入后的 FP32 partial state;
4. `pre_mlp_input`:MLP RMSNorm 的输入;Block 中是独立 MLP mixer 输出;
5. `mlp_branch_output`:MLP down projection 输出;
6. `post_mlp_state`:MLP branch 加入后的 FP32 partial state,即 Round 05 主对象。
每个位置必须有 32 个不同计算节点,shape 为 `[16,256,192]`,梯度全部 present / finite。
跨位置允许计算图语义上的共享来源,但同一位置的 32 个条目不得意外复用同一 storage。
捕获在一次 learned-mode diagnostic forward / backward 中完成;不能把六个位置拆成六次
不同 loss 的 backward:
- `attention_branch_output` / `mlp_branch_output` 在原 module 输出、转成 FP32 residual
之前捕获,保留其实际 autocast dtype;
- `post_attention_state` / `post_mlp_state` 在显式 FP32 residual accumulation 后捕获;
- 所有 `retain_grad()` 只允许出现在 diagnostic `capture=True` 路径;
- 8,000 个 optimizer training steps 必须走父 runner 的原始 `DepthMixer.forward`,
`capture=False`,不得进入 intervention custom autograd;
- 每次 diagnostic / intervention 前后都 `zero_grad(set_to_none=True)`;
- diagnostic 前后 optimizer-state tensor hash 必须 exact。
### 5.1 尖峰可见位置
固定目标集合:
```text
S = layers 21, 22, 23, 24, 25
R = other 27 layers
```
对每个位置和 seed:
```text
spike_contrast = mean(metric[S]) / mean(metric[R])
peak_normalized = max(metric) / mean(metric)
```
主判定**只使用 step 8,000**。若某个位置 `spike_contrast ≥ 1.5` 在 3 / 3 seed
成立,则称“该位置已可见局部峰”。六个位置按上述 forward 顺序报告;第一个满足者只标为
**earliest tensor where the pattern is observed**,禁止写成 origin、injection point 或
“在该算子生成”。其他 diagnostic steps 只展示轨迹,不参与位置判定。若没有位置 3 / 3
达标,结论为 position-mixed。
## 6. 同一 raw gradient tensor 的 reductions
令某层某位置梯度为 `g ∈ R[B,T,D]`,其中 `B=16,T=256,D=192`。
### 6.1 主 sensitivity family
1. `element_rms = sqrt(mean_btd(g²))`
2. `token_rms_mean = mean_bt(sqrt(mean_d(g²)))`
3. `token_rms_median = median_bt(sqrt(mean_d(g²)))`
4. `token_rms_p95 = p95_bt(sqrt(mean_d(g²)))`
这四项都测每 Token 梯度长度的分布,只改变平方根与 Token reduction 的次序/统计量。
median / p95 统一使用排序后的 **Hyndman–Fan Type 7 linear interpolation**:
```text
h = (N - 1) × p
j = floor(h)
q_p = x_sorted[j] + (h - j) × (x_sorted[j + 1] - x_sorted[j])
```
`p=.5/.95`,零基下标;若 `h` 为整数则直接取 `x_sorted[h]`。实现不得依赖 numpy /
torch 版本相关的默认 quantile 方法。
### 6.2 cancellation-sensitive diagnostics
5. `batch_mean_rms = sqrt(mean_td((mean_b g)²))`
6. `token_mean_rms = sqrt(mean_bd((mean_t g)²))`
它们允许正负梯度先抵消,测的是更相干的方向信号,只作探索性诊断,不进入主 robustness
判定。
### 6.3 代数控制
7. `global_l2 = sqrt(sum_btd(g²))`
固定 shape 下它应满足:
```text
global_l2 = element_rms × sqrt(B×T×D)
```
逐层 normalized spectrum、CV、spike contrast 应与 element RMS 在 `1e-6` 内相同。
### 6.4 reduction robustness 闸门
对最终 `post_mlp_state`,每个主 family reduction、每个 seed 必须同时满足:
1. `spike_contrast ≥ 1.5`;
2. 该 reduction 的 top-5 layers 与固定集合 `S` 至少重合 3 层;
3. 与 element RMS 的 32-layer Spearman `ρ ≥ 0.8`。
四种 reductions、三个 seed 全部满足才记为
`robust within the preregistered reduction family`。任何一格失败即为 `mixed`;
全数不满足才记为 `not robust at this threshold`。不添加事后替代阈值。
top-5 固定按 `metric descending, layer index ascending` 排序;Spearman 对并列值使用
average ranks。cancellation-sensitive diagnostics 不得进入本节判定。
## 7. mixer backward-path interventions
三种模式使用完全相同的 learned forward weights 与 model state。intervention 的作用域固定
为**全部 64 个 depth mixers 加最终 output mixer**;不允许结果后只改 layer 21–25 邻域。
因此本节回答的是“全局改写 mixer backward rule 后,固定尖峰指标是否变化”,不是把某个
局部 mixer 宣布为唯一原因。
### 7.1 `learned`
原始 mixer:
```text
w = softmax(qᵀ RMSNorm(sources))
y = Σ w_i source_i
```
反向同时经过 value coefficients 和 softmax / query / key 路径。
### 7.2 `detached_learned`
前向仍用同一 `w`,但 `w` 在反向中 detach:
```text
y = Σ stopgrad(w_i) source_i
```
它保留 learned value coefficients,切断 softmax / query / key 对 source gradient 的路径。
### 7.3 `uniform_value_backward`
使用自定义 autograd:
- 先调用父 runner 原始 `DepthMixer.forward` 得到 `y_parent`;
- custom Function 的 forward 直接返回已经计算出的 `y_parent`,不重算或做
`y + z - z` 式浮点抵消;
- backward 对每个 source 返回 `grad_y / N`;
- 不向 learned weights / query / key 回传。
因此 forward logits、loss、所有 activation 值必须与 `learned` **逐元素 exact**,但 source
value 的 backward coefficient 变为均匀。
`detached_learned` 同样以 custom Function 原样返回 `y_parent`,backward 才按 learned
`w_i` 把 `grad_y` 分配给 source。两种 custom Function 都只允许在 step 0 / 8,000
diagnostic 使用。
这些是**全局 backward-rule sensitivity diagnostics**,不是可训练模型变体,也不声称是
合理部署方案。
## 8. intervention 判定
只在 step 0 和 8,000 运行三模式。
### 8.1 forward identity gate
同 seed / step 三模式必须满足:
- logits tensor SHA-256 exact;
- loss FP32 value exact;
- 六位置 activation tensor hashes exact;
- mixer forward mean / quantile summaries exact。
任一失败,正式结果无效。
learned mode 还必须证明:训练和普通 diagnostic 的每个 mixer output 使用父 runner 数值
路径;custom Function 不得被训练 step 调用。
### 8.2 初始化负控制
step 0 的 mixer query 全为零,learned weights 是均匀分布。三模式的六位置
`element_rms`:
- 32 个 raw values 必须 finite 且严格大于 0;
- raw spectra 的逐层相对差必须 ≤ `1e-6`;
- normalized spectra 最大绝对差必须 ≤ `1e-6`。
失败则说明 intervention 实现没有隔离预期路径。
### 8.3 softmax / key derivative path
最终 `post_mlp_state`,且 reduction 固定为 `element_rms`:
```text
relative_drop_contrast =
(contrast_learned - contrast_detached) / contrast_learned
relative_drop_peak =
(peak_learned - peak_detached) / peak_learned
```
`contrast_learned` 与 `peak_learned` 必须 finite 且 `>1e-30`,否则本格 invalid 并停止
聚合。若两项都 `≥20%` 且 3 / 3 seed 同向,记为:
> 全局切断所有 mixer 的 softmax / query / key source-gradient path,在本阈值下对固定
> 尖峰指标有 material sensitivity。
禁止缩写成“layer 21–25 由 softmax/key path 造成”。
### 8.4 learned value coefficients
用 `detached_learned → uniform_value_backward` 的同一公式,分母也必须 finite 且
`>1e-30`。若 contrast 和 peak 都下降 `≥20%` 且 3 / 3 seed 同向,记为:
> 全部 mixer 的 value backward coefficients 从 learned `w` 改成 `1/N`,在本阈值下
> 对固定尖峰指标有 material sensitivity。
`N` 随 source count 变化;均匀系数不等于各 source 的数值贡献均匀。禁止写成“learned
value weights 是尖峰唯一原因”。
未过阈值只表示本协议没有达到“material”规则,不证明路径贡献为零。seed 或两个指标方向
分裂时统一记为 `mixed`。
## 9. mixer 分布摘要
每个子层 mixer 保存:
- source count;
- source labels;
- 每 source mean / p05 / median / p95;
- entropy mean;
- normalized entropy;
- max source mass;
- latest-source mass;
- group / layer / attention-or-MLP 身份。
相关分析报告 Pearson 与 Spearman,但永远标为 association;只有第 7–8 节的同前向
backward intervention 可以支持路径贡献判断。
不保存可还原语料内容的逐 Token weight arrays。
## 10. 训练等价与复现闸门
每个 formal seed 必须与对应 Round 05 depth-32 / Block raw 结果满足:
- final model-state hash exact;
- final optimizer-state hash exact;
- 六个 validation BPC exact;
- 六个 Round 05 post-MLP element-RMS arrays exact;
- training-history 冻结字段 exact。
此外,step-0 smoke 对六个位置逐一执行同一 loss 的 `×1 / ×2` backward:
- 每层每 reduction 中线性尺度应乘 2 的指标,其比值在 `2±1e-5`;
- normalized spectrum、CV、spike contrast 的绝对差 ≤ `1e-6`;
- shape、dtype、gradient presence / finite 与同位置 storage uniqueness 全部过闸。
普通 diagnostic 与三种 intervention 前后 optimizer-state hash 必须 exact;训练 step
禁止 `capture=True`。
seed-1 replay 还必须与 Round 06 formal seed-1 的以下字段 exact:
- 全部训练等价字段;
- 六位置、七 reductions、三 intervention 的全部数值;
- mixer quantile summaries;
- logits / activation tensor hashes;
- final model / optimizer hashes。
排除:
- run kind / output path;
- wall time / step time;
- peak allocated / reserved memory;
- process / host 瞬时字段。
任一训练等价字段失败,不能聚合机制结果;replay 失败则公开失败并停止网站结论。
## 11. 正式工件
```text
experiments/k3/attnres_spike/
README.md
manifest.json
scope.py
train.py
analyze.py
reproduction.json
results/raw/*.json
research/
K3_ATTNRES_SPIKE_SCOPING.md
K3_ATTNRES_SPIKE_PROTOCOL.md
K3_ATTNRES_SPIKE_AUDIT.md
src/data/
k3-attnres-spike.json
k3-attnres-spike-compact.json
```
网站必须把四种证据身份分开:
- Round 05 已知峰;
- observational mixer association;
- same-forward backward intervention;
- reduction robustness / failure。
## 12. 停止规则
出现以下任一情况立即停止正式聚合:
- 训练 hash 不匹配 Round 05;
- forward identity gate 失败;
- step-0 uniform negative control 失败;
- 六位置 loss×2 或 optimizer isolation gate 失败;
- activation gradient 缺失、非 finite 或 shape 错误;
- replay 数值不 exact;
- 正式 raw 文件缺失或 canonical hash 不闭合。
遇到反结果时不修改集合 `S`、20% 阈值、1.5 contrast、top-5 overlap 或 Spearman 阈值。