|
77 | 77 | clip_grad_norm_, |
78 | 78 | latest_checkpoint_path, |
79 | 79 | resolve_best_checkpoint_dir, |
| 80 | + resolve_keep_ckpt_count, |
80 | 81 | scoped_env_defaults, |
81 | 82 | ) |
82 | 83 | from deepmd.pt.train.validation import ( |
@@ -216,6 +217,7 @@ def __init__( |
216 | 217 | self.save_dir.mkdir(parents=True, exist_ok=True) |
217 | 218 | self.save_freq = training_params.get("save_freq", 1000) |
218 | 219 | self.max_ckpt_keep = training_params.get("max_ckpt_keep", 5) |
| 220 | + self.ckpt_keep_ratio = training_params.get("ckpt_keep_ratio") |
219 | 221 | self.enable_ema = bool(training_params.get("enable_ema", False)) |
220 | 222 | self.ema_decay = float(training_params.get("ema_decay", 0.999)) |
221 | 223 | self.ema_ckpt_keep = int(training_params.get("ema_ckpt_keep", 3)) |
@@ -729,6 +731,24 @@ def get_lr(lr_params: dict[str, Any]) -> BaseLR: |
729 | 731 | rank=self.rank, |
730 | 732 | ) |
731 | 733 |
|
| 734 | + # === Derive checkpoint retention from ckpt_keep_ratio === |
| 735 | + # num_steps is final here (including when derived from num_epoch), so the |
| 736 | + # ratio can be converted into an absolute keep count once. |
| 737 | + keep_ckpt_count = resolve_keep_ckpt_count( |
| 738 | + self.ckpt_keep_ratio, self.num_steps, self.save_freq |
| 739 | + ) |
| 740 | + if keep_ckpt_count is not None: |
| 741 | + self.max_ckpt_keep = keep_ckpt_count |
| 742 | + self.ema_ckpt_keep = keep_ckpt_count |
| 743 | + log.info( |
| 744 | + "Resolved checkpoint retention to %d from ckpt_keep_ratio=%s " |
| 745 | + "(num_steps=%d, save_freq=%d).", |
| 746 | + keep_ckpt_count, |
| 747 | + self.ckpt_keep_ratio, |
| 748 | + self.num_steps, |
| 749 | + self.save_freq, |
| 750 | + ) |
| 751 | + |
732 | 752 | # Learning rate |
733 | 753 | self.gradient_max_norm = training_params.get("gradient_max_norm", 0.0) |
734 | 754 | self.nonfinite_grad_guard = NonFiniteGradGuard() |
|
0 commit comments