Rate this Page
★ ★ ★ ★ ★

from_h5#

tensordict.from_h5(h5_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) → TensorDictBase#

Opens an HDF5 file as a PersistentTensorDict.

See TensorDictBase.from_h5.

Parameters:

h5_file (str or path) – the path to the HDF5 file.

Keyword Arguments:
  • mode (str, optional) – how the file is opened, as in h5py.File: "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 gives each nested tensordict the largest batch size that its entries share.

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

Returns:

A PersistentTensorDict backed by the file.