o
    eix                     @   s:   d dl mZ d dlmZ d dlmZ eG dd dZdS )    )	dataclass)reduce)_remote_devicec                   @   sp   e Zd ZU dZg dZee ed< ee ed< edB ed< 	ddee dee de	eB dB fddZ
d	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   Nr   c                 C   s   || _ || _t|trt|| _n|| _t| j t| jkr-tdt| j  d| j dtt| j D ]}| j | dk rAtd| j| dk rLtdq4d 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   i r   k/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/distributed/_shard/metadata.py__init__   s(   
zShardMetadata.__init__c                 C   s4   dd }t || jd}t || j|}||| j}|S )Nc                 S   s   | d> t | S )N   )hash)abr   r   r   _hash_reduce9   s   z,ShardMetadata.__hash__.<locals>._hash_reduce%   )r   r   r   r   )r   r   resr   r   r   __hash__8   s
   zShardMetadata.__hash__)N)__name__
__module____qualname____doc__	__slots__listint__annotations__r   r
   r   r   r   r   r   r   r      s   
 

r   N)dataclassesr   	functoolsr   torch.distributed.remote_devicer   r   r   r   r   r   <module>   s
   