Creates a distributed Tensor (i.e., Tensor with distributed attributes or DistTensor for short) from the input data, which can be a scalar, tuple, list, numpy.ndarray, or paddle.Tensor. If the ``data`` is already a Tensor, it will be transformed into a distributed Tensor. Args:
(
data: Tensor | TensorLike | NestedNumericSequence,
mesh: ProcessMesh,
placements: Sequence[Placement],
dtype: DTypeLike | None = None,
place: PlaceLike | None = None,
stop_gradient: bool | None = None,
)
| 244 | |
| 245 | |
| 246 | def shard_tensor( |
| 247 | data: Tensor | TensorLike | NestedNumericSequence, |
| 248 | mesh: ProcessMesh, |
| 249 | placements: Sequence[Placement], |
| 250 | dtype: DTypeLike | None = None, |
| 251 | place: PlaceLike | None = None, |
| 252 | stop_gradient: bool | None = None, |
| 253 | ) -> Tensor: |
| 254 | """ |
| 255 | Creates a distributed Tensor (i.e., Tensor with distributed attributes or DistTensor for short) |
| 256 | from the input data, which can be a scalar, tuple, list, numpy.ndarray, or paddle.Tensor. |
| 257 | |
| 258 | If the ``data`` is already a Tensor, it will be transformed into a distributed Tensor. |
| 259 | |
| 260 | Args: |
| 261 | data(scalar|tuple|list|ndarray|Tensor): Initial data for the tensor. |
| 262 | Can be a scalar, list, tuple, numpy.ndarray, paddle.Tensor. |
| 263 | mesh(paddle.distributed.ProcessMesh): The `ProcessMesh` object describes the Cartesian topology of the used processes. |
| 264 | placements(list[paddle.distributed.Placement]): the placements describe how to place the tensor on ProcessMesh, it can |
| 265 | be Shard, Replicate and Partial. |
| 266 | dtype(str|paddle.dtype|np.dtype, optional): The desired data type of returned tensor. |
| 267 | It Can be 'bool' , 'float16' , 'float32' , 'float64' , 'int8' , 'int16' , 'int32' , 'int64' , 'uint8', |
| 268 | 'complex64' , 'complex128'. Default: None. If None, the the dtype is inferred from ``data`` |
| 269 | except for python float number, in which case the dtype is inferred from ``get_default_type`` . |
| 270 | place(CPUPlace|CUDAPinnedPlace|CUDAPlace|str, optional): The place to allocate Tensor. Can be |
| 271 | CPUPlace, CUDAPinnedPlace, CUDAPlace. Default: None, means global place. If ``place`` is |
| 272 | string, It can be ``cpu``, ``gpu:x`` and ``gpu_pinned``, where ``x`` is the index of the GPUs. |
| 273 | stop_gradient(bool, optional): Whether to block the gradient propagation of Autograd. If |
| 274 | ``stop_gradient`` is None, set the returned Tensor's ``stop_gradient`` identical as the |
| 275 | ``data.stop_gradient`` when ``data`` has ``stop_gradient`` attribute and True otherwise. |
| 276 | Default: None. |
| 277 | |
| 278 | Returns: |
| 279 | Tensor: A Tensor constructed from ``data`` with distributed attributes. |
| 280 | |
| 281 | Examples: |
| 282 | .. code-block:: pycon |
| 283 | |
| 284 | >>> import paddle |
| 285 | >>> import paddle.distributed as dist |
| 286 | |
| 287 | >>> mesh = dist.ProcessMesh([[2, 4, 5], [0, 1, 3]], dim_names=['x', 'y']) |
| 288 | |
| 289 | >>> # dense tensor |
| 290 | >>> a = paddle.to_tensor( |
| 291 | ... [ |
| 292 | ... [1, 2, 3], |
| 293 | ... [5, 6, 7], |
| 294 | ... ] |
| 295 | ... ) |
| 296 | |
| 297 | >>> # doctest: +REQUIRES(env:DISTRIBUTED) |
| 298 | >>> # distributed tensor |
| 299 | >>> d_tensor = dist.shard_tensor(a, mesh, [dist.Shard(0), dist.Shard(1)]) |
| 300 | |
| 301 | >>> print(d_tensor) |
| 302 | |
| 303 | """ |
no test coverage detected