docs: address Codex review of WP3 plan (pools passthrough, holdout memo, DELETE table)
This commit is contained in:
@@ -201,9 +201,10 @@ git commit -m "fix: early_stop patience counts epochs not steps"
|
||||
## Task 4: 可训练性预检
|
||||
|
||||
**Files:**
|
||||
- Modify: `app/harness/runner.py:865-879`(_setup_train_run)
|
||||
- Modify: `app/harness/config.py`(RunConfig 加 `trainable_min_units`)+ `config/train_videomme.yaml`(WP 收尾建,先加字段默认)
|
||||
- Test: `tests/unit/test_harness_runner.py`
|
||||
- Modify: `app/harness/runner.py`(`train` 入口过滤 + `_setup_train_run` 接收 filtered task_types)
|
||||
- Modify: `app/harness/config.py`(RunConfig 加 `trainable_min_units` + 正整数校验)
|
||||
- Modify: `app/harness/checkpoint.py:37`(`trainable_min_units` 入 `_STRUCTURAL_KEYS` 指纹)
|
||||
- Test: `tests/unit/test_harness_runner.py`、`tests/unit/test_harness_checkpoint.py`
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
@@ -263,15 +264,20 @@ def _filter_untrainable_types(
|
||||
return new_pools, new_types
|
||||
```
|
||||
(确认 `from dataclasses import replace` 已 import;`Pools` 是否 frozen dataclass 支持 `replace`——若非,按其构造方式重建。)
|
||||
在 `_setup_train_run`(pools 加载后、`_init_gate_pools` L874 前)调用:
|
||||
|
||||
**过滤结果必须回传主循环(Codex Critical)**:`RunConfig` 是 `@dataclass(frozen=True)`,**不能** `self._config.task_types = ...`(会 FrozenInstanceError),且过滤后的 pools 必须被 `train()` 后续的 batch/step/slow-update/final-eval 全部使用。实现方式:
|
||||
- 在 `train(pools)` **入口第一步**(`_setup_train_run` 调用之前)过滤:
|
||||
```python
|
||||
pools, self._config.task_types = _filter_untrainable_types(
|
||||
pools, filtered_task_types = _filter_untrainable_types(
|
||||
pools, self._config.task_types,
|
||||
self._config.eval_min_per_class, self._config.trainable_min_units,
|
||||
)
|
||||
```
|
||||
(`RunConfig` 若 frozen,改用局部变量传递而非改 self._config;实现前读 config.py 确认可变性。)
|
||||
`app/harness/config.py` `RunConfig` 加字段 `trainable_min_units: int`(无默认,显式配置;train yaml 提供)。
|
||||
- 把 filtered `pools` 传给 `_setup_train_run(pools)` 与 train() 后续所有消费点(build_batches / slow_update / final_eval 均用这个 filtered pools,不再触碰原始 pools)。
|
||||
- 把 `filtered_task_types` 传给 gate 建立(`_setup_train_run`/`_init_gate_pools` 用它而非 `self._config.task_types`)——新增参数透传,不改 frozen config。
|
||||
|
||||
`app/harness/config.py`:`RunConfig` 加字段 `trainable_min_units: int`(无默认,显式配置;train yaml 提供);在配置校验函数(如 `validate_config`,config.py:277 附近)加 `trainable_min_units >= 1` 断言(<1 报错)。
|
||||
`app/harness/checkpoint.py:37` `_STRUCTURAL_KEYS` 加入 `"trainable_min_units"`——该值改变会改变 pools 过滤结果与训练轨迹,必须纳入 checkpoint 结构指纹,resume 时变化即拒绝复用旧 checkpoint。
|
||||
|
||||
- [ ] **Step 4: 测试通过 + 回归**
|
||||
|
||||
@@ -415,7 +421,7 @@ Expected: FAIL(当前 None → wrong_by_error 走 defect 正文)。
|
||||
"疑似 judge 基础设施故障,中止训练(不以降级信号驱动进化)。"
|
||||
)
|
||||
```
|
||||
(确认 `DiagnosisResult.degraded_count` 字段可用,L2311。)
|
||||
(确认 `DiagnosisResult.degraded_count` 字段可用,定义在 `core/evolution/types.py:299`。)
|
||||
|
||||
- [ ] **Step 5: 测试通过 + 回归**
|
||||
|
||||
@@ -455,13 +461,13 @@ Expected: FAIL(当前 append,无 DELETE)。
|
||||
|
||||
- [ ] **Step 3: _run_step 开头 DELETE**
|
||||
|
||||
`app/harness/runner.py` `_run_step`,在 rollout(L1012)之前加:
|
||||
`app/harness/runner.py` `_run_step`,在 rollout(L1012)之前加(**用 `IF EXISTS` 避免 fresh workspace 首跑时 predictions/traces 表尚未由 `run_inference._ensure_tables` 创建导致 `OperationalError: no such table`**):
|
||||
```python
|
||||
with HarnessLog(str(self._paths.db_path), run_id, register_run=False) as log:
|
||||
log.execute("DELETE FROM predictions WHERE run_id=?", (run_id,))
|
||||
log.execute("DELETE FROM traces WHERE run_id=?", (run_id,))
|
||||
```
|
||||
(`register_run=False` 来自 WP4 Task 8;若 HarnessLog 无 `execute` 便捷方法,用其现有 `query`/连接接口,实现前读 log.py 对齐。)
|
||||
> SQLite `DELETE FROM <t>` 对不存在的表会抛 `no such table`。两种消解方式择一(实现前读 log.py 确认):① rollout 由 `run_inference` 先建表——把 DELETE 移到**首次 rollout 之后、诊断之前**并只在 resume 重跑(step 已有旧行)时执行;② 或 DELETE 前先 `CREATE TABLE IF NOT EXISTS`(复用 inference 的 PREDICTIONS_SCHEMA/TRACES_SCHEMA),保证幂等无害。推荐 ②(无害且简单)。`register_run=False` 来自 WP4;若 HarnessLog 无 `execute` 便捷方法,用其现有连接接口。
|
||||
|
||||
- [ ] **Step 4: checkpoint 提到 gate save 之后(消除双计窗口)**
|
||||
|
||||
@@ -505,15 +511,17 @@ async def test_holdout_dedup_skips_reevaluated_versions(...):
|
||||
Run: `conda run -n Video-Tree-TRM python -m pytest tests/unit/test_harness_runner.py -k holdout_dedup -v`
|
||||
Expected: FAIL(当前四向各跑一次)。
|
||||
|
||||
- [ ] **Step 3: 实现去重**
|
||||
- [ ] **Step 3: 实现去重(进程内备忘录,不改 holdout_eval schema)**
|
||||
|
||||
`app/harness/runner.py` `_holdout_four_way`:
|
||||
- **baseline 向**:不调 `_eval_version_on_pool`,改从基线 predictions(baseline_run_id)读 test 题对错算 acc(test 题在 infer_adhoc 已推理);epoch>1 复用首次结果。
|
||||
- **final 向**:真评 600(不变)。
|
||||
- **best_hard 向**:维护"已评版本→test_acc"备忘录,resume 时从 `holdout_eval` 表 hydrate(查已落库 `(skills_v,prompts_v)→acc`);版本对未评过且 ≠ final 才真评,否则引用。
|
||||
- **best_mixed 向**:引用赢家(best_hard 或 final 之一,`_pick_mixed_best` 已定)的 test 成绩,写 holdout_eval 时标指针,不推理。
|
||||
> **schema 约束(Codex Critical)**:当前 `holdout_eval` 表(observation.py:78)不存 skills_version/prompts_version/pointer,无法按版本反查做跨-run hydrate。本 task **不扩展该 schema**(避免结构性风险),改用 **train() 进程内备忘录** `dict[(skills_v,prompts_v), float]` 去重。代价:resume 后备忘录清空、已评版本会重评一次——resume 是异常路径、重评 600 题成本可接受,换取零 schema 变更风险。完整跨-run hydrate 记 future work。
|
||||
|
||||
实现前完整读 `_holdout_four_way`(1881-1921)、`write_holdout_eval`、`_eval_version_on_pool`、`read`/hydrate 路径对齐。
|
||||
`app/harness/runner.py` `_holdout_four_way`(在 `_TrainState` 加一个 `holdout_memo: dict[tuple[str,str], float] = field(default_factory=dict)` 字段):
|
||||
- **baseline 向**:不调 `_eval_version_on_pool`,改从基线 predictions(`baseline_run_id`)读 test 题对错算 acc(test 题在 infer_adhoc 已全推理过);结果存 memo,epoch>1 直接复用(0 推理)。
|
||||
- **final 向**:真评 600,算完存 `memo[(final_sv,final_pv)]`。
|
||||
- **best_hard 向**:若 `(best_sv,best_pv)` 已在 `memo`(== final 或往轮已评)则引用,否则真评并存 memo。
|
||||
- **best_mixed 向**:`_pick_mixed_best` 选出的赢家必是 best_hard 或 final 之一,其 test acc 已在 memo,直接引用写 holdout_eval,0 推理。
|
||||
|
||||
实现前完整读 `_holdout_four_way`(~1885)、`write_holdout_eval`、`_eval_version_on_pool` 对齐;`write_holdout_eval` 调用保持不变(仍逐向写观测行,只是 acc 来源改为 memo 复用/基线推导)。
|
||||
|
||||
- [ ] **Step 4: 测试通过 + 回归**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user