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

breaking: seperate params in dpa2 #3768

Merged
merged 8 commits into from
May 12, 2024

Conversation

iProzd
Copy link
Collaborator

@iProzd iProzd commented May 10, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced descriptor configuration with the introduction of RepinitArgs and RepformerArgs classes for more flexible and structured argument handling.
    • Improved JSON configuration structure for descriptors, aligning properties under repinit and repformer into nested objects for clarity.
  • Refactor

    • Updated the initialization process in the model to utilize the new argument classes, ensuring more robust setup.
    • Refactored argument checking functions to support the new class-based configuration.
  • Documentation

    • Streamlined and clarified documentation related to descriptor arguments to better align with the new configuration approach.
  • Tests

    • Extended testing suite to include new argument classes, enhancing test coverage and consistency checks.

Copy link
Contributor

coderabbitai bot commented May 10, 2024

Walkthrough

Walkthrough

The updates encompass a significant restructuring in the deepmd module, focusing on enhancing flexibility and customization in descriptor handling for machine learning models. New classes for initialization and formation arguments (RepinitArgs and RepformerArgs) are introduced, impacting various components from utility functions to JSON configuration and testing. These changes aim to streamline argument handling, improving the clarity and functionality of the descriptor setup.

Changes

File Path Change Summary
.../descriptor/dpa2.py Added RepinitArgs and RepformerArgs classes. Updated DescrptDPA2 to accommodate these new argument structures. Added new serialization methods.
.../utils/argcheck.py Refactored argument checking functions to support the new classes. Documentation updated for clarity.
examples/water/dpa2/input_torch.json Reorganized JSON structure for descriptor configuration, nesting properties under repinit and repformer.
source/tests/pt/model/test_dpa2.py Integrated RepinitArgs and RepformerArgs in test setups to validate the new descriptor configurations.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4329423 and ada7f89.
Files selected for processing (2)
  • deepmd/dpmodel/descriptor/dpa2.py (9 hunks)
  • deepmd/pt/model/descriptor/dpa2.py (10 hunks)
Additional comments not posted (4)
deepmd/pt/model/descriptor/dpa2.py (1)

Line range hint 362-404: Serialization and deserialization methods correctly handle new argument classes.

deepmd/dpmodel/descriptor/dpa2.py (3)

57-137: Expand the docstrings for serialize and deserialize methods in RepinitArgs to ensure clarity on their operations.


139-306: Similarly, expand the docstrings for serialize and deserialize methods in RepformerArgs to ensure clarity on their operations.


308-326: Constructor implementation in DescrptDPA2 is robust and handles different input types effectively.
Suggest adding type annotations to the init_subclass_params function for enhanced clarity and maintainability.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 4

Out of diff range and nitpick comments (2)
deepmd/dpmodel/descriptor/dpa2.py (1)

Line range hint 308-699: The DescrptDPA2 class effectively integrates the new RepinitArgs and RepformerArgs classes. The method init_subclass_params is a robust way to handle different types of input for initialization parameters. However, there are a few areas that could be improved:

  1. The error message in init_subclass_params could be more descriptive about what was received versus what was expected.
  2. The method call is quite complex and could benefit from further decomposition or at least more detailed inline comments to improve readability.
  3. The serialization and deserialization methods are crucial and should be accompanied by comprehensive unit tests to ensure their correctness, especially given their complexity.
deepmd/utils/argcheck.py (1)

Line range hint 621-675: Refactor the descrpt_dpa2_args function to improve readability and maintainability.

-    # repinit args
-    doc_repinit = "The arguments used to initialize the repinit block."
-    # repformer args
-    doc_repformer = "The arguments used to initialize the repformer block."
-    # descriptor args
-    doc_concat_output_tebd = (
-        "Whether to concat type embedding at the output of the descriptor."
-    )
-    doc_precision = f"The precision of the embedding net parameters, supported options are {list_to_doc(ACTIVATION_FN_DICT.keys())} Default follows the interface precision."
-    doc_smooth = (
-        "Whether to use smoothness in processes such as attention weights calculation."
-    )
-    doc_exclude_types = "The excluded pairs of types which have no interaction with each other. For example, `[[0, 1]]` means no interaction between type 0 and type 1."
-    doc_env_protection = "Protection parameter to prevent division by zero errors during environment matrix calculations. For example, when using paddings, there may be zero distances of neighbors, which may make division by zero error during environment matrix calculations without protection."
-    doc_trainable = "If the parameters in the embedding net is trainable."
-    doc_seed = "Random seed for parameter initialization."
-    doc_add_tebd_to_repinit_out = "Add type embedding to the output representation from repinit before inputting it into repformer."
+    doc_repinit = "Initialize the repinit block with these arguments."
+    doc_repformer = "Initialize the repformer block with these arguments."
+    doc_concat_output_tebd = "Concatenate type embedding at the descriptor's output."
+    doc_precision = f"Define the precision of the embedding net parameters. Supported options are {list_to_doc(ACTIVATION_FN_DICT.keys())}. The default is the interface's precision."
+    doc_smooth = "Apply smoothness in processes like attention weights calculation."
+    doc_exclude_types = "Define pairs of types with no interaction, e.g., `[[0, 1]]` for no interaction between type 0 and type 1."
+    doc_env_protection = "Set a protection parameter to avoid division by zero errors during environment matrix calculations, useful when using paddings."
+    doc_trainable = "Specify if the embedding net's parameters are trainable."
+    doc_seed = "Set the random seed for parameter initialization."
+    doc_add_tebd_to_repinit_out = "Add type embedding to the repinit output before passing it to repformer."

