oneflow.empty

oneflow.empty(*size, *, dtype=None, device=None, placement=None, sbp=None, requires_grad=False, pin_memory=False)Tensor

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

Returns a tensor filled with uninitialized data. The shape of the tensor is defined by the variable argument size.

Parameters
  • size (int... or oneflow.Size) – Defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple or oneflow.Size.

  • 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.

  • pin_memory (bool, optional) – False.

For example:

>>> import oneflow as flow
>>> y = flow.empty(4, 5)  # construct local empty tensor
>>> y.shape
oneflow.Size([4, 5])
>>> y.is_global
False
>>> placement = flow.placement("cpu", ranks=[0])
>>> y = flow.empty(4, 5, placement=placement, sbp=flow.sbp.broadcast)  # construct consistent empty tensor
>>> y.is_global
True