# tensorplay.nested.as_nested_tensor Source: https://www.tensorplay.cn/docs/generated/tensorplay.nested.as_nested_tensor.html ```python tensorplay.nested.as_nested_tensor(ts, dtype=None, device=None, layout=None) ``` Constructs a nested tensor preserving autograd history from a tensor or a list / tuple of tensors. If a nested tensor is passed, it is returned directly unless the device / dtype differ. A dense tensor of rank two or more is treated as a batch of constituents of consistent size; its storage is shared when no device / dtype conversion is requested. Constituents given as a list / tuple are always copied into one packed buffer. Parameters: ts ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or List[[Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)] or Tuple[[Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)]) – a tensor to treat as a nested tensor or a list / tuple of tensors with the same rank. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – desired dtype of the result. Default: the dtype of the first input. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – desired device of the result. Default: the device of the first input. - layout – only the strided layout (None or 0) is supported. Returns: the nested tensor. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)