docs: T20 — Phase-2 systems-depth capstone (reframe README to two phases)

Re-conclude xtrain as TWO phases now that Phase-2 (T14–T18) is merged on main:

README.md
- Status header: "complete (T1–T13) + scaling v0–v8" → "complete — two phases"
  (Phase 1 = from-scratch stack T1–T13 + v0–v8 scaling study; Phase 2 = the five
  deferred systems-stack features T14–T18).
- Crate table: note the Phase-2 additions (fused flash-attn + repeat_kv + dropout
  in autodiff; GQA + dropout in model; grad-accum in train; process-per-GPU
  launcher in distributed).
- Build-journey section retitled Phase 1 + Phase 2; replaced the run-on T14–T18
  prose with a structured "## Phase 2" summary (5 features + honest results:
  flash = mem-not-walltime win, GQA group-sum backward, grad-accum −74% mem,
  dropout × recompute bit-exact, T17 throughput-neutral falsification).
- Engineering lessons: T17 added as the THIRD profile-first falsification;
  reinforced honest-correctness with the Phase-2 hard gates + md5 b04fc9f9.
- Doc index: doc range …14-* → …17-*; KI status line (process-per-GPU CLOSED,
  KI-4 accepted tradeoff).

docs/evolution.md
- New "三·五、Phase 2 systems-depth synthesis": ties the 5 features into the
  per-axis (算法/架构/Infra/数据) narrative + the two integration notes.

docs/known-issues.md
- KI-4 reframed as a deliberately-accepted modeling tradeoff (保 xserv closed
  loop; T19 DROPPED), not "open".
- New integration notes: (a) DDP tests need --test-threads=1 (parallel deadlock);
  (b) fresh-train md5 is non-deterministic (atomicAdd reduction order) → the valid
  determinism gate is export re-determinism, not fresh-train reproduction.
- (process-per-GPU item was already CLOSED=measured no-op in T17.)

Docs-only; no code touched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-18 18:11:47 +08:00
parent 71b0a1621f
commit db70abe450
3 changed files with 105 additions and 38 deletions

View File

@@ -64,6 +64,22 @@
- **容量轴有用,但也只有 ~3%v8**v6/v7 dim768 吃不动更多数据」,v8 用最干净的 A/B 回答了是数据见够还是容量不够」——**冻结数据子集纯把 dim768dim1024core 127M226M+78%** ~1 epoch FineWeb val **3.07→2.98↓0.085** v81.05ep还低于 v71.45ep 更多老数据 3.01。⇒ **容量有用v6/v7 部分是 capacity-limited不全是数据见够**放大容量比给小模型多喂老数据更值。**但增益只有 ~3%**与数据轴单步杠杆同量级
- 🧭 **元结论:单轴单步都已 ~3%/lever = 全面边际递减,要双轴一起 scaleChinchilla 小尺度复现)**把三条轴并起来看——数据量轴v5/v7 同子集多 epoch饱和~1.65%/)、数据广度轴v6 换语料是一次性换分布红利)、容量轴v8有用但 ~3%)——** v8任何单轴的单步杠杆都收敛到 ~3%/lever**。 v8 容量 +78% 却只配同样的 2.36B tokenval 末步仍在降 数据立刻成新瓶颈。⇒ **要继续进步,容量与数据必须匹配地一起 scale而不是单独猛拨一根轴**——这正是 Chinchilla 在这个 toy 尺度上的复现
## 三·五、Phase 2 系统栈深度综合T14T18 五条特性按四维收束)
scaling 科学线v0v8收官后项目重启回到本职学训练全栈」,把此前**显式延后**的五条训练栈特性补齐区别于 Phase 1 修真实瓶颈」(T10T13 每条都治一个 KIPhase 2 **补齐标配 + 一次诚实的负结果**。五条按四维落点
- **算法**三条 = **flash-attention(T14)** + **梯度累积(T16)** + **dropout(T18)**
- 三条里 **T14/T16 与 Phase 1 的 T13 一起构成可叠加的「显存三杠杆」**T13 压激活峰值T14 不物化 N×N attention scores收益随 seq 增长)、T16 解耦有效 batch 与激活显存显存随 micro 不随 N×)——三者正交叠加可放大有效 batch / seq
- **T18 dropout 的设计点是 stateless counter-based RNG**mask `(seed, 元素下标)` 无状态产出所以** T13 激活重计算天然 bit-exact 组合**——反向重算时同 seed 重生同一张 mask梯度逐位一致这是两条 Phase-2/Phase-1 特性的正交性被正确性闸门钉死的一个例子
- 诚实账flash-attention **赢在显存不赢墙钟**hd=64 小头维手写 kernel ~2.3× 慢于 cuBLAS tensor-coreopt-in 默认关不回归
- **模型架构**一条 = **真 GQA(T15)**:架构补齐到现代 LLM 标配MHA/GQA/MQA 一条 `num_kv_heads` )。实现关键 = `repeat_kv` broadcast 算子的**反向组内确定性求和 atomic** K/V 零改动喂进 composed + flash 两条 SDPA`group=1` MHA **逐位一致**作回归保护导出真 `num_key_value_heads` xserv 闭环真 GQA
- **Infra**一条 = **process-per-GPU(T17)**,但它是**实测负结果**而非性能提升:落地 torchrun 式独立进程/CUDA context 标准链路复用 T8 train_rank 零改动却实测本尺度**吞吐中性**thread ~5.27× vs proc ~5.31×@8<1%8 卡全 9599% util KI-5/T11 doc 长挂的共享单 context 致残留 ~5×@8猜想**钉死推翻**——残留是 NCCL all-reduce + PCIe 拓扑墙 context 串行。**方法论与 Phase 1 T11证伪分桶 all-reduce」)一脉相承profile/measure-first。**
- **数据集**零条Phase 2 不动数据轴KI-4 小词表用户拍板 **drop 以保 xserv gpt2-tokenizer 闭环**转记为接受的建模权衡 known-issues)。
**Phase 2 的统一闸门 = 诚实正确性,全程未为凑绿放宽容差**flash==composedgrad/PyTorch、GQA group=1 == MHA 逐位accum=1 逐位dropout p=0 逐位 + dropout×重算 bit-exact每条特性默认路径不变、**xserv 闭环 md5 `b04fc9f9` 两阶段全程逐位一致**。
> 📌 两条 integration 发现非回归pre-existing记账① **DDP 三个测试并行会争 2 卡 deadlock** → 文档/测试用 `--test-threads=1`(或标 serial跑。② **fresh-train md5 run-to-run 不定**——反向 atomicAdd 归约序非确定 → 有效的确定性闸门是**导出export重确定性**(同 ckpt 重导 safetensors md5 逐位一致),**不是** fresh-train 复现。
## 四、perf 杠杆台账(详见 [known-issues.md](known-issues.md)
- **已修**KI-1 单序列 launch-boundT10)· KI-5 per-op cudaMalloc 串行T11)· KI-2 bf16/OOMT12)· KI-3 激活重计算T13解锁 dim1024v8 用上)。

