unpack_memmap#
- tensordict.unpack_memmap(archive_path: str | Path, prefix: str | Path) Path#
Extracts a memory-mapped tensordict archive into a directory.
The inverse of
pack_memmap(), and the same asunzip: the directory has one file per leaf, whichload_memmap()reads. Existing files inprefixare overwritten.- Parameters:
archive_path (str or Path) – an archive written by
pack_memmap()or bysave().prefix (str or Path) – the directory to extract into. It is created if it does not exist.
- Returns:
The path of the directory, as a
Path.- Raises:
ValueError – if
archive_pathis not an archive (seeis_memmap_archive()).
Examples
>>> import tempfile >>> from pathlib import Path >>> import torch >>> from tensordict import TensorDict, unpack_memmap >>> td = TensorDict(a=torch.zeros(3)) >>> with tempfile.TemporaryDirectory() as path: ... _ = td.save(Path(path) / "td.tdz") ... directory = unpack_memmap(Path(path) / "td.tdz", Path(path) / "td") ... print(sorted(p.name for p in directory.iterdir())) ['a.memmap', 'meta.json']