Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 26, 2025

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.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] [Feature Request] Support dp change-bias for TF models feat(tf): add change-bias command support for TensorFlow backend Aug 26, 2025
@Copilot Copilot AI requested a review from njzjz August 26, 2025 18:50
Copilot finished work on behalf of njzjz August 26, 2025 18:50
Copilot finished work on behalf of njzjz August 27, 2025 03:33
@Copilot Copilot AI requested a review from njzjz August 27, 2025 03:33
…nOptions parameters, fix test signatures, add --pt flag to example

Co-authored-by: njzjz <[email protected]>
@Copilot Copilot AI requested a review from njzjz August 27, 2025 05:00
Copilot finished work on behalf of njzjz August 27, 2025 05:00
Copy link

codecov bot commented Aug 27, 2025

Codecov Report

❌ Patch coverage is 76.31579% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.45%. Comparing base (6349238) to head (5faffab).
⚠️ Report is 9 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/tf/entrypoints/change_bias.py 77.18% 34 Missing ⚠️
deepmd/tf/entrypoints/main.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4927      +/-   ##
==========================================
+ Coverage   84.29%   84.45%   +0.16%     
==========================================
  Files         703      705       +2     
  Lines       68728    69829    +1101     
  Branches     3573     3574       +1     
==========================================
+ Hits        57935    58975    +1040     
- Misses       9653     9716      +63     
+ Partials     1140     1138       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot finished work on behalf of njzjz August 27, 2025 06:19
@Copilot Copilot AI changed the title feat(tf): implement change-bias command with proper checkpoint variable restoration feat(tf): implement change-bias command with checkpoint preservation and proper variable restoration Aug 28, 2025
@Copilot Copilot AI requested a review from njzjz August 28, 2025 08:29
Copilot finished work on behalf of njzjz August 28, 2025 08:29
@Copilot Copilot AI changed the title feat(tf): implement change-bias command with checkpoint preservation and proper variable restoration feat(tf): implement change-bias command with checkpoint preservation in separate directory Aug 28, 2025
Copilot finished work on behalf of njzjz August 28, 2025 08:38
@Copilot Copilot AI requested a review from njzjz August 28, 2025 09:02
Copilot finished work on behalf of njzjz August 28, 2025 09:02
@njzjz njzjz marked this pull request as ready for review August 28, 2025 09:14
Copy link
Member

@njzjz njzjz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot The documentation change-bias.md should be revised. The current documentation only writes the PyTorch backend but not TensorFlow.

Copy link
Contributor Author

Copilot AI commented Aug 28, 2025

@copilot The documentation change-bias.md should be revised. The current documentation only writes the PyTorch backend but not TensorFlow.

Updated the change-bias documentation to include comprehensive TensorFlow backend support. The documentation now covers both TensorFlow and PyTorch backends with:

  • Backend-specific examples and usage patterns
  • Supported file formats for each backend (.ckpt/.pb for TF, .pt/.pth for PyTorch)
  • Common CLI parameters shared between backends
  • Backend-specific implementation details

The documentation follows the established multi-backend pattern used throughout the project. (2096f7a)

@Copilot Copilot AI changed the title feat(tf): implement change-bias command with checkpoint preservation in separate directory feat(tf): implement change-bias command with proper checkpoint variable restoration Aug 28, 2025
@Copilot Copilot AI requested a review from njzjz August 28, 2025 09:38
Copilot finished work on behalf of njzjz August 28, 2025 09:38
Removed redundant sections and updated command examples for changing bias in TensorFlow backend.

Signed-off-by: Jinzhe Zeng <[email protected]>
@github-actions github-actions bot added the Docs label Aug 28, 2025
@njzjz njzjz requested a review from iProzd August 28, 2025 11:34
@njzjz njzjz changed the title feat(tf): implement change-bias command with proper checkpoint variable restoration feat(tf): implement change-bias command Aug 28, 2025
@iProzd iProzd added this pull request to the merge queue Sep 2, 2025
Merged via the queue into devel with commit 581bcb6 Sep 2, 2025
105 checks passed
@iProzd iProzd deleted the copilot/fix-4018 branch September 2, 2025 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Support dp change-bias for TF models
3 participants