U
    ©Ê¹jƒ  ã                   @   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 r‚t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/bwave/python/venv/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
   