U
    9%e                     @   sN   d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 eG dd dZ
dS )    )	dataclass)ListUnionOptional)reduce)_remote_devicec                   @   sp   e Zd ZU dZdddgZee ed< ee ed< ee	 ed< dee ee ee
ee	f  d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	placementN)r	   r
   r   c                 C   s   || _ || _t|tr"t|| _n|| _t| j t| jkrZtdt| j  d| j dtt| j D ]0}| j | dk rtd| j| dk rhtdqhd 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   `/var/www/html/Darija-Ai-API/env/lib/python3.8/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_reduce7   s    z,ShardMetadata.__hash__.<locals>._hash_reduce%   )r   r	   r
   r   )r   r   resr   r   r   __hash__6   s
    zShardMetadata.__hash__)N)__name__
__module____qualname____doc__	__slots__r   int__annotations__r   r   r   r   r   r   r   r   r   r   r      s   

 r   N)dataclassesr   typingr   r   r   	functoolsr   Ztorch.distributed.remote_devicer   r   r   r   r   r   <module>   s
   