Commit f0cf2b9
fix(train): allow zero-step training with bias adjustment (#5477)
Problem
- `numb_steps=0` is a valid no-optimization path that should save the
initial checkpoint.
- When `change_bias_after_training` is enabled, the post-training bias
adjustment still ran after zero steps and evaluated
learning-rate/checkpoint metadata at step `-1`.
Change
- Skip post-training bias adjustment unless at least one training step
has run.
- Keep the existing zero-step initial checkpoint save path for both
PyTorch and Paddle backends.
- Add PT/PD regression tests that run zero-step training with
`change_bias_after_training=true` and verify the saved `*-0` checkpoint
metadata.
Notes
- `python3 -m pytest ...` could not run in this workspace because pytest
is not installed in the available Python environment.
- `uvx ruff check deepmd/pd/train/training.py
deepmd/pt/train/training.py source/tests/pd/test_training.py
source/tests/pt/test_training.py` passed.
- `uvx ruff format --check deepmd/pd/train/training.py
deepmd/pt/train/training.py source/tests/pd/test_training.py
source/tests/pt/test_training.py` passed.
- Closes #4988.
Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Prevented unintended bias-adjustment during zero-step PyTorch training
so the initial checkpoint is created and recorded correctly.
* **Refactor**
* Clarified the post-training bias-adjustment conditional in Paddle for
readability (no behavior change).
* **Tests**
* Added tests for zero-step training with bias-adjustment enabled for
both Paddle and PyTorch, verifying initial checkpoint creation and
training metadata.
<!-- review_stack_entry_start -->
[](https://app.coderabbit.ai/change-stack/deepmodeling/deepmd-kit/pull/5477?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)
<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Jinzhe Zeng <jinzhe.zeng@ustc.edu.cn>1 parent 4b6506d commit f0cf2b9
4 files changed
Lines changed: 68 additions & 2 deletions
File tree
- deepmd
- pd/train
- pt/train
- source/tests
- pd
- pt
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1038 | 1038 | | |
1039 | 1039 | | |
1040 | 1040 | | |
1041 | | - | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
1042 | 1046 | | |
1043 | 1047 | | |
1044 | 1048 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1846 | 1846 | | |
1847 | 1847 | | |
1848 | 1848 | | |
1849 | | - | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
1850 | 1854 | | |
1851 | 1855 | | |
1852 | 1856 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
163 | 167 | | |
164 | 168 | | |
165 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
166 | 197 | | |
167 | 198 | | |
168 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
268 | 295 | | |
269 | 296 | | |
270 | 297 | | |
| |||
0 commit comments