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

Chore(pt):rm old pt implementation #4223

Merged
merged 2 commits into from
Oct 17, 2024
Merged

Conversation

iProzd
Copy link
Collaborator

@iProzd iProzd commented Oct 16, 2024

Fix #3913.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced exclude_types parameter in DipoleFittingNet and PolarFittingNet constructors for improved flexibility.
    • Added SimpleLinear class to enhance network functionality.
  • Bug Fixes

    • Removed old_impl parameter across various classes, streamlining interfaces and ensuring consistent behavior.
  • Documentation

    • Updated test cases to reflect the removal of old_impl, focusing on new implementations.
  • Chores

    • Deleted obsolete files and classes to simplify the codebase and improve maintainability.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve significant modifications to several classes and files within the deepmd module. Key alterations include the removal of the old_impl parameter from multiple class constructors and serialization methods, which simplifies their interfaces. Additionally, several files related to old implementations have been deleted, affecting the public API of the module. New parameters have been introduced in some classes, and various test files have been updated to reflect these changes.

Changes

File Path Change Summary
deepmd/dpmodel/fitting/dipole_fitting.py Removed old_impl from DipoleFitting constructor and serialization. Updated constructor and serialization.
deepmd/dpmodel/fitting/polarizability_fitting.py Removed old_impl from PolarFitting constructor and serialization. Updated constructor and serialization.
deepmd/pt/model/backbone/__init__.py Deleted file; removed BackBone and Evoformer2bBackBone classes from public API.
deepmd/pt/model/backbone/backbone.py Deleted file; removed BackBone class.
deepmd/pt/model/backbone/evoformer2b.py Deleted file; removed Evoformer2bBackBone class.
deepmd/pt/model/descriptor/__init__.py Removed import for DescrptGaussianLcc.
deepmd/pt/model/descriptor/dpa1.py Removed old_impl from DescrptDPA1 constructor.
deepmd/pt/model/descriptor/dpa2.py Removed old_impl from DescrptDPA2 constructor.
deepmd/pt/model/descriptor/gaussian_lcc.py Deleted file; removed DescrptGaussianLcc class.
deepmd/pt/model/descriptor/repformer_layer_old_impl.py Deleted file; removed multiple classes and functions related to old implementation.
deepmd/pt/model/descriptor/repformers.py Removed old_impl from DescrptBlockRepformers constructor.
deepmd/pt/model/descriptor/se_a.py Removed old_impl from DescrptSeA and DescrptBlockSeA constructors.
deepmd/pt/model/descriptor/se_atten.py Removed old_impl from DescrptBlockSeAtten constructor.
deepmd/pt/model/descriptor/se_atten_v2.py Removed old_impl from DescrptSeAttenV2 constructor.
deepmd/pt/model/descriptor/se_r.py Removed old_impl from DescrptSeR constructor.
deepmd/pt/model/network/network.py Deleted multiple classes and added SimpleLinear. Updated Evoformer3bEncoder.
deepmd/pt/model/task/__init__.py Removed FittingNetAttenLcc from imports and __all__.
deepmd/pt/model/task/atten_lcc.py Deleted file; removed FittingNetAttenLcc class.
deepmd/pt/model/task/dipole.py Updated DipoleFittingNet to include exclude_types and removed old_impl.
deepmd/pt/model/task/fitting.py Modified GeneralFitting to remove ResidualDeep import and related logic.
deepmd/pt/model/task/polarizability.py Updated PolarFittingNet to include exclude_types and removed old_impl.
source/tests/pt/model/test_descriptor_hybrid.py Removed old_impl from DescrptSeA instantiation in tests.
source/tests/pt/model/test_descriptor_se_r.py Removed old_impl from DescrptSeR constructor calls in tests.
source/tests/pt/model/test_dpa1.py Removed references to old_impl in DescrptDPA1 tests.
source/tests/pt/model/test_dpa2.py Removed old_impl from DescrptDPA2 instantiation in tests.
source/tests/pt/model/test_embedding_net.py Removed old_impl variable in TestSeA.
source/tests/pt/model/test_ener_fitting.py Removed test_new_old method from TestInvarFitting.
source/tests/pt/model/test_se_atten_v2.py Removed old_impl from DescrptSeAttenV2 instantiation in tests.
source/tests/pt/model/test_se_e2_a.py No changes to public entities.

Possibly related PRs

Suggested labels

Docs

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

🧹 Outside diff range and nitpick comments (3)
source/tests/pt/model/test_embedding_net.py (1)

