Skip to content

Commit 0186465

Browse files
committed
fix: only create graph for valid
1 parent 9e8a1ca commit 0186465

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

deepmd/pt/model/model/make_hessian_model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ def forward_common(
120120
for nloc in range(force.shape[1]):
121121
for i in range(3):
122122
# TODO: possibility of parallelization?
123+
# use an eye matrix for grad_output and set is_grad_batched=True
123124
hess[nf, nloc, i] = torch.autograd.grad(
124125
outputs=force[nf, nloc, i],
125126
inputs=coord,
126-
create_graph=True,
127+
create_graph=self.training,
128+
retain_graph=True,
127129
)[0][nf] # only [nf] contains values, other chunks are zero
128130

129131
hess = hess.view(

0 commit comments

Comments
 (0)