Skip to content

Conversation

@Chengqian-Zhang
Copy link
Collaborator

@Chengqian-Zhang Chengqian-Zhang commented Aug 15, 2025

The UT of padding atoms(pytorch backend) sometimes fails like:

Mismatched elements: 1 / 2 (50%)
Max absolute difference among violations: 1.97471693e-08
Max relative difference among violations: 6.45619919e-07
 ACTUAL: array([[-0.236542],
       [ 0.030586]])
 DESIRED: array([[-0.236542],
       [ 0.030586]])
= 1 failed, 15442 passed, 4135 skipped, 97877 deselected, 224 warnings in 2825.25s (0:47:05) =

Summary by CodeRabbit

  • Tests
    • Adjusted numerical comparison assertions to use both absolute and relative tolerances in padding-related tests.
    • Aligns checks between computed results and references, improving resilience to minor floating-point variation.
    • Reduces intermittent test failures across environments and dependency versions.
    • No impact on features, performance, or user workflows.

@Chengqian-Zhang Chengqian-Zhang assigned njzjz and unassigned njzjz Aug 15, 2025
@Chengqian-Zhang Chengqian-Zhang requested a review from njzjz August 15, 2025 07:53
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

📝 Walkthrough

Walkthrough

Loosened numerical tolerances in a test: increased absolute tolerance, introduced relative tolerance, and applied both in assert_allclose comparisons within a single test case.

Changes

Cohort / File(s) Summary of Changes
Tests – tolerance updates
source/tests/pt/test_padding_atoms.py
Raised atol from 1e-8 to 1e-6; added rtol=1e-5; updated assert_allclose calls to use both atol and rtol for result vs. atom means and result vs. padding result comparisons.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

Python

Suggested reviewers

  • wanghan-iapcm

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 (3)
source/tests/pt/test_padding_atoms.py (3)

52-53: Relaxed tolerances look reasonable; add a brief rationale comment for future maintainers

Given the observed max abs≈2e-8 and rel≈6.5e-7, atol=1e-6 and rtol=1e-5 provide a small, sane margin (and rtol aligns with torch.allclose defaults). Add a comment so the change isn’t “tightened back” in future refactors.

Apply this diff to document the rationale:

         self.rcut_smth = 0.4
-        self.atol = 1e-6
-        self.rtol = 1e-5
+        # NOTE: Relax tolerances to deflake occasional PyTorch backend numeric drift.
+        # Observed maxima: abs~2e-8, rel~6.5e-7; keep a small margin suitable for float32 (see PR #4892).
+        self.atol = 1e-6
+        self.rtol = 1e-5

79-84: Improve diagnostics: include an error message for the “intensive” check

Adding err_msg will make failures more actionable without changing behavior.

         np.testing.assert_allclose(
             to_numpy_array(result[var_name].cpu().detach()),
             np.mean(to_numpy_array(result[f"atom_{var_name}"].cpu().detach()), axis=1),
             atol=self.atol,
-            rtol=self.rtol,
+            rtol=self.rtol,
+            err_msg=f"intensive property mismatch for '{var_name}'",
         )

106-111: Improve diagnostics: include padding_atoms in the assertion message

When this assert fails, knowing which padding_atoms caused it greatly speeds up triage.

         np.testing.assert_allclose(
             to_numpy_array(result[var_name].cpu().detach()),
             to_numpy_array(result_padding[var_name].cpu().detach()),
             atol=self.atol,
-            rtol=self.rtol,
+            rtol=self.rtol,
+            err_msg=f"padding invariance mismatch for '{var_name}' with padding_atoms={padding_atoms}",
         )
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e73bbff and ac44565.

📒 Files selected for processing (1)
  • source/tests/pt/test_padding_atoms.py (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Test C++ (true)

@codecov
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.29%. Comparing base (e73bbff) to head (ac44565).
⚠️ Report is 69 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4892      +/-   ##
==========================================
- Coverage   84.29%   84.29%   -0.01%     
==========================================
  Files         702      702              
  Lines       68665    68666       +1     
  Branches     3573     3573              
==========================================
  Hits        57884    57884              
- Misses       9642     9643       +1     
  Partials     1139     1139              

☔ 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 Aug 15, 2025
Merged via the queue into deepmodeling:devel with commit 565f0af Aug 15, 2025
60 checks passed
ChiahsinChu pushed a commit to ChiahsinChu/deepmd-kit that referenced this pull request Dec 17, 2025
…4892)

The UT of padding atoms(pytorch backend) sometimes fails like:
```
Mismatched elements: 1 / 2 (50%)
Max absolute difference among violations: 1.97471693e-08
Max relative difference among violations: 6.45619919e-07
 ACTUAL: array([[-0.236542],
       [ 0.030586]])
 DESIRED: array([[-0.236542],
       [ 0.030586]])
= 1 failed, 15442 passed, 4135 skipped, 97877 deselected, 224 warnings in 2825.25s (0:47:05) =
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Tests**
- Adjusted numerical comparison assertions to use both absolute and
relative tolerances in padding-related tests.
- Aligns checks between computed results and references, improving
resilience to minor floating-point variation.
- Reduces intermittent test failures across environments and dependency
versions.
  - No impact on features, performance, or user workflows.

<!-- 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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants