Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Atomic stat with multi-system #4370

Merged

Conversation

anyangml
Copy link
Collaborator

@anyangml anyangml commented Nov 17, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced model prediction process with improved batch handling.
    • Restructured output data processing for better compatibility during concatenation.
    • Added new test data files for water tensor dipole simulations.
  • Bug Fixes

    • Improved error handling for file existence checks and bias restoration in statistics computation.
  • Documentation

    • Updated function signatures to reflect internal logic modifications.
    • Expanded training data systems in configuration for water tensor training.

Copy link
Contributor

coderabbitai bot commented Nov 17, 2024

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (10)
  • source/tests/pt/water_tensor/dipole/O78H156/set.000/atomic_dipole.npy
  • source/tests/pt/water_tensor/dipole/O78H156/set.000/box.npy
  • source/tests/pt/water_tensor/dipole/O78H156/set.000/coord.npy
  • source/tests/pt/water_tensor/dipole/O78H156/set.000/energy.npy
  • source/tests/pt/water_tensor/dipole/O78H156/set.000/force.npy
  • source/tests/pt/water_tensor/dipole/O96H192/set.000/atomic_dipole.npy
  • source/tests/pt/water_tensor/dipole/O96H192/set.000/box.npy
  • source/tests/pt/water_tensor/dipole/O96H192/set.000/coord.npy
  • source/tests/pt/water_tensor/dipole/O96H192/set.000/energy.npy
  • source/tests/pt/water_tensor/dipole/O96H192/set.000/force.npy

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request focus on the deepmd/pt/utils/stat.py file, enhancing the handling of statistical data related to atomic and global outputs. Key modifications include the introduction of a new function for batch processing in model predictions, significant restructuring of output data reshaping for compatibility, and improved error handling in the statistics computation process. These updates aim to clarify data processing logic and ensure consistency in data formats for subsequent computations.

Changes

File Change Summary
deepmd/pt/utils/stat.py - Restructured _compute_model_predict to use model_forward_auto_batch_size for batch processing.
- Modified compute_output_stats_atomic to reshape outputs and natoms for better concatenation.
- Enhanced error handling in compute_output_stats for file existence checks and bias restoration.
- Updated function signatures for compute_output_stats and compute_output_stats_atomic with no parameter changes but modified internal logic.
source/tests/pt/water_tensor/dipole/O78H156/type.raw - New file added containing structured numerical entries for tensor properties.
source/tests/pt/water_tensor/dipole/O78H156/type_map.raw - New file created containing identifiers "O" and "H".
source/tests/pt/water_tensor/dipole/O96H192/type.raw - New file added containing binary data for testing purposes.
source/tests/pt/water_tensor/dipole/O96H192/type_map.raw - New file created containing identifiers "O" and "H".
source/tests/pt/water_tensor/se_e2_a.json - Updated training_data.systems to include new entries for O78H156 and O96H192.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Model
    participant Stats

    User->>Model: Request predictions
    Model->>Model: Process input with model_forward_auto_batch_size
    Model-->>User: Return predictions
    User->>Stats: Compute output statistics
    Stats->>Stats: Reshape outputs and natoms
    Stats-->>User: Return computed statistics
Loading

Possibly related PRs

  • fix(pt ut): make separated uts deterministic #4162: The changes in this PR involve adding a "seed" parameter to JSON configurations, which relates to ensuring reproducibility in model training, similar to the changes in the main PR that enhance data processing and error handling in statistical computations.

Suggested reviewers

  • njzjz
  • wanghan-iapcm

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
deepmd/pt/utils/stat.py (2)

551-551: Consider simplifying the reshaping of natoms for clarity

The list comprehension in line 551:

natoms = {k: [sys_v.reshape(-1, 1) for sys_v in v] for k, v in natoms.items()}

uses nested comprehensions, which can be difficult to read and maintain. Refactoring this line by introducing intermediate variables or using a loop can improve readability.

Consider refactoring as follows:

for k, v in natoms.items():
    reshaped_list = []
    for sys_v in v:
        reshaped_list.append(sys_v.reshape(-1, 1))
    natoms[k] = reshaped_list

552-558: Refactor the nested comprehensions in outputs for better readability

Lines 552-558 involve nested dictionary and list comprehensions:

outputs = {
    k: [
        sys.reshape(natoms[k][sys_idx].shape[0], 1, -1)
        for sys_idx, sys in enumerate(v)
    ]
    for k, v in outputs.items()
}

This complex nesting can make the code harder to understand and maintain. Consider breaking down the comprehensions into multiple steps or using helper functions to enhance clarity.

For example:

for k, v in outputs.items():
    reshaped_list = []
    for sys_idx, sys in enumerate(v):
        n_atoms = natoms[k][sys_idx].shape[0]
        reshaped_sys = sys.reshape(n_atoms, 1, -1)
        reshaped_list.append(reshaped_sys)
    outputs[k] = reshaped_list
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0ad4289 and dee7c76.

📒 Files selected for processing (1)
  • deepmd/pt/utils/stat.py (1 hunks)

Copy link

codecov bot commented Nov 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.54%. Comparing base (908689e) to head (95c6854).
Report is 7 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4370      +/-   ##
==========================================
+ Coverage   84.50%   84.54%   +0.04%     
==========================================
  Files         596      597       +1     
  Lines       56665    56813     +148     
  Branches     3460     3487      +27     
==========================================
+ Hits        47883    48033     +150     
+ Misses       7654     7653       -1     
+ Partials     1128     1127       -1     

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


🚨 Try these New Features:

Copy link
Collaborator

@wanghan-iapcm wanghan-iapcm left a comment

Choose a reason for hiding this comment

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

Could you please add a UT for detecting the bug?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dee7c76 and 5b87b7a.

📒 Files selected for processing (5)
  • source/tests/pt/water_tensor/dipole/O78H156/type.raw (1 hunks)
  • source/tests/pt/water_tensor/dipole/O78H156/type_map.raw (1 hunks)
  • source/tests/pt/water_tensor/dipole/O96H192/type.raw (1 hunks)
  • source/tests/pt/water_tensor/dipole/O96H192/type_map.raw (1 hunks)
  • source/tests/pt/water_tensor/se_e2_a.json (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • source/tests/pt/water_tensor/dipole/O78H156/type.raw
  • source/tests/pt/water_tensor/dipole/O78H156/type_map.raw
  • source/tests/pt/water_tensor/dipole/O96H192/type.raw
  • source/tests/pt/water_tensor/dipole/O96H192/type_map.raw
🔇 Additional comments (1)
source/tests/pt/water_tensor/se_e2_a.json (1)

63-65: LGTM: Training dataset expansion looks good!

The addition of larger water systems (O78H156 and O96H192) to the training dataset will help improve the model's ability to handle varying system sizes.

source/tests/pt/water_tensor/se_e2_a.json Show resolved Hide resolved
Copy link
Collaborator

@wanghan-iapcm wanghan-iapcm left a comment

Choose a reason for hiding this comment

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

The data files are too large (.5M).
The bug should be triggered with only one or two frames, thus please make it as small as possible to save the size of the package.

@anyangml
Copy link
Collaborator Author

The data files are too large (.5M). The bug should be triggered with only one or two frames, thus please make it as small as possible to save the size of the package.

Kept 2frames for each system.

@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Nov 19, 2024
Merged via the queue into deepmodeling:devel with commit db2bc94 Nov 19, 2024
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] dipole model (pt backend) does not work for systems with different number of atoms
3 participants