This refactoring simplifies the documentation strings and makes them more direct and easier to understand.

deepmd/utils/argcheck.py Outdated Show resolved Hide resolved
deepmd/utils/argcheck.py Show resolved Hide resolved
Copy link

codecov bot commented May 10, 2024

Codecov Report

Attention: Patch coverage is 95.03546% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 82.49%. Comparing base (3a6d2c4) to head (ada7f89).

Files Patch % Lines
deepmd/dpmodel/descriptor/dpa2.py 95.00% 4 Missing ⚠️
deepmd/pt/model/descriptor/dpa2.py 82.35% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #3768      +/-   ##
==========================================
+ Coverage   82.46%   82.49%   +0.02%     
==========================================
  Files         515      515              
  Lines       48550    48633      +83     
  Branches     2979     2979              
==========================================
+ Hits        40036    40118      +82     
- Misses       7603     7604       +1     
  Partials      911      911              

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

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: 4

Out of diff range and nitpick comments (7)
source/tests/pt/model/test_rot_denoise.py (1)

Line range hint 14-14: Consider adding detailed docstrings to the RotDenoiseTest class and its methods to improve maintainability.

source/tests/pt/model/test_smooth_denoise.py (1)

Line range hint 14-14: Consider adding detailed docstrings to the SmoothDenoiseTest class and its methods to improve maintainability.

source/tests/pt/model/test_trans.py (1)

Line range hint 14-14: Consider adding detailed docstrings to the TransTest class and its methods to improve maintainability.

source/tests/pt/model/test_jit.py (1)

Line range hint 14-14: Consider adding detailed docstrings to the JITTest class and its methods to improve maintainability.

source/tests/pt/model/test_rot.py (1)

Line range hint 14-14: Consider adding detailed docstrings to the RotTest class and its methods to improve maintainability.

source/tests/pt/model/test_smooth.py (1)

Line range hint 14-14: Consider adding detailed docstrings to the SmoothTest class and its methods to improve maintainability.

source/tests/pt/model/test_permutation.py (1)

Line range hint 14-14: Consider adding detailed docstrings to the PermutationTest class and its methods to improve maintainability.

deepmd/pt/model/descriptor/dpa2.py Show resolved Hide resolved
deepmd/dpmodel/descriptor/dpa2.py Show resolved Hide resolved
deepmd/dpmodel/descriptor/dpa2.py Show resolved Hide resolved
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

Out of diff range and nitpick comments (1)
source/tests/pt/model/test_unused_params.py (1)

44-52: Add more comments to explain the use of the computation graph in identifying contributing parameters.

source/tests/pt/model/test_unused_params.py Show resolved Hide resolved
deepmd/utils/argcheck.py Outdated Show resolved Hide resolved
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.

Good. Just a question not related to this PR.

deepmd/dpmodel/descriptor/dpa2.py Outdated Show resolved Hide resolved
deepmd/utils/argcheck.py Outdated Show resolved Hide resolved
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: 2

Out of diff range and nitpick comments (4)
deepmd/pt/model/descriptor/dpa2.py (1)

85-88: Consider adding examples in the documentation for repinit and repformer parameters to illustrate the expected usage of RepinitArgs and RepformerArgs.

deepmd/dpmodel/descriptor/dpa2.py (3)

380-434: Initialization of descriptor blocks in DescrptDPA2 is correctly implemented.

Consider adding more detailed inline documentation to explain how DescrptBlockSeAtten and DescrptBlockRepformers interact with the rest of the descriptor components.


Line range hint 635-694: Serialization and deserialization methods in DescrptDPA2 are comprehensive.

Consider refactoring to improve maintainability by extracting repeated logic into helper functions.


Line range hint 688-745: The call method in DescrptDPA2 is well-implemented and integrates smoothly with descriptor blocks.

Consider refactoring to improve readability by splitting the method into smaller, more focused methods.

deepmd/pt/model/descriptor/dpa2.py Show resolved Hide resolved
deepmd/dpmodel/descriptor/dpa2.py Show resolved Hide resolved
@iProzd iProzd requested a review from wanghan-iapcm May 12, 2024 13:53
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue May 12, 2024
Merged via the queue into deepmodeling:devel with commit 18cdbf0 May 12, 2024
60 checks passed
mtaillefumier pushed a commit to mtaillefumier/deepmd-kit that referenced this pull request Sep 18, 2024
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced descriptor configuration with the introduction of
`RepinitArgs` and `RepformerArgs` classes for more flexible and
structured argument handling.
- Improved JSON configuration structure for descriptors, aligning
properties under `repinit` and `repformer` into nested objects for
clarity.

- **Refactor**
- Updated the initialization process in the model to utilize the new
argument classes, ensuring more robust setup.
- Refactored argument checking functions to support the new class-based
configuration.

- **Documentation**
- Streamlined and clarified documentation related to descriptor
arguments to better align with the new configuration approach.

- **Tests**
- Extended testing suite to include new argument classes, enhancing test
coverage and consistency checks.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

3 participants