# torch 2.15.0 (BSD-3-Clause), harvested by tools/harvest_corpus.py
=== input

    Distribute a leaf ``torch.Tensor`` (i.e. nn.Parameter/buffers) to the ``device_mesh`` according
    to the ``placements`` specified. The rank of ``device_mesh`` and ``placements`` must be the
    same. The ``tensor`` to distribute is the logical or "global" tensor, and the API would use
    the ``tensor`` from first rank of the DeviceMesh dimension as the source of truth to preserve
    the single-device semantic. If you want to construct a DTensor in the middle of the Autograd
    computation, please use :meth:`DTensor.from_local` instead.

    Args:
        tensor (torch.Tensor): torch.Tensor to be distributed. Note that if you
            want to shard a tensor on a dimension that is not evenly divisible by
            the number of devices in that mesh dimension, we use ``torch.chunk``
            semantic to shard the tensor and scatter the shards. The uneven sharding
            behavior is experimental and subject to change.
        device_mesh (:class:`DeviceMesh`, optional): DeviceMesh to distribute the
            tensor, if not specified, must be called under a DeviceMesh context
            manager, default: None
        placements (List[:class:`Placement`], optional): the placements that
            describes how to place the tensor on DeviceMesh, must have the same
            number of elements as ``device_mesh.ndim``. If not specified, we will
            by default replicate the tensor across the ``device_mesh`` from the
            first rank of each dimension of the `device_mesh`.

    Keyword args:
        src_data_rank (int, optional): the rank of the source data for the logical/global tensor, it is
            used by :meth:`distribute_tensor` to scatter/broadcast the shards/replicas to other ranks.
            By default, we use ``group_rank=0`` on each DeviceMesh dimension as the source data to preserve
            the single-device semantic. If passing ``None`` explicitly, :meth:`distribute_tensor` simply uses
            its local data instead of trying to preserve the single-device semantic via scatter/broadcast.
            Default: 0

    Returns:
        A :class:`DTensor` or ``XLAShardedTensor`` object.

    Raises:
        ValueError: If ``placements`` contains mixed :class:`Partial` reduce types
            (e.g., both ``Partial("sum")`` and ``Partial("max")``). All Partial
            placements must use the same reduce operation.

    .. note::
        When initialize the DeviceMesh with the ``xla`` device_type, ``distribute_tensor``
        return `XLAShardedTensor` instead. see `this issue <https://github.com/pytorch/pytorch/issues/92909>`__
        for more details. The XLA integration is experimental and subject to change.
    
=== parse google
short_description: |
  Distribute a leaf ``torch.Tensor`` (i.e. nn.Parameter/buffers) to the ``device_mesh`` according
  to the ``placements`` specified. The rank of ``device_mesh`` and ``placements`` must be the
  same. The ``tensor`` to distribute is the logical or "global" tensor, and the API would use
  the ``tensor`` from first rank of the DeviceMesh dimension as the source of truth to preserve
  the single-device semantic. If you want to construct a DTensor in the middle of the Autograd
  computation, please use :meth:`DTensor.from_local` instead.
long_description: |
  .. note::
      When initialize the DeviceMesh with the ``xla`` device_type, ``distribute_tensor``
      return `XLAShardedTensor` instead. see `this issue <https://github.com/pytorch/pytorch/issues/92909>`__
      for more details. The XLA integration is experimental and subject to change.
blank_after_short_description: True
blank_after_long_description: True
style: google
- DocstringParam
  description: |
    torch.Tensor to be distributed. Note that if you
    want to shard a tensor on a dimension that is not evenly divisible by
    the number of devices in that mesh dimension, we use ``torch.chunk``
    semantic to shard the tensor and scatter the shards. The uneven sharding
    behavior is experimental and subject to change.
  kind: param
  key: 'param'
  arg_name: 'tensor'
  type_name: 'torch.Tensor'
  is_optional: False
- DocstringParam
  description: |
    DeviceMesh to distribute the
    tensor, if not specified, must be called under a DeviceMesh context
    manager, default: None
  kind: param
  key: 'param'
  arg_name: 'device_mesh'
  type_name: ':class:`DeviceMesh`'
  is_optional: True
  default: 'None'
  raw_type_name: ':class:`DeviceMesh`, optional'