Line range hint 178-185: Consider improving documentation and clarifying framework usage

While the changes improve the code, consider the following suggestions:

  1. Add a comment explaining the structure of parameter names and why this specific regex pattern is used. This would help future maintainers understand the code more easily.

  2. The test file uses both TensorFlow and PyTorch. While this might be intentional for comparison purposes, it would be helpful to add a comment explaining why both frameworks are necessary for this test.

These additions would further enhance the maintainability and clarity of the code.

deepmd/pt/model/descriptor/repformers.py (1)

247-282: LGTM! Consider updating the class docstring.

The removal of the old_impl parameter and related logic simplifies the code and aligns with the PR objective of removing the old implementation. This change improves code maintainability by removing deprecated options.

Consider updating the class docstring to remove any mentions of the old_impl parameter or the option to use an older implementation, ensuring the documentation accurately reflects the current implementation.

deepmd/pt/model/task/fitting.py (1)

477-490: Simplify complex conditional statements to improve readability

The nested condition with multiple negations can be difficult to read and understand:

if not (
    len(self.remove_vaccum_contribution) > type_i
    and not self.remove_vaccum_contribution[type_i]
):

Refactor the condition to eliminate double negatives:

if (len(self.remove_vaccum_contribution) <= type_i) or self.remove_vaccum_contribution[type_i]:

This version is more straightforward and improves code clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5050f61 and 5abdcde.

📒 Files selected for processing (29)
  • deepmd/dpmodel/fitting/dipole_fitting.py (0 hunks)
  • deepmd/dpmodel/fitting/polarizability_fitting.py (0 hunks)
  • deepmd/pt/model/backbone/init.py (0 hunks)
  • deepmd/pt/model/backbone/backbone.py (0 hunks)
  • deepmd/pt/model/backbone/evoformer2b.py (0 hunks)
  • deepmd/pt/model/descriptor/init.py (0 hunks)
  • deepmd/pt/model/descriptor/dpa1.py (0 hunks)
  • deepmd/pt/model/descriptor/dpa2.py (0 hunks)
  • deepmd/pt/model/descriptor/gaussian_lcc.py (0 hunks)
  • deepmd/pt/model/descriptor/repformer_layer_old_impl.py (0 hunks)
  • deepmd/pt/model/descriptor/repformers.py (1 hunks)
  • deepmd/pt/model/descriptor/se_a.py (2 hunks)
  • deepmd/pt/model/descriptor/se_atten.py (3 hunks)
  • deepmd/pt/model/descriptor/se_atten_v2.py (0 hunks)
  • deepmd/pt/model/descriptor/se_r.py (0 hunks)
  • deepmd/pt/model/network/network.py (0 hunks)
  • deepmd/pt/model/task/init.py (0 hunks)
  • deepmd/pt/model/task/atten_lcc.py (0 hunks)
  • deepmd/pt/model/task/dipole.py (0 hunks)
  • deepmd/pt/model/task/fitting.py (2 hunks)
  • deepmd/pt/model/task/polarizability.py (0 hunks)
  • source/tests/pt/model/test_descriptor_hybrid.py (0 hunks)
  • source/tests/pt/model/test_descriptor_se_r.py (0 hunks)
  • source/tests/pt/model/test_dpa1.py (0 hunks)
  • source/tests/pt/model/test_dpa2.py (0 hunks)
  • source/tests/pt/model/test_embedding_net.py (1 hunks)
  • source/tests/pt/model/test_ener_fitting.py (0 hunks)
  • source/tests/pt/model/test_se_atten_v2.py (0 hunks)
  • source/tests/pt/model/test_se_e2_a.py (0 hunks)
💤 Files with no reviewable changes (24)
  • deepmd/dpmodel/fitting/dipole_fitting.py
  • deepmd/dpmodel/fitting/polarizability_fitting.py
  • deepmd/pt/model/backbone/init.py
  • deepmd/pt/model/backbone/backbone.py
  • deepmd/pt/model/backbone/evoformer2b.py
  • deepmd/pt/model/descriptor/init.py
  • deepmd/pt/model/descriptor/dpa1.py
  • deepmd/pt/model/descriptor/dpa2.py
  • deepmd/pt/model/descriptor/gaussian_lcc.py
  • deepmd/pt/model/descriptor/repformer_layer_old_impl.py
  • deepmd/pt/model/descriptor/se_atten_v2.py
  • deepmd/pt/model/descriptor/se_r.py
  • deepmd/pt/model/network/network.py
  • deepmd/pt/model/task/init.py
  • deepmd/pt/model/task/atten_lcc.py
  • deepmd/pt/model/task/dipole.py
  • deepmd/pt/model/task/polarizability.py
  • source/tests/pt/model/test_descriptor_hybrid.py
  • source/tests/pt/model/test_descriptor_se_r.py
  • source/tests/pt/model/test_dpa1.py
  • source/tests/pt/model/test_dpa2.py
  • source/tests/pt/model/test_ener_fitting.py
  • source/tests/pt/model/test_se_atten_v2.py
  • source/tests/pt/model/test_se_e2_a.py
