TensorDictBase.memmap_refresh#
- TensorDictBase.memmap_refresh_(*, allow_pickle: bool | None = None)#
Reloads the tensordict from its
saved_path, and returnsself.Use it when another process has changed the files: added or removed entries, or written non-tensor data. It calls
load_memmap_()onsaved_path, then memory-maps the tensordict there again.- Keyword Arguments:
allow_pickle (bool, optional) – whether non-tensor data saved with
picklemay be loaded. Seeload_memmap(). Defaults toNone.- Raises:
RuntimeError – if the tensordict is not memory-mapped in a directory, for example a tensordict returned by
load_memmap()(for whichis_memmap()returnsFalse) or bymemmap()without a prefix.
Examples
>>> import tempfile >>> import torch >>> from tensordict import TensorDict >>> with tempfile.TemporaryDirectory() as path: ... td = TensorDict(a=torch.zeros(3)).memmap(path) ... _ = TensorDict(a=torch.ones(3), b=torch.ones(3)).memmap(path) ... _ = td.memmap_refresh_() ... print(sorted(td.keys()), td["a"]) ['a', 'b'] MemoryMappedTensor([1., 1., 1.])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.