Open Juenjie opened 3 months ago
you may need to import deepmd defined ops. https://github.com/deepmodeling/deepmd-kit/blob/f8a0b3128e51ee523515cce26e520dde09a973f9/deepmd/train/trainer.py#L23-L24
Thanks for the quick reply.
The "deepmd.op" is indeed imported:
I followed the CH4 case, with the command 'CUDA_VISIBLE_DEVICES=0 dp train --restart model.ckpt input.json'. The code runs completely fine without the modifications that I made (see modifications below):
I solved the issue with the updated version of 3.0.0a using Pytorch.
Two lines are modified:
`if batch_data[key] is not None:
if key == 'coord':
batch_data[key] = batch_data[key].to(DEVICE).requires_grad_(True)
else:
batch_data[key] = batch_data[key].to(DEVICE)`
and
coord_grad = input_dict['coord'].grad
This issue is similar to #2594. To use tf.gradients
, all OPs in the chain should register a gradient method, as indicated by the error message.
ProdEnvMatA
doesn't have such a method. Contribution is welcome.
Bug summary
I modified the 'deepmd/train/trainer.py' file, and added some codes for gradient:
Then I run
CUDA_VISIBLE_DEVICES=0 dp train --restart model.ckpt input.json
for the simple CH4 case, it outputs an error: No gradient defined for operation'ProdEnvMatA'DeePMD-kit Version
2.2.10
Backend and its version
TensorFlow v2.15.0
How did you download the software?
pip
Input Files, Running Commands, Error Log, etc.
The complete code for trainer.py is:
and the error code: