o
    ß—¦i	  ã                   @   sj   U d dl mZmZ d dlmZ g Zee ed< dedefdd„Zded	ed
eee	e	e	e	f  fdd„Z
dS )é    )ÚListÚTuple)ÚChunkStorageMetadataÚ__all__Úshard1Úshard2c                 C   sd   t | jƒ}t|ƒD ]&}| j| |j| |j|  kr dS |j| | j| | j|  kr/ dS q	dS )zCheck if two shards overlap.FT)ÚlenÚoffsetsÚrangeÚsizes)r   r   ÚndimsÚi© r   úe/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/torch/distributed/checkpoint/resharding.pyÚ"_check_shard_metadata_pair_overlap
   s   
ÿr   Úsaved_shardÚcurrent_shardÚreturnc                 C   sˆ   g }t t| j|j| j|jƒƒD ]2\}\}}}}t|| || ƒ}|t||ƒ }	||kr2d}
|| }n|| }
d}| ||
||	f¡ q|S )a[  
    Return the overlapping region between saved_shard and current_shard.

    There returned list has the same number of elements as the tensor's dimension.
    For each element, we produce a tuple with the following contents:
        (dimension, `saved_shard` offset, `current_shard` offset, length)

    Offsets are relative to each shard.
    r   )Ú	enumerateÚzipr	   r   ÚminÚmaxÚappend)r   r   ÚnarrowsÚdimÚsaved_shard_offsetÚcurrent_shard_offsetÚsaved_shard_sizeÚcurrent_shard_sizeÚmin_range_endÚlengthÚoffset_for_saved_tensorÚoffset_for_current_tensorr   r   r   Ú+_shards_get_overlap_region_wrt_saved_tensor   s8   üÿ
û	þ

ÿr#   N)Útypingr   r   Ú%torch.distributed.checkpoint.metadatar   r   ÚstrÚ__annotations__r   Úintr#   r   r   r   r   Ú<module>   s   ÿ
ÿÿÿþ