Skip to content

refactor: 收敛训练入口的重复样板 (#1241) - #1247

Merged
TATP-233 merged 1 commit into
dev/issue-1042-manager-based-apifrom
refactor/issue-1241-train-entry-boilerplate
Aug 21, 2026
Merged

refactor: 收敛训练入口的重复样板 (#1241)#1247
TATP-233 merged 1 commit into
dev/issue-1042-manager-based-apifrom
refactor/issue-1241-train-entry-boilerplate

Conversation

@TATP-233

Copy link
Copy Markdown
Collaborator

背景

Fixes #1241(Part of #1239)。基于 309894b 入口拆分后的现状,base 为 dev/issue-1042-manager-based-api(该拆分尚未合入 main)。

改动

库层收敛(src/unilab/training/):

  • run.py 新增共享 helper:build_run_dir_name(run 目录命名)、algo_config_dict(OmegaConf→dict)、format_play_checkpoint_error(checkpoint 未找到诊断)、resolve_nan_guard_cfg / apply_env_nan_guard(NanGuard 接线),并经 unilab.training 导出。
  • experiment.py 新增 build_run_config_payload / write_run_config_snapshotExperimentTracker.start()run_config.jsontrain_hora_distill.pydistill_run_config.json 共用同一写入路径,消除第二套快照写入逻辑。

入口脚本(train_rsl_rl / train_him_ppo / train_offpolicy / train_appo / play_interactive / play_viser / train_hora_distill)改为调用共享 helper;offpolicy 三个入口(sac/td3/flashsac)经共享实现 train_offpolicy.py 一处生效。

不做什么(与 issue 一致)

  • 各入口算法专属逻辑(DP 拓扑校验、replay_prefetch_mode 校验等)留在脚本;
  • run 目录命名规则不变(HORA 带 run_slug 的命名是不同规则,保留);
  • 输出文件内容与格式不变(distill_run_config.json key 顺序与结尾换行已实测保持一致)。

Validation

  • make test-all 通过(本地,最终提交内容一致;仅 1 个平台可选 mlx benchmark skip)。
  • grep 确认重复实现各只剩一份(_gpux / must resolve to a dict / Could not resolve a checkpoint for play mode / NanGuardCfg 接线)。
  • 受影响测试已同步:tests/scripts/test_train_scripts.py 的 monkeypatch 目标与 unilab.training stub。

…1241)

Move the mechanically duplicated helpers out of the four training
entries into the library layer:

- run dir naming, algo_config_dict (OmegaConf -> dict), the
  checkpoint-not-found play diagnostic, and NanGuard wiring now live in
  src/unilab/training/run.py and are re-exported from unilab.training
- run-config snapshot serialization is shared through
  write_run_config_snapshot in experiment.py; ExperimentTracker and the
  HORA distill entry both use it, with distill_run_config.json keeping
  its exact byte format (key order + trailing newline)

Entry scripts (train_rsl_rl / train_him_ppo / train_offpolicy /
train_appo / play_interactive / play_viser / train_hora_distill) now
call the shared helpers. Algo-specific validation stays in the scripts,
run dir naming rules and all output file formats are unchanged.

Validation: make test-all green.
@TATP-233
TATP-233 requested a review from caozx1110 as a code owner August 21, 2026 09:47
@TATP-233
TATP-233 merged commit c265c74 into dev/issue-1042-manager-based-api Aug 21, 2026
6 checks passed
@TATP-233
TATP-233 deleted the refactor/issue-1241-train-entry-boilerplate branch August 21, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant