Skip to content

Commit 0d18818

Browse files
committed
fix(lmdb): align statistics grouping and decoder shutdown
2 parents ee5627a + 4f827cc commit 0d18818

42 files changed

Lines changed: 2373 additions & 620 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ repos:
3030
exclude: ^source/3rdparty
3131
- repo: https://github.com/astral-sh/ruff-pre-commit
3232
# Ruff version.
33-
rev: v0.15.22
33+
rev: v0.16.0
3434
hooks:
3535
- id: ruff
3636
args: ["--fix"]

deepmd/dpmodel/atomic_model/base_atomic_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ def change_out_bias(
758758
delta_bias, out_std = compute_output_stats(
759759
sample_merged,
760760
self.get_ntypes(),
761-
keys=list(self.atomic_output_def().keys()),
761+
keys=self.bias_keys,
762762
stat_file_path=stat_file_path,
763763
model_forward=self._get_forward_wrapper_func(),
764764
rcond=self.rcond,
@@ -771,7 +771,7 @@ def change_out_bias(
771771
bias_out, std_out = compute_output_stats(
772772
sample_merged,
773773
self.get_ntypes(),
774-
keys=list(self.atomic_output_def().keys()),
774+
keys=self.bias_keys,
775775
stat_file_path=stat_file_path,
776776
rcond=self.rcond,
777777
preset_bias=self.preset_out_bias,

deepmd/dpmodel/descriptor/descriptor.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,37 @@ def get_stats(self) -> dict[str, StatItem]:
110110
"""Get the statistics of the descriptor."""
111111
raise NotImplementedError
112112

113+
def set_stat_mean_and_stddev(
114+
self,
115+
mean: Array,
116+
stddev: Array,
117+
) -> None:
118+
"""Update the normalization arrays of the descriptor block.
119+
120+
Parameters
121+
----------
122+
mean
123+
Mean of the environment matrix.
124+
stddev
125+
Standard deviation of the environment matrix.
126+
127+
Returns
128+
-------
129+
None
130+
"""
131+
self["davg"] = mean
132+
self["dstd"] = stddev
133+
134+
def get_stat_mean_and_stddev(self) -> tuple[Array, Array]:
135+
"""Return the normalization arrays of the descriptor block.
136+
137+
Returns
138+
-------
139+
tuple[Array, Array]
140+
Mean and standard deviation of the environment matrix.
141+
"""
142+
return self["davg"], self["dstd"]
143+
113144
def share_params(
114145
self, base_class: Any, shared_level: Any, resume: bool = False
115146
) -> None:

deepmd/dpmodel/descriptor/dpa1.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,15 +1461,7 @@ def compute_input_stats(
14611461
env_mat_stat = EnvMatStatSe(self, use_graph=True)
14621462
if path is not None:
14631463
path = path / env_mat_stat.get_hash()
1464-
if path is None or not path.is_dir():
1465-
if callable(merged):
1466-
# only get data for once
1467-
sampled = merged()
1468-
else:
1469-
sampled = merged
1470-
else:
1471-
sampled = []
1472-
env_mat_stat.load_or_compute_stats(sampled, path)
1464+
env_mat_stat.load_or_compute_stats(merged, path)
14731465
self.stats = env_mat_stat.stats
14741466
mean, stddev = env_mat_stat()
14751467
xp = array_api_compat.array_namespace(self.stddev)

deepmd/dpmodel/descriptor/repflows.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,7 @@ def compute_input_stats(
494494
env_mat_stat = EnvMatStatSe(self)
495495
if path is not None:
496496
path = path / env_mat_stat.get_hash()
497-
if path is None or not path.is_dir():
498-
if callable(merged):
499-
# only get data for once
500-
sampled = merged()
501-
else:
502-
sampled = merged
503-
else:
504-
sampled = []
505-
env_mat_stat.load_or_compute_stats(sampled, path)
497+
env_mat_stat.load_or_compute_stats(merged, path)
506498
self.stats = env_mat_stat.stats
507499
mean, stddev = env_mat_stat()
508500
xp = array_api_compat.array_namespace(self.stddev)

deepmd/dpmodel/descriptor/repformers.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,7 @@ def compute_input_stats(
459459
env_mat_stat = EnvMatStatSe(self)
460460
if path is not None:
461461
path = path / env_mat_stat.get_hash()
462-
if path is None or not path.is_dir():
463-
if callable(merged):
464-
# only get data for once
465-
sampled = merged()
466-
else:
467-
sampled = merged
468-
else:
469-
sampled = []
470-
env_mat_stat.load_or_compute_stats(sampled, path)
462+
env_mat_stat.load_or_compute_stats(merged, path)
471463
self.stats = env_mat_stat.stats
472464
mean, stddev = env_mat_stat()
473465
xp = array_api_compat.array_namespace(self.stddev)

deepmd/dpmodel/descriptor/se_e2_a.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,7 @@ def compute_input_stats(
349349
env_mat_stat = EnvMatStatSe(self)
350350
if path is not None:
351351
path = path / env_mat_stat.get_hash()
352-
if path is None or not path.is_dir():
353-
if callable(merged):
354-
# only get data for once
355-
sampled = merged()
356-
else:
357-
sampled = merged
358-
else:
359-
sampled = []
360-
env_mat_stat.load_or_compute_stats(sampled, path)
352+
env_mat_stat.load_or_compute_stats(merged, path)
361353
self.stats = env_mat_stat.stats
362354
mean, stddev = env_mat_stat()
363355
xp = array_api_compat.array_namespace(self.dstd)

deepmd/dpmodel/descriptor/se_r.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,7 @@ def compute_input_stats(
328328
env_mat_stat = EnvMatStatSe(self)
329329
if path is not None:
330330
path = path / env_mat_stat.get_hash()
331-
if path is None or not path.is_dir():
332-
if callable(merged):
333-
# only get data for once
334-
sampled = merged()
335-
else:
336-
sampled = merged
337-
else:
338-
sampled = []
339-
env_mat_stat.load_or_compute_stats(sampled, path)
331+
env_mat_stat.load_or_compute_stats(merged, path)
340332
self.stats = env_mat_stat.stats
341333
mean, stddev = env_mat_stat()
342334
xp = array_api_compat.array_namespace(self.dstd)

deepmd/dpmodel/descriptor/se_t.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,7 @@ def compute_input_stats(
303303
env_mat_stat = EnvMatStatSe(self)
304304
if path is not None:
305305
path = path / env_mat_stat.get_hash()
306-
if path is None or not path.is_dir():
307-
if callable(merged):
308-
# only get data for once
309-
sampled = merged()
310-
else:
311-
sampled = merged
312-
else:
313-
sampled = []
314-
env_mat_stat.load_or_compute_stats(sampled, path)
306+
env_mat_stat.load_or_compute_stats(merged, path)
315307
self.stats = env_mat_stat.stats
316308
mean, stddev = env_mat_stat()
317309
xp = array_api_compat.array_namespace(self.dstd)

deepmd/dpmodel/descriptor/se_t_tebd.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,7 @@ def compute_input_stats(
791791
env_mat_stat = EnvMatStatSe(self)
792792
if path is not None:
793793
path = path / env_mat_stat.get_hash()
794-
if path is None or not path.is_dir():
795-
if callable(merged):
796-
# only get data for once
797-
sampled = merged()
798-
else:
799-
sampled = merged
800-
else:
801-
sampled = []
802-
env_mat_stat.load_or_compute_stats(sampled, path)
794+
env_mat_stat.load_or_compute_stats(merged, path)
803795
self.stats = env_mat_stat.stats
804796
mean, stddev = env_mat_stat()
805797
xp = array_api_compat.array_namespace(self.stddev)

0 commit comments

Comments
 (0)