Skip to content

Conversation

@HydrogenSulfate
Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate commented Feb 26, 2025

The support for higher-order differentiation and complex control flow in paddle.jit static graphs is not very strong. Therefore, branches related to 0-size are ignored to avoid accuracy issues during training.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the consistency and stability of key computational processes across the application, ensuring that data processing occurs reliably under all conditions.
    • Enhanced compatibility with the underlying execution framework, leading to more predictable outcomes even in edge-case scenarios.
    • Adjusted control flow for handling empty coordinate tensors, allowing calculations to proceed under specific conditions.
    • Modified conditions for executing operations on variables, ensuring compatibility with the framework's operational modes.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

📝 Walkthrough

Walkthrough

The pull request modifies several control flow conditions within the DeepMD PD code. In the forward methods for both the descriptor and layer normalization components, as well as in the neighbor list functions, the original tensor-element count checks have been replaced with new conditions that allow for specific operations to proceed under certain circumstances. Comments note that these changes address limitations in Paddle's JIT compilation regarding double backward computations. No changes have been made to the declared public interfaces.

Changes

Files Change Summary
deepmd/.../descriptor/se_a.py
deepmd/.../network/layernorm.py
In the forward methods, conditional checks (e.g., if rr.numel() > 0 or using decomp.numel(xx)) have been replaced with conditions that allow execution when the framework is not in dynamic mode or when the tensor has elements. Comments explain the change due to paddle.jit limitations with double backward.
deepmd/.../nlist.py In the build_neighbor_list and build_directional_neighbor_list functions, the original condition checking tensor element counts has been replaced with new conditions that allow calculations to proceed under specific scenarios, while maintaining the original logic in other cases. Comments note compatibility issues with double backward in paddle.jit.

Sequence Diagram(s)

sequenceDiagram participant Caller as Caller participant Desc as DescrptBlockSeA.forward participant LN as LayerNorm.forward Caller->>Desc: Invoke forward(input) Note right of Desc: Bypass conditional check based on new logic Desc->>Desc: Multiply rr with mm and extract ss Desc->>Caller: Return descriptor output Caller->>LN: Invoke forward(input) Note right of LN: Bypass conditional check based on new logic LN->>LN: Compute variance and mean LN->>Caller: Return normalized output 
Loading
sequenceDiagram participant Caller as Caller participant NList as NeighborList Function Caller->>NList: Call with coordinates and rcut Note right of NList: Bypass original condition based on new logic NList->>NList: Compute xmax using maximum value plus offset NList->>Caller: Return neighbor list with computed xmax 
Loading

Suggested reviewers

  • iProzd

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f3489f1 and e31c969.

📒 Files selected for processing (3)
  • deepmd/pd/model/descriptor/se_a.py (2 hunks)
  • deepmd/pd/model/network/layernorm.py (1 hunks)
  • deepmd/pd/utils/nlist.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • deepmd/pd/model/descriptor/se_a.py
  • deepmd/pd/model/network/layernorm.py
  • deepmd/pd/utils/nlist.py
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C++ (cuda, cuda)
  • 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: Analyze (javascript-typescript)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)

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 generate docstrings to generate docstrings for 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 (4)
deepmd/pd/model/descriptor/se_a.py (1)

747-749: Changed tensor element check to unconditional execution

This change bypasses the original check for empty tensors, which is necessary because of limitations in paddle.jit's handling of control flow with double backward computation.

Note that there's a small typo in the comment - "ontrol" should be "control". This appears in all 3 files.

- # NOTE: ontrol flow with double backward is not supported well yet by paddle.jit + # NOTE: control flow with double backward is not supported well yet by paddle.jit
deepmd/pd/model/network/layernorm.py (1)

102-104: Changed tensor element check to unconditional execution

This change replaces the tensor element count check with an unconditional execution to work around limitations in paddle.jit's handling of control flow during double backward passes. Same approach as in the other files.

The same typo appears in the comment - "ontrol" should be "control".

- # NOTE: ontrol flow with double backward is not supported well yet by paddle.jit + # NOTE: control flow with double backward is not supported well yet by paddle.jit
deepmd/pd/utils/nlist.py (2)

101-103: Changed tensor element check to unconditional execution

Similar to the other files, this change replaces a check for empty tensors with an unconditional execution to avoid paddle.jit limitations with control flow during double backward passes.

Same comment typo - "ontrol" should be "control".

- # NOTE: ontrol flow with double backward is not supported well yet by paddle.jit + # NOTE: control flow with double backward is not supported well yet by paddle.jit

246-248: Changed tensor element check to unconditional execution

This change follows the same pattern as the others, replacing a tensor element count check with an unconditional block to avoid paddle.jit limitations with control flow during double backward passes.

Same typo in comment - "ontrol" should be "control".

- # NOTE: ontrol flow with double backward is not supported well yet by paddle.jit + # NOTE: control flow with double backward is not supported well yet by paddle.jit
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 47bbd65 and d9d1416.

📒 Files selected for processing (3)
  • deepmd/pd/model/descriptor/se_a.py (1 hunks)
  • deepmd/pd/model/network/layernorm.py (1 hunks)
  • deepmd/pd/utils/nlist.py (2 hunks)
@HydrogenSulfate HydrogenSulfate force-pushed the workaround_for_control_flow branch from bd18b76 to f3489f1 Compare February 28, 2025 03:44
@HydrogenSulfate HydrogenSulfate force-pushed the workaround_for_control_flow branch from f3489f1 to 5d3599c Compare February 28, 2025 03:47
pre-commit-ci bot and others added 2 commits February 28, 2025 03:48
empty commit Signed-off-by: HydrogenSulfate <490868991@qq.com>
@codecov
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.58%. Comparing base (80d445b) to head (1ea6964).
Report is 80 commits behind head on devel.

Additional details and impacted files
@@ Coverage Diff @@ ## devel #4617 +/- ## ========================================== - Coverage 84.58% 84.58% -0.01%  ========================================== Files 680 680 Lines 64547 64548 +1 Branches 3539 3540 +1 ========================================== Hits 54600 54600 - Misses 8806 8807 +1  Partials 1141 1141 

☔ 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.
@njzjz njzjz added this pull request to the merge queue Mar 3, 2025
Merged via the queue into deepmodeling:devel with commit 0c6c568 Mar 3, 2025
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants