From c21af182fb7b1e1c1ab91fd1ef4b0bd7deb5773c Mon Sep 17 00:00:00 2001 From: wuyang <5700876+banisherwy@user.noreply.gitee.com> Date: Wed, 29 Jul 2026 04:02:56 +0800 Subject: [PATCH] feat: publish numerics and optimization chapter --- PROGRESS.md | 18 +- README.md | 4 +- ROADMAP.md | 7 +- package.json | 3 +- research/NUMERICS_GROK_LEADS.md | 210 +++ research/NUMERICS_RESEARCH.md | 1097 +++++++++++++++ scripts/check-data-browser.mjs | 10 +- scripts/check-moe-browser.mjs | 2 +- scripts/check-numerics-browser.mjs | 292 ++++ scripts/check-reasoning-browser.mjs | 2 +- scripts/check-scaling-browser.mjs | 8 +- scripts/check-training-systems-browser.mjs | 2 +- src/components/NumericsLab.astro | 1214 +++++++++++++++++ src/components/SiteHeader.astro | 1 + src/data/chapters.ts | 10 +- src/data/papers.ts | 176 ++- src/pages/index.astro | 32 +- src/pages/progress/index.astro | 15 +- src/pages/systems/numerics/index.astro | 1426 ++++++++++++++++++++ 19 files changed, 4495 insertions(+), 34 deletions(-) create mode 100644 research/NUMERICS_GROK_LEADS.md create mode 100644 research/NUMERICS_RESEARCH.md create mode 100644 scripts/check-numerics-browser.mjs create mode 100644 src/components/NumericsLab.astro create mode 100644 src/pages/systems/numerics/index.astro diff --git a/PROGRESS.md b/PROGRESS.md index e555671..f106996 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -17,6 +17,7 @@ | 稀疏计算与 MoE | 完成首版 | 74% | 真实负载 traces 与专家特化案例 | | 长上下文专题 | 完成首版 | 72% | 真实模型配置、内核细节与失败案例 | | 大规模训练系统 | 完成首版 | 71% | 真实集群 traces、故障案例与精确 topology 配置 | +| 数值精度、优化器与稳定性 | 完成首版 | 75% | 真实 kernel 吞吐、长程训练 traces 与逐图论文精读 | | 引用与事实检查 | 进行中 | 57% | 自动化外链复查与来源等级扩展 | | 开源仓库 | 已完成首版 | 100% | 持续提交研究与网站迭代 | | k1412 部署 | 已完成首版 | 100% | 每轮发布保留不可变镜像与回滚点 | @@ -30,10 +31,10 @@ - [x] 提炼参考网站的编辑设计语言。 - [x] 确认 `git.k1412.top` 为 Gitea/Forgejo 兼容服务且本机 HTTPS 凭据可用于既有仓库。 - [x] 使用 Grok CLI 检索并形成约 95 篇一手论文的补充路线,主代理已回查关键来源。 -- [x] 完成 202 篇关键论文索引,覆盖 13 个标签专题与 Kimi/DeepSeek 聚光主线。 +- [x] 完成 223 篇关键论文索引,覆盖 14 个标签专题与 Kimi/DeepSeek 聚光主线。 - [x] 完成可检索、可按专题筛选的论文库页面。 -- [x] 完成 K3、Transformer 基础、DeepSeek 谱系、Scaling Laws、数据工程、长上下文、MoE、推理与训练系统九篇首版长文。 -- [x] 完成 K3 三轴架构、Self-Attention、DeepSeek 谱系、长上下文、MoE 路由、推理三页签,以及训练系统、Scaling 与数据工程各四页签等二十个原创交互视图。 +- [x] 完成 K3、Transformer 基础、DeepSeek 谱系、Scaling Laws、数据工程、长上下文、MoE、推理、训练系统与数值优化十篇首版长文。 +- [x] 完成 K3 三轴架构、Self-Attention、DeepSeek 谱系、长上下文、MoE 路由、推理三页签,以及训练系统、Scaling、数据工程与数值专题各四页签等二十四个原创交互视图。 - [x] 完成长上下文首版:五张成本账、26 篇一手论文、10+ 机制图与 8 策略交互实验室。 - [x] 核验 FlashAttention、DeepSeek-V2/V3.2/V4、Kimi Linear/K3 等六份论文原文,并建立长上下文研究账本。 - [x] 核验 Switch、ST-MoE、DeepSeekMoE、Loss-Free、V3、LatentMoE 与 K3 原文,并建立 MoE 研究账本。 @@ -67,12 +68,18 @@ - [x] 对 Scaling、训练系统、推理与 MoE 重新执行全量浏览器回归;13 项桌面 / 移动导航和首页数据新章入口无回归。 - [x] Astro 类型检查、生产构建、13 个页面路由、527 个站内引用和 20 个跨页锚点全部通过。 - [x] 数据工程首版以源提交 `ee0361b`、不可变镜像 `20260728T190932Z-ee0361b` 发布;NAS、VPS/Tailscale、NPM、DNS、HTTPS、证书、13 路由、门户与生产 Chrome 全链路通过。 +- [x] 启动数值精度、优化器与稳定性专题:回查 K2/K3、DeepSeek-V3/V4 原文,并缓存核验 mixed precision、BF16、FP8、MX、QAT、AdamW、μP、Muon 与稳定性论文。 +- [x] 使用 Grok Headless 扩展 40 个候选节点;将错误年份、不可核实新稿和无一手证据结论保留在独立 leads,不进入正式账本。 +- [x] 建立数值专题正式研究账本:十张数值账、格式/量化/优化器/稳定性主线、DeepSeek/Kimi 双谱系、四实验合同与公开未知项。 +- [x] 完成数值专题首版:19 节长文、36 个一手节点、十余组机制图与格式—状态—更新—失稳四联实验。 +- [x] 论文库新增「优化器」标签与 21 个一手节点,从 202 篇扩充至 223 篇。 ## 正在进行 - [ ] Scaling Laws 二轮精读:真实拟合复现、逐篇图表、置信区间、外推失败与更多模型族对照。 - [ ] 数据工程二轮:FineWeb / DCLM / Dolma / ROOTS 逐图精读、真实去重误伤、mixture traces 与污染案例。 - [ ] 大规模训练系统二轮:真实集群 traces、故障恢复案例与精确 topology / kernel 配置。 +- [ ] 数值与稳定性二轮:真实 kernel 吞吐、长程失稳 traces、optimizer / quantization 逐图复现。 - [ ] 推理专题二轮:真实 pass@k 曲线、PRM 失败案例与逐篇图表精读。 - [ ] 长上下文专题的真实模型配置对比、内核细节与失败案例二轮深化。 - [ ] MoE 专题的真实集群 traces、专家特化案例与二轮外部证据。 @@ -114,6 +121,11 @@ | 2026-07-29 | 数据工程首版用四个独立实验闭环 | 文档保留、去重误伤、领域 exposure 与改写课程分开建模,不合成伪“数据质量总分” | | 2026-07-29 | 论文库新增数据标签并扩充到 202 篇 | 新增 CCNet、ROOTS、Dedup、DoReMi、DCLM、WRAP、MATES、MM1、Swallow 等 20 个节点 | | 2026-07-29 | 数据工程首版用不可变镜像 `20260728T190932Z-ee0361b` 发布 | OCI digest `sha256:2fe8f3aa…59c8`;复用 `12010→8080`、NPM host 31 / cert 41、门户 order 180 与公开 Forgejo | +| 2026-07-29 | 数值专题拆成表示、缩放、计算、累加、搬运、更新、参数化、观测、恢复与证据经济十张账 | 防止把一个 dtype 标签误当成完整训练配方 | +| 2026-07-29 | Grok 数值研究包只保留为 `NUMERICS_GROK_LEADS.md` | 40 个候选必须回到论文/官方报告核验;错误元数据和不可核实结论不进入正文 | +| 2026-07-29 | K2/K3 与 DeepSeek-V3/V4 数值谱系显式保留边界 | Per-Head Muon 不替代 QK-Clip;K3 2.5× 不归因单项技巧;V3 失败实验与高精度保留项不省略 | +| 2026-07-29 | 数值首版用四个独立实验闭环 | 格式误差、状态字节、矩阵更新与失稳防线分开建模,不合成伪“效率总分” | +| 2026-07-29 | 论文库新增「优化器」标签并扩充到 223 篇 | 新增 Shampoo、Adafactor、μP、8-bit optimizer、FP8-LM、FP4 training、稳定性代理等 21 个节点 | ## 未决问题 diff --git a/README.md b/README.md index 64c5d38..a890199 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ - 持续进度:[PROGRESS.md](./PROGRESS.md) - 证据与写作规范:[research/METHODOLOGY.md](./research/METHODOLOGY.md) -当前里程碑包含 16 专题学习地图、202 篇关键论文索引、Kimi K3 完整导读、 -Transformer 基础、DeepSeek 技术谱系、Scaling Laws、数据工程、长上下文、MoE、推理与训练系统深度专题, +当前里程碑包含 16 专题学习地图、223 篇关键论文索引、Kimi K3 完整导读、 +Transformer 基础、DeepSeek 技术谱系、Scaling Laws、数据工程、长上下文、MoE、推理、训练系统与数值优化深度专题, 以及覆盖核心机制的原创交互实验室。 其余专题按进度账本持续扩建。 diff --git a/ROADMAP.md b/ROADMAP.md index 61070fc..0340585 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,6 +1,6 @@ # LLM Atlas 总体研究地图 -最后更新:2026-07-28 +最后更新:2026-07-29 ## 组织原则 @@ -63,6 +63,11 @@ Conditional Computation → Sparsely-Gated MoE → GShard/Switch → DeepSeekMoE Adam/AdamW、Adafactor、μP、Muon;FP16/BF16/FP8/MXFP4、量化感知训练、缩放与误差。重点讲 DeepSeek-V3 FP8 与 K3 per-head Muon/MXFP4。 +首版已发布:以“表示、缩放、计算、累加、搬运、更新、参数化、观测、恢复、证据经济”十张账串起 +2014–2026 的 36 个一手节点;重点拆解 Kimi K2 MuonClip、K3 Per-Head Muon / SiTU-GLU / MXFP4 QAT, +以及 DeepSeek-V3 fine-grained FP8 与 V4 hybrid Muon / spike mitigation / FP4 QAT,并提供格式显微镜、 +混合精度状态账、优化器几何与失稳控制室四个独立互动实验。 + ### 10. 指令微调与人类偏好 Instruction Tuning、SFT、RLHF/PPO、RLAIF、Constitutional AI、DPO 及其后续。解释 base model 如何变成可协作助手。 diff --git a/package.json b/package.json index c9c09fe..c40e8c7 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "check:reasoning-browser": "node scripts/check-reasoning-browser.mjs", "check:training-systems-browser": "node scripts/check-training-systems-browser.mjs", "check:scaling-browser": "node scripts/check-scaling-browser.mjs", - "check:data-browser": "node scripts/check-data-browser.mjs" + "check:data-browser": "node scripts/check-data-browser.mjs", + "check:numerics-browser": "node scripts/check-numerics-browser.mjs" }, "dependencies": { "@astrojs/sitemap": "3.7.3", diff --git a/research/NUMERICS_GROK_LEADS.md b/research/NUMERICS_GROK_LEADS.md new file mode 100644 index 0000000..411b1fe --- /dev/null +++ b/research/NUMERICS_GROK_LEADS.md @@ -0,0 +1,210 @@ +# 数值精度、优化器与训练稳定性 · Grok Discovery Leads + +> **未核验候选,不是正式研究账本。** +> +> 2026-07-29 使用本机 Grok CLI Headless 扩展论文召回。Grok 被要求不修改工作区、不调用子代理, +> 只返回原论文、标准与官方技术报告候选。正式结论只进入 `NUMERICS_RESEARCH.md`, +> 且必须由主代理重新打开原文、核对版本、章节、公式、实验设置与限制。 + +--- + +## 1. Grok 建议的三条历史主线 + +### A. 数字怎样在机器里活下来 + +```text +FP32 + → FP16 mixed precision:FP32 master weights + loss scaling + FP32 accumulate + → BF16:保留 FP32 的指数位宽,牺牲尾数精度 + → FP8 E4M3 / E5M2:按 tensor 缩放,计算与累加分层 + → fine-grained / block scaling:让离群值只影响小组 + → MXFP4:32 个 E2M1 元素共享 E8M0 scale + → QAT:训练时显式经历部署量化误差 +``` + +### B. 梯度怎样变成参数更新 + +```text +SGD / Momentum + → Adam:逐元素一阶矩 + 二阶矩 + → AdamW:把 weight decay 从自适应梯度中解耦 + → Adafactor:矩阵行列因子化二阶矩 + → Shampoo:保留张量结构的预条件 + → μP / μTransfer:让超参数跨宽度迁移 + → Muon:对矩阵 momentum 做 Newton–Schulz 正交化 + → scalable Muon:weight decay + update RMS matching + → MuonClip / Per-Head Muon / hybrid Muon–AdamW +``` + +### C. 一次昂贵训练怎样避免突然失控 + +```text +初始化 / warmup / residual scaling + → Pre-LN / DeepNorm + → QK normalization / z-loss / soft-cap + → 小模型高 LR proxy + → attention logit 与 SwiGLU outlier 定位 + → QK-Clip / activation clamp / bounded activation + → 路由、低精度、optimizer state 与集群确定性联合监控 +``` + +这些只是 discovery taxonomy;三条线互相影响,但不能被压缩成一个“稳定性分数”。 + +--- + +## 2. 候选一手来源 + +### 2014–2019:基础格式与自适应优化 + +| 年份 | 候选 | 原始入口 | Grok 给出的检查点 | +|---:|---|---|---| +| 2014 | Adam: A Method for Stochastic Optimization | | Algorithm 1;一阶/二阶矩与 bias correction | +| 2015 | Deep Learning with Limited Numerical Precision | | stochastic rounding 与 16-bit fixed-point | +| 2017 | Mixed Precision Training | | FP32 master weights、loss scaling、FP32 accumulate | +| 2017 | Decoupled Weight Decay Regularization | | L2 与 adaptive optimizer 中 weight decay 不等价 | +| 2017 | Quantization and Training of Neural Networks… | | simulated quantization、fake quant 与 QAT | +| 2018 | Shampoo | | tensor-mode preconditioner 与扩展成本 | +| 2018 | Adafactor | | factored second moment、update clipping | +| 2019 | A Study of BFLOAT16 for Deep Learning Training | | 1-8-7 格式与 FP32 同动态范围 | + +### 2020–2023:QK、μP、FP8、量化与 Microscaling + +| 年份 | 候选 | 原始入口 | Grok 给出的检查点 | +|---:|---|---|---| +| 2020 | GLU Variants Improve Transformer | | SwiGLU 原始定义;未讨论低精度 outlier | +| 2020 | Query-Key Normalization for Transformers | | head 维 L2 norm + learned scale | +| 2021 | 8-bit Optimizers via Block-wise Quantization | | block-wise dynamic quantization 与 stable embedding | +| 2022 | DeepNet: Scaling Transformers to 1,000 Layers | | residual scaling、初始化与 bounded update | +| 2022 | Tensor Programs V / μTransfer | | Maximal Update Parametrization 与跨宽度超参迁移 | +| 2022 | LLM.int8() | | emergent outlier features 与 mixed INT8/FP16 | +| 2022 | FP8 Formats for Deep Learning | | E4M3 / E5M2、缩放与 higher-precision output | +| 2022 | GPTQ | | one-shot weight-only PTQ 与近似二阶补偿 | +| 2022 | SmoothQuant | | 把 activation 难度迁移到 weight 的等价变换 | +| 2023 | Scaling Vision Transformers to 22B | | QK LayerNorm 与大规模 logit explosion | +| 2023 | Stable and low-precision training… | | SwitchBack;Adam 二阶矩低估与 loss spike | +| 2023 | QLoRA | | NF4、double quant、paged optimizer;训练基座仍冻结 | +| 2023 | LLM-QAT | | data-free distillation、W/A/KV QAT | +| 2023 | Small-scale proxies… | | 高 LR 小模型复现大尺度不稳定 | +| 2023 | Microscaling Data Formats | | 32-element block、E8M0 scale、MXFP4 E2M1 | +| 2023 | FP8-LM | | FP8 gradient / communication / optimizer | +| 2023 | Spike No More | | “小 sublayer、大 shortcut”的 Jacobian 视角 | + +### 2024–2026:Muon、长程 FP8 与生产级 FP4 QAT + +| 年份 | 候选 | 原始入口 | Grok 给出的检查点 | +|---:|---|---|---| +| 2024 | Deconstructing What Makes a Good Optimizer… | | Adam/Adafactor/Lion 对照;尺度只到 1.2B | +| 2024 | Scaling FP8 training to trillion-token LLMs | | 200B Token 后 SwiGLU outlier 与 Smooth-SwiGLU | +| 2024 | Methods of improving LLM training stability | | QK norm + soft-cap 的中等规模对照 | +| 2024 | DeepSeek-V3 Technical Report | | tile/block scaling、FP32 promotion、精度保留表 | +| 2024 | Muon: An Optimizer for Hidden Layers… | | 原始技术博文与 Newton–Schulz update | +| 2025 | Muon is Scalable for LLM Training | | weight decay、update RMS matching、Moonlight | +| 2025 | Kimi K2 Technical Report | | MuonClip、QK-Clip、per-head trigger | +| 2025 | FP4 All the Way | | fully quantized FP4 training 与 quantization-noise threshold | +| 2026 | PowLU | | bounded activation 与 loss-spike 对照 | +| 2026 | DeepSeek-V4 | | hybrid Muon、QK RMSNorm、SwiGLU clamp、FP4 QAT | +| 2026 | Kimi K3 | | Per-Head Muon、SiTU-GLU、MXFP4 QAT | + +--- + +## 3. Grok 建议、但首版不直接采用的线索 + +以下候选存在“过新、标题/版本漂移、只有推文或缺少大规模复现”等风险: + +- Pion、NorMuon、Muon+、Newton-Muon 等 2025–2026 Muon 分支; +- “Compositional Muon” 的社交媒体讨论; +- 仅由二手文献转述的某些 SwiGLU-Clip 来源; +- 只有厂商吞吐宣传、没有端到端精度与配方对照的格式页面; +- 把所有 outlier 论文合并成一个统一因果理论的综述式结论。 + +它们可以进入二轮阅读队列,但不得用来证明 K2/K3/V4 的生产实现。 + +--- + +## 4. 候选视觉与互动 + +### 视觉 A:浮点显微镜 + +- 一个值拆成 sign / exponent / mantissa; +- 同时展示 representable range、相邻格点间距、overflow、underflow; +- FP8 视图必须显示 scale,不允许让读者误以为格式单独工作。 + +### 视觉 B:一次 GEMM 的精度流水线 + +```text +BF16 master / activation + → group scale + → FP8 input + → low-precision multiply + → higher-precision partial accumulation + → BF16/FP32 output +``` + +必须区分“存储格式、乘法输入、累加器、输出、master weights、optimizer states”。 + +### 视觉 C:AdamW vs Muon 更新光谱 + +- AdamW:逐坐标二阶矩归一; +- Muon:矩阵 momentum → approximate orthogonalization; +- 显示 singular values,而不是把 Muon 错画成完整 SVD; +- Per-Head Muon 按逻辑独立 head 分块。 + +### 视觉 D:稳定性控制室 + +- attention logits; +- activation max / percentile; +- gradient norm; +- weight / update RMS; +- quantization saturation; +- MoE expert outlier; +- 每条防线标记它干预 forward、backward、optimizer 还是 routing。 + +--- + +## 5. 已由主代理回查并纠正的风险 + +1. **“少一半位数”不自动等于“快两倍”。** + 速度取决于硬件指令、kernel、shape、cast、scale、通信与内存瓶颈。 + +2. **FP8 training 不是“所有 tensor 都是 FP8”。** + DeepSeek-V3 让 GEMM 输入走 FP8,但 attention、normalization、router、master weights、 + accumulated gradients 等关键角色保留 BF16/FP32。 + +3. **MXFP4 不是一个独立标量类型的完整故事。** + 标准格式是 32 个 E2M1 元素共享 E8M0 scale;scale 粒度与轴是语义的一部分。 + +4. **PTQ、QAT 与低精度预训练不是同一件事。** + GPTQ/QLoRA 等只回答部分部署或微调问题,不能证明全程 FP4 预训练可行。 + +5. **Muon 的 `~2×` 是 Moonlight 报告的 scaling-law 作者结果。** + 它不是对所有模型、数据和超参数的普遍定理。 + +6. **K2 的 QK-Clip 与 DeepSeek-V4 的 QK normalization 是结构相关选择。** + K2 报告解释 MLA 中 key 不完全物化带来的约束;V4 的 attention 结构允许直接 RMSNorm。 + +7. **K3 不只是“继续用 MuonClip”。** + 报告同时给出 Per-Head Muon、继承 K2 weight clipping、有界 SiTU-GLU, + 以及在 post-training 全程对专家权重使用 MXFP4 QAT。 + +8. **DeepSeek-V4 确实披露训练中遇到 spike。** + 报告不是“稳定性完美”的宣传,而是公开 Anticipatory Routing 与 SwiGLU clamping 两个经验补丁。 + +9. **稳定性不是只有 loss 一条曲线。** + logits、activation、gradient、weight、update、scale、router 与系统错误需要分别监控。 + +--- + +## 6. 从候选晋级正式账本的门槛 + +每条进入正文的结论至少满足: + +1. 找到论文 / 标准 / 正式报告的一手入口; +2. 核对标题、版本、作者、年份; +3. 定位到支持结论的章节、公式、图或表; +4. 写清 tensor 角色、格式、group 粒度和计算阶段; +5. 写清模型规模、Token 预算、硬件与 baseline; +6. 区分作者报告、课程推导与标准定义; +7. 同时记录失败条件和不可外推范围; +8. 无法公开确认的实现细节明确写为未知。 + +这份文件保留 Grok 的“召回价值”,并永久阻止未核验摘要越过证据门槛。 diff --git a/research/NUMERICS_RESEARCH.md b/research/NUMERICS_RESEARCH.md new file mode 100644 index 0000000..66d84de --- /dev/null +++ b/research/NUMERICS_RESEARCH.md @@ -0,0 +1,1097 @@ +# 数值精度、优化器与训练稳定性研究账本 + +> 状态:第一轮证据框架 +> 研究截止:2026-07-29 +> 课程位置:专题 09「数值精度、优化器与训练稳定性」 +> 锚点:Kimi K2 §2.1 / Appendix D–E、Kimi K3 §2.3 / §2.5 / §3.3 / §4.1.4 / §5.2.2、DeepSeek LLM §2.4、DeepSeek-V3 §3.3 / Appendix B、DeepSeek-V4 §2.4 / §3.4.1 / §4.2.3 / §5.2.1 +> 目标:让读者理解“一个数怎样表示、一次乘法怎样累加、一个梯度怎样变成矩阵更新、一次训练为什么突然崩掉”,并能准确阅读 FP8、MXFP4、Muon、QK-Clip 与 QAT 报告。 +> 原则:P0 原论文 / 正式技术报告 / 开放标准优先;P1 作者实现与技术博文用于定义原始 Muon;Grok 只提供 discovery leads;所有性能数字保留作者报告边界。 + +--- + +## 0. 本章先拆掉五个误区 + +### 误区一:模型用 FP8 训练,就是所有东西都变成 FP8 + +不是。一个训练 step 至少包含: + +```text +参数存储 + → 前向输入 + → 乘法 + → 部分和累加 + → 激活输出 + → 反向激活梯度 + → 权重梯度 + → 跨卡通信 + → optimizer moments + → master weights + → checkpoint +``` + +每个角色可以用不同格式。DeepSeek-V3 的核心 GEMM 输入用 FP8,但 embedding、output head、 +attention、normalization、router 等保留 BF16 / FP32;master weights、累计梯度保留 FP32, +optimizer moments 可用 BF16。把这套“混合角色”写成“全 FP8”会直接误导。 + +### 误区二:位数减半,速度必然翻倍 + +位数变少可以降低: + +- 每个值的存储字节; +- HBM 与互连搬运的字节; +- 某些硬件矩阵单元的面积和能耗; +- 特定芯片上的矩阵乘峰值成本。 + +但端到端速度还取决于: + +- 芯片是否有原生指令; +- shape 是否匹配 Tensor Core; +- quantize / dequantize / scale 的开销; +- 累加是否要频繁 promotion; +- kernel 是否融合; +- 工作负载是 compute-bound 还是 memory / communication-bound; +- 未量化算子占比。 + +因此页面只展示“理论数据量 / 指定硬件能力”,不把它冒充真实训练 speedup。 + +### 误区三:低精度只是“小数不够准” + +低精度至少有三种不同失败: + +1. **Overflow**:绝对值超过最大可表示范围,变成饱和、Inf 或 NaN; +2. **Underflow**:太小的值变成 subnormal 或 0; +3. **Rounding noise**:仍在范围内,但落到相邻格点,细小更新被吞掉。 + +Exponent 位主要决定“能装多大 / 多小”,mantissa 位主要决定“同一数量级内能分多细”。 +scale 可以移动可表示窗口,却不能凭空增加格点数量。 + +### 误区四:优化器稳定,模型就稳定 + +一次 loss spike 可能来自: + +- attention logits; +- residual / layer depth; +- SwiGLU 乘法 outlier; +- Adam 二阶矩滞后; +- Muon update spectrum; +- MoE router 与 expert outlier 的反馈; +- 低精度 scale / accumulator; +- 数据异常; +- kernel / collective / hardware 错误。 + +优化器只是一层。K3 同时用 Per-Head Muon、weight clipping、RMSNorm、SiTU-GLU; +DeepSeek-V4 同时用 hybrid Muon、QK RMSNorm、SwiGLU clamping、Anticipatory Routing 和确定性 kernel。 + +### 误区五:PTQ、QAT、低精度微调、低精度预训练是一回事 + +| 范畴 | 什么时候量化 | 参数是否继续学 | 主要目标 | +|---|---|---|---| +| PTQ | 完成训练后 | 通常不做全模型训练 | 快速压缩部署 | +| QAT | 训练 / 微调时模拟或执行量化 | 是 | 让模型适应量化误差 | +| QLoRA 类 | 基座 4-bit 存储,adapter 训练 | 基座通常冻结 | 降低微调显存 | +| 低精度预训练 | 从头或长程训练中低精度计算 | 是 | 降低训练计算 / 通信 / 激活成本 | +| Fully quantized training | W/A/G 等广泛低精度 | 是 | 把训练本身推进到极低位 | + +一句话总纲: + +> 数值工程不是选一个 dtype;它是在一条完整训练与部署数据流里,为每种 tensor 角色分配范围、精度、存储、计算与恢复防线。 + +--- + +## 1. 十张不能混在一起的账 + +| 账本 | 核心问题 | 最小字段 | 常见误读 | +|---|---|---|---| +| N1 表示 | 一个 bit pattern 代表什么值 | sign / exponent / mantissa、subnormal、NaN/Inf | 只比较 bit 数 | +| N2 缩放 | 可表示窗口怎样移动 | per-tensor / channel / token / tile / block、scale dtype、axis | 把 block scale 当无成本 | +| N3 计算 | 哪些算子真正用低精度乘法 | operator、input dtype、hardware instruction | “模型 FP8”=所有算子 FP8 | +| N4 累加 | 小乘积在哪里、以多少位求和 | accumulator、promotion interval、reduction tree | 只看输入 dtype | +| N5 存储与通信 | 哪些 tensor 以低精度缓存 / 发送 | activation、gradient、optimizer state、KV、checkpoint | 计算快=显存也同比下降 | +| N6 更新 | 梯度如何变成参数更新 | momentum、preconditioner、update RMS、weight decay | AdamW 与 Muon 只是不同公式名 | +| N7 参数化 | 宽度、深度、head 如何改变更新尺度 | init、μP、logical matrix、head partition | 小模型超参直接复制 | +| N8 稳定性 | 哪个可观测量先异常 | max / percentile / norm / spectrum / saturation | 只看 loss | +| N9 恢复 | 异常时怎样止损和复现 | detect、skip、clip、rollback、determinism、checkpoint | rollback 等于解决根因 | +| N10 证据与经济 | 增益对什么基线、硬件与预算成立 | model、Token、hardware、quality、wall-clock、energy | 作者峰值吞吐外推到所有系统 | + +--- + +## 2. 浮点数显微镜 + +### 2.1 三个字段 + +典型二进制浮点数可写成: + +```text +(-1)^sign × significand × 2^exponent +``` + +- sign:正负; +- exponent:数量级; +- mantissa / fraction:同一数量级中的细分; +- normal 数通常有隐含 leading 1; +- subnormal 用更少有效位换取逐渐下溢; +- 特殊编码可用于 ±0、Inf、NaN。 + +### 2.2 常见格式对照 + +| 格式 | 位布局 | 约最大有限值 | 最小 normal | 单位附近间距 | 直觉 | +|---|---:|---:|---:|---:|---| +| FP32 | 1 / 8 / 23 | 3.4e38 | 1.18e-38 | 1.19e-7 | 范围和精度都宽,成本高 | +| FP16 | 1 / 5 / 10 | 65,504 | 6.10e-5 | 9.77e-4 | 尾数较细,范围明显窄 | +| BF16 | 1 / 8 / 7 | 3.4e38 | 1.18e-38 | 7.81e-3 | 保留 FP32 范围,牺牲细度 | +| FP8 E4M3 | 1 / 4 / 3 | 448 | 1.56e-2 | 1.25e-1 | 更精细,范围较窄 | +| FP8 E5M2 | 1 / 5 / 2 | 57,344 | 6.10e-5 | 2.5e-1 | 范围更宽,格点更粗 | +| MXFP4 | block scale + E2M1 element | 取决于共享 scale | 取决于共享 scale | 极粗 | 用局部共享尺度补偿 4-bit 元素 | + +注意: + +- “单位附近间距”是教学用 machine epsilon 直觉,不等于全数轴统一误差; +- E4M3 / E5M2 数字按 FP8 Formats 论文定义; +- MXFP4 必须连同 block size、scale dtype 与 axis 一起描述。 + +### 2.3 为什么 BF16 比 FP16 更适合大模型训练 + +Kalamkar et al. 2019: + +- BF16 与 FP32 都用 8-bit exponent,因此动态范围相近; +- BF16 尾数只有 7 bits,因此细节精度低于 FP16; +- 论文在多种工作负载上报告无需 FP16 那样的 loss-scaling 调参即可匹配 FP32。 + +不能外推成: + +- BF16 永不 overflow; +- BF16 所有算子都足够准确; +- optimizer state / gradient accumulation 可随意降到 BF16。 + +DeepSeek LLM 的公开做法正体现边界:主训练 BF16,但梯度在 FP32 累加; +cross entropy kernel 按需把 BF16 logits 转 FP32。 + +### 2.4 Rounding 不是无害格式转换 + +确定性 round-to-nearest: + +- 可重复; +- 很小的同方向更新可能反复变 0。 + +stochastic rounding: + +- 按相邻格点距离随机选择; +- 期望上可以保持无偏; +- 会引入随机性与实现成本; +- 对低精度梯度同步 / update 尤其重要。 + +Gupta et al. 2015 在 16-bit fixed-point 训练中展示 stochastic rounding 的关键作用; +DeepSeek-V4 在把 MoE gradient 通信量化到 BF16 时明确使用 stochastic rounding, +再在本地 FP32 求和,避免低精度 collective 累加误差。 + +--- + +## 3. 从 FP16 mixed precision 到 FP8 / MXFP4 + +### 3.1 2017:mixed precision 三件套 + +Micikevicius et al. 2017/2018 §3: + +1. **FP32 master weights** + forward / backward 使用 FP16 copy;真正累积小 update 的 master copy 保留 FP32。 + +2. **Loss scaling** + 放大 loss,使反向小梯度进入 FP16 可表示范围;更新前再 unscale。 + +3. **FP32 accumulation** + FP16 乘积在 FP32 输出中累加,再按需要写回较低精度。 + +关键边界: + +- FP16 小于 `2^-24` 的值会变 0; +- scale 太大又会 overflow; +- overflow 后更新权重会产生不可逆 NaN,因此动态 loss scaling 会检测并跳过 step; +- “乘法输入低精度、累加高精度”从一开始就是核心,而不是后来补丁。 + +### 3.2 2022:FP8 是两个格式,不是一个 + +FP8 Formats for Deep Learning: + +- E4M3:4 exponent + 3 mantissa,推荐 weight / activation; +- E5M2:5 exponent + 2 mantissa,推荐 gradient; +- 输入需通过 scale 移入可表示区间; +- 输出通常以更高精度产生; +- nonlinear、normalization、optimizer update 等可保留高精度; +- 是否使用 per-tensor scale 由网络决定。 + +论文自己的限制: + +- 格式论文不规定 scale heuristic; +- 许多训练实验是模拟格式,而不是同一硬件上的端到端系统结果; +- FP8 并不取消混合精度,只把角色划分做得更细。 + +### 3.3 2023:Microscaling 的关键不是 FP4,而是“局部共享范围” + +Rouhani et al. 2023 §2: + +```text +MX block = one shared scale X + k scalar elements P1…Pk +real value vi = X × Pi +``` + +公开 concrete formats: + +- block size `k = 32`; +- scale format `E8M0`; +- MXFP8 element:E4M3 / E5M2; +- MXFP6 element:E2M3 / E3M2; +- MXFP4 element:E2M1; +- MXINT8 element:INT8。 + +粒度变小的收益: + +- 一个极端 outlier 只压缩同 block 的有效精度; +- sub-8-bit 才有机会覆盖复杂 tensor 分布。 + +代价: + +- 每 32 个值多一个 scale; +- scale axis 是语义的一部分; +- transpose 可能改变 scale axis,量化与 transpose 不可交换; +- conversion recipe 与 clipping 会影响结果; +- vector op 仍常用 BF16 / FP32。 + +### 3.4 DeepSeek-V3:FP8 成功靠的是一整套角色分配 + +DeepSeek-V3 §3.3: + +#### GEMM + +- Fprop、Dgrad、Wgrad 的核心 GEMM 输入使用 FP8; +- 输出为 BF16 或 FP32; +- embedding、output head、MoE gate、normalization、attention 保留原精度; +- master weights、weight gradients、optimizer states 保留更高精度。 + +#### Fine-grained scale + +- activation:`1 × 128` tile,即 per token / 128 channels; +- weight:`128 × 128` block; +- 在线按当前 tile / block 计算 scale; +- 全部 tensor 使用 E4M3,依靠细粒度 scale 弥补 E5M2 范围。 + +#### Accumulation + +- H800 Tensor Core FP8 accumulation 作者测得约 14-bit; +- 每 `Nc = 128` 个元素将 partial result promotion 到 CUDA Core FP32 register; +- scale 乘法与 promotion 一起完成; +- 这是精度—吞吐折中,不是免费 FP32 accumulate。 + +#### Storage / communication + +- AdamW first / second moments 用 BF16; +- master weights 与 gradient accumulation 用 FP32; +- backward cached activations 可用 FP8; +- 对 attention backward 敏感激活使用自定义 E5M6; +- MoE dispatch 可 FP8,combine 保留 BF16。 + +#### 证据边界 + +- 两个约 16B / 230B baseline、约 1T / 0.9T Token 对照中,相对 BF16 loss error < 0.25%; +- Appendix B.2 报告:把 Dgrad activation gradient 改成 `128 × 128` block quantization, + 16B MoE 在约 300B Token 发散; +- 因此“更规整 block 更好实现”并不等于数值上可接受。 + +### 3.5 2024:长程训练暴露短实验看不到的 SwiGLU 问题 + +Fishman et al. 2024: + +- 短程 FP8 实验可能看不见后期 outlier; +- 其 Llama2-7B 实验在约 200B Token 后出现 activation outlier 和 FP8 loss divergence; +- 论文把它连接到 SwiGLU 两支 weight 向量的长期对齐; +- SwiGLU 在大正输入时近似两个线性项相乘,可呈二次增长; +- Smooth-SwiGLU 通过 per-channel scale 抑制进入量化层的 outlier,再在后续权重中吸收逆 scale。 + +边界: + +- 这是指定 Llama2 / FP8 delayed-scaling 配方上的作者结果; +- 不能证明所有 SwiGLU 模型都会在同 Token 发生同样失稳; +- 但它解释了为什么完整训练时长是低精度验证的一部分。 + +### 3.6 2025–2026:FP4 的三种完全不同路径 + +1. **FP4 All the Way** + 研究从头 fully quantized training;W/A/G 广泛 FP4,探索 NVFP4、rounding 和 quantization-noise threshold。 + +2. **DeepSeek-V4 FP4 QAT** + post-training 阶段把 MoE expert weights 与 CSA indexer QK path 纳入 MXFP4 QAT; + FP32 master → FP4 → lossless dequant to FP8(在其 scale 条件下)→ compute; + backward 用 STE 传回 FP32 master。 + +3. **Kimi K3 deployment-aware QAT** + 从 SFT 开始贯穿 RL;MoE expert weights 用 MXFP4,activation compute 用 MXFP8; + attention projection、latent MoE projection、shared expert、router 保留更高精度; + rollout 与 training 使用相同量化方案以减少 train–inference mismatch。 + +不能把三者混成“2026 模型都用 FP4 预训练”。 + +--- + +## 4. 量化:对象、粒度、时机 + +### 4.1 仿射量化的最小模型 + +常见 uniform affine quantization: + +```text +q = clamp(round(x / scale) + zero_point) +x_hat = scale × (q - zero_point) +``` + +- symmetric:zero point 通常为 0; +- asymmetric:允许区间中心偏移; +- per-tensor:整 tensor 一个 scale; +- per-channel:每输出 / 输入 channel 一个 scale; +- per-token:每 Token 一个 activation / KV scale; +- group / block:一小组共享 scale。 + +### 4.2 PTQ + +GPTQ: + +- one-shot weight-only PTQ; +- 用 calibration activation 和近似二阶信息补偿量化误差; +- 作者报告可在约 4 GPU-hours 内量化 OPT-175B 到 3/4 bit; +- 不代表 activation、KV、训练梯度都已量化。 + +SmoothQuant: + +- 对数学等价的 channel rescaling,把 activation outlier 难度迁移到 weight; +- 主要服务 W8A8 inference; +- 仍需校准 scale,且低到 4-bit 时问题不同。 + +### 4.3 QAT + +Jacob et al. 2018 §3: + +- 变量与主计算仍以 floating point 保存; +- forward 插入 fake quantization,模拟 inference rounding / clamp; +- backward 继续传梯度; +- fake-quant 节点位置必须匹配真实部署图。 + +LLM-QAT: + +- 用模型自身生成数据做 data-free distillation; +- 同时研究 weight、activation、KV cache; +- 作者在 LLaMA 7B/13B/30B 上报告低于 8 bit 时优于其 PTQ baseline; +- 论文也明确 4-bit activation 在其设置中仍不理想。 + +### 4.4 QLoRA 的精确边界 + +QLoRA: + +- frozen pretrained base 用 4-bit NF4 storage; +- 计算时 dequant 到 BF16; +- 训练 LoRA adapter,而不是完整 4-bit base update; +- double quant 减少 scale 元数据; +- paged optimizer 处理长序列显存峰值。 + +所以 QLoRA 证明“低显存微调可行”,不证明“从头 4-bit 预训练等价”。 + +--- + +## 5. 优化器:从逐坐标到矩阵几何 + +### 5.1 SGD / Momentum + +```text +m_t = μ m_(t-1) + g_t +θ_t = θ_(t-1) - η m_t +``` + +优点: + +- 状态少; +- 更新含义直接; +- 通信 / sharding 容易。 + +LLM 常见困难: + +- 不同参数坐标 / layer 的梯度尺度差异大; +- 高 LR 可用区间窄; +- 要靠参数化、归一化和精细 schedule 补偿。 + +### 5.2 Adam + +```text +m_t = β1 m_(t-1) + (1-β1) g_t +v_t = β2 v_(t-1) + (1-β2) g_t² +m_hat, v_hat = bias correction +θ_t = θ_(t-1) - η m_hat / (sqrt(v_hat) + ε) +``` + +直觉: + +- momentum 平滑方向; +- second moment 给每个坐标不同步长; +- 小梯度坐标不必永远被大尺度坐标淹没。 + +代价: + +- 两份状态; +- 逐元素 preconditioning 丢掉矩阵结构; +- `ε`、β2 与长程非平稳梯度会影响实际更新; +- optimizer state 常成为显存主项。 + +### 5.3 AdamW:weight decay 不是 L2 penalty 的别名 + +在 SGD 中,L2 gradient 与 weight decay 可在适当缩放下等价; +在 Adam 中,若把 `λθ` 混入 gradient,它也会被 `v_t` 的自适应分母改变。 + +AdamW: + +```text +θ_t = (1 - ηλ) θ_(t-1) - AdamUpdate(g_t) +``` + +把“根据 loss 更新”与“直接收缩权重”分开。 + +### 5.4 Adafactor:省的是 second moment,不是免费 Adam + +对矩阵 `V ∈ R^(n×m)`,不保存每元素 second moment, +而保存 row / column statistics,用 `O(n+m)` 近似 `O(nm)`。 + +论文还强调: + +- 去掉 momentum 可再省一份状态; +- stale second-moment estimator 可造成过大 update; +- update clipping 应裁真正的 adaptive update,而不仅是原始 gradient; +- relative step size 把参数 RMS 纳入步长。 + +### 5.5 Shampoo:保留矩阵 / tensor 结构 + +Shampoo 为张量每个 mode 维护预条件统计,并对 gradient 做 Kronecker 型变换。 + +收益: + +- 比逐坐标 Adam 更尊重矩阵结构; +- 为后来的矩阵级 optimizer 提供对照。 + +代价: + +- 预条件矩阵与矩阵根昂贵; +- 大模型需要 blocking、低频更新和分布式实现; +- 首版课程只作为“结构化 preconditioner”桥梁,不给出生产优胜排名。 + +### 5.6 μP:不是 optimizer,而是让 scale-up 的更新语义一致 + +Tensor Programs V: + +- standard parametrization 下,宽度变化会改变 activation / update 尺度; +- Maximal Update Parametrization 设计不同 parameter group 的 init / LR scaling; +- 在作者实验中,小代理模型调出的超参数可零样本迁移到更宽模型。 + +边界: + +- 主要解决宽度,不自动覆盖深度、数据、batch、optimizer 切换; +- 实现需要正确区分 matrix-like 与 vector-like 参数; +- 它与 optimizer 可以组合,不是 Adam / Muon 的直接替代。 + +### 5.7 Muon:对 momentum matrix 做 approximate orthogonalization + +原始 Muon / Moonlight 公式: + +```text +M_t = μ M_(t-1) + G_t +O_t = NewtonSchulz(M_t) ≈ U V^T +W_t = W_(t-1) - η O_t +``` + +若 `M = UΣVᵀ`,`UVᵀ` 可视作把非零 singular values 拉近 1, +从而避免 update 只沿少数 dominant direction。 + +重要澄清: + +- 生产实现不做完整 SVD; +- Newton–Schulz 用矩阵乘迭代近似; +- 只适合 logically independent 2D matrix parameter; +- embedding、norm、bias、head 等常由 AdamW 处理; +- 矩阵 shape 与 partition 会改变 update RMS。 + +### 5.8 “Muon is Scalable” 的两个关键补丁 + +Moonlight / Liu et al. 2025: + +1. **Weight decay** + vanilla Muon 长训时 weight / layer output RMS 增长,甚至越过 BF16 高精度范围; + 加 AdamW-style decay 改善作者 over-train 实验。 + +2. **Consistent update RMS** + full-rank `A×B` matrix 的理论 Muon update RMS 约 `1/sqrt(max(A,B))`; + 论文乘 `sqrt(max(A,B)) × 0.2`,让矩阵间尺度一致并复用 AdamW LR。 + +作者报告: + +- compute-optimal scaling 实验约 2× compute efficiency; +- 相同 loss 约需 AdamW 52% FLOPs; +- Moonlight 3B / 16B MoE 训练 5.7T Token。 + +这些是指定模型族与调参协议的作者结果,不是 Muon 普遍定理。 + +### 5.9 Kimi K2:MuonClip + +K2 观察: + +- Muon 在大尺度更容易出现 attention logit explosion; +- 9B-active / 53B-total 中间实验 vanilla Muon max logits 很快超过 1000; +- attention logit 由 `QKᵀ / sqrt(d)` 决定,Q / K weight spectral norm 增长会被乘积放大。 + +QK-Clip: + +```text +Smax_h = per-head max pre-softmax logit +γ_h = min(1, τ / Smax_h) +rescale head-specific Q / K weights after optimizer step +``` + +MLA 细节: + +- `qC`、`kC` 各乘 `sqrt(γ_h)`; +- `qR` 乘 `γ_h`; +- shared `kR` 不动,避免影响其他 heads。 + +K2 设置: + +- `τ = 100`; +- 前 70k steps 有 12.7% heads 至少触发一次; +- 后期自行降到阈值下,clip 不再触发; +- 报告 15.5T Token 训练未观察 loss spike。 + +作者假说而非定理: + +- Muon update spectrum 更高 rank; +- weight 与 update singular direction 更可能对齐; +- `Wq Wkᵀ` 再放大 spectral norm。 + +### 5.10 Kimi K3:Per-Head Muon + +K3 不对完整 Q / K / V projection momentum 统一正交化,而按 head block 分开: + +- 避免大 scale head 主导共享矩阵 update; +- 让不同 head update scale 更均衡; +- tall per-head block 的 Newton–Schulz 更便宜; +- 报告称提升大尺度训练稳定性。 + +训练 recipe 同时保留 K2 weight clipping,因此: + +```text +Per-Head Muon = 更新几何 +QK-Clip = 越界保护 +``` + +不能把两者合成一个算法名,也不能说 Per-Head Muon 已取代 QK-Clip。 + +### 5.11 DeepSeek-V4:Hybrid Muon–AdamW + +DeepSeek-V4: + +- majority modules:Muon; +- embedding、prediction head、mHC static bias / gate、RMSNorm weights:AdamW; +- Muon momentum `0.95`、weight decay `0.1`、update RMS scale `0.18`; +- hybrid Newton–Schulz:前 8 次快速系数,后 2 次稳定到 singular value 1; +- Q / KV 可直接 RMSNorm,因此不使用 K2 QK-Clip。 + +系统实现: + +- dense matrix 通过受限 ZeRO group 与 knapsack 分配; +- MoE expert matrix 保持逻辑独立,不切断单矩阵; +- 相同 shape 合并做 batched Newton–Schulz; +- BF16 matrix multiplication 做 NS; +- MoE gradient stochastic-round 到 BF16 通信,再本地 FP32 sum。 + +这说明 optimizer 公式、参数分组与分布式拓扑是一个整体。 + +--- + +## 6. 稳定性不是一个故障,而是五条反馈环 + +### 6.1 深度 / residual 反馈 + +症状: + +- model update 随深度累积; +- residual branch 过大; +- gradient vanishing / exploding; +- early training 直接卡进坏状态。 + +防线: + +- warmup; +- scaled initialization; +- Pre-LN / RMSNorm; +- residual scaling; +- DeepNorm; +- K3 Block AttnRes / DeepSeek mHC 等新结构需各自稳定性证明。 + +DeepNet: + +- 把 Post-LN 失稳定位为 early model update 过大; +- 用 residual up-scaling + branch weight down-scaling 让更新随深度有界; +- 作者展示可训练 1000-layer Transformer。 + +### 6.2 Attention logit 反馈 + +```text +weight norm / spectral norm ↑ + → ||Q||, ||K|| ↑ + → max(QKᵀ) ↑ + → softmax 近 one-hot,entropy ↓ + → gradient 与 head dynamics 更尖锐 + → 进一步推动 weight growth +``` + +可选防线: + +- QK L2 normalization + learned temperature; +- QK LayerNorm / RMSNorm; +- logit soft-cap; +- QK-Clip weight rescaling; +- z-loss 管 output logits,不与 attention logits 混同。 + +ViT-22B: + +- 8B 视觉模型无 QK norm 时 attention logits 超过 50,000; +- QK LayerNorm 让 `1e-3` LR 在更大 scale 保持稳定。 + +Small-scale proxies: + +- 用小模型 + 高 LR 复现 attention / output logit 不稳定; +- QK LayerNorm + z-loss 使作者设置跨三数量级 LR 可训练; +- 这是一种研究代理,不保证覆盖 data / system / MoE 全部故障。 + +### 6.3 Activation / SwiGLU 反馈 + +SwiGLU: + +```text +(xᵀw_up) × Swish(xᵀw_gate) +``` + +两支都大时,乘积可远大于单一 GeLU / ReLU。 + +防线谱系: + +- Smooth-SwiGLU:scale 转移,函数等价; +- hard clamp:限制 linear / gate 分支; +- K3 SiTU-GLU:两支分别用 smooth tanh cap; +- PowLU:另一种 bounded / stable activation 研究。 + +K3 SiTU-GLU: + +```text +β1 tanh(Wg x / β1) × sigmoid(Wg x) × β2 tanh(Wu x / β2) +β1 = 4, β2 = 25 +|output coordinate| < β1 β2 = 100 +``` + +它在原点附近一阶匹配 SwiGLU,极大值时有界;不是简单 hard clamp。 + +DeepSeek-V4: + +- linear component clamp 到 `[-10, 10]`; +- gate component upper cap `10`; +- 报告称两款 V4 训练均使用,未观察性能损失; +- 机制理论仍明确写为 open question。 + +### 6.4 Optimizer-statistic 反馈 + +Wortsman et al. 2023 VLM: + +- loss spike 常发生在 squared gradient 被 AdamW second moment 低估后 1–8 steps; +- gradient clipping 发生在 adaptive scaling 前,未必能限制真正 update; +- 其 AdamW–Adafactor hybrid 解决指定 CLIP ViT-H 实验的 spike。 + +Adafactor 更早已区分: + +- gradient clipping:裁 `g`; +- update clipping:裁 preconditioned update。 + +Muon 的风险不同: + +- 不用逐坐标 second moment; +- 但 matrix spectrum、shape-based RMS、Q/K logit 放大成为核心。 + +### 6.5 MoE routing / expert outlier 反馈 + +DeepSeek-V4 公开报告: + +```text +expert outlier + → routing 更偏向某些 expert + → 被选 expert 接收更多异常输入 / update + → outlier 与 routing 互相强化 + → loss spike +``` + +Anticipatory Routing: + +- step `t` feature 用当前 `θ_t`; +- routing indices 用历史 `θ_(t-Δt)` 预计算; +- spike 时短 rollback 并临时启用; +- 预计算本身作者报告约 20% wall-clock overhead; +- 动态启用后整体额外开销可忽略。 + +这是一种 break-the-loop 工程策略,不是通用 MoE 理论。 + +--- + +## 7. 一个稳定性控制室应该监控什么 + +| 信号 | 统计 | 它能提示什么 | 它不能证明什么 | +|---|---|---|---| +| training / validation loss | raw、EMA、per-domain | 已经影响目标 | 根因 | +| attention logits | max、p99.9、per-head | Q/K growth、softmax saturation | FFN / optimizer state 正常 | +| attention entropy | per-head / layer | 过尖或坍缩 | 一定有错 | +| activation | max、RMS、percentile、outlier channel | overflow / quantization risk | gradient update 原因 | +| gradient | global norm、per-layer、nonfinite | backward 异常 | adaptive update 真正大小 | +| update | RMS、param/update ratio、spectrum | optimizer 施加的实际步长 | forward outlier 根因 | +| weight | RMS、spectral norm、singular entropy | 长期增长与 rank | 即刻 loss spike | +| quantization | saturation、underflow、SNR、scale history | dtype / scale 失败 | 高精度算子正常 | +| optimizer state | moment max/min、scale、staleness | second moment 低估 / overflow | model architecture 正常 | +| MoE | per-expert activation、load、drop、bias | router–outlier feedback | dense layer正常 | +| system | checksum、nonfinite rank、bitwise replay | hardware / kernel / collective 错误 | 数据 / 算法正确 | + +控制动作也要分层: + +- skip update; +- dynamic loss / tensor scaling; +- gradient / update clip; +- QK normalize / QK-Clip; +- activation clamp; +- lower LR / longer warmup; +- change accumulator; +- rollback + replay; +- quarantine batch; +- temporary routing decoupling。 + +--- + +## 8. DeepSeek 数值主线 + +### 2024 · DeepSeek LLM + +- BF16 training; +- FP32 gradient accumulation; +- cross entropy 内按需 BF16 → FP32; +- AdamW; +- gradient norm clip `1.0`; +- 每 5 分钟异步 checkpoint,硬件失败最坏损失约 5 分钟。 + +意义:先把“低精度 compute、高精度关键路径、恢复能力”建立为工程基线。 + +### 2024 · DeepSeek-V2 + +- 继续 AdamW / BF16 主线; +- MLA 改变 Q/K 的物化方式; +- 这为 K2 选择 QK-Clip 而非直接 QK-Norm 提供结构背景,但不是 V2 自己的 QK-Clip 结论。 + +### 2024 · DeepSeek-V3 + +- 671B total / 37B active; +- 14.8T Token; +- fine-grained FP8 training; +- 1×128 activation / 128×128 weight scale; +- FP32 promotion interval 128; +- BF16 optimizer moments,FP32 master / accumulated gradients; +- 报告整个主训练无 irrecoverable loss spike / rollback。 + +注意: + +- 这是作者技术报告结果; +- Appendix B.2 同时给出 block Dgrad 导致发散的反例; +- 因而“V3 稳定”来自精确角色分配,不是 FP8 自然稳定。 + +### 2026 · DeepSeek-V4 + +- majority modules 改 Muon; +- 特定向量 / norm / head 保留 AdamW; +- Q / KV RMSNorm 避免 logit explosion,不用 QK-Clip; +- hybrid NS + BF16 compute + FP32 local sum; +- 训练真实遇到 loss spikes; +- Anticipatory Routing + SwiGLU clamping; +- post-training 对 MoE experts + indexer QK 做 FP4 QAT; +- rollout / inference 使用 native FP4。 + +这条主线最值得学习的地方: + +> V3 的“成功 FP8”没有让 V4 停止做稳定性工程;模型、优化器、attention、MoE 与 QAT 每次变化都会重新打开新的失稳路径。 + +--- + +## 9. Kimi 数值主线 + +### 2025 · Moonlight / scalable Muon + +- 从原始 Muon 补上 weight decay; +- matching update RMS; +- distributed Muon; +- 5.7T Token Moonlight; +- 作者报告相对 AdamW 约 2× compute efficiency。 + +### 2025 · Kimi K2 + +- 1.04T total / 32.6B active; +- 15.5T Token; +- MuonClip; +- QK-Clip threshold 100; +- per-head minimal intervention; +- 报告 zero observable loss spike。 + +### 2026 · Kimi K3 + +- 2.78T total / 104.2B active; +- 总训练 Token 未披露; +- Per-Head Muon; +- 保留 K2 weight clipping; +- Stable LatentMoE 加 RMSNorm; +- SiTU-GLU 两支有界,coordinate bound 100; +- most activation backward storage 用 block-wise FP8 + offload; +- distributed Muon 用 P2P 只取本地参数所需 shards; +- SFT → RL 全程 MXFP4 expert QAT; +- rollout / training 相同 quantization scheme。 + +不能外推: + +- K3 `2.5×` family-level scaling efficiency 是架构、数据、训练联合变化; +- 不是 Per-Head Muon 单项收益; +- 不是 MXFP4 throughput; +- 不是相对 DeepSeek 的公开对照。 + +--- + +## 10. K2 / K3 / V3 / V4 对照 + +| 系统 | 主要 optimizer | Attention 防线 | FFN / MoE 防线 | 低精度主线 | 报告边界 | +|---|---|---|---|---|---| +| DeepSeek-V3 | AdamW | attention 高精度 | fine-grained scale | FP8 pretraining | <0.25% loss error on two baselines;主 run 无不可恢复 spike | +| Kimi K2 | MuonClip | QK-Clip `τ=100` | — | 非本章主卖点 | 15.5T;zero observable spike | +| Kimi K3 | Per-Head Muon + K2 clip | per-head update + weight clip | RMSNorm + SiTU-GLU | FP8 activation cache;MXFP4 expert QAT | 总 Token 未公开;Per-Head 单项收益未公开 | +| DeepSeek-V4 | majority Muon + selected AdamW | Q/KV RMSNorm | Anticipatory Routing + SwiGLU clamp | FP4 QAT + FP8 compute/storage | 训练遇到 spikes;经验补丁理论仍开放 | + +--- + +## 11. 四个互动实验的合同 + +### Lab A · Format Microscope + +输入: + +- format:FP32 / FP16 / BF16 / E4M3 / E5M2 / MXFP4; +- real value; +- scale; +- block outlier; +- rounding mode。 + +输出: + +- 最近 representable value; +- absolute / relative error; +- overflow / underflow / rounded; +- block 内有效精度。 + +教学边界: + +- 是格式语义模拟,不是任一 GPU bit-exact implementation; +- MXFP4 强制显示 scale 和 block; +- NaN / subnormal 的厂商实现差异不做伪精确承诺。 + +### Lab B · Mixed Precision Ledger + +输入: + +- parameter count; +- activation cache; +- compute dtype; +- master weights; +- gradient accumulation; +- optimizer moments; +- activation / gradient communication。 + +输出: + +- 每种状态 GB; +- 总显存 / 通信相对基线; +- 风险列表; +- preset:BF16 baseline / classic FP16 / V3-like FP8 / K3 deployment-aware。 + +边界: + +- 不含 allocator、fragmentation、checkpoint、parallel sharding; +- speed 不从 byte ratio 自动推出; +- V3-like / K3-like 是教学配置,不是完整生产复现。 + +### Lab C · Optimizer Geometry + +输入: + +- 2×2 gradient / momentum matrix; +- AdamW / Muon / Per-Head Muon; +- momentum、weight decay、RMS matching; +- head scale imbalance。 + +输出: + +- update matrix; +- approximate singular-value balance; +- per-head update RMS; +- state bytes; +- logical matrix partition。 + +边界: + +- Newton–Schulz 可视化使用简化迭代; +- 不承诺等于生产 kernel; +- 2D teaching matrix 不代表真实 loss landscape。 + +### Lab D · Stability Control Room + +输入: + +- attention logit growth; +- SwiGLU outlier; +- quantization scale granularity; +- optimizer mode; +- MoE routing feedback; +- 防线 toggles。 + +输出: + +- softmax saturation risk; +- activation overflow risk; +- update risk; +- simulated timeline; +- “先看哪个监控量”的解释。 + +边界: + +- 不合成伪“总稳定分”; +- 使用独立 gauges; +- K2 / K3 / V3 / V4 preset 只映射报告公开机制。 + +--- + +## 12. 关键论文链 + +| 年份 | 来源 | 本章作用 | 证据边界 | +|---:|---|---|---| +| 2014 | Adam | adaptive moment baseline | 非 LLM 专用 | +| 2015 | Limited Numerical Precision | stochastic rounding 前史 | fixed-point / 小模型 | +| 2017 | Mixed Precision Training | FP32 master + loss scale + accumulate | FP16 时代 | +| 2017 | AdamW | decoupled weight decay | 视觉主实验 | +| 2017 | Integer-only QAT | fake quant / QAT 起点 | CNN 部署 | +| 2018 | Shampoo | tensor structured preconditioner | 扩展成本高 | +| 2018 | Adafactor | factored second moment + update clip | MT Transformer | +| 2019 | BFLOAT16 Study | range vs precision | 多领域但非现代万亿 LLM | +| 2020 | GLU Variants | SwiGLU 起点 | 未讨论 outlier | +| 2020 | QK Normalization | cosine Q/K + learned scale | 低资源 MT | +| 2021 | 8-bit Optimizers | block-wise state quantization | 到 1.5B LM | +| 2022 | DeepNet | depth / residual stability | 以 MT / 深度为主 | +| 2022 | Tensor Programs V | μP / μTransfer | 宽度主线 | +| 2022 | LLM.int8 | activation outlier | inference | +| 2022 | FP8 Formats | E4M3 / E5M2 标准语义 | scale heuristic 不在范围 | +| 2022 | GPTQ | weight-only PTQ | 不含 W/A/KV 全量 | +| 2022 | SmoothQuant | W8A8 outlier migration | inference | +| 2023 | ViT-22B | QK LayerNorm 与 50k logits | 视觉模型 | +| 2023 | Stable low-precision VLM | moment underestimation / SwitchBack | CLIP | +| 2023 | QLoRA | 4-bit frozen-base finetuning | 非 4-bit base training | +| 2023 | LLM-QAT | data-free W/A/KV QAT | LLaMA ≤30B | +| 2023 | Small-scale proxies | high-LR stability proxy | 不覆盖全部生产故障 | +| 2023 | MX Formats | E8M0 + 32-block + MXFP4 | 到 1.5B GPT training | +| 2023 | FP8-LM | end-to-end FP8 system | 作者硬件栈 | +| 2023 | Spike No More | small sublayer / large shortcut | 理论假设与中等模型 | +| 2024 | DeepSeek LLM | BF16 + FP32 accumulate | 67B | +| 2024 | Deconstructing Optimizers | Adam / Adafactor / Lion 对照 | ≤1.2B | +| 2024 | Scaling FP8 to trillion Token | late SwiGLU outlier | Llama2 / delayed scale | +| 2024 | DeepSeek-V3 | fine-grained FP8 production recipe | 作者报告 | +| 2024 | Muon blog | 原始 Muon 定义 | 技术博文 | +| 2025 | Muon is Scalable | decay + update RMS | 作者 scaling law | +| 2025 | Kimi K2 | MuonClip / QK-Clip | 作者报告 | +| 2025 | FP4 All the Way | fully quantized training | 7B / 200B Token | +| 2026 | PowLU | bounded activation 对照 | 新论文 | +| 2026 | DeepSeek-V4 | hybrid Muon + FP4 QAT + spike mitigation | 作者报告 | +| 2026 | Kimi K3 | Per-Head Muon + SiTU + MXFP4 QAT | 作者报告 | + +--- + +## 13. 正文必须保留的公开未知项 + +1. K3 总预训练 Token 数与完整 dtype placement 未公开; +2. K3 Per-Head Muon 的单项 ablation 数字未公开; +3. K3 MXFP4 QAT 相对高精度的完整 capability / latency 对照未公开; +4. K2 zero spike 不是独立复现; +5. DeepSeek-V3 `<0.25%` 来自两组 baseline,不是所有 tensor policy 的保证; +6. DeepSeek-V4 Anticipatory Routing 的触发阈值、持续步数与全部 spike trace 未公开; +7. DeepSeek-V4 FP4 QAT 的完整质量 ablation 与硬件端到端收益未公开; +8. Muon 相对 AdamW 的最优性依赖模型族、参数分组、调参预算与 Token regime; +9. 新 Muon 分支快速演化,首版不把未经大规模复现的变体写成继任者; +10. 所有 teaching lab 都是机制模型,不是 bit-exact kernel 或真实训练预测器。 + +--- + +## 14. 一手来源定位摘要 + +### Kimi + +- Kimi K2 §2.1:MuonClip / QK-Clip 公式与 Figure 2; +- Kimi K2 Appendix D:QK-Clip 无质量损伤与 self-deactivation; +- Kimi K2 Appendix E:Muon logit explosion 假说; +- Kimi K3 §2.3.1:LatentMoE RMSNorm; +- Kimi K3 §2.3.2 / Appendix B:SiTU-GLU 与 bound 100; +- Kimi K3 §2.5:Per-Head Muon; +- Kimi K3 §3.3:Per-Head Muon + K2 weight clipping; +- Kimi K3 §4.1.4:MXFP4 expert QAT; +- Kimi K3 §5.2.2:block-wise FP8 activation cache、P2P Muon。 + +### DeepSeek + +- DeepSeek LLM §2.4:BF16、FP32 gradient accumulation、checkpoint; +- DeepSeek-V3 §3.3.1:mixed precision role map; +- DeepSeek-V3 §3.3.2:1×128 / 128×128 scale 与 FP32 promotion; +- DeepSeek-V3 §3.3.3:optimizer state、activation、communication; +- DeepSeek-V3 Appendix B.1:BF16 vs FP8; +- DeepSeek-V3 Appendix B.2:block Dgrad divergence; +- DeepSeek-V4 §2.4:Muon 与 hybrid Newton–Schulz; +- DeepSeek-V4 §3.4.1:distributed Muon / BF16 sync / FP32 sum; +- DeepSeek-V4 §4.2.3:Anticipatory Routing / SwiGLU clamp; +- DeepSeek-V4 §5.2.1:FP4 QAT / STE / native rollout。 + +### 通用论文 + +- Mixed Precision §3.1–3.3; +- BFLOAT16 §1–2 / Table 1; +- FP8 Formats §2–3 / Table 1; +- MX Formats §2 / Table 1 / Figure 1; +- Adam Algorithm 1; +- AdamW §2; +- Adafactor §3 / §5–6; +- μP / TP-V main theorem and transfer experiments; +- Muon Scalable §2.2–2.3 / §3; +- QK Norm §2; +- ViT-22B §2 / Appendix B; +- Small-scale proxies §3; +- Scaling FP8 §3–5; +- QAT Jacob §3; +- LLM-QAT §2–3。 + +--- + +## 15. 本地证据缓存说明 + +主干 PDF / text 已缓存到: + +```text +research/sources/numerics/ +research/sources/training-systems/1710.03740.* +research/sources/scaling-laws/2401.02954.* +research/sources/moe/2412.19437.* +research/sources/reasoning/2507.20534.* +research/sources/long-context/2606.19348.* +research/sources/kimi-k3/k3_tech_report.* +``` + +缓存受 `.gitignore` 排除;公开仓库只提交 canonical URL、原创研究笔记与课程内容, +不重新分发论文全文。 diff --git a/scripts/check-data-browser.mjs b/scripts/check-data-browser.mjs index 02d96f3..3957c2e 100644 --- a/scripts/check-data-browser.mjs +++ b/scripts/check-data-browser.mjs @@ -230,15 +230,15 @@ if (transform.keyboard.selected !== "transform" || transform.keyboard.visible != if (layout.articleSections !== 18 || layout.paperLinks !== 31 || layout.labTabs !== 4 || layout.views !== 4) { failures.push("章节、论文或实验数量异常"); } -if (layout.navLinks !== 13 || mobile.mobileLinks !== 13 || home.navLinks !== 13) failures.push("全站导航未同步数据工程"); +if (layout.navLinks !== 14 || mobile.mobileLinks !== 14 || home.navLinks !== 14) failures.push("全站导航未同步数值专题"); if (layout.documentOverflow > 0 || mobile.documentOverflow > 0 || home.documentOverflow > 0) failures.push("页面存在横向溢出"); if (layout.navGap < 0) failures.push(`桌面导航碰撞:${layout.navGap}px`); if (!mobile.menuVisible || mobile.menuOpen !== "true") failures.push("移动端菜单不可用"); -if (home.releaseCards !== 6 || !home.firstRelease.includes("一万亿 Token") || home.firstHref !== "/pretraining/data/") { - failures.push("首页数据工程新章入口异常"); +if (home.releaseCards !== 7 || !home.firstRelease.includes("少几个比特") || home.firstHref !== "/systems/numerics/") { + failures.push("首页数值新章入口异常"); } -if (home.paperCount !== "202") failures.push(`首页论文总数异常:${home.paperCount}`); -if (!papers.hasDataFilter || papers.total !== 202 || papers.visible < 25) failures.push("论文库数据标签或论文总数异常"); +if (home.paperCount !== "223") failures.push(`首页论文总数异常:${home.paperCount}`); +if (!papers.hasDataFilter || papers.total !== 223 || papers.visible < 25) failures.push("论文库数据标签或论文总数异常"); if (exceptions.length) failures.push(`浏览器脚本异常:${exceptions.join("; ")}`); socket.close(); diff --git a/scripts/check-moe-browser.mjs b/scripts/check-moe-browser.mjs index 54f7b24..e5d35e8 100644 --- a/scripts/check-moe-browser.mjs +++ b/scripts/check-moe-browser.mjs @@ -177,7 +177,7 @@ if (layout.documentOverflow > 0 || mobile.documentOverflow > 0 || home.documentO } if (layout.navGap < 0) failures.push(`桌面导航碰撞:${layout.navGap}px`); if (!mobile.menuVisible) failures.push("移动端菜单按钮未显示"); -if (home.releaseCards !== 6) failures.push(`首页新章卡数量异常:${home.releaseCards}`); +if (home.releaseCards !== 7) failures.push(`首页新章卡数量异常:${home.releaseCards}`); if (exceptions.length) failures.push(`浏览器脚本异常:${exceptions.join("; ")}`); socket.close(); diff --git a/scripts/check-numerics-browser.mjs b/scripts/check-numerics-browser.mjs new file mode 100644 index 0000000..e83f162 --- /dev/null +++ b/scripts/check-numerics-browser.mjs @@ -0,0 +1,292 @@ +import { writeFileSync } from "node:fs"; + +const cdpPort = process.env.CDP_PORT ?? "9227"; +const baseUrl = process.env.SITE_URL ?? "http://127.0.0.1:4326"; +const pages = await fetch(`http://127.0.0.1:${cdpPort}/json/list`).then((response) => response.json()); +const page = pages.find((entry) => entry.type === "page"); +if (!page) throw new Error(`CDP ${cdpPort} 没有可用页面`); + +const socket = new WebSocket(page.webSocketDebuggerUrl); +await new Promise((resolve, reject) => { + socket.addEventListener("open", resolve, { once: true }); + socket.addEventListener("error", reject, { once: true }); +}); + +let nextId = 0; +const pending = new Map(); +const exceptions = []; +socket.addEventListener("message", (event) => { + const message = JSON.parse(event.data); + if (message.id && pending.has(message.id)) { + const { resolve, reject } = pending.get(message.id); + pending.delete(message.id); + if (message.error) reject(new Error(message.error.message)); + else resolve(message.result); + } + if (message.method === "Runtime.exceptionThrown") { + exceptions.push(message.params.exceptionDetails.exception?.description ?? message.params.exceptionDetails.text); + } +}); + +const command = (method, params = {}) => new Promise((resolve, reject) => { + const id = ++nextId; + pending.set(id, { resolve, reject }); + socket.send(JSON.stringify({ id, method, params })); +}); +const pause = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)); +const evaluate = async (expression) => { + const result = await command("Runtime.evaluate", { expression, returnByValue: true, awaitPromise: true }); + if (result.exceptionDetails) throw new Error(result.exceptionDetails.exception?.description ?? result.exceptionDetails.text); + return result.result.value; +}; +const navigate = async (path) => { + await command("Page.navigate", { url: `${baseUrl}${path}` }); + for (let attempt = 0; attempt < 50; attempt += 1) { + await pause(100); + if (await evaluate("document.readyState === 'complete'")) return; + } + throw new Error(`${path} 加载超时`); +}; +const screenshot = async (path, full = false) => { + const params = { format: "png", captureBeyondViewport: full }; + if (full) { + const metrics = await command("Page.getLayoutMetrics"); + params.clip = { + x: 0, + y: 0, + width: metrics.cssContentSize.width, + height: metrics.cssContentSize.height, + scale: 1, + }; + } + const result = await command("Page.captureScreenshot", params); + writeFileSync(path, Buffer.from(result.data, "base64")); +}; + +await command("Page.enable"); +await command("Runtime.enable"); +await command("Emulation.setDeviceMetricsOverride", { + width: 1440, + height: 1100, + deviceScaleFactor: 1, + mobile: false, +}); +await navigate("/systems/numerics/"); +await screenshot("/tmp/llm-atlas-numerics-desktop.png"); + +const format = await evaluate(`(() => { + const root = document.querySelector("[data-numerics-lab]"); + const metric = (name) => root.querySelector('[data-format-metric="' + name + '"]').textContent; + const initial = { + storage: metric("storage"), + status: metric("status"), + error: metric("absolute"), + }; + root.querySelector('[data-format-choice="fp16"]').click(); + root.querySelector('[data-format-preset="tiny"]').click(); + const tinyFp16 = { status: metric("status"), encoded: metric("encoded") }; + root.querySelector('[data-format-choice="e4m3"]').click(); + root.querySelector('[data-format-preset="large"]').click(); + const largeE4M3 = { status: metric("status"), encoded: metric("encoded") }; + root.querySelector('[data-format-choice="mxfp4"]').click(); + root.querySelector('[data-format-preset="one"]').click(); + const outlier = root.querySelector('[data-format-input="outlier"]'); + const local = { error: metric("absolute"), encoded: metric("encoded") }; + outlier.value = "64"; + outlier.dispatchEvent(new Event("input", { bubbles: true })); + return { + initial, + tinyFp16, + largeE4M3, + local, + shared: { + error: metric("absolute"), + encoded: metric("encoded"), + note: root.querySelector("[data-format-scale-note]").textContent, + }, + }; +})()`); + +const ledger = await evaluate(`(() => { + const root = document.querySelector("[data-numerics-lab]"); + root.querySelector('[data-num-tab="ledger"]').click(); + const read = () => ({ + total: root.querySelector('[data-ledger-metric="total"]').textContent, + saving: root.querySelector('[data-ledger-metric="saving"]').textContent, + activation: root.querySelector('[data-ledger-metric="activation"]').textContent, + communication: root.querySelector('[data-ledger-metric="communication"]').textContent, + risks: root.querySelector("[data-ledger-risks]").textContent, + rows: root.querySelectorAll("[data-state-stack] > div").length, + }); + root.querySelector('[data-precision-preset="bf16"]').click(); + const bf16 = read(); + root.querySelector('[data-precision-preset="v3"]').click(); + const v3 = read(); + root.querySelector('[data-precision-preset="k3"]').click(); + const k3 = read(); + return { bf16, v3, k3 }; +})()`); + +const optimizer = await evaluate(`(() => { + const root = document.querySelector("[data-numerics-lab]"); + root.querySelector('[data-num-tab="optimizer"]').click(); + const ratio = root.querySelector('[data-optimizer-input="ratio"]'); + ratio.value = "24"; + ratio.dispatchEvent(new Event("input", { bubbles: true })); + const read = () => ({ + label: root.querySelector("[data-optimizer-label]").textContent, + imbalance: root.querySelector('[data-optimizer-metric="imbalance"]').textContent, + unit: root.querySelector('[data-optimizer-metric="unit"]').textContent, + note: root.querySelector("[data-optimizer-note]").textContent, + cells: root.querySelectorAll('[data-matrix="output"] i').length, + }); + root.querySelector('[data-optimizer-choice="muon"]').click(); + const full = read(); + root.querySelector('[data-optimizer-choice="perhead"]').click(); + const perHead = read(); + return { full, perHead }; +})()`); + +const stability = await evaluate(`(() => { + const root = document.querySelector("[data-numerics-lab]"); + root.querySelector('[data-num-tab="stability"]').click(); + const read = () => ({ + summary: root.querySelector("[data-stability-summary]").textContent, + levels: [...root.querySelectorAll("[data-gauge] b")].map((node) => node.textContent), + defenses: [...root.querySelectorAll("[data-defense]:checked")].map((node) => node.dataset.defense), + timeline: root.querySelectorAll("[data-risk-timeline] i").length, + }); + root.querySelector('[data-stability-preset="k2"]').click(); + const k2 = read(); + root.querySelector('[data-stability-preset="v4"]').click(); + const v4 = read(); + const firstTab = root.querySelector('[data-num-tab="format"]'); + firstTab.focus(); + firstTab.dispatchEvent(new KeyboardEvent("keydown", { key: "End", bubbles: true })); + return { + k2, + v4, + keyboard: { + selected: root.querySelector('[data-num-tab][aria-selected="true"]').dataset.numTab, + visible: root.querySelector("[data-num-view]:not([hidden])").dataset.numView, + }, + }; +})()`); + +const layout = await evaluate(`(() => { + const nav = document.querySelector(".top-nav"); + const meta = document.querySelector(".header-meta"); + return { + documentOverflow: document.documentElement.scrollWidth - document.documentElement.clientWidth, + navGap: Number((meta.getBoundingClientRect().left - nav.getBoundingClientRect().right).toFixed(1)), + navLinks: document.querySelectorAll(".top-nav a").length, + articleSections: document.querySelectorAll(".article-section").length, + paperLinks: document.querySelectorAll(".paper-chain a").length, + labTabs: document.querySelectorAll("[data-num-tab]").length, + views: document.querySelectorAll("[data-num-view]").length, + }; +})()`); + +await evaluate(`document.querySelector("[data-numerics-lab]").scrollIntoView({ block: "start", behavior: "instant" })`); +await pause(150); +await screenshot("/tmp/llm-atlas-numerics-lab-desktop.png"); + +await command("Emulation.setDeviceMetricsOverride", { + width: 390, + height: 844, + deviceScaleFactor: 1, + mobile: true, +}); +await navigate("/systems/numerics/"); +await evaluate(`document.querySelector("[data-numerics-lab]").scrollIntoView({ block: "start", behavior: "instant" })`); +await pause(100); +await screenshot("/tmp/llm-atlas-numerics-lab-mobile.png"); +const mobile = await evaluate(`(() => { + const toggle = document.querySelector("#menu-toggle"); + toggle.click(); + return { + documentOverflow: document.documentElement.scrollWidth - document.documentElement.clientWidth, + menuVisible: getComputedStyle(toggle).display !== "none", + menuOpen: toggle.getAttribute("aria-expanded"), + mobileLinks: document.querySelectorAll("#mobile-nav a").length, + }; +})()`); + +await command("Emulation.setDeviceMetricsOverride", { + width: 1440, + height: 1100, + deviceScaleFactor: 1, + mobile: false, +}); +await navigate("/"); +const home = await evaluate(`({ + documentOverflow: document.documentElement.scrollWidth - document.documentElement.clientWidth, + releaseCards: document.querySelectorAll(".release-card").length, + firstRelease: document.querySelector(".release-card h2").textContent, + firstHref: document.querySelector(".release-card").getAttribute("href"), + paperCount: document.querySelector(".hero-stats div:nth-child(3) b").textContent, + navLinks: document.querySelectorAll(".top-nav a").length, +})`); + +await navigate("/papers/"); +const papers = await evaluate(`(() => { + const optimizer = [...document.querySelectorAll("[data-filter]")].find((node) => node.dataset.filter === "优化器"); + optimizer?.click(); + return { + hasOptimizerFilter: Boolean(optimizer), + total: document.querySelectorAll("[data-paper]").length, + visible: [...document.querySelectorAll("[data-paper]")].filter((node) => !node.hidden).length, + }; +})()`); + +const report = { format, ledger, optimizer, stability, layout, mobile, home, papers, exceptions }; +console.log(JSON.stringify(report, null, 2)); + +const numeric = (value) => Number.parseFloat(value.replaceAll(",", "")); +const failures = []; +if (format.initial.storage !== "2.000 B/value") failures.push("BF16 初始字节口径异常"); +if (!["SUBNORMAL", "ROUNDED"].includes(format.tinyFp16.status)) failures.push("FP16 微小梯度未进入 subnormal/rounding 边界"); +if (format.largeE4M3.status !== "OVERFLOW") failures.push("E4M3 大激活未触发 overflow"); +if (numeric(format.shared.error) <= numeric(format.local.error) || !format.shared.note.includes("teaching scale")) { + failures.push("MXFP4 block outlier 没有压缩普通值格点"); +} +if (ledger.bf16.rows !== 6 || ledger.v3.rows !== 6 || ledger.k3.rows !== 6) failures.push("混合精度状态栈数量异常"); +if (numeric(ledger.v3.total) >= numeric(ledger.bf16.total) || numeric(ledger.k3.total) >= numeric(ledger.bf16.total)) { + failures.push("低精度预设没有降低教学状态字节"); +} +if (!ledger.v3.risks.includes("1×128") || !ledger.k3.risks.includes("post-training")) failures.push("V3/K3 证据边界缺失"); +if (optimizer.full.cells !== 8 || optimizer.perHead.cells !== 8) failures.push("更新矩阵没有完整渲染"); +if (optimizer.perHead.unit.trim() !== "attention head" || !optimizer.perHead.label.includes("Per-Head")) { + failures.push("Per-Head Muon 逻辑单位异常"); +} +if ( + numeric(optimizer.perHead.imbalance) > 1.25 + || numeric(optimizer.perHead.imbalance) >= numeric(optimizer.full.imbalance) * 0.1 +) failures.push("Per-Head Muon 没有显著降低两个 head 的更新失衡"); +if (stability.v4.timeline !== 24 || stability.k2.timeline !== 24) failures.push("稳定性时间线数量异常"); +if (!stability.v4.summary.includes("均低于 HIGH") || stability.v4.defenses.length !== 5) { + failures.push("DeepSeek-V4 防线预设没有压低四条教学风险"); +} +if (stability.keyboard.selected !== "stability" || stability.keyboard.visible !== "stability") { + failures.push("实验页签键盘导航异常"); +} +if (layout.articleSections !== 19 || layout.paperLinks !== 36 || layout.labTabs !== 4 || layout.views !== 4) { + failures.push("章节、论文或实验数量异常"); +} +if (layout.navLinks !== 14 || mobile.mobileLinks !== 14 || home.navLinks !== 14) failures.push("全站导航未同步数值专题"); +if (layout.documentOverflow > 0 || mobile.documentOverflow > 0 || home.documentOverflow > 0) failures.push("页面存在横向溢出"); +if (layout.navGap < 0) failures.push(`桌面导航碰撞:${layout.navGap}px`); +if (!mobile.menuVisible || mobile.menuOpen !== "true") failures.push("移动端菜单不可用"); +if (home.releaseCards !== 7 || !home.firstRelease.includes("少几个比特") || home.firstHref !== "/systems/numerics/") { + failures.push("首页数值新章入口异常"); +} +if (home.paperCount !== "223") failures.push(`首页论文总数异常:${home.paperCount}`); +if (!papers.hasOptimizerFilter || papers.total !== 223 || papers.visible < 8) failures.push("论文库优化器标签或论文总数异常"); +if (exceptions.length) failures.push(`浏览器脚本异常:${exceptions.join("; ")}`); + +socket.close(); +if (failures.length) { + failures.forEach((failure) => console.error(`- ${failure}`)); + process.exit(1); +} +console.log("数值精度、优化器与稳定性专题真实 Chrome 断言通过。"); diff --git a/scripts/check-reasoning-browser.mjs b/scripts/check-reasoning-browser.mjs index 62f335a..60cad72 100644 --- a/scripts/check-reasoning-browser.mjs +++ b/scripts/check-reasoning-browser.mjs @@ -289,7 +289,7 @@ if (layout.documentOverflow > 0 || mobile.documentOverflow > 0 || home.documentO } if (layout.navGap < 0) failures.push(`桌面导航碰撞:${layout.navGap}px`); if (!mobile.menuVisible || mobile.menuOpen !== "true") failures.push("移动端菜单不可用"); -if (home.releaseCards !== 6 || !home.firstRelease.includes("一万亿 Token")) failures.push("首页新章入口异常"); +if (home.releaseCards !== 7 || !home.firstRelease.includes("少几个比特")) failures.push("首页数值新章入口异常"); if (exceptions.length) failures.push(`浏览器脚本异常:${exceptions.join("; ")}`); socket.close(); diff --git a/scripts/check-scaling-browser.mjs b/scripts/check-scaling-browser.mjs index 626089f..458cfc1 100644 --- a/scripts/check-scaling-browser.mjs +++ b/scripts/check-scaling-browser.mjs @@ -269,14 +269,14 @@ if (emergence.paths.some((length) => length < 500)) failures.push("涌现多指 if (layout.articleSections !== 16 || layout.paperLinks !== 29 || layout.labTabs !== 4 || layout.views !== 4) { failures.push("章节、论文或实验数量异常"); } -if (layout.navLinks !== 13 || mobile.mobileLinks !== 13 || home.navLinks !== 13) failures.push("全站导航未同步 Scaling"); +if (layout.navLinks !== 14 || mobile.mobileLinks !== 14 || home.navLinks !== 14) failures.push("全站导航未同步数值专题"); if (layout.documentOverflow > 0 || mobile.documentOverflow > 0 || home.documentOverflow > 0) failures.push("页面存在横向溢出"); if (layout.navGap < 0) failures.push(`桌面导航碰撞:${layout.navGap}px`); if (!mobile.menuVisible || mobile.menuOpen !== "true") failures.push("移动端菜单不可用"); -if (home.releaseCards !== 6 || !home.firstRelease.includes("一万亿 Token") || home.firstHref !== "/pretraining/data/") { - failures.push("首页数据工程新章入口异常"); +if (home.releaseCards !== 7 || !home.firstRelease.includes("少几个比特") || home.firstHref !== "/systems/numerics/") { + failures.push("首页数值新章入口异常"); } -if (home.paperCount !== "202") failures.push(`首页论文总数异常:${home.paperCount}`); +if (home.paperCount !== "223") failures.push(`首页论文总数异常:${home.paperCount}`); if (exceptions.length) failures.push(`浏览器脚本异常:${exceptions.join("; ")}`); socket.close(); diff --git a/scripts/check-training-systems-browser.mjs b/scripts/check-training-systems-browser.mjs index 627883c..84f7349 100644 --- a/scripts/check-training-systems-browser.mjs +++ b/scripts/check-training-systems-browser.mjs @@ -233,7 +233,7 @@ if (layout.articleSections !== 16 || layout.paperLinks !== 37 || layout.labTabs if (layout.documentOverflow > 0 || mobile.documentOverflow > 0 || home.documentOverflow > 0) failures.push("页面存在横向溢出"); if (layout.navGap < 0) failures.push(`桌面导航碰撞:${layout.navGap}px`); if (!mobile.menuVisible || mobile.menuOpen !== "true") failures.push("移动端菜单不可用"); -if (home.releaseCards !== 6 || !home.firstRelease.includes("一万亿 Token")) failures.push("首页新章入口异常"); +if (home.releaseCards !== 7 || !home.firstRelease.includes("少几个比特")) failures.push("首页数值新章入口异常"); if (exceptions.length) failures.push(`浏览器脚本异常:${exceptions.join("; ")}`); socket.close(); diff --git a/src/components/NumericsLab.astro b/src/components/NumericsLab.astro new file mode 100644 index 0000000..ba436de --- /dev/null +++ b/src/components/NumericsLab.astro @@ -0,0 +1,1214 @@ +--- +const formatOptions = [ + ["fp32", "FP32", "1 · 8 · 23"], + ["fp16", "FP16", "1 · 5 · 10"], + ["bf16", "BF16", "1 · 8 · 7"], + ["e4m3", "FP8 E4M3", "1 · 4 · 3"], + ["e5m2", "FP8 E5M2", "1 · 5 · 2"], + ["mxfp4", "MXFP4", "E8M0 + 32×E2M1"], +]; + +const precisionPresets = [ + ["bf16", "BF16 基线", "常见稳定训练基线;关键状态 FP32。"], + ["fp16", "经典 FP16", "master weights、loss scaling 与 FP32 accumulate。"], + ["v3", "V3-like FP8", "细粒度 scale;GEMM FP8,关键角色保留高精度。"], + ["k3", "K3 QAT-like", "专家权重 MXFP4;非专家与 master 保留高精度。"], +]; + +const stabilityPresets = [ + ["k2", "Kimi K2", "MuonClip + per-head QK-Clip"], + ["k3", "Kimi K3", "Per-Head Muon + clip + SiTU-GLU"], + ["v3", "DeepSeek-V3", "fine-grained FP8 + FP32 promotion"], + ["v4", "DeepSeek-V4", "QK norm + clamp + anticipatory routing"], +]; +--- + +
+
+
+

