
    קg                     h    d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 e G d d                      Z
dS )    )	dataclass)reduce)ListOptionalUnion)_remote_devicec            
           e Zd ZU dZg dZee         ed<   ee         ed<   ee	         ed<   	 d	dee         dee         dee
ee	f                  fdZd ZdS )
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   r   Nc                    || _         || _        t          |t                    rt	          |          | _        n|| _        t          | j                   t          | j                  k    r-t          dt          | j                    d| j         d          t          t          | j                             D ]B}| j         |         dk     rt          d          | j        |         dk     rt          d          Cd S )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/ai-engine/env/lib/python3.11/site-packages/torch/distributed/_shard/metadata.py__init__zShardMetadata.__init__    s    +&i%% 	'+I66DNN&DNt!""c$*:&;&;;;769$:L6M6M7 7'7 7 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_reduce:   s    Fd1gg%%r   %   )r   r   r   r   )r   r   ress      r   __hash__zShardMetadata.__hash__9   sS    	& 	& 	& \4#5r::\4#3S99l3//
r   )N)__name__
__module____qualname____doc__	__slots__r   int__annotations__r   r   r   r   r   r"    r   r   r
   r
   	   s           >==I9c'''' ;?	? ?Cy? #Y? E#~"567	? ? ? ?2    r   r
   N)dataclassesr   	functoolsr   typingr   r   r   torch.distributed.remote_devicer   r
   r*   r   r   <module>r/      s    ! ! ! ! ! !       ( ( ( ( ( ( ( ( ( ( : : : : : : 6 6 6 6 6 6 6 6 6 6r   