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

Returns a tensor filled with random numbers from a uniform distribution on the interval [0, 1)

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.

  • generator (flow.Generator, optional) – a pseudorandom number generator for sampling

  • device (flow.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, optional) – The desired sbp of returned global tensor. It must be equal with the numbers of placement.

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

For example:

>>> import oneflow as flow
>>> x = flow.rand(3,3) # construct local tensor
>>> x.shape
oneflow.Size([3, 3])
>>> x.is_global
>>> placement = flow.placement("cpu", ranks=[0])
>>> sbp = flow.sbp.broadcast
>>> x = flow.rand(3, 3, placement=placement, sbp=sbp) # construct global tensor
>>> x.is_global