Rate this Page
★ ★ ★ ★ ★

TensorDictBase.is_locked#

property TensorDictBase.is_locked: bool#

True if the tensordict is locked.

A locked tensordict raises RuntimeError on any operation that adds, removes or renames an entry, or that replaces a leaf with a new tensor. Writes into the existing leaves still work. See lock_().

Setting td.is_locked = True calls lock_(), and td.is_locked = False calls unlock_().

Examples

>>> from tensordict import TensorDict
>>> td = TensorDict({"a": 0})
>>> td.is_locked
False
>>> td.is_locked = True
>>> td.is_locked
True

Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.

Tutorials that use is_locked#

Devices and memory-mapped tensors

Devices and memory-mapped tensors