Skip to content

[WIP] pd: support dpa3 dynamic shape for pd backend #4828

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

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

HydrogenSulfate
Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate commented Jun 30, 2025

support running input_torch_dynamic.json with paddle backend(including CINN)

TODO list:

Summary by CodeRabbit

  • Bug Fixes

    • Resolved issues with tensor shape and indexing consistency, preventing assertion errors during model execution.
    • Improved handling of default tensor initialization to avoid JIT assertion issues.
  • Refactor

    • Standardized tensor dimension handling and broadcasting for improved clarity and maintainability.
    • Enhanced code readability with clearer indexing conventions and formatting.
  • New Features

    • Added an option to control graph index mapping behavior for greater flexibility in advanced use cases.

@HydrogenSulfate HydrogenSulfate changed the base branch from master to devel June 30, 2025 07:13
Copy link
Contributor

coderabbitai bot commented Jun 30, 2025

📝 Walkthrough

Walkthrough

This change standardizes tensor dimension handling and indexing conventions across several modules, primarily affecting how edge and angle indices are structured and used. It introduces explicit reshaping, modifies the shape and construction of index tensors, and clarifies broadcasting logic, without altering core algorithms or public interfaces.

Changes

File(s) Change Summary
deepmd/pd/model/descriptor/repflow_layer.py Standardized tensor dimension handling and reshaping; changed edge/angle index slicing from column to row-based; clarified broadcasting; minor formatting improvements.
deepmd/pd/model/descriptor/repflows.py Changed initialization of edge/angle index tensors to new shapes; updated owner argument to match new indexing.
deepmd/pd/model/network/utils.py Modified aggregate to compute bin_count only when needed; changed output tensor initialization; added assertion; updated get_graph_index to stack indices along axis 0 and added use_loc_mapping parameter.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RepFlowLayer
    participant Utils

    User->>RepFlowLayer: forward(nlist, nlist_mask, ...)
    RepFlowLayer->>Utils: get_graph_index(nlist, nlist_mask, ...)
    Utils-->>RepFlowLayer: edge_index [2, n_edge], angle_index [3, n_angle]
    RepFlowLayer->>RepFlowLayer: _cal_hg_dynamic(..., owner=edge_index[0], ...)
    RepFlowLayer->>Utils: aggregate(data, owners, average, num_owner)
    Utils-->>RepFlowLayer: aggregated tensor
    RepFlowLayer-->>User: output
Loading

Possibly related PRs

Suggested reviewers

  • iProzd

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Pylint (3.3.7)
deepmd/pd/model/descriptor/repflow_layer.py

No files to lint: exiting.

deepmd/pd/model/network/utils.py

No files to lint: exiting.

deepmd/pd/model/descriptor/repflows.py

No files to lint: exiting.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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

🧹 Nitpick comments (1)
deepmd/pd/model/descriptor/repflow_layer.py (1)

752-752: Remove unused variable assignment.

The variable nall is assigned but never used in this scope. Consider removing this assignment to clean up the code.

-        nall = node_ebd_ext.shape[1]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8f01cb and dd70e99.

