Skip to content

Commit 8d71b11

Browse files
fix
1 parent 59d5c6f commit 8d71b11

File tree

16 files changed

+175
-87
lines changed

16 files changed

+175
-87
lines changed

deepmd/pd/entrypoints/main.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ def freeze(
353353
)
354354
model = inference.Tester(model, head=head).model
355355
model.eval()
356+
# print(model.get_buffer_rcut.__func__.__qualname__)
357+
# print(model.get_buffer_rcut.__func__.__module__)
358+
# print(model.get_buffer_rcut.__func__.__code__.co_filename)
359+
# print(model.get_buffer_rcut.__func__.__code__.co_firstlineno)
360+
# print(model.get_buffer_type_map())
361+
# exit()
356362
from paddle.static import (
357363
InputSpec,
358364
)
@@ -411,14 +417,14 @@ def freeze(
411417
full_graph=True,
412418
)
413419
for method_name in [
414-
"get_rcut",
415-
"get_type_map",
416-
"get_dim_fparam",
417-
"get_dim_aparam",
418-
"get_intensive",
419-
"get_sel_type",
420-
"get_numb_dos",
421-
"get_task_dim",
420+
"get_buffer_rcut",
421+
"get_buffer_type_map",
422+
"get_buffer_dim_fparam",
423+
"get_buffer_dim_aparam",
424+
"get_buffer_intensive",
425+
"get_buffer_sel_type",
426+
"get_buffer_numb_dos",
427+
"get_buffer_task_dim",
422428
]:
423429
if hasattr(model, method_name):
424430
setattr(

deepmd/pd/infer/deep_eval.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ def __init__(
150150
self.static_model = False
151151
elif str(self.model_path).endswith(".json"):
152152
self.dp = paddle.jit.load(self.model_path.split(".json")[0])
153-
self.rcut = self.dp.get_rcut().item()
153+
self.rcut = self.dp.get_buffer_rcut().item()
154154
self.type_map: list[str] = "".join(
155-
[chr(x) for x in self.dp.get_type_map().numpy()]
155+
[chr(x) for x in self.dp.get_buffer_type_map().numpy()]
156156
).split(" ")
157157
config = paddle_inference.Config(
158158
self.model_path, self.model_path.replace(".json", ".pdiparams")
@@ -214,13 +214,13 @@ def get_type_map(self) -> list[str]:
214214
def get_dim_fparam(self) -> int:
215215
"""Get the number (dimension) of frame parameters of this DP."""
216216
if self.static_model:
217-
return self.dp.get_dim_fparam()
217+
return self.dp.get_buffer_dim_fparam()
218218
return self.dp.model["Default"].get_dim_fparam()
219219

220220
def get_dim_aparam(self) -> int:
221221
"""Get the number (dimension) of atomic parameters of this DP."""
222222
if self.static_model:
223-
return self.dp.get_dim_aparam()
223+
return self.dp.get_buffer_dim_aparam()
224224
return self.dp.model["Default"].get_dim_aparam()
225225

226226
def has_default_fparam(self) -> bool:

deepmd/pd/model/atomic_model/base_atomic_model.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ def get_type_map(self) -> list[str]:
134134
"""Get the type map."""
135135
return self.type_map
136136

137+
def get_buffer_type_map(self) -> list[str]:
138+
"""Get the type map."""
139+
return self.buffer_type_map
140+
137141
def get_compute_stats_distinguish_types(self) -> bool:
138142
"""Get whether the fitting net computes stats which are not distinguished between different types of atoms."""
139143
return True
@@ -581,8 +585,9 @@ def _store_out_stat(
581585
paddle.assign(out_std_data, self.out_std)
582586

583587
def get_ntypes(self):
584-
if paddle.in_dynamic_mode():
585-
return len(self.type_map)
588+
return len(self.type_map)
589+
590+
def get_buffer_ntypes(self):
586591
return self.buffer_ntypes
587592

588593
def _fetch_out_stat(

deepmd/pd/model/atomic_model/dp_atomic_model.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ def __init__(
7171
def _string_to_array(s: Union[str, list[str]]) -> list[int]:
7272
return [ord(c) for c in s]
7373

74-
self.register_buffer(
75-
"buffer_type_map",
76-
paddle.to_tensor(_string_to_array(" ".join(self.type_map)), dtype="int32"),
77-
)
78-
self.buffer_type_map.name = "buffer_type_map"
74+
if type_map is not None:
75+
self.register_buffer(
76+
"buffer_type_map",
77+
paddle.to_tensor(
78+
_string_to_array(" ".join(self.type_map)), dtype="int32"
79+
),
80+
)
81+
self.buffer_type_map.name = "buffer_type_map"
7982
if hasattr(self.descriptor, "has_message_passing"):
8083
# register 'has_message_passing' as buffer(cast to int32 as problems may meets with vector<bool>)
8184
self.register_buffer(
@@ -148,15 +151,23 @@ def fitting_output_def(self) -> FittingOutputDef:
148151

149152
def get_rcut(self) -> float:
150153
"""Get the cut-off radius."""
151-
if paddle.in_dynamic_mode():
152-
return self.rcut
153-
return self.descriptor.get_rcut()
154+
return self.rcut
154155

155156
def get_sel(self) -> list[int]:
156157
"""Get the neighbor selection."""
157-
if paddle.in_dynamic_mode():
158-
return self.sel
159-
return self.descriptor.get_sel()
158+
return self.sel
159+
160+
def get_buffer_type_map(self) -> paddle.Tensor:
161+
"""Get the neighbor selection."""
162+
return self.buffer_type_map
163+
164+
def get_buffer_rcut(self) -> paddle.Tensor:
165+
"""Get the cut-off radius."""
166+
return self.descriptor.get_buffer_rcut()
167+
168+
def get_buffer_sel(self) -> paddle.Tensor:
169+
"""Get the neighbor selection."""
170+
return self.descriptor.get_buffer_sel()
160171

161172
def set_case_embd(self, case_idx: int):
162173
"""

deepmd/pd/model/descriptor/dpa1.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,18 @@ def get_rcut(self) -> float:
325325
"""Returns the cut-off radius."""
326326
return self.se_atten.get_rcut()
327327

328+
def get_buffer_rcut(self) -> float:
329+
"""Returns the cut-off radius."""
330+
return self.se_atten.get_buffer_rcut()
331+
328332
def get_rcut_smth(self) -> float:
329333
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
330334
return self.se_atten.get_rcut_smth()
331335

336+
def get_buffer_rcut_smth(self) -> float:
337+
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
338+
return self.se_atten.get_buffer_rcut_smth()
339+
332340
def get_nsel(self) -> int:
333341
"""Returns the number of selected atoms in the cut-off radius."""
334342
return self.se_atten.get_nsel()
@@ -343,8 +351,10 @@ def get_ntypes(self) -> int:
343351

344352
def get_type_map(self) -> list[str]:
345353
"""Get the name to each type of atoms."""
346-
if paddle.in_dynamic_mode():
347-
return self.type_map
354+
return self.type_map
355+
356+
def get_buffer_type_map(self) -> paddle.Tensor:
357+
"""Get the name to each type of atoms."""
348358
return self.buffer_type_map
349359

350360
def get_dim_out(self) -> int:

deepmd/pd/model/descriptor/dpa2.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,19 @@ def init_subclass_params(sub_data, sub_class):
334334

335335
def get_rcut(self) -> float:
336336
"""Returns the cut-off radius."""
337-
if paddle.in_dynamic_mode():
338-
return self.rcut
339-
return self.repinit.get_rcut()
337+
return self.rcut
340338

341339
def get_rcut_smth(self) -> float:
342340
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
343-
if paddle.in_dynamic_mode():
344-
return self.rcut_smth
345-
return self.repinit.get_rcut_smth()
341+
return self.rcut_smth
342+
343+
def get_buffer_rcut(self) -> paddle.Tensor:
344+
"""Returns the cut-off radius."""
345+
return self.repinit.get_buffer_rcut()
346+
347+
def get_buffer_rcut_smth(self) -> paddle.Tensor:
348+
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
349+
return self.repinit.get_buffer_rcut_smth()
346350

347351
def get_nsel(self) -> int:
348352
"""Returns the number of selected atoms in the cut-off radius."""
@@ -780,7 +784,7 @@ def forward(
780784
type_embedding = None
781785
g1, _, _, _, _ = self.repinit(
782786
nlist_dict[
783-
get_multiple_nlist_key(self.repinit.get_rcut(), self.repinit.get_nsel())
787+
get_multiple_nlist_key(self.repinit.rcut, sum(self.repinit.sel))
784788
],
785789
extended_coord,
786790
extended_atype,

deepmd/pd/model/descriptor/dpa3.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,11 @@ def init_subclass_params(sub_data, sub_class):
176176
self.use_loc_mapping = use_loc_mapping
177177
self.use_tebd_bias = use_tebd_bias
178178
self.type_map = type_map
179-
self.register_buffer(
180-
"buffer_type_map",
181-
paddle.to_tensor([ord(c) for c in " ".join(self.type_map)]),
182-
)
179+
if type_map is not None:
180+
self.register_buffer(
181+
"buffer_type_map",
182+
paddle.to_tensor([ord(c) for c in " ".join(self.type_map)]),
183+
)
183184
self.tebd_dim = self.repflow_args.n_dim
184185
self.type_embedding = TypeEmbedNet(
185186
ntypes,
@@ -222,24 +223,30 @@ def init_subclass_params(sub_data, sub_class):
222223

223224
def get_rcut(self) -> float:
224225
"""Returns the cut-off radius."""
225-
if paddle.in_dynamic_mode():
226-
return self.rcut
227-
return self.repflows.get_rcut()
226+
return self.rcut
228227

229228
def get_rcut_smth(self) -> float:
230229
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
231-
if paddle.in_dynamic_mode():
232-
return self.rcut_smth
233-
return self.repflows.get_rcut_smth()
230+
return self.rcut_smth
231+
232+
def get_buffer_rcut(self) -> paddle.Tensor:
233+
"""Returns the cut-off radius."""
234+
return self.repflows.get_buffer_rcut()
235+
236+
def get_buffer_rcut_smth(self) -> paddle.Tensor:
237+
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
238+
return self.repflows.get_buffer_rcut_smth()
234239

235240
def get_nsel(self) -> int:
236241
"""Returns the number of selected atoms in the cut-off radius."""
237242
return sum(self.sel)
238243

239244
def get_sel(self) -> list[int]:
240245
"""Returns the number of selected atoms for each type."""
241-
if paddle.in_dynamic_mode():
242-
return self.sel
246+
return self.sel
247+
248+
def get_buffer_sel(self) -> paddle.Tensor:
249+
"""Returns the number of selected atoms for each type."""
243250
return self.repflows.get_sel()
244251

245252
def get_ntypes(self) -> int:
@@ -248,8 +255,10 @@ def get_ntypes(self) -> int:
248255

249256
def get_type_map(self) -> list[str]:
250257
"""Get the name to each type of atoms."""
251-
if paddle.in_dynamic_mode():
252-
return self.type_map
258+
return self.type_map
259+
260+
def get_buffer_type_map(self) -> paddle.Tensor:
261+
"""Get the name to each type of atoms."""
253262
return self.buffer_type_map
254263

255264
def get_dim_out(self) -> int:

deepmd/pd/model/descriptor/repflows.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,10 @@ def __init__(
358358

359359
def get_rcut(self) -> float:
360360
"""Returns the cut-off radius."""
361-
if paddle.in_dynamic_mode():
362-
return self.e_rcut
361+
return self.e_rcut
362+
363+
def get_buffer_rcut(self) -> paddle.Tensor:
364+
"""Returns the cut-off radius."""
363365
return self.buffer_rcut
364366

365367
def get_rcut_smth(self) -> float:
@@ -372,8 +374,10 @@ def get_nsel(self) -> int:
372374

373375
def get_sel(self) -> list[int]:
374376
"""Returns the number of selected atoms for each type."""
375-
if paddle.in_dynamic_mode():
376-
return self.sel
377+
return self.sel
378+
379+
def get_buffer_sel(self) -> paddle.Tensor:
380+
"""Returns the number of selected atoms for each type."""
377381
return self.buffer_sel
378382

379383
def get_ntypes(self) -> int:

deepmd/pd/model/descriptor/repformers.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,18 @@ def __init__(
323323

324324
def get_rcut(self) -> float:
325325
"""Returns the cut-off radius."""
326-
if paddle.in_dynamic_mode():
327-
return self.rcut
328-
return self.buffer_rcut
326+
return self.rcut
329327

330328
def get_rcut_smth(self) -> float:
331329
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
332-
if paddle.in_dynamic_mode():
333-
return self.rcut_smth
330+
return self.rcut_smth
331+
332+
def get_buffer_rcut(self) -> paddle.Tensor:
333+
"""Returns the cut-off radius."""
334+
return self.buffer_rcut
335+
336+
def get_buffer_rcut_smth(self) -> paddle.Tensor:
337+
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
334338
return self.buffer_rcut_smth
335339

336340
def get_nsel(self) -> int:

deepmd/pd/model/descriptor/se_a.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ def get_ntypes(self) -> int:
141141

142142
def get_type_map(self) -> list[str]:
143143
"""Get the name to each type of atoms."""
144-
if paddle.in_dynamic_mode():
145-
return self.type_map
144+
return self.type_map
145+
146+
def get_buffer_type_map(self) -> paddle.Tensor:
147+
"""Get the name to each type of atoms."""
146148
return self.buffer_type_map
147149

148150
def get_dim_out(self) -> int:
@@ -519,14 +521,18 @@ def __init__(
519521

520522
def get_rcut(self) -> float:
521523
"""Returns the cut-off radius."""
522-
if paddle.in_dynamic_mode():
523-
return self.rcut
524-
return self.buffer_rcut
524+
return self.rcut
525525

526526
def get_rcut_smth(self) -> float:
527527
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
528-
if paddle.in_dynamic_mode():
529-
return self.rcut_smth
528+
return self.rcut_smth
529+
530+
def get_buffer_rcut(self) -> paddle.Tensor:
531+
"""Returns the cut-off radius."""
532+
return self.buffer_rcut
533+
534+
def get_buffer_rcut_smth(self) -> paddle.Tensor:
535+
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
530536
return self.buffer_rcut_smth
531537

532538
def get_nsel(self) -> int:

0 commit comments

Comments
 (0)