From 07b6b44f50e2a110531c4fc1ae74c544ed1ab247 Mon Sep 17 00:00:00 2001 From: Michelle0474 <2170308303@qq.com> Date: Fri, 3 Jul 2026 17:37:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(cv):=20=E6=96=AD=E7=82=B9=E7=BB=AD?= =?UTF-8?q?=E8=B7=91=20-=20=E4=B8=BB=E5=BE=AA=E7=8E=AF=E8=B7=B3=E8=BF=87?= =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90=E7=9A=84=20outer=20fold?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 启动时若 fold_dir 已有 test_metrics/best_params/epoch_mean,直接读回结果跳过训练。 仅对主循环生效(precomputed_best_params is None),不影响 repeat 阶段。 应对服务器偶发崩溃,崩溃重启后重跑同一 output-dir 可接续未完成的 fold。 --- lnp_ml/modeling/nested_cv_optuna.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lnp_ml/modeling/nested_cv_optuna.py b/lnp_ml/modeling/nested_cv_optuna.py index b235d10..5fd94c3 100644 --- a/lnp_ml/modeling/nested_cv_optuna.py +++ b/lnp_ml/modeling/nested_cv_optuna.py @@ -632,6 +632,21 @@ def _run_single_outer_fold( fold_dir.mkdir(parents=True, exist_ok=True) full_dataset = LNPDataset(df) + # === 断点续跑:已完成的 fold 直接跳过(读回磁盘结果)=== + _tm = fold_dir / "test_metrics.json" + _bp = fold_dir / "best_params.json" + _em = fold_dir / "epoch_mean.json" + if precomputed_best_params is None and _tm.exists() and _bp.exists() and _em.exists(): + logger.success(f"[SKIP] Outer fold {outer_fold} already done, loading cached results.") + with open(_tm) as _f: _tmd = json.load(_f) + with open(_bp) as _f: _bpd = json.load(_f) + with open(_em) as _f: _emd = json.load(_f) + return { + "fold": outer_fold, + "best_params": _bpd, + "epoch_mean": int(_emd.get("epoch_mean", _emd) if isinstance(_emd, dict) else _emd), + "test_metrics": _tmd, + } logger.info(f"\n{'='*60}") logger.info(f"OUTER FOLD {outer_fold}")