📒 Files selected for processing (3)
  • deepmd/pd/model/descriptor/repflow_layer.py (9 hunks)
  • deepmd/pd/model/descriptor/repflows.py (2 hunks)
  • deepmd/pd/model/network/utils.py (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
deepmd/pd/model/descriptor/repflows.py (2)
Learnt from: njzjz
PR: deepmodeling/deepmd-kit#4160
File: deepmd/dpmodel/utils/env_mat.py:52-64
Timestamp: 2024-10-08T15:32:11.479Z
Learning: Negative indices in `nlist` are properly handled by masking later in the computation, so they do not cause issues in indexing operations.
Learnt from: njzjz
PR: deepmodeling/deepmd-kit#4160
File: deepmd/dpmodel/utils/env_mat.py:52-64
Timestamp: 2024-09-24T01:59:37.973Z
Learning: Negative indices in `nlist` are properly handled by masking later in the computation, so they do not cause issues in indexing operations.
deepmd/pd/model/network/utils.py (2)
Learnt from: njzjz
PR: deepmodeling/deepmd-kit#4160
File: deepmd/dpmodel/utils/env_mat.py:52-64
Timestamp: 2024-09-24T01:59:37.973Z
Learning: Negative indices in `nlist` are properly handled by masking later in the computation, so they do not cause issues in indexing operations.
Learnt from: njzjz
PR: deepmodeling/deepmd-kit#4160
File: deepmd/dpmodel/utils/env_mat.py:52-64
Timestamp: 2024-10-08T15:32:11.479Z
Learning: Negative indices in `nlist` are properly handled by masking later in the computation, so they do not cause issues in indexing operations.
🧬 Code Graph Analysis (1)
deepmd/pd/model/network/utils.py (1)
source/tests/consistent/descriptor/test_dpa3.py (1)
  • data (78-134)
🪛 Ruff (0.11.9)
deepmd/pd/model/descriptor/repflow_layer.py

752-752: Local variable nall is assigned to but never used

Remove assignment to unused variable nall

(F841)

🪛 Flake8 (7.2.0)
deepmd/pd/model/descriptor/repflow_layer.py

[error] 752-752: local variable 'nall' is assigned to but never used

(F841)

⏰ Context from checks skipped due to timeout of 90000ms (21)
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build C library (2.14, >=2.5.0rc0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Analyze (c-cpp)
🔇 Additional comments (13)
deepmd/pd/model/descriptor/repflows.py (2)

518-519: LGTM: Tensor shape initialization updated to match new indexing conventions.

The initialization of edge_index and angle_index has been correctly updated from shapes [1, 3] to [2, 1] and [3, 1] respectively, which aligns with the new tensor dimension conventions where these tensors are structured as [2, n_edge] and [3, n_angle].


570-570: LGTM: Indexing updated to match new tensor shape convention.

The change from edge_index[:, 0] (column-wise indexing) to edge_index[0] (row-wise indexing) is consistent with the new tensor shape where edge_index has dimensions [2, n_edge] instead of [n_edge, 2].

deepmd/pd/model/network/utils.py (5)

32-43: LGTM: Optimized bin_count computation for better performance.

This optimization computes bin_count only when needed (num_owner is None or averaging is requested), which can improve performance in cases where bincount computation is expensive and unnecessary.


46-50: LGTM: Improved tensor initialization and assertion for safety.

The output tensor initialization now consistently uses num_owner for the first dimension, and the assertion ensures bin_count is not None before division when averaging is requested, preventing potential runtime errors.


59-59: LGTM: Added use_loc_mapping parameter for flexible index calculation.

The new parameter provides control over how frame_shift is computed, allowing the function to work with different indexing schemes based on whether local mapping is used.


109-111: LGTM: Frame shift calculation adapted for different mapping modes.

The conditional logic correctly adjusts the frame shift calculation based on use_loc_mapping, using either nall or nloc as the multiplier, which maintains proper indexing behavior across different execution modes.


140-143: LGTM: Tensor stacking changes align with new indexing conventions.

The change from concatenation to stacking transforms the output tensor shapes from [n_edge, 2] and [n_angle, 3] to [2, n_edge] and [3, n_angle] respectively, which standardizes the indexing convention across the codebase.

deepmd/pd/model/descriptor/repflow_layer.py (6)

375-377: LGTM: Improved code clarity with explicit tensor operations.

The change from ellipsis-based indexing to explicit .unsqueeze() calls makes the tensor operations more explicit and easier to understand, improving code readability.


588-592: LGTM: Standardized tensor reshaping with list arguments.

Using list arguments for reshape() instead of tuple unpacking is more explicit and consistent with modern tensor operation practices.


703-704: LGTM: Documentation updated to reflect new tensor shapes.

The function signature documentation correctly reflects the new tensor shapes 2 x n_edge and 3 x n_angle, maintaining consistency with the implementation changes.


764-769: LGTM: Updated tensor indexing to match new shape conventions.

The change from column-wise indexing (e.g., edge_index[:, 0]) to row-wise indexing (e.g., edge_index[0]) correctly adapts to the new tensor shapes where edge_index has dimensions [2, n_edge] and angle_index has dimensions [3, n_angle].


900-900: LGTM: Consistent use of explicit reshaping.

The change to use list arguments in reshape() maintains consistency with the other tensor operations in the codebase.


1046-1049: LGTM: Explicit tensor operations improve readability.

The use of explicit .unsqueeze() calls instead of implicit broadcasting makes the tensor operations more transparent and easier to debug.

Copy link

codecov bot commented Jun 30, 2025

Codecov Report

Attention: Patch coverage is 25.00000% with 15 lines in your changes missing coverage. Please review.

Project coverage is 84.56%. Comparing base (f8f01cb) to head (dd70e99).

Files with missing lines Patch % Lines
deepmd/pd/model/network/utils.py 0.00% 13 Missing ⚠️
deepmd/pd/model/descriptor/repflow_layer.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4828      +/-   ##
==========================================
- Coverage   84.57%   84.56%   -0.01%     
==========================================
  Files         699      699              
  Lines       68036    68040       +4     
  Branches     3540     3540              
==========================================
  Hits        57540    57540              
- Misses       9361     9364       +3     
- Partials     1135     1136       +1     

☔ 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.

@HydrogenSulfate HydrogenSulfate changed the title [WIP] pd: support pd dynamic shape [WIP] pd: support dpa3 dynamic shape for pd backend Jun 30, 2025
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.

1 participant