oneflow.Tensor.to_local¶
-
Tensor.
to_local
(**kwargs) → Tensor¶ Returns the local component of this global tensor in the current rank.
- Keyword Arguments
copy (bool, optional) – When copy is set, a new replicated tensor of the local component of this global tensor in the current rank is returned. Default: False
Note
This tensor should be a global tensor, and it returns a empty tensor if there is no local component in the current rank.
No copy occurred in this operation if copy is not set.
For example:
>>> # Run on 2 ranks respectively >>> import oneflow as flow >>> x = flow.tensor([0., 1.], dtype=flow.float32, placement=flow.placement("cpu", ranks=[0, 1]), sbp=[flow.sbp.split(0)]) >>> y = x.to_local() >>> print(y.size()) >>> print(y)
>>> # results on rank 0 oneflow.Size([1]) tensor([0.], dtype=oneflow.float32)
>>> # results on rank 1 oneflow.Size([1]) tensor([1.], dtype=oneflow.float32)