deepmodeling / deepmd-kit

A deep learning package for many-body potential energy representation and molecular dynamics
https://docs.deepmodeling.com/projects/deepmd/
GNU Lesser General Public License v3.0
1.41k stars 486 forks source link

pt: add 4 tabulate_fusion op #3877

Closed cherryWangY closed 1 week ago

cherryWangY commented 3 weeks ago

OP: tabulate_multi_device.cc -> tabulate_fusion_se_a & atten & r & t Compile: add compile file Test: source/tests, se_t has no test, and all other ops pass the forward and backward tests.

Summary by CodeRabbit

coderabbitai[bot] commented 3 weeks ago
Walkthrough ## Walkthrough This update introduces a new file, `tabulate_multi_device.cc`, which adds functionality to perform and register fusion operations for deep learning models using PyTorch tensors. This involves defining new classes and functions for forward, backward, and gradient computations across multiple devices, and integrating these operations into the existing build system via updates to `CMakeLists.txt`. ## Changes | File | Changes Summary | |----------------------------------------|-----------------------------------------------------------------------------------------------------------------| | `source/op/pt/CMakeLists.txt` | Added `tabulate_multi_device.cc` to the `OP_SRC` variable. | | `source/op/pt/tabulate_multi_device.cc` | Introduced functions and classes for forward, backward, and gradient computations for fusion operations on multiple devices and registered new operations with PyTorch libraries. | ## Sequence Diagram(s) ```mermaid sequenceDiagram participant Developer as Developer participant BuildSys as Build System participant PyTorch as PyTorch Library participant Model as Deep Learning Model Developer->>BuildSys: Modify CMakeLists.txt BuildSys->>tabulate_multi_device.cc: Add to OP_SRC Note over tabulate_multi_device.cc: New functions and classes added for operations Model->>tabulate_multi_device.cc: Request fusion operation A (forward) tabulate_multi_device.cc->>PyTorch: Register TabulateFusionSeAOp PyTorch->>Model: Perform fusion operation A Model->>tabulate_multi_device.cc: Request gradient of fusion operation A (forward) tabulate_multi_device.cc->>PyTorch: Register TabulateFusionSeAGradOp PyTorch->>Model: Compute gradient of fusion operation A Model->>tabulate_multi_device.cc: Request gradient of gradient of fusion operation A (forward) tabulate_multi_device.cc->>PyTorch: Register TabulateFusionSeAGradGradOp PyTorch->>Model: Perform gradient of gradient computation Model->>tabulate_multi_device.cc: Request fusion operation T (forward) tabulate_multi_device.cc->>PyTorch: Register TabulateFusionSeTOp PyTorch->>Model: Perform fusion operation T Model->>tabulate_multi_device.cc: Request fusion operation R (forward) tabulate_multi_device.cc->>PyTorch: Register TabulateFusionSeROp PyTorch->>Model: Perform fusion operation R Model->>tabulate_multi_device.cc: Request attention-based fusion operation (forward) tabulate_multi_device.cc->>PyTorch: Register TabulateFusionSeAttenOp PyTorch->>Model: Perform attention-based fusion operation ```

Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 9920e57bf62410d6305e0b05a4bad7abfafce7a2 and 1523196543db982a4842981ec8b719ee2fd95b61.
Files selected for processing (2) * source/op/pt/CMakeLists.txt (1 hunks) * source/tests/pt/test_tabulate_fusion_se_t.py (1 hunks)
Files not summarized due to errors (1) * source/tests/pt/test_tabulate_fusion_se_t.py: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (1) * source/op/pt/CMakeLists.txt
Additional comments not posted (6)
source/tests/pt/test_tabulate_fusion_se_t.py (6)
`1681-1702`: **Ensure correctness of forward function testing.** The forward function test checks the shape and value closeness of the result tensor. Confirm that the assertions are robust enough to catch potential discrepancies in the operation's output. --- `1704-1749`: **Review backward function testing for completeness.** The backward function test checks the gradients' shapes and values. Ensure that these tests are comprehensive and cover all scenarios that might affect gradient computation. --- `436-1507`: **Validate tensor reshaping and gradient settings.** The tensors are reshaped and their gradient settings are explicitly defined. Confirm that the reshaping dimensions and gradient requirements are as expected for the operation being tested.
Verification successful --- The gradient settings for the tensors in the provided code snippet are consistent with other tests in the repository. Specifically, the `requires_grad` attribute is set correctly for the tensors used in the tests. - `self.table_info_tensor.requires_grad = False` - `self.table_tensor.requires_grad = False` - `self.em_x_tensor.requires_grad = True` These settings align with the expected behavior for gradient computations in the tests.
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify tensor reshaping and gradient settings. # Test: Check for gradient settings consistency in other tests. rg --type python 'requires_grad =' 'source/tests' ``` Length of output: 80 --- --- Script: ```shell #!/bin/bash # Description: Verify tensor reshaping and gradient settings. # Test: Check for gradient settings consistency in other tests. rg --type py 'requires_grad =' source/tests ``` Length of output: 1550
--- `23-27`: **Check precision setting for floating point comparisons.** The precision settings are different for `float64` and `float32` types. Ensure that these precision levels are appropriate and consistent with other tests in the project. --- `18-19`: **Check conditional test skipping logic.** The test is skipped if `ENABLE_CUSTOMIZED_OP` is false. Ensure that this is the intended behavior, especially if this operation is crucial and should be tested regardless of the configuration.
Verification successful --- The `ENABLE_CUSTOMIZED_OP` conditional test skipping logic is consistently used across multiple test files, indicating that it is an intended behavior. - `source/tests/pt/test_tabulate_fusion_se_t.py` - `source/tests/pt/test_tabulate_fusion_se_r.py` - `source/tests/pt/test_tabulate_fusion_se_a.py` - `source/tests/pt/test_tabulate_fusion_se_atten.py` This confirms that the approach to skip tests when `ENABLE_CUSTOMIZED_OP` is not enabled is consistent and likely intentional.
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the condition for skipping tests. # Test: Search for `ENABLE_CUSTOMIZED_OP` usage in other test files. Expect: Consistent usage. rg --type python 'ENABLE_CUSTOMIZED_OP' ``` Length of output: 70 --- --- Script: ```shell #!/bin/bash # Description: Verify the condition for skipping tests. # Test: Search for `ENABLE_CUSTOMIZED_OP` usage in other test files. Expect: Consistent usage. rg --type py 'ENABLE_CUSTOMIZED_OP' ``` Length of output: 1197
--- `28-424`: **Check tensor initialization and reshape operations.** The tensor is reshaped to (8, 174), resulting in a total of 1392 elements. Ensure that the tensor dimensions and the total number of elements are correctly calculated and aligned with the expected use in tests.
Verification successful --- The search results show numerous instances of tensor reshaping logic across various test files, including the file in question (`source/tests/pt/test_tabulate_fusion_se_t.py`). The specific line of interest, where the tensor is reshaped to `(8, 174)`, is explicitly found in the search results: ``` source/tests/pt/test_tabulate_fusion_se_t.py: ).reshape(8, 174) # 1392 ``` Given this, we can verify that the tensor reshaping logic is consistent and the dimensions align with the expected number of elements (8 * 174 = 1392). There is no evidence of a mismatch or inconsistency in the tensor dimensions or the total number of elements. - **File:** `source/tests/pt/test_tabulate_fusion_se_t.py` - **Line:** 424
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify tensor reshaping logic. # Test: Check for similar tensor reshaping logic in other tests or in the operation implementation. rg --type python 'reshape' 'source/tests' ``` Length of output: 70 --- --- Script: ```shell #!/bin/bash # Description: Verify tensor reshaping logic. # Test: Check for similar tensor reshaping logic in other tests or in the operation implementation. rg 'reshape' --type py source/tests ``` Length of output: 117785
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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.` - `@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 as 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. 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 84.42029% with 43 lines in your changes missing coverage. Please review.

Project coverage is 82.72%. Comparing base (f9d5f56) to head (7dd7f6a).

:exclamation: Current head 7dd7f6a differs from pull request most recent head 1523196

Please upload reports for the commit 1523196 to get more accurate results.

Files Patch % Lines
source/op/pt/tabulate_multi_device.cc 84.42% 16 Missing and 27 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## devel #3877 +/- ## ========================================== - Coverage 82.74% 82.72% -0.02% ========================================== Files 518 518 Lines 50215 50414 +199 Branches 2982 3018 +36 ========================================== + Hits 41548 41705 +157 - Misses 7757 7773 +16 - Partials 910 936 +26 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

njzjz commented 2 weeks ago

@coderabbitai resolve