🧰 Additional context used
🔇 Additional comments (7)
source/tests/pt/model/test_embedding_net.py (2)

Line range hint 178-185: Improved consistency in parameter name extraction

The changes in this section have simplified the code by removing the old_impl parameter and using a consistent regex pattern for parameter name extraction. This aligns well with the PR objective of removing old implementations and improves code clarity.

The new regex pattern r"(\d)\.layers\.(\d)\.([a-z]+)" appears to correctly capture the structure of parameter names in the current implementation.


Line range hint 1-224: Changes align with PR objectives and maintain test integrity

The modifications in this file are focused and minimal, primarily involving the removal of the old_impl parameter and simplification of the parameter name extraction logic. These changes align well with the PR objective of removing old implementations.

Key points:

  1. The core functionality of the test remains intact, continuing to compare TensorFlow and PyTorch implementations.
  2. The simplification improves code clarity and maintainability.
  3. The minimal nature of the changes reduces the risk of introducing new bugs.

The test file continues to serve its purpose of ensuring consistency between implementations while becoming more streamlined.

deepmd/pt/model/descriptor/repformers.py (1)

Line range hint 1-24: Summary: Removal of old implementation improves code clarity

The changes in this file successfully remove the old_impl parameter and related logic from the DescrptBlockRepformers class. This aligns with the PR objective of removing the old PT implementation and results in cleaner, more maintainable code.

Key improvements:

  1. Simplified __init__ method signature
  2. Removed conditional logic for different implementations
  3. Consistent use of the current implementation across the class

These changes should make the code easier to understand and maintain going forward.

Also applies to: 247-282

deepmd/pt/model/task/fitting.py (1)

471-475: Verify correct indexing and application of atom biases in mixed types

In the mixed types scenario, you are accessing self.bias_atom_e[atype] and adding it to the atom_property. Ensure that atype correctly indexes into self.bias_atom_e without causing index out-of-bounds errors.

atom_property = self.filter_layers.networks[0](xx) + self.bias_atom_e[atype]

Run the following script to confirm that all values in atype are within the valid range:

This script searches for instances where self.bias_atom_e[atype] is used and outputs lines involving atype. Verify that atype does not contain indices outside the range [0, self.ntypes - 1].

deepmd/pt/model/descriptor/se_a.py (1)

612-654: Avoided Performance Degradation by Skipping Mask Application

The decision to set ti_mask = None when self.type_one_side is True avoids applying a mask that could degrade performance, as mentioned in the comments. This logic enhances the efficiency of the computation.

deepmd/pt/model/descriptor/se_atten.py (2)

192-207: Initialization of self.dpa1_attention Simplified and Correct

The removal of the old_impl conditional logic has streamlined the initialization of self.dpa1_attention. The parameters passed to NeighborGatedAttention are appropriate and align with its constructor.


225-237: Verify the Correct Initialization of filter_layers

The filter_layers are initialized and assigned correctly. However, please ensure that the NetworkCollection and EmbeddingNet are properly configured to handle the new initialization without the old_impl logic.

To confirm the correct setup, you can review the configuration of filter_layers:

deepmd/pt/model/task/fitting.py Show resolved Hide resolved
deepmd/pt/model/task/fitting.py Show resolved Hide resolved
deepmd/pt/model/descriptor/se_a.py Show resolved Hide resolved
deepmd/pt/model/descriptor/se_a.py Show resolved Hide resolved
deepmd/pt/model/descriptor/se_atten.py Show resolved Hide resolved
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.55%. Comparing base (5050f61) to head (5abdcde).
Report is 3 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4223      +/-   ##
==========================================
+ Coverage   83.52%   84.55%   +1.02%     
==========================================
  Files         542      536       -6     
  Lines       52544    51235    -1309     
  Branches     3043     3047       +4     
==========================================
- Hits        43888    43320     -568     
+ Misses       7709     6967     -742     
- Partials      947      948       +1     

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

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.

[Feature Request] Old implemetation of pytorch models need to be removed
4 participants