remove_gradients#
- metatensor.remove_gradients(tensor: TensorMap, remove: List[str] | None = None) TensorMap [source]#
Remove some or all of the gradients from a
TensorMap
.This function is related but different to
metatensor.detach()
. This function removes the explicit forward mode gradients stored in the blocks, whilemetatensor.detach()
separate the values (as well as any potential gradients) from the underlying computational graph use by PyTorch to run backward differentiation.- Parameters:
- Returns:
A new
TensorMap
without the gradients inremove
.- Return type:
- metatensor.remove_gradients_block(block: TensorBlock, remove: List[str] | None = None) TensorBlock [source]#
Remove some or all of the gradients from a
TensorBlock
.This function is related but different to
metatensor.detach_block()
. This function removes the explicit forward mode gradients stored in theblock
, whilemetatensor.detach_block()
separate the values (as well as any potential gradients) from the underlying computational graph use by PyTorch to run backward differentiation.- Parameters:
block (TensorBlock) –
TensorBlock
with gradients to be removedremove (List[str] | None) – which gradients should be excluded from the new block. If this is set to
None
(this is the default), all the gradients will be removed.
- Returns:
A new
TensorBlock
without the gradients inremove
.- Return type: