TensorDictBase.unlock#
- TensorDictBase.unlock_() Self#
Unlocks the tensordict and its sub-tensordicts, and returns it.
After this call, entries can be added, removed and renamed again. See
lock_()for what a lock blocks.Can be used as a context manager: the tensordict is locked again when the
withblock exits, also if the block raises an exception.- Raises:
RuntimeError – if this tensordict, or one of its sub-tensordicts, is also an entry of another locked tensordict. Unlock that parent first. The tensordict stays locked.
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.zeros(3), batch_size=[3], lock=True) >>> with td.unlock_(): ... td["b"] = torch.ones(3) >>> td.is_locked True >>> sorted(td.keys()) ['a', 'b']
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.