feat: 損失・学習ループ・公式 main(losses / trainer / main) - #57
Conversation
losses, trainer, main, visualization と対応テスト。 Ellipse params [a,b,theta] at each point in points. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Codex review item 3(NaN skip 後に全 batch skip だと metrics が空入力になり得る件)については、確かに制御フロー上の edge case ではありますが、私は merge blocker ほどではない と見ています。 現状の ただし、これは通常の設定で頻繁に起きる failure mode ではなく、数値的に完全に壊れた config / backend の検出に近い状況です。その意味では、研究実験の安全性としては優先度 medium 以下でよいと思います。 軽く直すなら、epoch 末の metrics 計算前に if steps_completed == 0 or not all_train_labels:
raise RuntimeError(
f"All training batches were skipped at epoch={epoch}; loss was NaN for every batch."
)程度の明示的な controlled failure を入れるのが十分です。NaN metrics を無理に返して training を継続するより、ここまで壊れた場合は明示的に落とす方が分かりやすいと思います。 |
Raise RuntimeError instead of calling sklearn metrics on empty labels when an entire epoch produced only NaN-skipped batches. Co-authored-by: Cursor <cursoragent@cursor.com>
|
epoch 末の train metrics 計算前に、全 batch が NaN skip された場合は |
|
|
||
| if self.mode == 'barrier': | ||
| barrier_term = F.relu(aspect_ratios - self.barrier_threshold).pow(2).mean() | ||
| loss = 10.0 * barrier_term |
| clean_pc = clean_pc.to(self.device, non_blocking=True) | ||
|
|
||
| if self.config.get('training', {}).get('rotation_augmentation', False): | ||
| theta = torch.rand(1, device=self.device) * 2 * 3.141592653589793 |
|
スカッシュコミット da38fc4 を main に直接 push して適用済み(PR#56 同様、squash merge 累積によるコンフリクト回避のためローカルでマージ)。 |
概要
PR5(距離バックエンド・持続ホモロジー)の上に、損失・学習ループ・公式エントリポイントを追加する PR です(分割 PR の 6 本目)。
tda_ml/losses.py: 分類 BCE、楕円サイズ/異方性正則化、位相 Wasserstein 損失(distance_backend対応)。tda_ml/trainer.py: 学習・検証ループ、AMP、可視化フック、clean PD 計算。tda_ml/main.py:NoisyMNISTDataset+Trainerによる公式学習入口(python -m tda_ml.main --config dev等)。tda_ml/visualization.py: エポックごとの GT/予測/楕円プロット。tests/test_trainer.py,tests/test_losses_topo_distance.py。Depends on #56(PR5)。未マージ時は PR1〜5 の変更も差分に含まれる場合があります。
楕円パラメータ
points:(N, 2)各点の座標。params:(N, 3)各点の[a, b, theta](中心はpoints)。位相損失とバックエンド
TopologicalLossはsigmoid(logits)を outlier 確率として距離に織り込む。distance_backendと同様)。公平比較の注意は PR7 の README 参照。この PR に含めないもの
experiments/run_backend_multiseed.py,REPRODUCIBILITY.md(PR7)pytest/ 再現スモーク(引き続き ruff のみ)テスト計画
Ruff成功uv run pytest tests/test_trainer.py tests/test_losses_topo_distance.pyuv run python -m tda_ml.main --config dev(3 epoch スモーク)