Files
ts-as-modality/scripts/train_stage1.sh
T
张宗平 5e3030a20e feat(train): crash-resilient resume + EMA loss logging (stage1 & stage2)
Addresses both points from review:

1) Resume (so a killed run converges across multiple restarts, like gen_supervisor):
   - checkpoints now carry optimizer state + EMA value in a 'train_state' field
   - --resume auto-picks the latest step ckpt and continues; --resume_from for explicit
   - stage2 resume rebuilds the LoRA structure via enable_lora (same path as fresh)
     then overlays saved adapter weights via set_peft_model_state_dict. Using
     PeftModel.from_pretrained instead reset requires_grad and shrank the trainable
     set 129->33 tensors, corrupting the optimizer state — verified and fixed.
   - Smoke-verified: stage1 step4->10, stage2 step4->8, both restore optimizer +
     EMA + LoRA with no state mismatch.

2) EMA loss logging (honest answer to 'is the loss swing a real problem?'):
   - the old log printed the raw per-micro-batch loss every N steps; on
     heterogeneous 6-task data that swings 2-3x purely from sampling (anomaly
     JSON is low-loss, forecast numbers high-loss), so it looked 'unstable'
     while the model may well have been converging.
   - EMA(alpha=0.05) now logged alongside raw + as a tensorboard scalar
     (total_loss_ema / sft_loss_ema). Read the EMA, not the raw, to judge
     convergence. lr left unchanged (1e-4) pending EMA evidence.

Adds scripts/train_full_supervisor.sh: stage1->stage2 resume loop, same
crash-convergence guarantee as gen_full_supervisor.
2026-07-01 01:06:15 +00:00

27 lines
742 B
Bash
Executable File

#!/usr/bin/env bash
# Stage ① alignment training (T3.2).
# Loads align.jsonl (50万 target), freezes LLM, trains Encoder+Projector.
set -euo pipefail
DATA="${1:-data/align.jsonl}"
MAX_STEPS="${2:-10000}"
CKPT_DIR="${3:-checkpoints/stage1}"
cd "$(dirname "$0")/.."
export PYTHONPATH=src PYTHONUNBUFFERED=1
.venv/bin/python -m tsmm.train.stage1 \
--data "$DATA" \
--ckpt_dir "$CKPT_DIR" \
--max_steps "$MAX_STEPS" \
--bs 8 \
--grad_accum 4 \
--ctx 512 \
--lr 1e-4 \
--lambda_contrast 0.1 \
--perturb_std 0.1 \
--log_every 20 \
--ckpt_every 2000 \
--tensorboard
# Resume support: pass --resume to continue from the latest step ckpt.
# Usage: scripts/train_stage1.sh data/align.jsonl 30000 checkpoints/stage1 --resume