set_printoptions#
- class tensordict.set_printoptions(*, verbose: bool = True, **kwargs)#
Sets the options that control what the repr of a tensordict shows.
Use it as a context manager or a decorator to change the options for a block of code; the previous options come back at the end of the block. Call
set_printoptions(...).set()to change them for the rest of the program. The options that are not passed keep their current value. Printing and display describes every option with examples, andget_printoptions()returns the current values.- Keyword Arguments:
verbose (bool, optional) – if
False, hides the device, dtype andis_sharedattributes, unless a keyword argument sets them. Defaults toTrue.**kwargs – the options to set:
show_batch_size,show_device,show_is_shared,show_shape,show_field_device,show_dtype,show_field_is_shared,show_grad,show_is_contiguous,show_is_view,show_storage_size,plain,sort_keys,compactandhtml.compact=True, the default, prints each entry as its dtype and its feature dimensions (f32[3]);compact=Falseprints each entry as aTensor(...)line with its full shape, device, dtype andis_shared. The options that only the detailed form uses (show_is_shared,show_shape,show_field_device,show_field_is_shared,show_grad,show_is_contiguous,show_is_view,show_storage_sizeandplain) also setcompact=Falsewhencompactis not passed; with an explicitcompact=True, the compact form ignores them.html=Falseturns off the HTML display of notebooks; withcompact=False, a notebook shows the detailed text instead of the HTML tree.
- Raises:
TypeError – if an option is unknown.
Examples
>>> import torch >>> from tensordict import TensorDict, set_printoptions >>> td = TensorDict(a=torch.zeros(3), batch_size=[3]) >>> print(td) TensorDict(batch_size=[3], fields={a: f32[]}) >>> with set_printoptions(compact=False, verbose=False): ... print(td) TensorDict( fields={ a: Tensor(shape=torch.Size([3]))}, batch_size=torch.Size([3]))