Rate this Page
★ ★ ★ ★ ★

from_zarr#

tensordict.from_zarr(zarr_file, *, mode: str = 'r', auto_batch_size: bool = False, batch_dims: int | None = None, batch_size: Size | None = None, non_tensor_as_stack: bool = False, allow_pickle: bool | None = None) → TensorDictBase#

Opens a zarr store as a PersistentTensorDict.

Requires zarr>=3.1.1. See TensorDictBase.from_zarr.

Parameters:

zarr_file (str, path or zarr store) – the path to the zarr store (a directory), or a zarr.abc.store.Store instance.

Keyword Arguments:
  • mode (str, optional) – how the store is opened: "r" (read only), "r+" (read and write), and so on. Defaults to "r".

  • auto_batch_size (bool, optional) – if True, sets the batch size to the largest leading shape that all the entries share. Exclusive with batch_size. Defaults to False.

  • batch_dims (int, optional) – with auto_batch_size, the maximum number of batch dimensions. Ignored without auto_batch_size, with a FutureWarning when it would change the result. Starting with TensorDict 0.17, the default will change to turning on auto_batch_size when batch_dims is given, as from_dict does. Defaults to None.

  • batch_size (Size or list of int, optional) – the batch size of the result: the leading dimensions that all its entries share. Exclusive with auto_batch_size. Defaults to None, which reads the batch size that to_zarr() stored, or computes it for a store written by another tool.

  • non_tensor_as_stack (bool, optional) – if True, a non-tensor array that tensordict did not write reads as a NonTensorStack of its rows when its leading dimensions equal the batch size. Defaults to False.

  • allow_pickle (bool, optional) – whether to decode pickled non-tensor values. False rejects them. True permits them, only for data you trust. None permits them with a FutureWarning. Starting with TensorDict 0.17, the default will change to allow_pickle=False. Defaults to None.

Returns:

A PersistentTensorDict backed by the store.