fix: fake border op import#5451
Conversation
for more information, see https://pre-commit.ci
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR defers registration of ChangesDeferred comm operator registration
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@deepmd/pt_expt/utils/comm.py`:
- Around line 192-213: ensure_comm_registered currently checks global
_registered without synchronization, allowing a race; wrap the registration
block in a module-level lock (e.g., _register_lock) inside
ensure_comm_registered, acquire the lock, re-check _registered, then perform the
fake registrations and torch.library.register_autograd calls (referencing
_border_op_fake, _border_op_backward_fake, _border_op_backward, and
_border_op_setup_context) and set _registered = True before releasing the lock
to make the lazy-registration atomic and idempotent.
In `@deepmd/pt_expt/utils/serialization.py`:
- Around line 672-679: The code currently imports and calls
ensure_comm_registered() before checking whether the model actually requires a
comm artifact, which can prematurely load libdeepmd_op_pt.so; move the
_needs_with_comm_artifact(model) check before importing/calling
ensure_comm_registered so you reject non-comm models first. Concretely, evaluate
if not _needs_with_comm_artifact(model) and raise the existing ValueError (or
return) before executing the from deepmd.pt_expt.utils.comm import
ensure_comm_registered and ensure_comm_registered() calls; keep the import/call
only in the branch where _needs_with_comm_artifact(model) is True.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: dd6a77be-24bf-427d-b826-ddd0d908fb81
📒 Files selected for processing (4)
deepmd/pt_expt/utils/__init__.pydeepmd/pt_expt/utils/comm.pydeepmd/pt_expt/utils/serialization.pysource/tests/pt_expt/conftest.py
There was a problem hiding this comment.
Pull request overview
This PR makes PyTorch custom-op (border_op) registration for pt_expt lazy, deferring libdeepmd_op_pt.so loading and the fake/autograd metadata registration until the comm-dict export path is actually exercised. The intent is to avoid import-time side effects that can cause fake-op registration order conflicts, especially in tests.
Changes:
- Introduces
ensure_comm_registered()indeepmd.pt_expt.utils.commto explicitly load the op library and register fake/autograd metadata on demand. - Calls
ensure_comm_registered()from thewith_comm_dictexport path inserialization.pyand removes eager import ofcommfromdeepmd.pt_expt.utils.__init__. - Updates test conftest/comments to reflect the new lazy-loading behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
source/tests/pt_expt/conftest.py |
Updates commentary to describe lazy comm/op loading behavior in tests. |
deepmd/pt_expt/utils/serialization.py |
Lazily imports and calls ensure_comm_registered() in the with_comm_dict export path. |
deepmd/pt_expt/utils/comm.py |
Adds explicit, idempotent ensure_comm_registered() and removes import-time registration side effects. |
deepmd/pt_expt/utils/__init__.py |
Stops importing comm at package import time; documents lazy registration approach. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5451 +/- ##
==========================================
- Coverage 82.48% 82.47% -0.01%
==========================================
Files 830 830
Lines 88522 88535 +13
Branches 4232 4233 +1
==========================================
+ Hits 73015 73018 +3
- Misses 14220 14229 +9
- Partials 1287 1288 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
njzjz-bot
left a comment
There was a problem hiding this comment.
Looks good to me. The change is small/scoped and CI is green or currently progressing for the relevant checks.
Reviewed by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5).
Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
c6f2479
Summary by CodeRabbit