
    ix                     F    d dl mZ d dlmZ d dlmZ e G d d             Zy)    )	dataclass)reduce)_remote_devicec                       e Zd ZU dZg dZee   ed<   ee   ed<   edz  ed<   	 d	dee   dee   de	ez  dz  fdZ
d Zy)
ShardMetadataaH  
    Represents a shard of the overall Tensor including its
    offsets, lengths and device placement.

    Args:
        shard_offsets(List[int]): Offsets in the original tensor indicating
            the start offsets for this shard. Should have the same rank as
            the original tensor.
        shard_sizes(List[int]): Integers indicating the size of each
            dimension for this shard. Should have the same rank as the
            original tensor.
        placement(:class:`torch.distributed._remote_device`):
            Specifies the placement of this shard.
    )shard_offsetsshard_sizes	placementr   r	   Nr
   c                    || _         || _        t        |t              rt	        |      | _        n|| _        t        | j                         t        | j                        k7  r/t        dt        | j                          d| j                   d      t        t        | j                               D ]<  }| j                   |   dk  rt        d      | j                  |   dk  s3t        d       y )NzMshard_offsets and shard_sizes should have the same number of elements, found z and z respectivelyr   zshard_offsets should be >=0zshard_sizes should be >= 0)	r   r	   
isinstancestrr   r
   len
ValueErrorrange)selfr   r	   r
   is        [/var/www/html/engine/venv/lib/python3.12/site-packages/torch/distributed/_shard/metadata.py__init__zShardMetadata.__init__   s     +&i%+I6DN&DNt!!"c$*:*:&;;669$:L:L6M5N O''(7  s4--./ 	?A!!!$q( !>??"Q& !=>>		?    c                     d }t        || j                  d      }t        || j                  |      } ||| j                        }|S )Nc                 $    | dz  t        |      z   S )N   )hash)abs     r   _hash_reducez,ShardMetadata.__hash__.<locals>._hash_reduce9   s    Fd1g%%r   %   )r   r   r	   r
   )r   r   ress      r   __hash__zShardMetadata.__hash__8   sF    	& \4#5#5r:\4#3#3S93/
r   )N)__name__
__module____qualname____doc__	__slots__listint__annotations__r   r   r   r    r   r   r   r      sj     >I9c$$ 26	?Cy? #Y? '$.	?2r   r   N)dataclassesr   	functoolsr   torch.distributed.remote_devicer   r   r(   r   r   <module>r,      s'    !  : 6 6 6r   