Commit 581bcb6
feat(tf): implement change-bias command (#4927)
Implements TensorFlow support for the `dp change-bias` command with
proper checkpoint handling and variable restoration. This brings the
TensorFlow backend to feature parity with the PyTorch implementation.
## Key Features
- **Checkpoint file support**: Handles individual checkpoint files
(`.ckpt`, `.meta`, `.data`, `.index`) and frozen models (`.pb`)
- **Proper variable restoration**: Variables are correctly restored from
checkpoints using session initialization before bias modification
- **User-defined bias support**: Supports `-b/--bias-value` option with
proper validation against model type_map
- **Data-based bias calculation**: Leverages existing
`change_energy_bias_lower` functionality for automatic bias computation
- **Checkpoint preservation**: Saves modified variables to separate
checkpoint directory for continued training
- **Cross-backend consistency**: Identical CLI interface and
functionality as PyTorch backend
## Before vs After
**Variable restoration**:
- Before: `Change energy bias of ['O', 'H'] from [0. 0.] to [calculated
values]` (variables never restored)
- After: `Change energy bias of ['O', 'H'] from [-93.57 -187.15] to
[-93.60 -187.19]` (proper restoration)
**Output**: Creates both updated checkpoint files AND frozen model for
continued training
**Documentation**: Comprehensive documentation covering both TensorFlow
and PyTorch backends with examples and backend-specific details
The implementation includes comprehensive test coverage with real model
training to validate functionality without mocks.
Fixes #4018.
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/deepmodeling/deepmd-kit/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Signed-off-by: Jinzhe Zeng <njzjz@qq.com>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@ustc.edu.cn>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Co-authored-by: Jinzhe Zeng <jinzhe.zeng@ustc.edu.cn>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent db22802 commit 581bcb6
7 files changed
Lines changed: 714 additions & 12 deletions
File tree
- deepmd
- tf/entrypoints
- doc/model
- source/tests/tf
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| 62 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
752 | 752 | | |
753 | 753 | | |
754 | 754 | | |
755 | | - | |
| 755 | + | |
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
759 | 759 | | |
760 | | - | |
| 760 | + | |
| 761 | + | |
761 | 762 | | |
762 | 763 | | |
763 | 764 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
| |||
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
0 commit comments