- DocstringParam
  description: |
    the placements that
    describes how to place the tensor on DeviceMesh, must have the same
    number of elements as ``device_mesh.ndim``. If not specified, we will
    by default replicate the tensor across the ``device_mesh`` from the
    first rank of each dimension of the `device_mesh`.
  kind: param
  key: 'param'
  arg_name: 'placements'
  type_name: 'List[:class:`Placement`]'
  is_optional: True
  raw_type_name: 'List[:class:`Placement`], optional'
- DocstringParam
  description: |
    the rank of the source data for the logical/global tensor, it is
    used by :meth:`distribute_tensor` to scatter/broadcast the shards/replicas to other ranks.
    By default, we use ``group_rank=0`` on each DeviceMesh dimension as the source data to preserve
    the single-device semantic. If passing ``None`` explicitly, :meth:`distribute_tensor` simply uses
    its local data instead of trying to preserve the single-device semantic via scatter/broadcast.
    Default: 0
  kind: keyword
  key: 'keyword'
  arg_name: 'src_data_rank'
  type_name: 'int'
  is_optional: True
  default: '0'
  raw_type_name: 'int, optional'
- DocstringReturns
  description: 'A :class:`DTensor` or ``XLAShardedTensor`` object.'
  kind: returns
  key: 'returns'
  is_generator: False
- DocstringRaises
  description: |
    If ``placements`` contains mixed :class:`Partial` reduce types
    (e.g., both ``Partial("sum")`` and ``Partial("max")``). All Partial
    placements must use the same reduce operation.
  kind: raises
  key: 'raises'
  type_name: 'ValueError'
=== detect
google
=== compose google
Distribute a leaf ``torch.Tensor`` (i.e. nn.Parameter/buffers) to the ``device_mesh`` according
to the ``placements`` specified. The rank of ``device_mesh`` and ``placements`` must be the
same. The ``tensor`` to distribute is the logical or "global" tensor, and the API would use
the ``tensor`` from first rank of the DeviceMesh dimension as the source of truth to preserve
the single-device semantic. If you want to construct a DTensor in the middle of the Autograd
computation, please use :meth:`DTensor.from_local` instead.

.. note::
    When initialize the DeviceMesh with the ``xla`` device_type, ``distribute_tensor``
    return `XLAShardedTensor` instead. see `this issue <https://github.com/pytorch/pytorch/issues/92909>`__
    for more details. The XLA integration is experimental and subject to change.

Args:
    tensor (torch.Tensor): torch.Tensor to be distributed. Note that if you
        want to shard a tensor on a dimension that is not evenly divisible by
        the number of devices in that mesh dimension, we use ``torch.chunk``
        semantic to shard the tensor and scatter the shards. The uneven sharding
        behavior is experimental and subject to change.
    device_mesh (:class:`DeviceMesh`, optional): DeviceMesh to distribute the
        tensor, if not specified, must be called under a DeviceMesh context
        manager, default: None
    placements (List[:class:`Placement`], optional): the placements that
        describes how to place the tensor on DeviceMesh, must have the same
        number of elements as ``device_mesh.ndim``. If not specified, we will
        by default replicate the tensor across the ``device_mesh`` from the
        first rank of each dimension of the `device_mesh`.

Keyword Args:
    src_data_rank (int, optional): the rank of the source data for the logical/global tensor, it is
        used by :meth:`distribute_tensor` to scatter/broadcast the shards/replicas to other ranks.
        By default, we use ``group_rank=0`` on each DeviceMesh dimension as the source data to preserve
        the single-device semantic. If passing ``None`` explicitly, :meth:`distribute_tensor` simply uses
        its local data instead of trying to preserve the single-device semantic via scatter/broadcast.
        Default: 0

Returns:
    A :class:`DTensor` or ``XLAShardedTensor`` object.

Raises:
    ValueError: If ``placements`` contains mixed :class:`Partial` reduce types
        (e.g., both ``Partial("sum")`` and ``Partial("max")``). All Partial
        placements must use the same reduce operation.
