oneflow.empty_like

oneflow.empty_like(input, *, dtype=None, device=None, placement=None, sbp=None, requires_grad=False)Tensor

The interface is consistent with PyTorch. The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.empty_like.html.

Returns an uninitialized tensor with the same size as input. oneflow.empty_like(input) is equivalent to oneflow.empty(input.size(), dtype=input.dtype, device=input.device).

Parameters
  • input (Tensor) – The size of input will determine size of the output tensor.

  • dtype (flow.dtype, optional) – The desired data type of returned tensor. Default: flow.float32.

  • device (oneflow.device, optional) – The desired device of returned local tensor. If None, uses the current device.

  • placement (flow.placement, optional) – The desired device of returned global tensor. If None, will construct local tensor.

  • sbp (flow.sbp or List[flow.sbp], optional) – The desired sbp of returned global tensor.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

For example:

>>> import oneflow as flow
>>> x = flow.randn(2, 3)
>>> y = flow.empty_like(x)
>>> y.shape
oneflow.Size([2, 3])