
    9i                     f    % S SK Jr  / r\\   \S'   S\S\S\4S jrS\S\S\\\	\	\	\	4      4S	 jr
g
)    )ChunkStorageMetadata__all__shard1shard2returnc                    [        U R                  5      n[        U5       Hg  nU R                  U   UR                  U   UR                  U   -   :  a    gUR                  U   U R                  U   U R                  U   -   :  d  Mg    g   g)zCheck if two shards overlap.FT)lenoffsetsrangesizes)r   r   ndimsis       g/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/distributed/checkpoint/resharding.py"_check_shard_metadata_pair_overlapr      sy     E5\>>!q 1FLLO CC>>!q 1FLLO CC	      saved_shardcurrent_shardc                 ,   / n[        [        U R                  UR                  U R                  UR                  5      5       HN  u  nu  nnnn[	        XF-   XW-   5      nU[        XT5      -
  n	XE:  a  Sn
XE-
  nOXT-
  n
SnUR                  X:X45        MP     U$ )aC  
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_tensors               r   +_shards_get_overlap_region_wrt_saved_tensorr$      s     G 
!!		

	  1 5

 %9!NN4&'#(:(Q%&:&O#()%+DM	
-
4 Nr   N)%torch.distributed.checkpoint.metadatar   r   liststr__annotations__boolr   tupleintr$    r   r   <module>r-      se    F c  *>	$,%,6J,	%S#s"
#$,r   