Commit e679b8d
fix(pt_expt): let deepmd.pt import errors propagate in comm op check (#5474)
## Summary
`_check_underlying_ops_loaded()` in `deepmd/pt_expt/utils/comm.py` wraps
`import deepmd.pt` in a blanket `except Exception: pass`, then falls
through to a generic `RuntimeError` telling the user to build
`libdeepmd_op_pt.so`.
The problem: when the .so *is* built but loaded against a mismatched
torch version, `import deepmd.pt` raises an `ImportError` with
diagnostic detail (e.g. `undefined symbol: ...`) — exactly the message
the user needs. The current code hides it and tells them to rebuild a
library that's already built.
This PR removes the `try/except` and lets the import error propagate.
The downstream `RuntimeError` still fires for the case where the import
succeeds but the ops still aren't registered.
## Trade-off
External callers that previously caught `RuntimeError` from `comm.py`
import will now see the raw `ImportError` for the .so-mismatch case. No
in-tree caller does this. The diagnostic gain outweighs the contract
change.
## Test plan
- [x] Existing pt_expt tests (every consumer imports `comm.py`) — happy
path unchanged
- [ ] CI green
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved initialization error reporting: when native registrations
fail to load, the underlying import/ABI error is now preserved and
surfaced instead of being masked by a generic message, making root
causes clearer for troubleshooting.
<!-- review_stack_entry_start -->
[](https://app.coderabbit.ai/change-stack/deepmodeling/deepmd-kit/pull/5474?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)
<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>1 parent 93f5580 commit e679b8d
1 file changed
Lines changed: 29 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
58 | 63 | | |
59 | 64 | | |
60 | 65 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
72 | 85 | | |
73 | 86 | | |
74 | 87 | | |
| |||
0 commit comments