INTERACTIVE FOUR INDEPENDENT LEDGERS

+

数值工程四联实验室

+

四个视图彼此独立:表示误差、状态字节、更新几何和失稳信号不能合成一个“总分”。

+
+
+ TEACHING MODEL + 机制模拟,不是 GPU bit-exact kernel、真实训练预测器或厂商性能基准。 +
+
+ +
+ + + + +
+ +
+
+
+ 选择格式 +
+ {formatOptions.map(([id, label, bits], index) => ( + + ))} +
+
+ + + +
+ + + +
+
+ +
+
+ INPUT + 1.300000 + + REPRESENTED + 1.296875 +
+
+
SIGN1 bit
+
EXPONENT8 bits
+
MANTISSA7 bits
+
+ +
+
STATUS
ROUNDED
+
ABS ERROR
0.003125
+
REL ERROR
0.240%
+
STORAGE
2.000 B/value
+
+
+ 为什么 BF16 能装得大,却不够细? +

8-bit exponent 保留 FP32 级动态范围;7-bit mantissa 让单位附近只剩约 0.78% 的格点间距。

+
+
+
+ + + + + + +
+ + + + diff --git a/src/components/SiteHeader.astro b/src/components/SiteHeader.astro index b7ce2e0..1b8ff7d 100644 --- a/src/components/SiteHeader.astro +++ b/src/components/SiteHeader.astro @@ -16,6 +16,7 @@ const items = [ { id: "long-context", href: "/long-context/", label: "长上下文" }, { id: "reasoning", href: "/reasoning/", label: "推理" }, { id: "training-systems", href: "/training-systems/", label: "训练系统" }, + { id: "numerics", href: "/systems/numerics/", label: "数值" }, { id: "papers", href: "/papers/", label: "论文库" }, { id: "progress", href: "/progress/", label: "进度" }, ]; diff --git a/src/data/chapters.ts b/src/data/chapters.ts index b4d9165..965ff9e 100644 --- a/src/data/chapters.ts +++ b/src/data/chapters.ts @@ -138,12 +138,12 @@ export const chapters: Chapter[] = [ title: "数值精度、优化器与稳定性", kicker: "OPTIMIZATION", question: "为什么少几个比特能省巨资,也可能让训练瞬间崩掉?", - summary: "解释 AdamW、μP、Muon、BF16/FP8/MXFP4 与量化感知训练的数值直觉。", - status: "queued", - progress: 13, - papers: 16, + summary: "用十张数值账解释 AdamW、μP、Muon、BF16/FP8/MXFP4、QAT 与训练失稳反馈环。", + status: "published", + progress: 75, + papers: 36, prerequisites: ["02", "08"], - highlights: ["FP8", "Muon", "MXFP4"], + highlights: ["FP8", "MuonClip", "MXFP4", "稳定性控制室"], }, { number: "10", diff --git a/src/data/papers.ts b/src/data/papers.ts index 454d6f9..1bf4d57 100644 --- a/src/data/papers.ts +++ b/src/data/papers.ts @@ -6,6 +6,7 @@ export type PaperTopic = | "Scaling" | "数据" | "训练系统" + | "优化器" | "低精度" | "后训练" | "推理" @@ -867,7 +868,7 @@ export const papers: Paper[] = [ year: 2014, title: "Adam: A Method for Stochastic Optimization", url: "https://arxiv.org/abs/1412.6980", - topics: ["训练系统"], + topics: ["训练系统", "优化器"], contribution: "自适应一阶/二阶矩估计,成为 LLM 优化器基线。", verified: true, }, @@ -875,7 +876,7 @@ export const papers: Paper[] = [ year: 2017, title: "Decoupled Weight Decay Regularization", url: "https://arxiv.org/abs/1711.05101", - topics: ["训练系统"], + topics: ["训练系统", "优化器"], contribution: "AdamW 将权重衰减与梯度更新正确解耦。", verified: true, }, @@ -1081,11 +1082,19 @@ export const papers: Paper[] = [ spotlight: "Kimi", verified: true, }, + { + year: 2024, + title: "Muon: An Optimizer for Hidden Layers in Neural Networks", + url: "https://kellerjordan.github.io/posts/muon/", + topics: ["优化器"], + contribution: "把 momentum matrix 经 Newton–Schulz 近似正交化,给出 Muon 的原始定义与参考实现。", + verified: true, + }, { year: 2025, title: "Muon is Scalable for LLM Training", url: "https://arxiv.org/abs/2502.16982", - topics: ["训练系统"], + topics: ["训练系统", "优化器"], contribution: "补足 Muon 在 LLM 规模的权重衰减与更新尺度配方。", spotlight: "Kimi", verified: true, @@ -1130,6 +1139,166 @@ export const papers: Paper[] = [ contribution: "基于近似二阶信息逐层量化大模型权重。", verified: true, }, + { + year: 2015, + title: "Deep Learning with Limited Numerical Precision", + url: "https://arxiv.org/abs/1502.02551", + topics: ["低精度"], + contribution: "系统研究定点低精度训练,并用 stochastic rounding 保住微小更新的长期积累。", + verified: true, + }, + { + year: 2017, + title: "Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference", + url: "https://arxiv.org/abs/1712.05877", + topics: ["低精度"], + contribution: "建立 fake quantization 与量化感知训练的经典整数推理配方。", + verified: true, + }, + { + year: 2018, + title: "Shampoo: Preconditioned Stochastic Tensor Optimization", + url: "https://arxiv.org/abs/1802.09568", + topics: ["优化器"], + contribution: "沿 tensor 各 mode 构造结构化预条件器,在逐坐标自适应之外利用矩阵几何。", + verified: true, + }, + { + year: 2018, + title: "Adafactor: Adaptive Learning Rates with Sublinear Memory Cost", + url: "https://arxiv.org/abs/1804.04235", + topics: ["优化器", "训练系统"], + contribution: "用行列因子近似二阶矩,并以 update clipping 降低优化器状态与失稳风险。", + verified: true, + }, + { + year: 2019, + title: "A Study of BFLOAT16 for Deep Learning Training", + url: "https://arxiv.org/abs/1905.12322", + topics: ["低精度", "训练系统"], + contribution: "解释 BF16 保留 FP32 exponent、压缩 mantissa 的范围—精度取舍。", + verified: true, + }, + { + year: 2020, + title: "Query-Key Normalization for Transformers", + url: "https://arxiv.org/abs/2010.04245", + topics: ["Transformer", "优化器"], + contribution: "归一化每个 attention head 的 Q/K 并学习缩放,直接约束 Softmax logit 尺度。", + verified: true, + }, + { + year: 2021, + title: "8-bit Optimizers via Block-wise Quantization", + url: "https://arxiv.org/abs/2110.02861", + topics: ["优化器", "低精度"], + contribution: "用 block-wise dynamic quantization 压缩 optimizer state,同时隔离离群值影响。", + verified: true, + }, + { + year: 2022, + title: "DeepNet: Scaling Transformers to 1,000 Layers", + url: "https://arxiv.org/abs/2203.00555", + topics: ["Transformer", "优化器"], + contribution: "用 DeepNorm 的残差缩放与初始化界约束深层 Transformer 更新。", + verified: true, + }, + { + year: 2022, + title: "Tensor Programs V: Tuning Large Neural Networks via Zero-Shot Hyperparameter Transfer", + url: "https://arxiv.org/abs/2203.03466", + topics: ["Scaling", "优化器"], + contribution: "μP 让小代理模型调出的超参数可随宽度迁移到更大网络。", + verified: true, + }, + { + year: 2023, + title: "Scaling Vision Transformers to 22 Billion Parameters", + url: "https://arxiv.org/abs/2302.05442", + topics: ["Transformer", "优化器", "多模态"], + contribution: "以 QK LayerNorm 等改动缓解超大 ViT 的 attention logit 爆炸。", + verified: true, + }, + { + year: 2023, + title: "Stable and Low-precision Training for Large-scale Vision-language Models", + url: "https://arxiv.org/abs/2304.13013", + topics: ["低精度", "优化器", "多模态"], + contribution: "用 SwitchBack 与稳定性诊断研究低精度 VLM 训练中的 outlier 和 Adam second-moment spike。", + verified: true, + }, + { + year: 2023, + title: "QLoRA: Efficient Finetuning of Quantized LLMs", + url: "https://arxiv.org/abs/2305.14314", + topics: ["低精度", "后训练"], + contribution: "以 NF4、double quantization 和 paged optimizers 微调冻结的 4-bit 基座。", + verified: true, + }, + { + year: 2023, + title: "LLM-QAT: Data-Free Quantization Aware Training for Large Language Models", + url: "https://arxiv.org/abs/2305.17888", + topics: ["低精度", "后训练"], + contribution: "用自生成数据进行 weight、activation 与 KV cache 的量化感知训练。", + verified: true, + }, + { + year: 2023, + title: "Small-scale Proxies for Large-scale Transformer Training Instabilities", + url: "https://arxiv.org/abs/2309.14322", + topics: ["优化器", "训练系统"], + contribution: "用高学习率小模型代理复现大模型失稳,降低稳定性机制的研究成本。", + verified: true, + }, + { + year: 2023, + title: "FP8-LM: Training FP8 Large Language Models", + url: "https://arxiv.org/abs/2310.18313", + topics: ["低精度", "训练系统"], + contribution: "把 FP8 扩展到计算、优化器与分布式通信的端到端 LLM 训练。", + verified: true, + }, + { + year: 2023, + title: "Spike No More: Stabilizing the Pre-training of Large Language Models", + url: "https://arxiv.org/abs/2312.16903", + topics: ["优化器", "Transformer"], + contribution: "从“小 sublayer、大 shortcut”原则解释并抑制预训练早期 loss spike。", + verified: true, + }, + { + year: 2024, + title: "Deconstructing What Makes a Good Optimizer for Language Models", + url: "https://arxiv.org/abs/2407.07972", + topics: ["优化器"], + contribution: "拆解 Adam、Adafactor、Lion 等方法的更新尺度、方向与超参边界。", + verified: true, + }, + { + year: 2024, + title: "Scaling FP8 Training to Trillion-Token LLMs", + url: "https://arxiv.org/abs/2409.12517", + topics: ["低精度", "训练系统"], + contribution: "研究万亿 Token 长程 FP8 训练的 SwiGLU outlier,并提出 Smooth-SwiGLU。", + verified: true, + }, + { + year: 2025, + title: "FP4 All the Way: Fully Quantized Training of LLMs", + url: "https://arxiv.org/abs/2505.19115", + topics: ["低精度", "训练系统"], + contribution: "探索权重、激活与梯度广泛采用 FP4 的 fully quantized 训练边界。", + verified: true, + }, + { + year: 2026, + title: "PowLU: Power-Law Units for Stable and Efficient LLM Training", + url: "https://arxiv.org/abs/2605.25704", + topics: ["优化器", "低精度", "Transformer"], + contribution: "用有界幂律激活控制极值,连接 activation 设计与低精度稳定性。", + verified: true, + }, { year: 2023, title: "AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration", @@ -1669,6 +1838,7 @@ export const paperTopics: PaperTopic[] = [ "Scaling", "数据", "训练系统", + "优化器", "低精度", "后训练", "推理", diff --git a/src/pages/index.astro b/src/pages/index.astro index 998cfc1..694a7c0 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -13,6 +13,7 @@ const routes: Record = { "long-context": "/long-context/", reasoning: "/reasoning/", "training-systems": "/training-systems/", + "systems/numerics": "/systems/numerics/", }; const paths = [ @@ -86,6 +87,7 @@ const paths = [ 长上下文专题 推理专题 训练系统专题 + 数值与优化专题
研究范围 -

表示学习 · Transformer · Scaling · 数据工程 · MoE · 长上下文 · 训练系统 · 后训练 · 推理 · Agent · 多模态 · 服务与评测

+

表示学习 · Transformer · Scaling · 数据工程 · MoE · 长上下文 · 训练系统 · 数值优化 · 后训练 · 推理 · Agent · 多模态 · 服务与评测

查看实时进度 →
+ +
+

NEW / CHAPTER 09 PRECISION · OPTIMIZATION · STABILITY

+

少几个比特为什么省巨资,也可能让训练瞬间崩掉?

+

+ 用表示、缩放、计算、累加、搬运、更新、参数化、观测、恢复与证据十张账, + 从 mixed precision、BF16、FP8 和 MXFP4,一路走到 AdamW、Muon、Kimi K2/K3 与 DeepSeek-V3/V4。 +

+
+
+
LINEAGE
2014 → 2026
+
PAPERS
36 个一手节点
+
LAB
格式 · 状态 · 更新 · 失稳
+
+ +

NEW / CHAPTER 05 DATA & PRE-TRAINING

@@ -438,6 +456,7 @@ const paths = [ transition: transform 180ms ease, border-color 180ms ease; } + .numerics-release, .data-release, .scaling-release, .training-release, @@ -446,6 +465,14 @@ const paths = [ min-height: 510px; } + .numerics-release { + background: + radial-gradient(circle at 82% 18%, rgba(113, 82, 137, 0.2), transparent 30%), + repeating-linear-gradient(90deg, transparent 0 64px, rgba(113, 82, 137, 0.045) 64px 65px), + repeating-linear-gradient(0deg, transparent 0 64px, rgba(76, 118, 112, 0.04) 64px 65px), + var(--paper-raised); + } + .data-release { background: radial-gradient(circle at 82% 18%, rgba(76, 118, 112, 0.2), transparent 30%), @@ -536,6 +563,7 @@ const paths = [ padding-bottom: 76px; } + .numerics-release, .data-release, .scaling-release, .training-release, diff --git a/src/pages/progress/index.astro b/src/pages/progress/index.astro index 21de459..4872f3c 100644 --- a/src/pages/progress/index.astro +++ b/src/pages/progress/index.astro @@ -18,6 +18,7 @@ const workstreams = [ { label: "稀疏计算与 MoE", value: 74, next: "补充真实集群 traces 与专家特化案例" }, { label: "长上下文专题", value: 72, next: "加入更多论文逐图笔记与真实模型配置对比" }, { label: "大规模训练系统", value: 71, next: "补真实集群 traces、故障案例与精确 topology 配置" }, + { label: "数值精度、优化器与稳定性", value: 75, next: "加入真实 kernel 吞吐、长程训练 traces 与逐图论文精读" }, { label: "引用与事实检查", value: 57, next: "自动化外链复查与来源等级扩展" }, { label: "开源与部署", value: 100, next: "每轮保留不可变镜像、提交与回滚点" }, ]; @@ -42,7 +43,7 @@ const workstreams = [
OVERALL
专题平均 {average}%
READABLE
{published} 个首版可读专题
ACTIVE
{researching} 个研究/写作中
-
UPDATED
2026-07-29 03:01 CST
+
UPDATED
2026-07-29 03:55 CST
MODE
持续迭代,不锁死版本
@@ -52,7 +53,7 @@ const workstreams = [

01 WORKSTREAMS

-

十三条工作流同时推进,但不混淆“有页面”和“已核验”

+

十四条工作流同时推进,但不混淆“有页面”和“已核验”

内容首版优先打通全局脉络;随后每轮迭代选择一个专题推进到论文/工程层,并做独立事实复核。 @@ -89,15 +90,16 @@ const workstreams = [

K3 报告已结构化拆解

47 页报告目录、151 条参考来源和架构/后训练/系统主线已经提取。

16 专题知识图

从语言模型基础到评测安全,包含先修依赖和三条贯穿案例。

编辑式网站系统

响应式导航、章节模板、侧栏、进度、论文链和证据提示组件。

-

二十个原创交互视图

K3、注意力、DeepSeek、长上下文、MoE、推理,以及训练系统、Scaling 与数据工程的多页签实验。

-

九篇首版长文

K3、Transformer、DeepSeek、Scaling、数据工程、长上下文、MoE、推理与训练系统专题。

+

二十四个原创交互视图

K3、注意力、DeepSeek、长上下文、MoE、推理,以及训练系统、Scaling、数据工程和数值专题的多页签实验。

+

十篇首版长文

K3、Transformer、DeepSeek、Scaling、数据工程、长上下文、MoE、推理、训练系统与数值优化专题。

Scaling Laws 深度专题

九张账、29 个一手节点、DeepSeek/Kimi 双谱系与曲面—部署—复用—涌现四联实验。

数据工程深度专题

十二张账、31 个一手节点、DeepSeek/Kimi 双谱系与流水线—去重—混合—改写四联实验。

长上下文深度专题

五张成本账、26 篇一手论文、10+ 机制图与 8 策略交互实验室。

MoE 深度专题

六张账、19 篇一手论文、DeepSeek/K3 主线与路由—容量—通信交互实验室。

推理深度专题

八张账、30 篇一手论文链、DeepSeek/Kimi 双主线与三页签互动实验室。

训练系统深度专题

九张账、37 个一手节点、DeepSeek/Kimi 双谱系与显存—网格—气泡—通信实验室。

-

202 篇关键论文索引

新增数据专题标签和 20 个一手节点,继续支持全文搜索与 Kimi/DeepSeek 聚光主线。

+

数值、优化器与稳定性深度专题

十张账、36 个一手节点、K2/K3 与 DeepSeek-V3/V4 双谱系,以及格式—状态—更新—失稳四联实验。

+

223 篇关键论文索引

新增「优化器」标签和 21 个一手节点,继续支持全文搜索与 Kimi/DeepSeek 聚光主线。

公开仓库与自托管发布

源码公开到 git.k1412.top,网站由不可变镜像、Compose Manager 与 HTTPS 交付。

@@ -115,6 +117,7 @@ const workstreams = [
P0Scaling Laws 二轮

真实拟合复现 → 置信区间 → 更多模型族与下游任务外推

可复现实验 + 逐图笔记
P1数据工程二轮

FineWeb / DCLM 逐图 → 真实去重误伤 → mixture traces 与污染案例

逐图笔记 + 案例库
P1大规模训练系统二轮

真实集群 traces → 故障恢复 → 精确 topology / kernel 配置

案例库 + 实测边界
+
P1数值与稳定性二轮

真实 kernel 吞吐 → 长程失稳 traces → optimizer / quantization 逐图复现

实测边界 + 逐图笔记
P1长上下文二轮深化

真实模型配置 → 内核细节 → 长上下文评测与失败案例

配置比较器 + 逐图论文笔记
P1MoE 二轮深化

真实负载 traces → 专家特化可解释性 → 共享专家语义

案例库 + 集群证据
P1推理二轮深化

真实 pass@k 曲线 → PRM 失败案例 → 逐篇图表精读

案例库 + 真实 traces
@@ -162,6 +165,8 @@ const workstreams = [
Scaling Laws 按九张账组织

把观测量、模型、数据、算术、配比、配方、外推、经济目标与能力阶段分开核算。

数据工程按十二张账组织

把来源、解析、语言、质量、唯一性、污染、混合、变换、Tokenizer、Packing、课程与价值分开核算。

Grok 数据线索与正式账本永久分离

1264 行正式研究账本只接受回查一手来源后的结论;203 行 Grok 产物保留为未核验发现队列。

+
数值专题按十张账组织

把格式、缩放、计算、累加、搬运、更新、参数化、观测、恢复与证据经济分开核算。

+
低精度结论必须写完整角色合同

对象、格式、scale 粒度、accumulator、输出与硬件不再被压缩成一个 dtype 标签。

diff --git a/src/pages/systems/numerics/index.astro b/src/pages/systems/numerics/index.astro new file mode 100644 index 0000000..8a6f4f7 --- /dev/null +++ b/src/pages/systems/numerics/index.astro @@ -0,0 +1,1426 @@ +--- +import BaseLayout from "@/layouts/BaseLayout.astro"; +import NumericsLab from "@/components/NumericsLab.astro"; + +const toc = [ + ["00", "map", "十张数值账"], + ["01", "bits", "一个数的三块地盘"], + ["02", "half", "FP16 与 BF16"], + ["03", "fp8", "FP8 不是单一格式"], + ["04", "mx", "Microscaling 与 MXFP4"], + ["05", "roles", "混合精度角色图"], + ["06", "quant", "PTQ、QAT 与低精度训练"], + ["07", "optimizer-map", "优化器历史地图"], + ["08", "adam", "Adam → AdamW"], + ["09", "structured", "Adafactor、Shampoo 与 μP"], + ["10", "muon", "Muon 的矩阵几何"], + ["11", "kimi-k2", "K2 / MuonClip"], + ["12", "kimi-k3", "K3 / Per-Head Muon"], + ["13", "deepseek-v3", "DeepSeek-V3 / FP8"], + ["14", "deepseek-v4", "DeepSeek-V4 / Muon + FP4"], + ["15", "stability", "五条失稳反馈环"], + ["16", "lab", "四联互动实验"], + ["17", "audit", "怎样审计一份精度报告"], + ["18", "papers", "关键论文链"], +]; + +const ledgers = [ + ["N1 / REPRESENT", "表示", "sign / exponent / mantissa 怎样决定范围、格点与特殊值?"], + ["N2 / SCALE", "缩放", "一个 scale 服务整 tensor、channel、token、tile 还是 32-element block?"], + ["N3 / COMPUTE", "计算", "哪些 GEMM 真用低精度,哪些敏感算子仍在 BF16 / FP32?"], + ["N4 / ACCUMULATE", "累加", "成千上万个低精度乘积在哪里、以多少位求和?"], + ["N5 / MOVE", "存储与通信", "参数、激活、梯度、moments、KV 与 checkpoint 各占多少字节?"], + ["N6 / UPDATE", "参数更新", "逐坐标自适应、矩阵预条件与正交化到底改变什么?"], + ["N7 / SCALE-UP", "参数化", "宽度、深度、head 分块怎样改变初始化、LR 与 update RMS?"], + ["N8 / OBSERVE", "稳定信号", "logit、activation、gradient、update、spectrum 与 saturation 谁先异常?"], + ["N9 / RECOVER", "恢复", "scale、clip、skip、rollback、确定性 replay 分别解决哪一层?"], + ["N10 / EVIDENCE", "证据与经济", "增益对什么模型、Token、硬件、质量与 wall-clock 基线成立?"], +]; + +const formatHistory = [ + ["1985 / IEEE 754", "FP32 成为通用基线", "范围与精度宽,但训练规模扩大后,存储与数据搬运成为主要成本。"], + ["2015", "Stochastic rounding", "低精度小 update 不必永远被 round-to-nearest 吞成 0。"], + ["2017", "FP16 mixed precision", "FP32 master weights、loss scaling、FP32 accumulation 组成经典三件套。"], + ["2019", "BF16", "保留 FP32 的 8-bit exponent,牺牲 mantissa,换取更容易训练的动态范围。"], + ["2022", "FP8 E4M3 / E5M2", "前向更偏 E4M3,梯度更偏 E5M2;scale 与 higher-precision output 成为必需角色。"], + ["2023", "MX formats", "32 个窄元素共享 E8M0 scale,把可表示窗口缩小到局部 block。"], + ["2024", "Fine-grained FP8", "DeepSeek-V3 用 1×128 activation tile、128×128 weight block 与 FP32 promotion。"], + ["2025–26", "FP4 training / QAT", "全量 FP4 训练仍在探索;V4/K3 先把专家与特定路径纳入部署感知 QAT。"], +]; + +const roleRows = [ + ["GEMM INPUT", "FP8 / MX element", "缩放后进入矩阵乘;低位吞吐收益主要发生在这里。"], + ["MULTIPLY", "FP8 × FP8 / FP4 × FP8", "硬件支持决定峰值;没有原生指令就未必更快。"], + ["PARTIAL SUM", "limited / FP32 promoted", "内积很长时,累加精度比单次乘法更容易被忽略。"], + ["OUTPUT", "BF16 / FP32", "下一算子、residual 或 backward 对输出范围有自己的要求。"], + ["MASTER WEIGHT", "FP32", "保留小 update;低精度 working copy 可每 step 重新生成。"], + ["GRADIENT", "FP8 / BF16 / FP32", "计算、累计和通信可以再次分成三种格式。"], + ["OPTIMIZER STATE", "FP8 / BF16 / FP32", "一阶矩与二阶矩的范围需求不同,不能一刀切。"], + ["CHECKPOINT", "高精度或部署格式", "用于恢复训练的状态与用于线上推理的权重不是同一份契约。"], +]; + +const quantTaxonomy = [ + ["PTQ", "训练后", "GPTQ / SmoothQuant", "便宜、快速", "极低位、activation / KV 与分布漂移可能掉点"], + ["QAT", "训练 / 微调时", "Jacob 2018 / LLM-QAT", "模型可适应 rounding / clamp", "需要数据、反向和 fake/native quant 一致"], + ["LOW-BIT FINETUNE", "adapter 训练", "QLoRA", "冻结 4-bit 基座,大幅省微调显存", "不等于 4-bit base update 或预训练"], + ["LOW-PREC PRETRAIN", "从头 / 长程", "FP8-LM / DeepSeek-V3", "训练 GEMM、激活和通信共同受益", "长时 outlier、scale 与 accumulator 都需验证"], + ["FULLY QUANTIZED", "W/A/G 广泛低位", "FP4 All the Way", "继续压缩训练成本", "仍属前沿;Token、模型、硬件边界严格"], +]; + +const optimizers = [ + ["1951", "SGD", "一份梯度,直接沿下降方向走;状态最少,scale mismatch 最直接。"], + ["2014", "Adam", "用逐坐标一阶矩与二阶矩构造自适应步长。"], + ["2017", "AdamW", "把 weight decay 从 adaptive gradient 中解耦。"], + ["2018", "Adafactor", "用矩阵行 / 列统计因子化 second moment,并裁真正 update。"], + ["2018", "Shampoo", "为 tensor 各 mode 建结构化预条件器,代价是矩阵根与状态。"], + ["2022", "μP / μTransfer", "不是 optimizer;让宽度变化时 activation / update 语义保持可迁移。"], + ["2024–25", "Muon", "momentum matrix 经 Newton–Schulz 近似正交化;再补 decay 与 RMS matching。"], + ["2025–26", "MuonClip / Per-Head / Hybrid", "把 attention 越界保护、head 分块与 AdamW 参数组接回生产系统。"], +]; + +const stabilityLoops = [ + { + code: "01 / DEPTH", + title: "深度—残差", + chain: ["model update 累积", "residual 过大", "gradient 消失 / 爆炸", "early divergence"], + defenses: "warmup · scaled init · Pre-LN / DeepNorm · mHC", + }, + { + code: "02 / ATTENTION", + title: "Q/K—Softmax", + chain: ["Wq / Wk norm 增长", "QKᵀ logit 爆炸", "attention 近 one-hot", "head dynamics 继续变尖"], + defenses: "QK norm · soft-cap · QK-Clip · per-head monitor", + }, + { + code: "03 / ACTIVATION", + title: "SwiGLU—低精度", + chain: ["两支对齐 / 增大", "乘积 outlier", "scale 被极值占满", "普通值失去格点"], + defenses: "Smooth-SwiGLU · clamp · SiTU-GLU · PowLU", + }, + { + code: "04 / OPTIMIZER", + title: "统计量—Update", + chain: ["second moment 滞后", "adaptive update 过大", "loss spike", "moment 继续污染"], + defenses: "update clip · β₂ / ε 审计 · update RMS · skip", + }, + { + code: "05 / ROUTING", + title: "Expert—Router", + chain: ["expert outlier", "路由偏好加剧", "异常 expert 更热", "MoE spike"], + defenses: "per-expert monitor · bounded activation · Anticipatory Routing", + }, +]; + +const paperChain = [ + ["2014", "Adam: A Method for Stochastic Optimization", "https://arxiv.org/abs/1412.6980", "逐坐标一阶 / 二阶矩基线。"], + ["2015", "Deep Learning with Limited Numerical Precision", "https://arxiv.org/abs/1502.02551", "stochastic rounding 与低精度训练前史。"], + ["2017", "Mixed Precision Training", "https://arxiv.org/abs/1710.03740", "FP32 master、loss scaling、FP32 accumulate。"], + ["2017", "Decoupled Weight Decay Regularization", "https://arxiv.org/abs/1711.05101", "AdamW 与 L2 / decay 边界。"], + ["2017", "Quantization and Training of Neural Networks…", "https://arxiv.org/abs/1712.05877", "fake quant 与 QAT 起点。"], + ["2018", "Shampoo", "https://arxiv.org/abs/1802.09568", "结构化 tensor preconditioning。"], + ["2018", "Adafactor", "https://arxiv.org/abs/1804.04235", "factor second moment 与 update clipping。"], + ["2019", "A Study of BFLOAT16 for Deep Learning Training", "https://arxiv.org/abs/1905.12322", "BF16 范围—精度取舍。"], + ["2020", "GLU Variants Improve Transformer", "https://arxiv.org/abs/2002.05202", "SwiGLU 原始主线。"], + ["2020", "Query-Key Normalization for Transformers", "https://arxiv.org/abs/2010.04245", "Q/K 余弦化与 learned scale。"], + ["2021", "8-bit Optimizers via Block-wise Quantization", "https://arxiv.org/abs/2110.02861", "optimizer state 的 block-wise 量化。"], + ["2022", "DeepNet: Scaling Transformers to 1,000 Layers", "https://arxiv.org/abs/2203.00555", "residual scaling 与 update bound。"], + ["2022", "Tensor Programs V / μTransfer", "https://arxiv.org/abs/2203.03466", "跨宽度超参迁移。"], + ["2022", "LLM.int8()", "https://arxiv.org/abs/2208.07339", "大模型 activation outlier。"], + ["2022", "FP8 Formats for Deep Learning", "https://arxiv.org/abs/2209.05433", "E4M3 / E5M2 交换格式。"], + ["2022", "GPTQ", "https://arxiv.org/abs/2210.17323", "近似二阶 weight-only PTQ。"], + ["2022", "SmoothQuant", "https://arxiv.org/abs/2211.10438", "W8A8 activation outlier 迁移。"], + ["2023", "Scaling Vision Transformers to 22 Billion Parameters", "https://arxiv.org/abs/2302.05442", "QK LayerNorm 与 logit explosion。"], + ["2023", "Stable and low-precision training…", "https://arxiv.org/abs/2304.13013", "SwitchBack 与 Adam second-moment spike。"], + ["2023", "QLoRA", "https://arxiv.org/abs/2305.14314", "NF4 frozen-base 微调边界。"], + ["2023", "LLM-QAT", "https://arxiv.org/abs/2305.17888", "data-free W/A/KV QAT。"], + ["2023", "Small-scale proxies for large-scale Transformer instabilities", "https://arxiv.org/abs/2309.14322", "高 LR 小模型研究代理。"], + ["2023", "Microscaling Data Formats for Deep Learning", "https://arxiv.org/abs/2310.10537", "E8M0 + 32-element MX block。"], + ["2023", "FP8-LM", "https://arxiv.org/abs/2310.18313", "FP8 compute、gradient 与通信。"], + ["2023", "Spike No More", "https://arxiv.org/abs/2312.16903", "小 sublayer、大 shortcut。"], + ["2024", "DeepSeek LLM", "https://arxiv.org/abs/2401.02954", "BF16 + FP32 gradient accumulation。"], + ["2024", "Deconstructing What Makes a Good Optimizer…", "https://arxiv.org/abs/2407.07972", "Adam / Adafactor / Lion 对照边界。"], + ["2024", "Scaling FP8 training to trillion-token LLMs", "https://arxiv.org/abs/2409.12517", "长程 SwiGLU outlier 与 Smooth-SwiGLU。"], + ["2024", "DeepSeek-V3 Technical Report", "https://arxiv.org/abs/2412.19437", "fine-grained FP8 生产配方。"], + ["2024", "Muon: An Optimizer for Hidden Layers", "https://kellerjordan.github.io/posts/muon/", "Muon 原始定义与实现。"], + ["2025", "Muon is Scalable for LLM Training", "https://arxiv.org/abs/2502.16982", "decay、update RMS 与 distributed Muon。"], + ["2025", "Kimi K2 Technical Report", "https://arxiv.org/abs/2507.20534", "MuonClip 与 QK-Clip。"], + ["2025", "FP4 All the Way", "https://arxiv.org/abs/2505.19115", "fully quantized FP4 training。"], + ["2026", "PowLU", "https://arxiv.org/abs/2605.25704", "有界 activation 稳定性对照。"], + ["2026", "DeepSeek-V4", "https://arxiv.org/abs/2606.19348", "hybrid Muon、spike mitigation、FP4 QAT。"], + ["2026", "Kimi K3", "https://arxiv.org/abs/2607.24653", "Per-Head Muon、SiTU-GLU、MXFP4 QAT。"], +]; +--- + + +
+
+
+

NUMERICS / 09 PRECISION · OPTIMIZATION · STABILITY

+

少几个比特为什么省巨资,
也可能让训练瞬间崩掉?

+

+ 一个 LLM 不是“用某种精度”训练。参数、乘法、累加、梯度、优化器状态、通信与部署权重 + 各有自己的数值合同;任何一环太粗、太窄或尺度错位,都可能让万亿 Token 的长跑前功尽弃。 +

+
+
+
LEDGERS
10 张不能混的账
+
CORE SOURCES
36 个一手节点
+
LINEAGE
2014 → 2026
+
LAB
格式 · 状态 · 更新 · 失稳
+
SPOTLIGHT
DeepSeek × Kimi
+
+
+
+ +
+ + +
+
+

00 TEN LEDGERS

+

第一步不是选 dtype,而是给每种 Tensor 分配一份数值合同

+

+ “FP8 训练”“Muon 更高效”“没有 loss spike”都是不完整句子。 + 必须继续追问:什么对象、哪个阶段、怎样缩放、在哪里累加、对什么基线、观察了多久。 +

+ +
+ {ledgers.map(([code, title, body], index) => ( +
+ {code}

{title}

{body}

+
+ ))} +
+ +
+ 一句话总纲 +

+ 数值工程不是把所有 tensor 强行降到同一种格式;它要在速度、字节、范围、舍入误差与恢复能力之间, + 为 forward、backward、optimizer、communication 和 deployment 分别选精度。 +

+
+
+ +
+

01 NUMBER ANATOMY

+

Exponent 决定“能装多大”,Mantissa 决定“同一数量级分多细”

+

+ 二进制浮点数可以先想成一张科学计数法卡片: + (−1)sign × significand × 2exponent。 + 减少 exponent bits 会缩窄动态范围;减少 mantissa bits 会拉大相邻格点。 + scale 能移动这扇窗口,但不会增加窗内格点。 +

+ +
+
1 BITS

正负号

+
RANGEE

数量级与 overflow / underflow

+
PRECISIONM

相邻可表示值的距离

+
+ +
+
格式S / E / M最大有限值单位附近间距关键直觉
+
FP321 / 8 / 23≈ 3.4e38≈ 1.19e−7

范围、细度都宽;存储与带宽贵。

+
FP161 / 5 / 1065,504≈ 9.77e−4

比 BF16 细,但动态范围窄。

+
BF161 / 8 / 7≈ 3.4e38≈ 7.81e−3

保留 FP32 范围;单位附近只有 128 个刻度 / binade。

+
FP8 E4M31 / 4 / 34480.125

更偏细度;常给 weight / activation。

+
FP8 E5M21 / 5 / 257,3440.25

更偏范围;常给 gradient。

+
MXFP4E8M0 + 32×E2M1由 scale 决定很粗

局部共享指数,不能脱离 block 描述。

+
+ +
+ 三个不同错误 +

Overflow 是装不下;Underflow 是小到变 0;Rounding 是还装得下,却落到邻近格点。三者需要不同监控和防线。

+
+ +

四十年格式演进:每次降位都伴随一层新的保护

+
+ {formatHistory.map(([year, name, body], index) => ( +
+ + {String(index + 1).padStart(2, "0")} +

{name}

+

{body}

+
+ ))} +
+
+ +
+

02 FP16 → BF16

+

2017 年的突破不是“直接改 FP16”,而是让高低精度分工

+

+ Mixed Precision Training 的经典配方从一开始就有三层保护: + FP16 负责大批量存储与乘法,FP32 master 保存小 update,loss scaling 把小梯度移进可表示窗口, + FP32 accumulator 再把大量乘积稳定求和。 +

+ +
+
+ 01 / FORWARD + BACKWARD +

FP16 working copy

+

参数、激活与梯度降低存储 / 带宽;Tensor Core 做低精度乘法。

+
+ +
+ 02 / PROTECT SMALL GRADIENT +

Loss scaling

+

先放大 loss,再在 update 前 unscale;overflow 时跳过 update 并调 scale。

+
+ +
+ 03 / UPDATE +

FP32 master weights

+

FP16 中小于一个格点的 update,仍能在 FP32 参数里逐步累积。

+
+
+ +

BF16 为什么更省心?

+

+ BF16 与 FP32 都使用 8-bit exponent,所以能覆盖相似数量级;它把成本省在 mantissa。 + 这通常减少 FP16 式 overflow / loss-scale 调参,但并不意味着所有累加、optimizer state 和 softmax + 都可以降为 BF16。DeepSeek LLM 就是 BF16 训练、FP32 累计梯度,并在 cross entropy 内把 logits 临时提升到 FP32。 +

+ +
+
错误

BF16 比 FP16“全面更精确”

BF16 范围更宽;FP16 在同一数量级的 mantissa 更细。

+
错误

FP32 accumulate 抵消全部误差

输入已经被量化的误差不会因为高精度相加自动消失。

+
错误

低位字节能直接换算速度

cast、scale、kernel、shape 与硬件原生支持共同决定端到端收益。

+
+
+ +
+

03 FP8

+

E4M3 与 E5M2 是两种取舍;真正训练时还要带上 scale 与 accumulator

+

+ 2022 年 FP8 格式论文提出两个 8-bit 编码。E4M3 用一个 exponent bit 换一个 mantissa bit, + 更适合相对集中的 weight / activation;E5M2 范围更宽,适合长尾更重的 gradient。 + 论文同时明确:FP8 input 通常要 scale,数学输出通常以更高精度产生。 +

+ +
+
+ E4M3 +
SE E E EM M M
+
MAX
448
MIN SUBNORMAL
2⁻⁹
+

较多 mantissa,较窄范围。DeepSeek-V3 依靠细粒度 scale,让 forward / backward tensor 都可统一用 E4M3。

+
+
+ E5M2 +
SE E E E EM M
+
MAX
57,344
MIN SUBNORMAL
2⁻¹⁶
+

范围更宽、格点更粗。格式论文推荐给 gradient;长程 FP8 optimizer 也发现 second moment 更需要 E5M2 范围。

+
+
+ +
+ FP8 不是一个 dtype 标签 +

至少要写成:对象 + 格式 + scale 粒度 + accumulator + 输出格式 + hardware。例如“1×128 activation tile 量化到 E4M3,每 128 个 K 元素 promotion 到 FP32”。

+
+
+ +
+

04 MICROSCALING

+

从“整张地图共用比例尺”到“每 32 个数一把尺”

+

+ per-tensor scaling 的麻烦是:一个离群值会把整张 tensor 的 scale 拉大,普通值被挤到少数格点。 + Microscaling 把共享范围缩到一个小 block。OCP MX concrete formats 使用 32 个元素共享一个 E8M0 scale; + MXFP4 的每个元素本体是 E2M1。 +

+ +
+
+ PER-TENSOR + 1 SCALE +
{Array.from({ length: 32 }, (_, index) => )}
+

一个 outlier 压缩全部普通值的有效刻度。

+
+ +
+ MICROSCALING + 1 SCALE / 32 ELEMENTS +
{Array.from({ length: 32 }, (_, index) => )}
+

异常只影响局部 block;scale 元数据、axis 和转换逻辑成为新成本。

+
+
+ +
+
SHARED SCALEE8M0 · 8 bits

只保存指数型比例尺。

+ × +
32 ELEMENTSE2M1 · 4 bits each

每个值本身极粗。

+ = +
BLOCK136 bits / 32 values

平均 4.25 bits / value,不含布局 padding。

+
+ +
+ Transpose 也会改变语义 +

scale 通常沿 GEMM reduction axis 共享。矩阵 transpose 后,scale axis 也要变化;“先量化再转置”不总等于“先转置再量化”。

+
+
+ +
+

05 MIXED-PRECISION ROLE MAP

+

不要问“模型是什么精度”,要问每个角色是什么精度

+
+ {roleRows.map(([role, format, body], index) => ( +
+ {String(index + 1).padStart(2, "0")} / {role} +

{format}

+

{body}

+
+ ))} +
+ +

DeepSeek-V3 的公开 role map

+
+
+ BF16 INPUTFP8 FPROP GEMMBF16 / FP32 OUTPUT +
+
+ FP8 ACTIVATION CACHEFP8 DGRAD / WGRADFP32 GRADIENT +
+
+ BF16 m₁ / m₂+FP32 MASTERONLINE QUANTIZE +
+
+ +

+ 关键高精度保留项包括 embedding、output head、MoE gate、normalization 与 attention。 + MoE dispatch 可以 FP8,combine 保留 BF16;attention backward 敏感 activation 甚至使用自定义 E5M6。 + 所以 V3 的亮点不是“大胆全降位”,而是知道哪里不能降。 +

+
+ +
+

06 QUANTIZATION TAXONOMY

+

同样写“4-bit”,可能在回答五个完全不同的问题

+
+
范畴发生时机代表优势边界
+ {quantTaxonomy.map(([name, when, examples, strength, boundary]) => ( +
{name}{when}{examples}

{strength}

{boundary}

+ ))} +
+ +
+
FP32 MASTER可连续更新

小 update 仍能积累。

+ +
FAKE / NATIVE QUANTround + clamp + scale

forward 经历部署误差。

+ +
DEQUANT / COMPUTE低精度行为

输出与 rollout 对齐。

+ +
STE近似穿过 rounding

gradient 回到 master weight。

+
+ +
+ QLoRA 的边界 +

QLoRA 把冻结基座以 NF4 存储,计算时 dequant 到 BF16,只训练 adapter。它证明低显存微调可行,不证明基座从头以 4-bit 更新也等价。

+
+
+ +
+

07 OPTIMIZER LINEAGE

+

优化器演进的核心不是“公式更复杂”,而是更新单位越来越贴近参数结构

+
+ {optimizers.map(([year, name, body], index) => ( +
+ + {String(index + 1).padStart(2, "0")} +

{name}

+

{body}

+
+ ))} +
+
+ +
+

08 ADAM → ADAMW

+

Adam 给每个坐标一把尺;AdamW 再把“学任务”与“缩权重”分开

+
+
FIRST MOMENTmₜ = β₁mₜ₋₁ + (1−β₁)gₜ

平滑方向。

+
SECOND MOMENTvₜ = β₂vₜ₋₁ + (1−β₂)gₜ²

估计逐坐标尺度。

+
ADAPTIVE UPDATEΔθ = −η · m̂ / (√v̂ + ε)

不同坐标获得不同有效步长。

+
ADAMW DECAYθ ← (1−ηλ)θ + Δθ

不让 L2 项穿过 adaptive denominator。

+
+ +

为什么 gradient clipping 还不够?

+

+ gradient clipping 限制的是 g;Adam 之后的真正 update 还会除以 √v。 + 当 second moment 低估当前 squared gradient,adaptive update 仍可能过大。Adafactor 因而提出 + update clipping;2023 年低精度 VLM 工作又观察到 loss spike 常在 second moment 低估后 1–8 steps 出现。 +

+ +
+ 反过来,Adam 也不是不可替代 +

2024/2025 的系统对照在 150M–1.2B decoder-only LM 上发现,除 SGD 外,Adam、带 momentum 的 Adafactor、Lion、Signum 的最优 loss 与 LR robustness 相近。这个结果挑战“Adam 唯一最好”,但规模远小于 K3/V4,不能推翻大模型生产选择。

+
+
+ +
+

09 STRUCTURE & SCALE-UP

+

Adafactor 省状态,Shampoo 看矩阵,μP 保持放大时的更新语义

+
+
+ ADAFACTOR +

nm 个 second moments → n+m 个行列统计

+
R₁…RₙC₁…Cₘ
+

省掉完整二阶矩;还提出 update clipping、动态 β₂ 与 relative step size。它不是无损 Adam,momentum 与稳定性配方需要重新选。

+
+
+ SHAMPOO +

不把一张矩阵摊平成独立坐标

+
L⁻¼GR⁻¼
+

为 tensor 各 mode 做结构化预条件;更尊重矩阵几何,却带来矩阵根、blocking、低频更新与分布式成本。

+
+
+ μP / μTRANSFER +

先让“小模型的一步”与“大模型的一步”可比

+
13M同一更新语义6.7B
+

μP 不是 optimizer;它用参数组相关的初始化 / LR scaling,让宽度变化时超参更可迁移。深度、batch、数据和 optimizer 切换仍要另外研究。

+
+
+
+ +
+

10 MUON

+

AdamW 问“每个坐标多大”,Muon 问“整张更新矩阵沿哪些方向走”

+

+ Muon 先做 momentum,再用 Newton–Schulz 矩阵乘迭代近似 UVᵀ。 + 如果原 momentum 的 SVD 是 UΣVᵀ,这个变换把非零 singular values 拉向相近尺度, + 避免少数 dominant direction 吞掉全部更新。 +

+ +
+
GRADIENTGₜ

一张逻辑独立矩阵。

+ +
MOMENTUMMₜ = μMₜ₋₁ + Gₜ

可加 Nesterov look-ahead。

+ +
NEWTON–SCHULZM → UVᵀ

用矩阵乘近似,不做完整 SVD。

+ +
RMS + DECAY0.2√max(n,m) · O

Moonlight 配方匹配 AdamW 步长。

+
+ +
+
+ RAW MOMENTUM SPECTRUM + +

少数方向占主导。

+
+ Newton–Schulz +
+ MUON UPDATE SPECTRUM + +

方向尺度更均衡。

+
+
+ +

为什么原始 Muon 不能直接放大?

+
    +
  • 权重增长:Moonlight 报告长训时 vanilla Muon 的 weight / output RMS 持续上升,因此补 AdamW-style weight decay。
  • +
  • Shape 依赖:A×B full-rank matrix 的理论 update RMS 约为 1/√max(A,B),需要 shape-aware rescale。
  • +
  • 参数分组:embedding、LM head、norm、bias 并非都适合矩阵正交化,通常继续 AdamW。
  • +
  • 分布式:Newton–Schulz 需要完整逻辑矩阵,不能像逐元素 Adam 那样随意切开。
  • +
+ +
+ 作者报告边界 +

Muon is Scalable 报告 compute-optimal scaling 下约 2× efficiency、达到相同 loss 约需 AdamW 的 52% FLOPs。这是其模型族、数据、参数组与调参协议下的结果,不是所有 LLM 的普遍定理。

+
+
+ +
+

11 KIMI K2 / MUONCLIP

+

Muon 学得快,却把少数 attention head 的 logits 推过了悬崖

+

+ K2 报告在 9B active / 53B total 中间实验中观察到 vanilla Muon 的 max attention logits 很快超过 1000, + 带来 loss spike 与偶发 divergence。RMSNorm 能控制输入 x,但 + q·k = (xWq)(xWk)ᵀ 仍会把 Q/K weight spectral norm 的增长相乘放大。 +

+ +
+
‖Wq‖ / ‖Wk‖ ↑01
+
max QKᵀ ↑02
+
Softmax entropy ↓03
+
训练尖锐 / spike04
+
+ +

QK-Clip 不改当前 forward,而是在 optimizer step 后缩回越界权重

+
+ Smaxh = max pre-softmax logit of head h + γh = min(1, τ / Smaxh) + Wq, Wk ← head-specific rescale +
+ +
+
THRESHOLDτ = 100

K2 公开设置。

+
FIRST 70K STEPS12.7% heads

至少触发过一次。

+
LATERSelf-deactivated

所有 head 曾降回阈值以下。

+
FULL RUN15.5T Token

报告未观察 loss spike。

+
+ +

+ K2 解释 QK-Norm 不适合其 MLA:key matrix 在 inference 不完全物化。QK-Clip 只缩 head-specific + qC/kC/qR,不碰 shared rotary kR。这是一种结构相关选择, + 不能简化成“clip 永远优于 normalization”。 +

+
+ +
+

12 KIMI K3 / PER-HEAD MUON

+

K3 把“按 head 监控”推进到“按 head 计算 Muon update”

+

+ 完整 Q/K/V projection 的 momentum matrix 可能把多个 attention heads 耦合成一个大 block。 + 大尺度 head 主导共享正交化,小尺度 head 得不到充分归一。K3 把 momentum 沿 head 维切成逻辑块, + 每个 head 独立 Newton–Schulz,再组合回 projection。 +

+ +
+
+ FULL-MATRIX MUON +
H1H2H3H4
+ one shared orthogonalization +

大 scale head 影响共同 update。

+
+ +
+ PER-HEAD MUON +
NS(H1)NS(H2)NS(H3)NS(H4)
+ four logical matrices +

每个 head 独立匹配方向与尺度。

+
+
+ +

Optimizer 只是 K3 稳定性组合的一层

+
+
UPDATE

Per-Head Muon

按 head 平衡 Q/K/V update;tall block 也降低 NS 开销。

+
LOGIT

K2 weight clipping

训练 recipe 明确继续使用 K2 引入的越界保护。

+
MoE SCALE

RMSNorm

expert aggregate 进入 up-projection 前归一。

+
ACTIVATION

SiTU-GLU

两支 smooth tanh cap;每坐标输出绝对值小于 100。

+
+ +
+
+ SWIGLU + + + + 大正值近似继续增长 +
+
+ SITU-GLU + + + + + |output coordinate| < 4 × 25 = 100 +
+
+ +

K3 的低精度落点:部署感知 post-training

+

+ 从 SFT 起贯穿 RL:routed expert weights 用 MXFP4,expert input activations 以 MXFP8 计算; + attention、latent MoE projection、shared expert 与 router 保持高精度。rollout 与 training 使用同一量化方案, + 以减少 train–inference mismatch。K3 总预训练 Token 与完整 dtype map 未公开。 +

+
+ +
+

13 DEEPSEEK-V3 / FP8

+

DeepSeek-V3 的亮点不是“FP8 很勇”,而是把每一处误差路径写成工程选择

+
+
MODEL671B total · 37B active
+
DATA14.8T Token
+
FORMATE4M3 for all FP8 tensors
+
AUTHOR RESULT<0.25% relative loss error
+
+ +
+
+ 01 / QUANTIZE SMALL GROUPS +

Activation 1×128 · Weight 128×128

+

每 Token 的 128 channels 一把尺;每 128×128 weight block 一把尺。outlier 不再拖累整 tensor。

+
+
+ 02 / ACCUMULATE CAREFULLY +

每 128 个 K 元素 promotion

+

H800 Tensor Core partial sum 作者测得约 14-bit;定期移到 CUDA Core FP32 register。

+
+
+ 03 / KEEP SENSITIVE ROLES HIGH +

Attention / Norm / Router 不降

+

embedding、output head、MoE gate、normalization、attention 保留原精度。

+
+
+ 04 / COMPRESS MOVEMENT +

Activation cache / MoE dispatch FP8

+

真正节省的不只 GEMM;backward cache 与跨卡 dispatch 同时减字节,combine 仍 BF16。

+
+
+ +
+ APPENDIX B.2 / NEGATIVE RESULT +

把 Dgrad activation gradient 也改成规整的 128×128 block,模型发散

+

+ 在约 16B MoE、约 300B Token 实验中,activation gradient 的 token-correlated outlier + 无法被 block-wise grouping 处理。这个失败案例比“FP8 成功”更重要: + 量化粒度必须服从数据分布,不能只服从 kernel 布局。 +

+
+
+ +
+

14 DEEPSEEK-V4 / HYBRID MUON + FP4

+

V3 已经稳定跑完 FP8,V4 仍然遇到新的 loss spikes

+

+ V4 改变了 attention、residual、optimizer、上下文和 MoE 规模。任何一项变化都可能重开失稳路径。 + 报告明确写出训练遇到 notable instability,并公开两个经验补丁,而不是只展示平滑 loss。 +

+ +
+
+ OPTIMIZER +

Majority Muon · Selected AdamW

+

embedding、prediction head、mHC static bias/gate、RMSNorm weights 留在 AdamW;其余逻辑矩阵 Muon。

+
+
+ ORTHOGONALIZATION +

8 fast + 2 stable NS iterations

+

先快速把 singular values 拉近 1,再用稳定系数精确收尾;Q/KV 可 RMSNorm,所以不采用 QK-Clip。

+
+
+ SPIKE RESPONSE +

Anticipatory Routing

+

spike 后短 rollback,暂时用历史参数预计算 routing indices,打断 router 与 expert outlier 同步反馈。

+
+
+ ACTIVATION +

SwiGLU Clamping

+

linear branch 限制在 [−10,10],gate branch 上限 10;作者称无性能损失,理论机制仍开放。

+
+
+ POST-TRAIN +

MXFP4 QAT

+

MoE expert weights + CSA indexer QK path;FP32 master 经 FP4 模拟,再 lossless dequant 到 FP8 compute(在报告 scale 条件下)。

+
+
+ DISTRIBUTED NUMERICS +

BF16 sync · FP32 local sum

+

gradient stochastic-round 到 BF16 通信,再本地 FP32 相加,避开低精度 collective adder 长链误差。

+
+
+ +
+ DeepSeek 亮点 +

V4 最值得学的不是“Muon / FP4 都用了”,而是它公开承认:数值格式、优化器、attention、routing、activation 与 collective 必须一起设计;一个成功的上一代配方不会自动继承稳定性。

+
+
+ +
+

15 FIVE FEEDBACK LOOPS

+

Loss 是最后报警器;真正的根因常在几十步、几千步甚至几百 B Token 前出现

+
+ {stabilityLoops.map((loop) => ( +
+ {loop.code} +

{loop.title}

+
{loop.chain.map((step, index) => <>{step}{index < loop.chain.length - 1 && })}
+

防线:{loop.defenses}

+
+ ))} +
+ +

稳定性控制室要监控十种信号

+
+ {[ + ["LOSS", "raw / EMA / per-domain", "结果已受影响,不给根因"], + ["ATTN LOGIT", "max / p99.9 / per-head", "Q/K growth 与 softmax saturation"], + ["ENTROPY", "per-head / layer", "过尖不一定有错,但值得联查"], + ["ACTIVATION", "max / RMS / outlier channel", "overflow 与 scale 风险"], + ["GRADIENT", "global / per-layer / nonfinite", "backward 信号;不等于真正 update"], + ["UPDATE", "RMS / param ratio / spectrum", "optimizer 实际施加的步长"], + ["WEIGHT", "RMS / spectral norm", "长期增长与 attention 放大"], + ["QUANT", "saturation / underflow / SNR", "scale、格式与 accumulator"], + ["MoE", "expert load / activation / drop", "router–outlier feedback"], + ["SYSTEM", "checksum / replay / bad rank", "kernel、collective、hardware fault"], + ].map(([name, measure, meaning]) => ( +
{name}{measure}

{meaning}

+ ))} +
+
+ +
+

16 INTERACTIVE LAB

+

亲手把四张账分开:一个小误差怎样变成系统级风险

+

+ 先在格式显微镜里观察格点,再看 mixed precision 状态字节;随后用同一组 head scale + 对比 AdamW、Muon 与 Per-Head Muon,最后把 K2/K3/V3/V4 的公开防线装进控制室。 +

+ +
+ +
+

17 AUDIT PROTOCOL

+

看到“FP4 / FP8 / 2× / stable”,至少继续问十二个问题

+
+ {[ + ["对象", "weight、activation、gradient、KV、moment 还是 communication?"], + ["阶段", "pre-training、SFT、RL、rollout 还是 inference?"], + ["格式", "INT、IEEE-like FP、E4M3/E5M2、MXFP4 还是厂商自定义?"], + ["粒度", "tensor、channel、token、tile、block;block size 与 axis 是什么?"], + ["缩放", "online / delayed;scale dtype;outlier / overflow 怎样处理?"], + ["乘法", "硬件是否原生支持;实际 kernel shape 与利用率?"], + ["累加", "partial sum 位宽、promotion interval、reduction order?"], + ["高精度保留", "master、norm、router、attention、loss、gradient accumulation 各是什么?"], + ["质量基线", "与 BF16 / FP16 对什么 loss、任务和训练时长比较?"], + ["系统基线", "吞吐是 peak GEMM、MFU、tokens/s 还是完整 wall-clock?"], + ["稳定性", "监控了哪些内部信号;是否有 rollback、skip 或隐藏恢复?"], + ["证据", "作者报告、独立复现、标准定义,还是教学推导?"], + ].map(([title, body], index) => ( +
{String(index + 1).padStart(2, "0")}

{title}

{body}

+ ))} +
+ +
+ PUBLIC UNKNOWNS +
    +
  • K3 总预训练 Token、完整 dtype placement 与 Per-Head Muon 单项 ablation 未公开;
  • +
  • K3 / V4 MXFP4 QAT 相对高精度的完整质量—延迟—能耗对照未公开;
  • +
  • V4 Anticipatory Routing 的完整触发阈值、持续步数与全部 spike trace 未公开;
  • +
  • Muon 相对 AdamW 的收益依赖模型族、参数分组、调参预算与训练 regime;
  • +
  • 本章所有互动数值均为机制教学,不是生产 kernel 或真实模型预测。
  • +
+
+
+ +
+

18 PRIMARY-SOURCE CHAIN

+

36 个一手节点:先读格式与更新,再进入 Kimi / DeepSeek 生产配方

+

+ 推荐顺序:Mixed Precision → BF16 → FP8 / MX → AdamW / μP / Muon → + QK / SwiGLU stability → DeepSeek-V3 / K2 → K3 / V4。 + 每个节点只承担它真正证明的部分,不把相邻论文拼成虚假的统一结论。 +

+
+ {paperChain.map(([year, title, url, note], index) => ( + + {String(index + 1).padStart(2, "0")} / {year} +

{title}

+

{note}

+
+ ))} +
+ +
+ 来源协议 +

+ 研究截止 2026-07-29。K3/K2/V3/V4 数字来自正式技术报告;Muon 原始定义来自作者技术博文, + 大规模结论来自后续 Moonlight 报告。Grok 产物永久保留在未核验 leads, + 正文事实逐项回查本地 PDF / 标准。论文图仅提炼机制,本页全部图形为原创简化重绘。 +

+
+
+
+
+ + +