Rate this Page
★ ★ ★ ★ ★

TensorDictBase.make_memmap#

TensorDictBase.make_memmap(key: NestedKey, shape: Size | Tensor, *, dtype: dtype | None = None, robust_key: bool | None = True) → MemoryMappedTensor#

Creates an empty memory-mapped tensor given a shape and possibly a dtype.

Warning

This method is not lock-safe by design. A memory-mapped TensorDict instance present on multiple nodes will need to be updated using the method memmap_refresh_().

Writing an existing entry will result in an error.

Parameters:
  • key (NestedKey) – the key of the new entry to write. If the key is already present in the tensordict, an exception is raised.

  • shape (Size or equivalent, torch.Tensor for nested tensors) – the shape of the tensor to write.

Keyword Arguments:
  • dtype (dtype, optional) – the dtype of the new tensor.

  • robust_key (bool, optional) – if True (default), uses robust key encoding that safely handles keys with path separators and special characters. If False, uses legacy behavior (keys used as-is). If None, uses the default robust behavior.

Returns:

A new memory mapped tensor.

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