View File

@@ -156,6 +156,20 @@ _(KI-3 已在 T13 FIXED见上方 Fixed。本节暂无待启项。)_
## Modeling notes
### KI-4 · 大词表 embedding 占比过高
### KI-4 · 大词表 embedding 占比过高 — `接受的建模权衡用户拍板T19 DROPPED`
- gpt2 `vocab=50257` 在 dim 小时让 embed+lm_head 主导参数v1 25.7M/34M、v2 38.6M/66.9Mcore transformer 才是学习主体。
- 后续可考虑更贴合 TinyStories 的小 vocab会牺牲 xserv gpt2-tokenizer 复用);或在更大 dim 下让 core 自然成为主体(继续 scaling 即可缓解占比)
- **决定(不是 open是一个被接受的权衡**:曾计划 T19 训一个更贴语料的小 vocab 来压 embed 占比,**用户拍板 DROP**——保住 **xserv gpt2-tokenizer 闭环**(项目皇冠:导出权重回流 xserv 逐 token 一致)比清理 embedding 占比更值。小 dim 下 embed 占比高=复用 gpt2 大词表的**已知、接受的代价**
- 缓解路径仍在:更大 dim 时 core 自然成为主体(继续 scaling 即可摊薄占比v8 dim1024 core 226M 已主导);若日后愿意放弃该版闭环再重启小词表(见 [`~/toc/projects/xtrain.md`](../../toc/projects/xtrain.md) T19
---
## 集成 / 测试注记pre-existing非回归记账
### DDP 三测并行会争卡 deadlock → `--test-threads=1`
- `xtrain-distributed` 的三个 DDP 测试thread-per-GPU correctness / scaling、process-per-GPU `ddp_proc`)若被 cargo **并行**跑,会在共享的 2 卡上互相争 GPU/NCCL 资源 **deadlock**(不是数值 bug是测试调度
- **跑法**`cargo test ... -- --test-threads=1`(或把 DDP 测试标 serial串行跑即全绿。Phase-2 全回归 capture 均在 `--test-threads=1` 下取得。
### fresh-train md5 run-to-run 不定 → 有效确定性闸门是「导出重确定性」而非「fresh-train 复现」
- **现象**从随机初始化全新训练fresh-train产出的 ckpt其 md5 **run-to-run 不逐位复现**
- **根因**:反向里多处 `atomicAdd` 归约(如跨行 dK/dV、扇出累加的浮点**加法序非确定**GPU 原子操作完成序不固定)→ 末位 ULP 抖动逐步累积 → ckpt 字节不同。属本机/本版的已知浮点非确定性,**不是正确性回归**loss 轨迹仍同量级收敛)。
- **因此项目的确定性硬闸门定义为「导出export重确定性」**:拿**同一个已固定的 ckpt** 重新导出 HF-safetensorsmd5 与 registry **逐位一致**`b04fc9f9`,两阶段全程)——这条是确定性的、承重的;**不要求** fresh-train 字节复现。