Constructs a tensor with data, return a global tensor if placement and sbp are in kwargs,

otherwise return a local tensor.


data – Initial data for the tensor. Can be a list, tuple, NumPy ndarray, scalar or tensor.

Keyword Arguments
  • dtype (oneflow.dtype, optional) – Default: if None, infers data type from data.

  • device (oneflow.device, optional) – the desired device of returned tensor. If placement and sbp is None, uses the current cpu for the default tensor type.

  • placement (oneflow.placement, optional) – the desired placement of returned tensor.

  • sbp (oneflow.sbp or tuple of oneflow.sbp, optional) – the desired sbp of returned tensor.

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

  • pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False.


The Keyword Argument device is mutually exclusive with placement and sbp.

For example:

>>> import oneflow as flow

>>> x = flow.tensor([1,2,3])
>>> x
tensor([1, 2, 3], dtype=oneflow.int64)