Closed bananenpampe closed 7 months ago
You need to compute explicit gradients in calculator.compute(system)
, i.e. replace the call by calculator.compute(system, gradients=["positions"])
Thank you! Does this result in an increased memory consumption of the feats, after potential densification?
It should not, especially if you remove the gradient blocks with
rascaline.torch.register_autograd(system, feats)
feats = metatensor.remove_gradients(feats)
If you don't remove the gradients, it might increase memory.
okay, but will it be possible to train/evaluate a model using double backprop (I am thinking about forces here) using these lines ?:
rascaline.torch.register_autograd(system, feats)
feats = metatensor.remove_gradients(feats)
loss(target, model(feats)).backward()
remove_gradients
removes the explicit, forward mode gradient stored inside TensorBlock. detach
is the function that would break the computational graph. So yes, this should be fine!
okay, awesome, thank you very much
closing, but I should add some documentation
@E-Rum
Hello,
I am receiving this error when using the register autograd function:
ValueError: expected the precomputed TensorMap to contain gradients with respect to 'positions' since one of the system ``requires_grad`` for its positions
I was hoping that the register autograd function could actually be used to register precomputed features using rascaline.torch after having called
.backward(retain_graph=False)
which detachesfeats
from the computational graph thatsystem.positions
are part of.This is the minimal example: