Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deepmd/jax/atomic_model/linear_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __setattr__(self, name: str, value: Any) -> None:
if name == "zbl_weight":
# discard since it's only used in tests
# to fix flax.errors.TraceContextError: Cannot mutate 'FlaxModule' from different trace level
return
return None
return super().__setattr__(name, value)

def forward_common_atomic(
Expand Down
12 changes: 6 additions & 6 deletions deepmd/kernels/triton/sezm/so2_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def _to_local_fwd_kernel(
coeff_rows = tl.load(idx_ptr + row, mask=row_mask, other=0).to(tl.int64)

acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
for k0 in range(0, tl.cdiv(dim_full, BLOCK_K)):
for k0 in range(tl.cdiv(dim_full, BLOCK_K)):
kk = k0 * BLOCK_K + tl.arange(0, BLOCK_K) # over D
k_mask = kk < dim_full
w_tile = tl.load(
Expand Down Expand Up @@ -333,7 +333,7 @@ def _to_local_bwd_dx_kernel(
src_idx = tl.load(src_ptr + edge).to(tl.int64)

acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
for k0 in range(0, tl.cdiv(reduced_dim, BLOCK_K)):
for k0 in range(tl.cdiv(reduced_dim, BLOCK_K)):
mm = k0 * BLOCK_K + tl.arange(0, BLOCK_K) # over Dm
m_mask = mm < reduced_dim
coeff = tl.load(idx_ptr + mm, mask=m_mask, other=0).to(tl.int64)
Expand Down Expand Up @@ -395,7 +395,7 @@ def _to_local_bwd_dw_kernel(
src_idx = tl.load(src_ptr + edge).to(tl.int64)

acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
for k0 in range(0, tl.cdiv(channels, BLOCK_K)):
for k0 in range(tl.cdiv(channels, BLOCK_K)):
cc = k0 * BLOCK_K + tl.arange(0, BLOCK_K) # over C
c_mask = cc < channels
go_tile = tl.load(
Expand Down Expand Up @@ -454,7 +454,7 @@ def _back_fwd_kernel(
chan_mask = chan < channels

acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
for k0 in range(0, tl.cdiv(dim_full, BLOCK_K)):
for k0 in range(tl.cdiv(dim_full, BLOCK_K)):
kk = k0 * BLOCK_K + tl.arange(0, BLOCK_K) # over D (contraction)
k_mask = kk < dim_full
inv_k = tl.load(inv_ptr + kk, mask=k_mask, other=-1).to(tl.int64)
Expand Down Expand Up @@ -517,7 +517,7 @@ def _back_bwd_dx_kernel(
keep = inv_k >= 0

acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
for k0 in range(0, tl.cdiv(dim_full, BLOCK_K)):
for k0 in range(tl.cdiv(dim_full, BLOCK_K)):
dd = k0 * BLOCK_K + tl.arange(0, BLOCK_K) # over D (contraction)
d_mask = dd < dim_full
w_tile = tl.load(
Expand Down Expand Up @@ -578,7 +578,7 @@ def _back_bwd_dw_kernel(
keep = inv_k >= 0

acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
for k0 in range(0, tl.cdiv(channels, BLOCK_K)):
for k0 in range(tl.cdiv(channels, BLOCK_K)):
cc = k0 * BLOCK_K + tl.arange(0, BLOCK_K) # over C (contraction)
c_mask = cc < channels
go_tile = tl.load(
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pd/entrypoints/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def prepare_trainer_input_single(
seed: int | None = None,
) -> tuple[DpLoaderSet, DpLoaderSet | None, DPPath | None]:
training_dataset_params = data_dict_single["training_data"]
validation_dataset_params = data_dict_single.get("validation_data", None)
validation_dataset_params = data_dict_single.get("validation_data")
validation_systems = (
validation_dataset_params["systems"] if validation_dataset_params else None
)
Expand All @@ -115,7 +115,7 @@ def prepare_trainer_input_single(
validation_systems = process_systems(validation_systems, val_patterns)

# stat files
stat_file_path_single = data_dict_single.get("stat_file", None)
stat_file_path_single = data_dict_single.get("stat_file")
if rank != 0:
stat_file_path_single = None
elif stat_file_path_single is not None:
Expand Down
1 change: 0 additions & 1 deletion deepmd/pd/train/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def state_dict(self) -> dict[str, Any]:
def set_extra_state(self, extra_state: dict[str, Any]) -> None:
self.model_params = extra_state["model_params"]
self.train_infos = extra_state["train_infos"]
return None

def get_extra_state(self) -> dict:
extra_state = {
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pd/utils/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def __init__(
Thread.__init__(self)
self._queue = queue
self._source = source # Main DL iterator
self._max_len = max_len #
self._max_len = max_len

def run(self) -> None:
for item in self._source:
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pd/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def to_numpy_array(
# Create a reverse mapping of PD_PRECISION_DICT
reverse_precision_dict = {v: k for k, v in PD_PRECISION_DICT.items()}
# Use the reverse mapping to find keys with the desired value
prec = reverse_precision_dict.get(xx.dtype, None)
prec = reverse_precision_dict.get(xx.dtype)
prec = NP_PRECISION_DICT.get(prec, np.float64)
if prec is None:
raise ValueError(f"unknown precision {xx.dtype}")
Expand Down Expand Up @@ -293,7 +293,7 @@ def to_paddle_tensor(
# Create a reverse mapping of NP_PRECISION_DICT
reverse_precision_dict = {v: k for k, v in NP_PRECISION_DICT.items()}
# Use the reverse mapping to find keys with the desired value
prec = reverse_precision_dict.get(xx.dtype.type, None)
prec = reverse_precision_dict.get(xx.dtype.type)
prec = PD_PRECISION_DICT.get(prec, None)
if prec is None:
raise ValueError(f"unknown precision {xx.dtype}")
Expand Down
8 changes: 4 additions & 4 deletions deepmd/pt/entrypoints/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ def prepare_trainer_input_single(
]:
# get data modifier
modifier = None
modifier_params = model_params_single.get("modifier", None)
modifier_params = model_params_single.get("modifier")
if modifier_params is not None:
modifier = get_data_modifier(modifier_params).to(DEVICE)

training_dataset_params = data_dict_single["training_data"]
validation_dataset_params = data_dict_single.get("validation_data", None)
validation_dataset_params = data_dict_single.get("validation_data")
validation_systems = (
validation_dataset_params["systems"] if validation_dataset_params else None
)
training_systems = training_dataset_params["systems"]

# stat files
stat_file_path_single = data_dict_single.get("stat_file", None)
stat_file_path_single = data_dict_single.get("stat_file")
if rank != 0:
stat_file_path_single = None
elif stat_file_path_single is not None:
Expand All @@ -185,7 +185,7 @@ def _make_dp_loader_set(
dataset_params: dict[str, Any],
) -> DpLoaderSet:
"""Create a DpLoaderSet from systems with pattern expansion."""
patterns = dataset_params.get("rglob_patterns", None)
patterns = dataset_params.get("rglob_patterns")
systems = process_systems(systems, patterns=patterns)
return DpLoaderSet(
systems,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/optimizer/hybrid_muon.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _mmt_kernel(
b_ptrs = x + (offs_xn[:, None] * stride_xm + offs_k[None, :] * stride_xk)

accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_M), dtype=tl.float32)
for k in range(0, tl.cdiv(K, BLOCK_SIZE_K)):
for k in range(tl.cdiv(K, BLOCK_SIZE_K)):
a = tl.load(a_ptrs, mask=offs_k[None, :] < K - k * BLOCK_SIZE_K, other=0.0)
b = tl.load(b_ptrs, mask=offs_k[None, :] < K - k * BLOCK_SIZE_K, other=0.0)
accumulator = tl.dot(a, tl.permute(b, (1, 0)), accumulator)
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/train/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def get_dataloader_and_iter_lmdb(
rank=self.rank,
world_size=self.world_size,
shuffle=True,
seed=_training_params.get("seed", None),
seed=_training_params.get("seed"),
block_targets=_block_targets,
)
else:
Expand Down
1 change: 0 additions & 1 deletion deepmd/pt/train/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def _forward_without_loss(
def set_extra_state(self, state: dict) -> None:
self.model_params = state["model_params"]
self.train_infos = state["train_infos"]
return None

def get_extra_state(self) -> dict:
state = {
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def to_numpy_array(
# Create a reverse mapping of PT_PRECISION_DICT
reverse_precision_dict = {v: k for k, v in PT_PRECISION_DICT.items()}
# Use the reverse mapping to find keys with the desired value
prec = reverse_precision_dict.get(xx.dtype, None)
prec = reverse_precision_dict.get(xx.dtype)
prec = NP_PRECISION_DICT.get(prec, None)
if prec is None:
raise ValueError(f"unknown precision {xx.dtype}")
Expand Down Expand Up @@ -277,7 +277,7 @@ def to_torch_tensor(
# Create a reverse mapping of NP_PRECISION_DICT
reverse_precision_dict = {v: k for k, v in NP_PRECISION_DICT.items()}
# Use the reverse mapping to find keys with the desired value
prec = reverse_precision_dict.get(xx.dtype.type, None)
prec = reverse_precision_dict.get(xx.dtype.type)
prec = PT_PRECISION_DICT.get(prec, None)
if prec is None:
raise ValueError(f"unknown precision {xx.dtype}")
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt_expt/entrypoints/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ def _build_data_system(
)
systems = process_systems(
systems_raw,
patterns=dataset_params.get("rglob_patterns", None),
patterns=dataset_params.get("rglob_patterns"),
)
return DeepmdDataSystem(
systems=systems,
batch_size=dataset_params["batch_size"],
test_size=1,
type_map=type_map,
trn_all_set=True,
sys_probs=dataset_params.get("sys_probs", None),
sys_probs=dataset_params.get("sys_probs"),
auto_prob_style=dataset_params.get("auto_prob", "prob_sys_size"),
)

Expand Down
10 changes: 5 additions & 5 deletions deepmd/pt_expt/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def __setattr__(self, name: str, value: Any) -> None:
if val is None:
if name in self._parameters:
self._parameters[name] = None
return
return None
if name in self._buffers:
self._buffers[name] = None
return
return None
return super().__setattr__(name, None)
if getattr(self, "trainable", False):
param = (
Expand All @@ -107,14 +107,14 @@ def __setattr__(self, name: str, value: Any) -> None:
)
if name in self._parameters:
self._parameters[name] = param
return
return None
return super().__setattr__(name, param)
if name in self._buffers:
self._buffers[name] = val
return
return None
# Register on first assignment so tensors are in state_dict and moved by .to().
self.register_buffer(name, val)
return
return None
return super().__setattr__(name, value)

def call(self, x: torch.Tensor) -> torch.Tensor:
Expand Down
2 changes: 1 addition & 1 deletion deepmd/tf/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def _pass_filter(
trainable: bool = True,
) -> tuple[tf.Tensor, tf.Tensor]:
if input_dict is not None:
type_embedding = input_dict.get("type_embedding", None)
type_embedding = input_dict.get("type_embedding")
if type_embedding is not None:
self.use_tebd = True
else:
Expand Down
7 changes: 3 additions & 4 deletions deepmd/tf/descriptor/se_atten.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,9 @@ def _pass_filter(
trainable: bool = True,
) -> tuple[tf.Tensor, None]:
assert (
input_dict is not None
and input_dict.get("type_embedding", None) is not None
input_dict is not None and input_dict.get("type_embedding") is not None
), "se_atten descriptor must use type_embedding"
type_embedding = input_dict.get("type_embedding", None)
type_embedding = input_dict.get("type_embedding")
inputs = tf.reshape(inputs, [-1, natoms[0], self.ndescrpt])
output = []
output_qmat = []
Expand Down Expand Up @@ -1961,7 +1960,7 @@ def serialize(self, suffix: str = "") -> dict:
raise RuntimeError(
"The implementation for smooth_type_embedding is inconsistent with other backends"
)
# todo support serialization when tebd_input_mode=='strip' and type_one_side is True
# TODO support serialization when tebd_input_mode=='strip' and type_one_side is True
if self.stripped_type_embedding and self.type_one_side:
raise NotImplementedError(
"serialization is unsupported when tebd_input_mode=='strip' and type_one_side is True"
Expand Down
2 changes: 1 addition & 1 deletion deepmd/tf/descriptor/se_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ def clear_ij(type_i: int, type_j: int) -> None:
clear_ij(i, j)
clear_ij(j, i)
for i in range(ntypes):
for j in range(0, i):
for j in range(i):
clear_ij(i, j)

if suffix != "":
Expand Down
6 changes: 3 additions & 3 deletions deepmd/tf/fit/dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _build_lower(
rot_mat_i = tf.slice(rot_mat, [0, start_index, 0], [-1, natoms, -1])
rot_mat_i = tf.reshape(rot_mat_i, [-1, self.dim_rot_mat_1, 3])
layer = inputs_i
for ii in range(0, len(self.n_neuron)):
for ii in range(len(self.n_neuron)):
if ii >= 1 and self.n_neuron[ii] == self.n_neuron[ii - 1]:
layer += one_layer(
layer,
Expand Down Expand Up @@ -282,8 +282,8 @@ def build(
"""
if input_dict is None:
input_dict = {}
type_embedding = input_dict.get("type_embedding", None)
atype = input_dict.get("atype", None)
type_embedding = input_dict.get("type_embedding")
atype = input_dict.get("atype")
nframes = input_dict.get("nframes")
start_index = 0
inputs = tf.reshape(input_d, [-1, natoms[0], self.dim_descrpt])
Expand Down
6 changes: 3 additions & 3 deletions deepmd/tf/fit/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def _build_lower(
one_layer = one_layer_nvnmd
else:
one_layer = one_layer_deepmd
for ii in range(0, len(self.n_neuron)):
for ii in range(len(self.n_neuron)):
if self.layer_name is not None and self.layer_name[ii] is not None:
layer_suffix = "share_" + self.layer_name[ii] + type_suffix
layer_reuse = tf.AUTO_REUSE
Expand Down Expand Up @@ -452,8 +452,8 @@ def build(
if input_dict is None:
input_dict = {}
bias_dos = self.bias_dos
type_embedding = input_dict.get("type_embedding", None)
atype = input_dict.get("atype", None)
type_embedding = input_dict.get("type_embedding")
atype = input_dict.get("atype")
if self.numb_fparam > 0:
if self.fparam_avg is None:
self.fparam_avg = 0.0
Expand Down
6 changes: 3 additions & 3 deletions deepmd/tf/fit/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def _build_lower(
one_layer = one_layer_nvnmd
else:
one_layer = one_layer_deepmd
for ii in range(0, len(self.n_neuron)):
for ii in range(len(self.n_neuron)):
if self.layer_name is not None and self.layer_name[ii] is not None:
layer_suffix = "share_" + self.layer_name[ii] + type_suffix
layer_reuse = tf.AUTO_REUSE
Expand Down Expand Up @@ -519,8 +519,8 @@ def build(
if input_dict is None:
input_dict = {}
bias_atom_e = self.bias_atom_e
type_embedding = input_dict.get("type_embedding", None)
atype = input_dict.get("atype", None)
type_embedding = input_dict.get("type_embedding")
atype = input_dict.get("atype")
if self.numb_fparam > 0:
if self.fparam_avg is None:
self.fparam_avg = 0.0
Expand Down
6 changes: 3 additions & 3 deletions deepmd/tf/fit/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _build_lower(
)
rot_mat_i = tf.reshape(rot_mat_i, [-1, self.dim_rot_mat_1, 3])
layer = inputs_i
for ii in range(0, len(self.n_neuron)):
for ii in range(len(self.n_neuron)):
if ii >= 1 and self.n_neuron[ii] == self.n_neuron[ii - 1]:
layer += one_layer(
layer,
Expand Down Expand Up @@ -470,8 +470,8 @@ def build(
"""
if input_dict is None:
input_dict = {}
type_embedding = input_dict.get("type_embedding", None)
atype = input_dict.get("atype", None)
type_embedding = input_dict.get("type_embedding")
atype = input_dict.get("atype")
nframes = input_dict.get("nframes")
start_index = 0

Expand Down
2 changes: 1 addition & 1 deletion deepmd/tf/loss/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TensorLoss(Loss):
"""Loss function for tensorial properties."""

def __init__(self, jdata: dict | None, **kwarg: Any) -> None:
model = kwarg.get("model", None)
model = kwarg.get("model")
if model is not None:
self.type_sel = model.get_sel_type()
else:
Expand Down
Loading
Loading