requires_grad

metatensor.requires_grad(tensor: TensorMap, requires_grad: bool = True) TensorMap[source]

Set requires_grad on all arrays (blocks and gradients of blocks) in this tensor to the provided value.

This is mainly intended for torch arrays, and will warn if trying to set requires_grad=True with numpy arrays.

Parameters:
Return type:

TensorMap

metatensor.requires_grad_block(block: TensorBlock, requires_grad: bool = True) TensorBlock[source]

Set requires_grad on the values and all gradients in this block to the provided value.

This is mainly intended for torch arrays, and will warn if trying to set requires_grad=True with numpy arrays.

Parameters:
Return type:

TensorBlock