Skip to content

Commit

Permalink
remove the dependency on inputs from inputs_zero
Browse files Browse the repository at this point in the history
When profiling on multiple CPU threads, I notice that `inputs_zero` always runs after descriptor is computed. However, Some threads have nothing to do during ProdEnvMatA.

(cherry picked from commit e704b4a)
  • Loading branch information
njzjz committed Jan 13, 2022
1 parent 0d30288 commit 85e7acd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions deepmd/fit/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def _build_lower(
def build (self,
inputs : tf.Tensor,
natoms : tf.Tensor,
nframes : tf.Tensor,
input_dict : dict = {},
reuse : bool = None,
suffix : str = '',
Expand All @@ -352,6 +353,8 @@ def build (self,
natoms[0]: number of local atoms
natoms[1]: total number of atoms held by this processor
natoms[i]: 2 <= i < Ntypes+2, number of type i atoms
nframes : tf.Tensor
The number of frames
reuse
The weights in the networks should be reused when get the variable.
suffix
Expand Down Expand Up @@ -398,10 +401,11 @@ def build (self,
trainable = False,
initializer = tf.constant_initializer(self.aparam_inv_std))

inputs = tf.reshape(inputs, [-1, self.dim_descrpt * natoms[0]])
inputs = tf.reshape(inputs, [nframes, self.dim_descrpt * natoms[0]])
if len(self.atom_ener):
# only for atom_ener
inputs_zero = tf.zeros_like(inputs, dtype=self.fitting_precision)
# like inputs, but we don't want to add a dependency on inputs
inputs_zero = tf.zeros((nframes, self.dim_descrpt * natoms[0]), dtype=self.fitting_precision)


if bias_atom_e is not None :
Expand Down
2 changes: 2 additions & 0 deletions deepmd/model/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def build (self,

coord = tf.reshape (coord_, [-1, natoms[1] * 3])
atype = tf.reshape (atype_, [-1, natoms[1]])
nframes = tf.shape(coord)[0]

# type embedding if any
if self.typeebd is not None:
Expand Down Expand Up @@ -187,6 +188,7 @@ def build (self,

atom_ener = self.fitting.build (dout,
natoms,
nframes,
input_dict,
reuse = reuse,
suffix = suffix)
Expand Down

0 comments on commit 85e7acd

Please sign in to comment.