Skip to content

Commit 4865c4e

Browse files
author
Han Wang
committed
chore: drop redundant import deepmd.pt preloads
After 87c9f3f ``deepmd.pt_expt.utils.comm`` self-bootstraps ``libdeepmd_op_pt.so`` via ``_check_underlying_ops_loaded()``, so the explicit ``import deepmd.pt`` preloads in conftest.py and test_border_op_backward.py are no longer needed. Closes 2 of the 13 GitHub Advanced Security CodeQL "unused import" alerts on the PR. The remaining 5 Python alerts (other tests' ``import deepmd.pt_expt.utils.comm`` for opaque-op registration) and 6 C++ alerts (TORCH_LIBRARY_* / border_op_export reachable only through macro-expanded static initialization) are CodeQL false positives that need to be dismissed in the GitHub Security UI rather than fixed in source.
1 parent 87c9f3f commit 4865c4e

2 files changed

Lines changed: 6 additions & 11 deletions

File tree

source/tests/pt_expt/conftest.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@
1717
_get_current_function_mode_stack,
1818
)
1919

20-
# Import ``deepmd.pt`` at conftest evaluation time so libdeepmd_op_pt.so
21-
# is loaded and ``deepmd_export::{border_op, border_op_backward}`` are
22-
# registered before any pt_expt test module imports
23-
# ``deepmd.pt_expt.utils`` (which transitively imports ``comm.py`` and
24-
# its ``_check_underlying_ops_loaded()`` runtime check). Previously this
25-
# worked only when collected alongside earlier tests that happened to
26-
# import deepmd.pt first.
27-
import deepmd.pt # noqa: F401 - side-effect: register custom ops
20+
# ``deepmd.pt_expt.utils.comm`` self-bootstraps libdeepmd_op_pt.so via
21+
# ``_check_underlying_ops_loaded()``, so we no longer need to preload
22+
# ``deepmd.pt`` here.
2823

2924

3025
def _pop_device_contexts() -> list:

source/tests/pt_expt/utils/test_border_op_backward.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
import pytest
3131
import torch
3232

33-
# Ensure the new C++ symbol is loaded. pt_expt imports deepmd.pt for
34-
# the custom-op .so.
35-
import deepmd.pt
33+
# comm self-bootstraps the underlying libdeepmd_op_pt.so when needed, so
34+
# this single side-effect import is enough to register both the C++
35+
# ops (deepmd::border_op_backward) and their fake/autograd metadata.
3636
import deepmd.pt_expt.utils.comm # noqa: F401 - registers deepmd_export::border_op
3737

3838

0 commit comments

Comments
 (0)