Commit Graph

6 Commits

Author SHA1 Message Date
iomgaa de7f36828a 层2/U2: 纯逻辑 token_divergence(式(2) 全词表 KL/JSD)+ 梯度爆炸演示单测
trainer.py(对应 docs/03 §5 U2,与 sft_loss 同为纯张量损失函数):
- token_divergence: 全词表精确 KL(β=1 反向=式(2) / β=0 前向 / (0,1) JSD)
- 只吃两组已对齐 logits + labels 掩码,不做移位(复用 T4 几何,留给 U4)
- 删参考实现 top-k/尾桶/nan_to_num(本地全词表恒有限);按 β 分支省一份 probs
- per-token mean 与 sft_loss 同尺度;全掩码/beta 越界显式报错

test_divergence.py(对应 docs/03 §6.1):
- 对拍 PyTorch torch.distributions.kl_divergence(独立 oracle,非同式自证)
- 方向性: 反向罚越界(mode-seeking) / 前向罚漏覆盖(mode-covering)
- §4.1 梯度爆炸: teacher 概率 1e-1→1e-6 时 student 梯度范数单调暴涨(层5对照桩)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 04:00:25 -04:00
iomgaa 20e6d97427 层1/T2: teacher.py 批量生成 + sha256 JSONL 缓存;teacher 改定 MiniMax-M3
- teacher.py: 通用 OpenAI 兼容客户端(配置驱动 base_url,替代 OpenRouter 专用);
  缓存即断点(逐条落盘+flush,重跑自动续传);单条失败先落盘其余、结束汇总显式报错;
  M3 思考段 <think>...</think> 入库前剥离(只剥开头一段)
- configs.py: 新增 TeacherGenConfig(采样参数显式化;连接三元组走 .env)
- scripts/generate_teacher_completions.py: 自包含生成脚本(本地跑,与训练侧
  同 seed 同子集约束已注明)
- teacher 决策变更同步:.env.example / docs/00 关键设定与存档点 / docs/02
- tests/test_teacher.py: 10 个单测(假客户端注入),含与 attach 的端到端契约闭环

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 07:52:53 -04:00
iomgaa f5bb852fde 层1/T4: trainer.py 掩码 SFT 损失 + 最小 HF Trainer 子类(docs/02 §2.4)
- sft_loss 纯张量函数:batch-min prompt_length、移位切片、labels 重掩码;
  空 batch/无 prompt 行显式报错(参考实现静默归零,差异已标注)
- SFTTrainer 只重写 compute_loss 与 log;不向模型传 labels(防内部损失
  绕过重掩码);日志并入每步有效 token 数供 sanity 监控
- tests/test_trainer.py: 7 个单测,含手算对拍、移位对齐、窗口外无关性、
  漏切重掩码

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 05:02:41 -04:00
iomgaa 5ea58ddf59 层1/T3: data.py 数据管线——加载、messages 归一、teacher 缓存挂接、双预算 collator(docs/02 §2.2-2.3)
- to_messages 三分支归一,except:pass 改显式报错(差异标注在注释)
- prompt_key: sha256 内容寻址,作为与 teacher.py 的缓存契约单点定义
- attach_teacher_completions: 缺键一次性报全,绝不静默跳过
- SFTCollator: 双预算截断 + 未截断长度定边界(坑二)+ -100 掩码 + 左 padding;
  prompt-only 行显式报错(层 2 接 on-policy 再放开)
- tests/test_data.py: 19 个单测,玩具字符级 tokenizer 覆盖超长解答/超长题目/
  enable_thinking 双取值/左 padding/缓存契约

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 04:51:19 -04:00
iomgaa 58d75cc56a 层1/T1: SFTConfig dataclass 与构造校验(docs/02 §4)
- ars_opd/configs.py: 冻结 dataclass,机器路径无默认强制显式传入;
  双预算/enable_thinking/lr 差异均按 §7 规范标注
- __post_init__ 构造即校验,防"completion 预算为零→loss 恒 0"静默空训练
- tests/test_configs.py: 6 个校验测试

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 04:40:45 -04:00
iomgaa 72799a34dc tests: 预置 π̂ detach 命门守护测试(对应 docs/01 §3.4,层 3 接入真实 estimator)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 02:32:05 -04:00