oneflow.empty(*size, dtype: Optional[oneflow._oneflow_internal.dtype] = None, device: Optional[Union[str, oneflow._oneflow_internal.device]] = None, placement: Optional[oneflow._oneflow_internal.placement] = None, sbp: Optional[Union[oneflow._oneflow_internal.sbp.sbp, List[oneflow._oneflow_internal.sbp.sbp]]] = None, requires_grad: bool = False, pin_memory: bool = False)

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

  • 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
>>> placement = flow.placement("cpu", ranks=[0])
>>> y = flow.empty(4, 5, placement=placement, sbp=flow.sbp.broadcast)  # construct consistent empty tensor
>>> y.is_global