Files
iomgaa 8b362eae09 层2: max_grad_norm 提进 DistillConfig(显式化静默稳定器)+ noclip 对照模式
首冒烟发现:sanity 的 loss 平滑、无预期毛刺,因 HF 默认 max_grad_norm=1.0 把
反向 KL 的梯度爆炸(§4.1,实测 grad_norm 14→2 是裁剪前范数)默默压平了——正是
本项目要堵的"静默行为"。

- configs.py: DistillConfig 加 max_grad_norm=1.0(默认=原 HF 行为),docstring 讲清
  它是 §4.1 爆炸的隐形稳定器、日志 grad_norm 是裁剪前值;__post_init__ 校验 >0
- train_whitebox.py: FULL 显式写出、TrainingArguments 传入;build_config 加 noclip
  模式(max_grad_norm=1e9≈关裁剪 + lr 5× + 15 步)暴露原始爆炸供教学对照
- .sh: 用法加 noclip 模式说明

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 08:34:14 -04:00

37 lines
2.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 层 2white-box OPD 训练(远程 gpu-a800-060 专用;本地不跑训练)。
#
# 用法(tmux 内执行,日志实时可查):
# bash scripts/train_whitebox.sh sanity # 50 步冒烟:首 prompt 自检 + KL loss + 生成数
# bash scripts/train_whitebox.sh noclip # §4.1 对照:15 步,关裁剪+抬 lr,暴露原始
# # 梯度爆炸(loss 毛刺);与 sanity 平滑曲线并排
# bash scripts/train_whitebox.sh # 正式:1k 子集 1 epoch
#
# 前置检查清单:
# 1. nvidia-smi 确认下方 GPUS 四张卡空闲(只许用 8 卡中的 4 张,严禁自动选卡)。
# ⚠️ 白盒显存比层 1 紧:student 训练全套 + teacher(4B) 推理副本 + **两份**全词表
# logits(student/teacher),§5 估算 B=4/T=2048 起步安全,但首跑必须盯 nvidia-smi;
# 若 OOM,降 per_device_train_batch_size 到 2,仍不够再开 gradient_checkpointing
# (改 DistillConfig,注意 checkpointing 与 generate 的 use_cache 交互)。
# 2. data/dapo-math-17k-unique.parquet 已在(层 2 无需 teacher 缓存,纯 prompt-only):
# scp data/dapo-math-17k-unique.parquet <远程>:/data/zym/ars-opd-rebuild/data/
# 3. 代码最新:git -C /data/zym/ars-opd-rebuild pull
# 4. 首跑会下载 teacher Qwen3-4BGB 级)到 HF_HOME,确保 /data 有空间
set -euo pipefail
cd "$(dirname "$0")/.." # 锚定仓库根
GPUS=0,1,2,3 # ⚠️ 改这里前先 nvidia-smi
MODE=${1:-full}
export CUDA_VISIBLE_DEVICES=$GPUS
export PYTHONUNBUFFERED=1 # 禁止日志缓存(CLAUDE.md §5
export PYTORCH_ALLOC_CONF=expandable_segments:True # 变长生成序列易碎片化,按需扩段
export HF_ENDPOINT=${HF_ENDPOINT:-https://hf-mirror.com}
export HF_HOME=${HF_HOME:-/data/zym/hf_cache} # 模型缓存落 /data,根分区已满
# 非显然坑:hf-mirror 不代理 HF 的 Xet CAS——大权重走 Xet 会直连
# cas-server.xethub.hf.co 并返 4012026-07-19 teacher 4B 下载实撞)。禁用 Xet
# 退回经典 HTTP/LFS 下载(镜像支持)。若仍不行:pip uninstall hf_xet
export HF_HUB_DISABLE_XET=1
torchrun --nproc_per_node=4 --master_port=29572 scripts/train_whitebox.py "$MODE"