TensorDictBase.make_memmap_from_storage#
- TensorDictBase.make_memmap_from_storage(key: NestedKey, storage: UntypedStorage, shape: Size | Tensor, *, dtype: dtype | None = None, robust_key: bool | None = True) MemoryMappedTensor#
Creates an empty memory-mapped tensor given a storage, 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_().Note
If the storage has a filename associated, it must match the new filename for the file. If it has not a filename associated but the tensordict has an associated path, this will result in an exception.
- Parameters:
key (NestedKey) – the key of the new entry to write. If the key is already present in the tensordict, an exception is raised.
storage (UntypedStorage) – the storage to use for the new MemoryMappedTensor. Must be a physical memory storage.
shape (Size or equivalent, torch.Tensor for nested tensors) – the shape of the tensor to write.
- Keyword Arguments:
- 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.