oneflow.randint_like(input, low=0, high, size, *, dtype=None, generator=None, device=None, placement=None, sbp=None, requires_grad=False)Tensor

Returns a tensor filled with random integers generated uniformly between low (inclusive) and high (exclusive).

The interface is consistent with PyTorch. The documentation is referenced from:

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

  • low (int, optional) – Lowest integer to be drawn from the distribution. Default: 0.

  • high (int) – One above the highest integer to be drawn from the distribution.

Keyword Arguments
  • dtype (oneflow.dtype, optional) – The desired data type of returned tensor. Default: flow.int64.

  • generator (oneflow.Generator, optional) –

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

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

  • sbp (oneflow.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
>>> generator = flow.Generator()
>>> generator.manual_seed(0) 
<oneflow._oneflow_internal.Generator object at ...>
>>> x = flow.randn(2, 2, generator=generator)
>>> y = flow.randint_like(x, 0, 5, generator=generator) # construct local tensor
>>> y
tensor([[3, 4],
        [2, 4]], dtype=oneflow.int64)
>>> y.is_global
>>> placement = flow.placement("cpu", ranks=[0])
>>> y = flow.randint_like(x, 0, 5, generator=generator, placement=placement, sbp=flow.sbp.broadcast) # construct global tensor
>>> y.is_global