Skip to content

Commit

Permalink
chore: fix spelling PRECISON -> PRECISION (#4508)
Browse files Browse the repository at this point in the history
Luckily, this variable has never been used otherwhere.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Corrected the spelling of `RESERVED_PRECISON_DICT` to
`RESERVED_PRECISION_DICT` across multiple files to ensure consistency
and prevent potential runtime errors.
  
- **Documentation**
- Updated comments and documentation to reflect the corrected variable
name, enhancing clarity without altering functionality.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
njzjz authored Dec 26, 2024
1 parent bd2395c commit 5788f79
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 45 deletions.
10 changes: 5 additions & 5 deletions deepmd/dpmodel/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}
assert VALID_PRECISION.issubset(PRECISION_DICT.keys())

RESERVED_PRECISON_DICT = {
RESERVED_PRECISION_DICT = {
np.float16: "float16",
np.float32: "float32",
np.float64: "float64",
Expand All @@ -52,7 +52,7 @@
ml_dtypes.bfloat16: "bfloat16",
np.bool_: "bool",
}
assert set(RESERVED_PRECISON_DICT.keys()) == set(PRECISION_DICT.values())
assert set(RESERVED_PRECISION_DICT.keys()) == set(PRECISION_DICT.values())
DEFAULT_PRECISION = "float64"


Expand All @@ -74,9 +74,9 @@ def get_xp_precision(
elif precision == "bool":
return bool
elif precision == "default":
return get_xp_precision(xp, RESERVED_PRECISON_DICT[PRECISION_DICT[precision]])
return get_xp_precision(xp, RESERVED_PRECISION_DICT[PRECISION_DICT[precision]])
elif precision == "global":
return get_xp_precision(xp, RESERVED_PRECISON_DICT[GLOBAL_NP_FLOAT_PRECISION])
return get_xp_precision(xp, RESERVED_PRECISION_DICT[GLOBAL_NP_FLOAT_PRECISION])
elif precision == "bfloat16":
return ml_dtypes.bfloat16
else:
Expand Down Expand Up @@ -225,6 +225,6 @@ def safe_cast_array(
"GLOBAL_ENER_FLOAT_PRECISION",
"GLOBAL_NP_FLOAT_PRECISION",
"PRECISION_DICT",
"RESERVED_PRECISON_DICT",
"RESERVED_PRECISION_DICT",
"NativeOP",
]
10 changes: 5 additions & 5 deletions deepmd/dpmodel/model/make_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
GLOBAL_ENER_FLOAT_PRECISION,
GLOBAL_NP_FLOAT_PRECISION,
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
NativeOP,
)
from deepmd.dpmodel.model.base_model import (
Expand Down Expand Up @@ -169,7 +169,7 @@ def __init__(
self.atomic_model: T_AtomicModel = T_AtomicModel(*args, **kwargs)
self.precision_dict = PRECISION_DICT
# not supported by flax
# self.reverse_precision_dict = RESERVED_PRECISON_DICT
# self.reverse_precision_dict = RESERVED_PRECISION_DICT
self.global_np_float_precision = GLOBAL_NP_FLOAT_PRECISION
self.global_ener_float_precision = GLOBAL_ENER_FLOAT_PRECISION

Expand Down Expand Up @@ -373,7 +373,7 @@ def input_type_cast(
str,
]:
"""Cast the input data to global float type."""
input_prec = RESERVED_PRECISON_DICT[self.precision_dict[coord.dtype.name]]
input_prec = RESERVED_PRECISION_DICT[self.precision_dict[coord.dtype.name]]
###
### type checking would not pass jit, convert to coord prec anyway
###
Expand All @@ -382,7 +382,7 @@ def input_type_cast(
for vv in [box, fparam, aparam]
]
box, fparam, aparam = _lst
if input_prec == RESERVED_PRECISON_DICT[self.global_np_float_precision]:
if input_prec == RESERVED_PRECISION_DICT[self.global_np_float_precision]:
return coord, box, fparam, aparam, input_prec
else:
pp = self.global_np_float_precision
Expand All @@ -401,7 +401,7 @@ def output_type_cast(
) -> dict[str, np.ndarray]:
"""Convert the model output to the input prec."""
do_cast = (
input_prec != RESERVED_PRECISON_DICT[self.global_np_float_precision]
input_prec != RESERVED_PRECISION_DICT[self.global_np_float_precision]
)
pp = self.precision_dict[input_prec]
odef = self.model_output_def()
Expand Down
6 changes: 3 additions & 3 deletions deepmd/pd/infer/deep_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from deepmd.pd.utils.env import (
DEVICE,
GLOBAL_PD_FLOAT_PRECISION,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
enable_prim,
)
from deepmd.pd.utils.utils import (
Expand Down Expand Up @@ -355,7 +355,7 @@ def _eval_model(
request_defs: list[OutputVariableDef],
):
model = self.dp.to(DEVICE)
prec = NP_PRECISION_DICT[RESERVED_PRECISON_DICT[GLOBAL_PD_FLOAT_PRECISION]]
prec = NP_PRECISION_DICT[RESERVED_PRECISION_DICT[GLOBAL_PD_FLOAT_PRECISION]]

nframes = coords.shape[0]
if len(atom_types.shape) == 1:
Expand All @@ -370,7 +370,7 @@ def _eval_model(
place=DEVICE,
)
type_input = paddle.to_tensor(
atom_types.astype(NP_PRECISION_DICT[RESERVED_PRECISON_DICT[paddle.int64]]),
atom_types.astype(NP_PRECISION_DICT[RESERVED_PRECISION_DICT[paddle.int64]]),
dtype=paddle.int64,
place=DEVICE,
)
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pd/model/descriptor/dpa1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from deepmd.pd.utils.env import (
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pd.utils.update_sel import (
UpdateSel,
Expand Down Expand Up @@ -503,7 +503,7 @@ def serialize(self) -> dict:
"use_tebd_bias": self.use_tebd_bias,
"type_map": self.type_map,
# make deterministic
"precision": RESERVED_PRECISON_DICT[obj.prec],
"precision": RESERVED_PRECISION_DICT[obj.prec],
"embeddings": obj.filter_layers.serialize(),
"attention_layers": obj.dpa1_attention.serialize(),
"env_mat": DPEnvMat(obj.rcut, obj.rcut_smth).serialize(),
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pd/model/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from deepmd.pd.utils.env import (
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pd.utils.env_mat_stat import (
EnvMatStatSe,
Expand Down Expand Up @@ -334,7 +334,7 @@ def serialize(self) -> dict:
"set_davg_zero": obj.set_davg_zero,
"activation_function": obj.activation_function,
# make deterministic
"precision": RESERVED_PRECISON_DICT[obj.prec],
"precision": RESERVED_PRECISION_DICT[obj.prec],
"embeddings": obj.filter_layers.serialize(),
"env_mat": DPEnvMat(obj.rcut, obj.rcut_smth).serialize(),
"exclude_types": obj.exclude_types,
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pd/model/descriptor/se_t_tebd.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)
from deepmd.pd.utils.env import (
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pd.utils.env_mat_stat import (
EnvMatStatSe,
Expand Down Expand Up @@ -358,7 +358,7 @@ def serialize(self) -> dict:
"use_econf_tebd": self.use_econf_tebd,
"type_map": self.type_map,
# make deterministic
"precision": RESERVED_PRECISON_DICT[obj.prec],
"precision": RESERVED_PRECISION_DICT[obj.prec],
"embeddings": obj.filter_layers.serialize(),
"env_mat": DPEnvMat(obj.rcut, obj.rcut_smth).serialize(),
"type_embedding": self.type_embedding.embedding.serialize(),
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pd/model/model/make_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
GLOBAL_PD_ENER_FLOAT_PRECISION,
GLOBAL_PD_FLOAT_PRECISION,
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pd.utils.nlist import (
extend_input_and_build_neighbor_list,
Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__(
else:
self.atomic_model: T_AtomicModel = T_AtomicModel(*args, **kwargs)
self.precision_dict = PRECISION_DICT
self.reverse_precision_dict = RESERVED_PRECISON_DICT
self.reverse_precision_dict = RESERVED_PRECISION_DICT
self.global_pd_float_precision = GLOBAL_PD_FLOAT_PRECISION
self.global_pd_ener_float_precision = GLOBAL_PD_ENER_FLOAT_PRECISION

Expand Down
6 changes: 3 additions & 3 deletions deepmd/pd/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
PRECISION_DICT["default"] = GLOBAL_PD_FLOAT_PRECISION
assert VALID_PRECISION.issubset(PRECISION_DICT.keys())
# cannot automatically generated
RESERVED_PRECISON_DICT = {
RESERVED_PRECISION_DICT = {
paddle.float16: "float16",
paddle.float32: "float32",
paddle.float64: "float64",
Expand All @@ -64,7 +64,7 @@
paddle.bfloat16: "bfloat16",
paddle.bool: "bool",
}
assert set(PRECISION_DICT.values()) == set(RESERVED_PRECISON_DICT.keys())
assert set(PRECISION_DICT.values()) == set(RESERVED_PRECISION_DICT.keys())
DEFAULT_PRECISION = "float64"

# throw warnings if threads not set
Expand Down Expand Up @@ -163,7 +163,7 @@ def enable_prim(enable: bool = True):
"LOCAL_RANK",
"NUM_WORKERS",
"PRECISION_DICT",
"RESERVED_PRECISON_DICT",
"RESERVED_PRECISION_DICT",
"SAMPLER_RECORD",
"enable_prim",
]
8 changes: 4 additions & 4 deletions deepmd/pt/infer/deep_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from deepmd.pt.utils.env import (
DEVICE,
GLOBAL_PT_FLOAT_PRECISION,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pt.utils.utils import (
to_numpy_array,
Expand Down Expand Up @@ -406,7 +406,7 @@ def _eval_model(
request_defs: list[OutputVariableDef],
):
model = self.dp.to(DEVICE)
prec = NP_PRECISION_DICT[RESERVED_PRECISON_DICT[GLOBAL_PT_FLOAT_PRECISION]]
prec = NP_PRECISION_DICT[RESERVED_PRECISION_DICT[GLOBAL_PT_FLOAT_PRECISION]]

nframes = coords.shape[0]
if len(atom_types.shape) == 1:
Expand All @@ -421,7 +421,7 @@ def _eval_model(
device=DEVICE,
)
type_input = torch.tensor(
atom_types.astype(NP_PRECISION_DICT[RESERVED_PRECISON_DICT[torch.long]]),
atom_types.astype(NP_PRECISION_DICT[RESERVED_PRECISION_DICT[torch.long]]),
dtype=torch.long,
device=DEVICE,
)
Expand Down Expand Up @@ -553,7 +553,7 @@ def _eval_model_spin(
np.abs(shape),
np.nan,
dtype=NP_PRECISION_DICT[
RESERVED_PRECISON_DICT[GLOBAL_PT_FLOAT_PRECISION]
RESERVED_PRECISION_DICT[GLOBAL_PT_FLOAT_PRECISION]
],
)
) # this is kinda hacky
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/descriptor/dpa1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from deepmd.pt.utils.env import (
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pt.utils.tabulate import (
DPTabulate,
Expand Down Expand Up @@ -505,7 +505,7 @@ def serialize(self) -> dict:
"use_tebd_bias": self.use_tebd_bias,
"type_map": self.type_map,
# make deterministic
"precision": RESERVED_PRECISON_DICT[obj.prec],
"precision": RESERVED_PRECISION_DICT[obj.prec],
"embeddings": obj.filter_layers.serialize(),
"attention_layers": obj.dpa1_attention.serialize(),
"env_mat": DPEnvMat(obj.rcut, obj.rcut_smth).serialize(),
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from deepmd.pt.utils.env import (
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pt.utils.env_mat_stat import (
EnvMatStatSe,
Expand Down Expand Up @@ -379,7 +379,7 @@ def serialize(self) -> dict:
"set_davg_zero": obj.set_davg_zero,
"activation_function": obj.activation_function,
# make deterministic
"precision": RESERVED_PRECISON_DICT[obj.prec],
"precision": RESERVED_PRECISION_DICT[obj.prec],
"embeddings": obj.filter_layers.serialize(),
"env_mat": DPEnvMat(obj.rcut, obj.rcut_smth).serialize(),
"exclude_types": obj.exclude_types,
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/descriptor/se_atten_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
env,
)
from deepmd.pt.utils.env import (
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.utils.version import (
check_version_compatibility,
Expand Down Expand Up @@ -223,7 +223,7 @@ def serialize(self) -> dict:
"use_tebd_bias": self.use_tebd_bias,
"type_map": self.type_map,
# make deterministic
"precision": RESERVED_PRECISON_DICT[obj.prec],
"precision": RESERVED_PRECISION_DICT[obj.prec],
"embeddings": obj.filter_layers.serialize(),
"embeddings_strip": obj.filter_layers_strip.serialize(),
"attention_layers": obj.dpa1_attention.serialize(),
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/descriptor/se_r.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
from deepmd.pt.utils.env import (
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pt.utils.env_mat_stat import (
EnvMatStatSe,
Expand Down Expand Up @@ -549,7 +549,7 @@ def serialize(self) -> dict:
"set_davg_zero": self.set_davg_zero,
"activation_function": self.activation_function,
# make deterministic
"precision": RESERVED_PRECISON_DICT[self.prec],
"precision": RESERVED_PRECISION_DICT[self.prec],
"embeddings": self.filter_layers.serialize(),
"env_mat": DPEnvMat(self.rcut, self.rcut_smth).serialize(),
"exclude_types": self.exclude_types,
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/descriptor/se_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from deepmd.pt.utils.env import (
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pt.utils.env_mat_stat import (
EnvMatStatSe,
Expand Down Expand Up @@ -413,7 +413,7 @@ def serialize(self) -> dict:
"resnet_dt": obj.resnet_dt,
"set_davg_zero": obj.set_davg_zero,
"activation_function": obj.activation_function,
"precision": RESERVED_PRECISON_DICT[obj.prec],
"precision": RESERVED_PRECISION_DICT[obj.prec],
"embeddings": obj.filter_layers.serialize(),
"env_mat": DPEnvMat(obj.rcut, obj.rcut_smth).serialize(),
"exclude_types": obj.exclude_types,
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/descriptor/se_t_tebd.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)
from deepmd.pt.utils.env import (
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pt.utils.env_mat_stat import (
EnvMatStatSe,
Expand Down Expand Up @@ -354,7 +354,7 @@ def serialize(self) -> dict:
"use_econf_tebd": self.use_econf_tebd,
"type_map": self.type_map,
# make deterministic
"precision": RESERVED_PRECISON_DICT[obj.prec],
"precision": RESERVED_PRECISION_DICT[obj.prec],
"embeddings": obj.filter_layers.serialize(),
"env_mat": DPEnvMat(obj.rcut, obj.rcut_smth).serialize(),
"type_embedding": self.type_embedding.embedding.serialize(),
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/model/make_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
GLOBAL_PT_ENER_FLOAT_PRECISION,
GLOBAL_PT_FLOAT_PRECISION,
PRECISION_DICT,
RESERVED_PRECISON_DICT,
RESERVED_PRECISION_DICT,
)
from deepmd.pt.utils.nlist import (
extend_input_and_build_neighbor_list,
Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__(
else:
self.atomic_model: T_AtomicModel = T_AtomicModel(*args, **kwargs)
self.precision_dict = PRECISION_DICT
self.reverse_precision_dict = RESERVED_PRECISON_DICT
self.reverse_precision_dict = RESERVED_PRECISION_DICT
self.global_pt_float_precision = GLOBAL_PT_FLOAT_PRECISION
self.global_pt_ener_float_precision = GLOBAL_PT_ENER_FLOAT_PRECISION

Expand Down
6 changes: 3 additions & 3 deletions deepmd/pt/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
PRECISION_DICT["default"] = GLOBAL_PT_FLOAT_PRECISION
assert VALID_PRECISION.issubset(PRECISION_DICT.keys())
# cannot automatically generated
RESERVED_PRECISON_DICT = {
RESERVED_PRECISION_DICT = {
torch.float16: "float16",
torch.float32: "float32",
torch.float64: "float64",
Expand All @@ -63,7 +63,7 @@
torch.bfloat16: "bfloat16",
torch.bool: "bool",
}
assert set(PRECISION_DICT.values()) == set(RESERVED_PRECISON_DICT.keys())
assert set(PRECISION_DICT.values()) == set(RESERVED_PRECISION_DICT.keys())
DEFAULT_PRECISION = "float64"

# throw warnings if threads not set
Expand All @@ -87,6 +87,6 @@
"LOCAL_RANK",
"NUM_WORKERS",
"PRECISION_DICT",
"RESERVED_PRECISON_DICT",
"RESERVED_PRECISION_DICT",
"SAMPLER_RECORD",
]

0 comments on commit 5788f79

Please sign in to comment.