Skip to content

Commit adf5b83

Browse files
wanghan-iapcmHan Wang
andauthored
perf(test): reduce redundant .pt2 compilations in GPU CI (#5379)
## Summary - **Strategy 1**: Share frozen `.pt2`/`.pte` in `setUpClass` for `test_dp_freeze.py` and `test_change_bias.py`, avoiding redundant AOTInductor compilations (~82s each) - **Strategy 2**: Remove `test_min_nbor_dist_roundtrip_pt2` — `.pte` test already covers the same metadata round-trip path (identical `metadata.json` in ZIP) - **Strategy 3**: Move `dp.init()` from per-test `SetUp()` to static `SetUpTestSuite()` in 9 C++ test files, loading each model once per typed test suite instead of once per test - **Strategy 4**: Parallelize 6 gen scripts in `test_cc_local.sh` (2 groups of 3 with PID-based error propagation) - **Cleanup**: Remove stale `.pt2`/`.pte` files before regeneration so outdated model files cannot be accidentally reused ## Benchmark (V100-SXM2-16GB, torch 2.10) | Test | Before | After | Saving | |------|--------|-------|--------| | test_dp_freeze.py | 536s | 299s | 237s (44%) | | test_change_bias.py | 495s | 460s | 35s (7%) | | C++ PtExpt tests | 467s | 71s | 396s (85%) | | **Total measured** | **1498s** | **830s** | **668s (11 min)** | Strategy 4 (parallel gen scripts) saves additional build-phase time (~200s estimated). ## Test plan - [x] `python -m pytest source/tests/pt_expt/test_dp_freeze.py -v` — 7/7 passed - [x] `python -m pytest source/tests/pt_expt/test_change_bias.py -v` — 11/11 passed - [x] C++ PtExpt tests (`runUnitTests_cc --gtest_filter='*PtExpt*'`) — 128/128 passed - [ ] Full CI pass <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Fixtures now share model instances across test cases and initialize/reset them once per suite, reducing per-test overhead and adjusting skip behavior when optional backends aren’t present. * Python tests now reuse pre-generated frozen artifacts across tests instead of regenerating per-test. * Removed a redundant metadata round-trip unit test. * **Chores** * Model-generation script now cleans stale artifacts and runs generation tasks in parallel to speed setup. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
1 parent efc27cf commit adf5b83

13 files changed

+355
-175
lines changed

source/api_cc/tests/test_deeppot_a_fparam_aparam_nframes_ptexpt.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <vector>
99

1010
#include "DeepPot.h"
11+
#include "DeepPotPTExpt.h"
1112
#include "test_utils.h"
1213

1314
template <class VALUETYPE>
@@ -113,13 +114,18 @@ class TestInferDeepPotAFparamAparamNFramesPtExpt : public ::testing::Test {
113114
std::vector<double> expected_tot_e;
114115
std::vector<VALUETYPE> expected_tot_v;
115116

116-
deepmd::DeepPot dp;
117+
static deepmd::DeepPot dp;
118+
119+
static void SetUpTestSuite() {
120+
#if defined(BUILD_PYTORCH) && BUILD_PT_EXPT
121+
dp.init("../../tests/infer/fparam_aparam.pt2");
122+
#endif
123+
}
117124

118125
void SetUp() override {
119-
#ifndef BUILD_PYTORCH
126+
#if !defined(BUILD_PYTORCH) || !BUILD_PT_EXPT
120127
GTEST_SKIP() << "Skip because PyTorch support is not enabled.";
121128
#endif
122-
dp.init("../../tests/infer/fparam_aparam.pt2");
123129

124130
natoms = expected_e.size() / nframes;
125131
EXPECT_EQ(nframes * natoms * 3, expected_f.size());
@@ -142,8 +148,13 @@ class TestInferDeepPotAFparamAparamNFramesPtExpt : public ::testing::Test {
142148
};
143149

144150
void TearDown() override {};
151+
152+
static void TearDownTestSuite() { dp = deepmd::DeepPot(); }
145153
};
146154

155+
template <class VALUETYPE>
156+
deepmd::DeepPot TestInferDeepPotAFparamAparamNFramesPtExpt<VALUETYPE>::dp;
157+
147158
TYPED_TEST_SUITE(TestInferDeepPotAFparamAparamNFramesPtExpt, ValueTypes);
148159

149160
TYPED_TEST(TestInferDeepPotAFparamAparamNFramesPtExpt, cpu_build_nlist) {

source/api_cc/tests/test_deeppot_a_fparam_aparam_ptexpt.cc

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <vector>
1010

1111
#include "DeepPot.h"
12+
#include "DeepPotPTExpt.h"
1213
#include "neighbor_list.h"
1314
#include "test_utils.h"
1415

@@ -73,13 +74,18 @@ class TestInferDeepPotAFParamAParamPtExpt : public ::testing::Test {
7374
double expected_tot_e;
7475
std::vector<VALUETYPE> expected_tot_v;
7576

76-
deepmd::DeepPot dp;
77+
static deepmd::DeepPot dp;
78+
79+
static void SetUpTestSuite() {
80+
#if defined(BUILD_PYTORCH) && BUILD_PT_EXPT
81+
dp.init("../../tests/infer/fparam_aparam.pt2");
82+
#endif
83+
}
7784

7885
void SetUp() override {
79-
#ifndef BUILD_PYTORCH
86+
#if !defined(BUILD_PYTORCH) || !BUILD_PT_EXPT
8087
GTEST_SKIP() << "Skip because PyTorch support is not enabled.";
8188
#endif
82-
dp.init("../../tests/infer/fparam_aparam.pt2");
8389

8490
natoms = expected_e.size();
8591
EXPECT_EQ(natoms * 3, expected_f.size());
@@ -98,8 +104,13 @@ class TestInferDeepPotAFParamAParamPtExpt : public ::testing::Test {
98104
};
99105

100106
void TearDown() override {};
107+
108+
static void TearDownTestSuite() { dp = deepmd::DeepPot(); }
101109
};
102110

111+
template <class VALUETYPE>
112+
deepmd::DeepPot TestInferDeepPotAFParamAParamPtExpt<VALUETYPE>::dp;
113+
103114
TYPED_TEST_SUITE(TestInferDeepPotAFParamAParamPtExpt, ValueTypes);
104115

105116
TYPED_TEST(TestInferDeepPotAFParamAParamPtExpt, cpu_build_nlist) {
@@ -325,18 +336,28 @@ TYPED_TEST(TestInferDeepPotAFParamAParamPtExpt, cpu_lmp_nlist_atomic) {
325336
template <class VALUETYPE>
326337
class TestInferDeepPotNoDefaultFParamPtExpt : public ::testing::Test {
327338
protected:
328-
deepmd::DeepPot dp;
339+
static deepmd::DeepPot dp;
340+
341+
static void SetUpTestSuite() {
342+
#if defined(BUILD_PYTORCH) && BUILD_PT_EXPT
343+
dp.init("../../tests/infer/fparam_aparam.pt2");
344+
#endif
345+
}
329346

330347
void SetUp() override {
331-
#ifndef BUILD_PYTORCH
348+
#if !defined(BUILD_PYTORCH) || !BUILD_PT_EXPT
332349
GTEST_SKIP() << "Skip because PyTorch support is not enabled.";
333350
#endif
334-
dp.init("../../tests/infer/fparam_aparam.pt2");
335351
};
336352

337353
void TearDown() override {};
354+
355+
static void TearDownTestSuite() { dp = deepmd::DeepPot(); }
338356
};
339357

358+
template <class VALUETYPE>
359+
deepmd::DeepPot TestInferDeepPotNoDefaultFParamPtExpt<VALUETYPE>::dp;
360+
340361
TYPED_TEST_SUITE(TestInferDeepPotNoDefaultFParamPtExpt, ValueTypes);
341362

342363
TYPED_TEST(TestInferDeepPotNoDefaultFParamPtExpt, no_default_fparam) {

source/api_cc/tests/test_deeppot_default_fparam_ptexpt.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <vector>
1111

1212
#include "DeepPot.h"
13+
#include "DeepPotPTExpt.h"
1314
#include "neighbor_list.h"
1415
#include "test_utils.h"
1516

@@ -78,13 +79,18 @@ class TestInferDeepPotDefaultFParamPtExpt : public ::testing::Test {
7879
double expected_tot_e;
7980
std::vector<VALUETYPE> expected_tot_v;
8081

81-
deepmd::DeepPot dp;
82+
static deepmd::DeepPot dp;
83+
84+
static void SetUpTestSuite() {
85+
#if defined(BUILD_PYTORCH) && BUILD_PT_EXPT
86+
dp.init("../../tests/infer/fparam_aparam_default.pt2");
87+
#endif
88+
}
8289

8390
void SetUp() override {
84-
#ifndef BUILD_PYTORCH
91+
#if !defined(BUILD_PYTORCH) || !BUILD_PT_EXPT
8592
GTEST_SKIP() << "Skip because PyTorch support is not enabled.";
8693
#endif
87-
dp.init("../../tests/infer/fparam_aparam_default.pt2");
8894

8995
natoms = expected_e.size();
9096
EXPECT_EQ(natoms * 3, expected_f.size());
@@ -103,8 +109,13 @@ class TestInferDeepPotDefaultFParamPtExpt : public ::testing::Test {
103109
};
104110

105111
void TearDown() override {};
112+
113+
static void TearDownTestSuite() { dp = deepmd::DeepPot(); }
106114
};
107115

116+
template <class VALUETYPE>
117+
deepmd::DeepPot TestInferDeepPotDefaultFParamPtExpt<VALUETYPE>::dp;
118+
108119
TYPED_TEST_SUITE(TestInferDeepPotDefaultFParamPtExpt, ValueTypes);
109120

110121
TYPED_TEST(TestInferDeepPotDefaultFParamPtExpt, attrs) {

source/api_cc/tests/test_deeppot_dpa1_ptexpt.cc

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <vector>
1111

1212
#include "DeepPot.h"
13+
#include "DeepPotPTExpt.h"
1314
#include "neighbor_list.h"
1415
#include "test_utils.h"
1516

@@ -72,13 +73,18 @@ class TestInferDeepPotDpa1PtExpt : public ::testing::Test {
7273
double expected_tot_e;
7374
std::vector<VALUETYPE> expected_tot_v;
7475

75-
deepmd::DeepPot dp;
76+
static deepmd::DeepPot dp;
77+
78+
static void SetUpTestSuite() {
79+
#if defined(BUILD_PYTORCH) && BUILD_PT_EXPT
80+
dp.init("../../tests/infer/deeppot_dpa1.pt2");
81+
#endif
82+
}
7683

7784
void SetUp() override {
78-
#ifndef BUILD_PYTORCH
85+
#if !defined(BUILD_PYTORCH) || !BUILD_PT_EXPT
7986
GTEST_SKIP() << "Skip because PyTorch support is not enabled.";
8087
#endif
81-
dp.init("../../tests/infer/deeppot_dpa1.pt2");
8288

8389
natoms = expected_e.size();
8490
EXPECT_EQ(natoms * 3, expected_f.size());
@@ -97,8 +103,13 @@ class TestInferDeepPotDpa1PtExpt : public ::testing::Test {
97103
};
98104

99105
void TearDown() override {};
106+
107+
static void TearDownTestSuite() { dp = deepmd::DeepPot(); }
100108
};
101109

110+
template <class VALUETYPE>
111+
deepmd::DeepPot TestInferDeepPotDpa1PtExpt<VALUETYPE>::dp;
112+
102113
TYPED_TEST_SUITE(TestInferDeepPotDpa1PtExpt, ValueTypes);
103114

104115
TYPED_TEST(TestInferDeepPotDpa1PtExpt, cpu_build_nlist) {
@@ -218,13 +229,18 @@ class TestInferDeepPotDpa1PtExptNoPbc : public ::testing::Test {
218229
double expected_tot_e;
219230
std::vector<VALUETYPE> expected_tot_v;
220231

221-
deepmd::DeepPot dp;
232+
static deepmd::DeepPot dp;
233+
234+
static void SetUpTestSuite() {
235+
#if defined(BUILD_PYTORCH) && BUILD_PT_EXPT
236+
dp.init("../../tests/infer/deeppot_dpa1.pt2");
237+
#endif
238+
}
222239

223240
void SetUp() override {
224-
#ifndef BUILD_PYTORCH
241+
#if !defined(BUILD_PYTORCH) || !BUILD_PT_EXPT
225242
GTEST_SKIP() << "Skip because PyTorch support is not enabled.";
226243
#endif
227-
dp.init("../../tests/infer/deeppot_dpa1.pt2");
228244

229245
natoms = expected_e.size();
230246
EXPECT_EQ(natoms * 3, expected_f.size());
@@ -243,8 +259,13 @@ class TestInferDeepPotDpa1PtExptNoPbc : public ::testing::Test {
243259
};
244260

245261
void TearDown() override {};
262+
263+
static void TearDownTestSuite() { dp = deepmd::DeepPot(); }
246264
};
247265

266+
template <class VALUETYPE>
267+
deepmd::DeepPot TestInferDeepPotDpa1PtExptNoPbc<VALUETYPE>::dp;
268+
248269
TYPED_TEST_SUITE(TestInferDeepPotDpa1PtExptNoPbc, ValueTypes);
249270

250271
TYPED_TEST(TestInferDeepPotDpa1PtExptNoPbc, cpu_build_nlist) {

source/api_cc/tests/test_deeppot_dpa2_ptexpt.cc

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <vector>
1010

1111
#include "DeepPot.h"
12+
#include "DeepPotPTExpt.h"
1213
#include "neighbor_list.h"
1314
#include "test_utils.h"
1415

@@ -71,13 +72,18 @@ class TestInferDeepPotDpa2PtExpt : public ::testing::Test {
7172
double expected_tot_e;
7273
std::vector<VALUETYPE> expected_tot_v;
7374

74-
deepmd::DeepPot dp;
75+
static deepmd::DeepPot dp;
76+
77+
static void SetUpTestSuite() {
78+
#if defined(BUILD_PYTORCH) && BUILD_PT_EXPT
79+
dp.init("../../tests/infer/deeppot_dpa2.pt2");
80+
#endif
81+
}
7582

7683
void SetUp() override {
77-
#ifndef BUILD_PYTORCH
84+
#if !defined(BUILD_PYTORCH) || !BUILD_PT_EXPT
7885
GTEST_SKIP() << "Skip because PyTorch support is not enabled.";
7986
#endif
80-
dp.init("../../tests/infer/deeppot_dpa2.pt2");
8187

8288
natoms = expected_e.size();
8389
EXPECT_EQ(natoms * 3, expected_f.size());
@@ -96,8 +102,13 @@ class TestInferDeepPotDpa2PtExpt : public ::testing::Test {
96102
};
97103

98104
void TearDown() override {};
105+
106+
static void TearDownTestSuite() { dp = deepmd::DeepPot(); }
99107
};
100108

109+
template <class VALUETYPE>
110+
deepmd::DeepPot TestInferDeepPotDpa2PtExpt<VALUETYPE>::dp;
111+
101112
TYPED_TEST_SUITE(TestInferDeepPotDpa2PtExpt, ValueTypes);
102113

103114
TYPED_TEST(TestInferDeepPotDpa2PtExpt, cpu_build_nlist) {
@@ -492,13 +503,18 @@ class TestInferDeepPotDpa2PtExptNoPbc : public ::testing::Test {
492503
double expected_tot_e;
493504
std::vector<VALUETYPE> expected_tot_v;
494505

495-
deepmd::DeepPot dp;
506+
static deepmd::DeepPot dp;
507+
508+
static void SetUpTestSuite() {
509+
#if defined(BUILD_PYTORCH) && BUILD_PT_EXPT
510+
dp.init("../../tests/infer/deeppot_dpa2.pt2");
511+
#endif
512+
}
496513

497514
void SetUp() override {
498-
#ifndef BUILD_PYTORCH
515+
#if !defined(BUILD_PYTORCH) || !BUILD_PT_EXPT
499516
GTEST_SKIP() << "Skip because PyTorch support is not enabled.";
500517
#endif
501-
dp.init("../../tests/infer/deeppot_dpa2.pt2");
502518

503519
natoms = expected_e.size();
504520
EXPECT_EQ(natoms * 3, expected_f.size());
@@ -517,8 +533,13 @@ class TestInferDeepPotDpa2PtExptNoPbc : public ::testing::Test {
517533
};
518534

519535
void TearDown() override {};
536+
537+
static void TearDownTestSuite() { dp = deepmd::DeepPot(); }
520538
};
521539

540+
template <class VALUETYPE>
541+
deepmd::DeepPot TestInferDeepPotDpa2PtExptNoPbc<VALUETYPE>::dp;
542+
522543
TYPED_TEST_SUITE(TestInferDeepPotDpa2PtExptNoPbc, ValueTypes);
523544

524545
TYPED_TEST(TestInferDeepPotDpa2PtExptNoPbc, cpu_build_nlist) {

0 commit comments

Comments
 (0)