TensorDictBase.make_memmap_from_tensor#
- TensorDictBase.make_memmap_from_tensor(key: NestedKey, tensor: Tensor, *, copy_data: bool = True, robust_key: bool | None = True) MemoryMappedTensor#
Creates an empty memory-mapped tensor given a tensor.
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_().This method always copies the storage content if
copy_dataisTrue(i.e., the storage is not shared).- Parameters:
- Keyword Arguments:
copy_data (bool, optionaL) – if
False, the new tensor will share the metadata of the input such as shape and dtype, but the content will be empty. Defaults toTrue.robust_key (bool, optional) – if
True(default), uses robust key encoding that safely handles keys with path separators and special characters. IfFalse, uses legacy behavior (keys used as-is). IfNone, uses the default robust behavior.
- Returns:
A new memory mapped tensor with the given storage.
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.