Commit 71239f9
Han Wang
refactor(pt_expt): NativeSpinEnergyModel via make_native_spin_model; registry dispatch replaces native-spin seams
The pt_expt twin instantiates the shared factory on THIS backend's
EnergyModel and registers under 'native_spin' in the PT_EXPT BaseModel
registry, so the public BaseModel.deserialize returns the torch class
(backend-aware, no hard-coded branches). Consequences:
- The bespoke deserialize override and the __getattr__ delegation shim
are deleted: the factory's deserialize closure rebuilds through the
pt_expt EnergyModel, and inheritance replaces delegation. forward and
forward_lower_graph_exportable (spin@index-10 ABI unchanged) now call
the inherited call_common/forward_common_lower_graph_exportable on
self instead of a backbone attribute.
- get_native_spin_model (public, matching its sibling builders) routes
the backbone through get_sezm_model for the DPA4/SeZM family (keeping
its guards) or get_standard_model otherwise, gates on
descriptor.supports_native_spin(), and re-classes via atomic_model_.
The standard-typed get_model path now dispatches scheme='native' too,
so a future native-spin descriptor works from a plain standard config.
- deep_eval and deserialize_to_file drop their native-spin special
cases (registry + has_spin() cover them); the eval_typeebd unwrap is
isinstance-precise on the virtual-atom SpinModel only.
- NEW NativeSpinModelKind marker base in the factory module: each
backend's concrete class is a parallel factory product with NO
subclass relation, so the old isinstance-against-dpmodel-class
with-comm gate went silently dead -- the freeze then compiled a
with-comm artifact for the single-rank-only spin ABI (caught by
test_native_spin_graph_freeze cold-cache A/B). Seams test the shared
marker instead.
Validated locally: native-spin+spin batteries 25, export file 4/5
(test_dpa4_freeze_to_pt2[auto-graph] fails identically at the
pre-refactor commit with a cold inductor cache -- pre-existing local
inductor codegen bug, not a regression), deep_eval 93, dpmodel 19.1 parent 24abf3c commit 71239f9
9 files changed
Lines changed: 153 additions & 177 deletions
File tree
- deepmd
- dpmodel/model
- pt_expt
- infer
- model
- utils
- source/tests
- infer
- pt_expt/model
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
29 | 42 | | |
30 | 43 | | |
31 | 44 | | |
| |||
56 | 69 | | |
57 | 70 | | |
58 | 71 | | |
59 | | - | |
| 72 | + | |
60 | 73 | | |
61 | 74 | | |
62 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
352 | 346 | | |
353 | | - | |
| 347 | + | |
354 | 348 | | |
355 | 349 | | |
356 | 350 | | |
| |||
1662 | 1656 | | |
1663 | 1657 | | |
1664 | 1658 | | |
1665 | | - | |
| 1659 | + | |
1666 | 1660 | | |
1667 | 1661 | | |
1668 | 1662 | | |
| |||
1851 | 1845 | | |
1852 | 1846 | | |
1853 | 1847 | | |
1854 | | - | |
| 1848 | + | |
1855 | 1849 | | |
1856 | 1850 | | |
1857 | 1851 | | |
| |||
2353 | 2347 | | |
2354 | 2348 | | |
2355 | 2349 | | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
2356 | 2354 | | |
2357 | | - | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
2358 | 2358 | | |
2359 | 2359 | | |
2360 | 2360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
| 29 | + | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
217 | | - | |
| 216 | + | |
| 217 | + | |
218 | 218 | | |
219 | | - | |
220 | | - | |
| 219 | + | |
| 220 | + | |
221 | 221 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
227 | 230 | | |
228 | 231 | | |
229 | 232 | | |
| |||
234 | 237 | | |
235 | 238 | | |
236 | 239 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | 240 | | |
242 | 241 | | |
243 | 242 | | |
| |||
252 | 251 | | |
253 | 252 | | |
254 | 253 | | |
255 | | - | |
256 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
257 | 276 | | |
258 | 277 | | |
259 | 278 | | |
| |||
355 | 374 | | |
356 | 375 | | |
357 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
358 | 382 | | |
359 | 383 | | |
360 | 384 | | |
| |||
Lines changed: 28 additions & 83 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
65 | 68 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
69 | 75 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
74 | 79 | | |
75 | 80 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
81 | 84 | | |
82 | 85 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | 86 | | |
143 | 87 | | |
144 | 88 | | |
| |||
188 | 132 | | |
189 | 133 | | |
190 | 134 | | |
191 | | - | |
| 135 | + | |
192 | 136 | | |
193 | 137 | | |
194 | 138 | | |
| |||
253 | 197 | | |
254 | 198 | | |
255 | 199 | | |
256 | | - | |
257 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
258 | 203 | | |
259 | 204 | | |
260 | 205 | | |
| |||
312 | 257 | | |
313 | 258 | | |
314 | 259 | | |
315 | | - | |
| 260 | + | |
316 | 261 | | |
317 | 262 | | |
318 | 263 | | |
| |||
0 commit comments