
    Phr                         U d Z ddlmZmZmZmZ ddlmZ ddlm	Z	 g Z
ee   ed<    G d d      Zd	eej                     d
efdZy)z8Static skip connection layout of ``@skippable`` modules.    )DictIterableListTuple)nn   )	Namespace__all__c                       e Zd ZU dZeeeef   eeef   f   e	d<   e
e
eeeef         e	d<   dedeeeef   eeef   f   ddfdZd	edeeeeef      fd
ZdededefdZy)
SkipLayoutz6Represents a skip connection layout across partitions.
by_ns_nameby_partitionnum_partitionsskip_routesreturnNc                    || _         t        |      D cg c]  }g  c}| _        |j                         D ],  \  \  }}\  }}| j                  |   j	                  |||f       . | j                  D ]  }|j                           y c c}w N)r   ranger   itemsappendsort)	selfr   r   _nsnameprev_jnext_jps	            vC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/distributed/pipeline/sync/skip/layout.py__init__zSkipLayout.__init__   s    % */~)>?)>AR)>?,7,=,=,?(JR(f%,,fb$-?@ -@ ""AFFH # @s   	Br   c              #   V   K   | j                   |   D ]  \  }}}||k(  r|||f  yw)zGenerates skip routes for the given destination partition number.
        The skip routes are sorted by source partition number in ascending
        order.

        Yields:
            Each tuple of (source partition number, namespace, name).

        N)r   )r   r   r   r   r   s        r   copy_policyzSkipLayout.copy_policy'   s>      !% 1 1& 9FB 2t$$ !:s   ')r   r   c                 N    | j                   j                  ||fd      \  }}||k7  S )zbWhether the given namespace and name requires partition-to-partition
        copy or not.
        )r$   )r   get)r   r   r   r   r   s        r   requires_copyzSkipLayout.requires_copy8   s-     ,,b$ZB    )__name__
__module____qualname____doc__r   r   r	   strint__annotations__r   r    r   r"   boolr&    r'   r   r   r      s    @ U9c>*E#s(O;<< tE#y#"56788s eIsN>SUZ[^`c[cUd>d9e ko %# %(5i9L3M*N %" 	      r'   r   
partitionsr   c                     ddl m i i t        |       D ]?  \  }fd}t        |t        j
                        r|D ]
  } ||        8 ||       A t        t        |             S )z<Inspects the skip connection layout in the given partitions.r   )	Skippablec                     t        |       sy | j                         D ]  \  }}||f<    | j                         D ]!  \  }}j                  ||f      }|f||f<   # y r   )
isinstance	stashablepoppablepop)layerr   r   r   r3   jr   
stashed_ats       r   inspect_layerz*inspect_skip_layout.<locals>.inspect_layerK   sn    eY/!OO-D)*
B:& . "NN,D#T
3+11+RJ' -r'   )	skippabler3   	enumerater5   r   
Sequentialr   len)r1   	partitionr<   r9   r3   r:   r   r;   s       @@@@r   inspect_skip_layoutrB   @   si    
 %@BK35J!*-9		6 i/"e$ # )$! .$ c*o{33r'   N)r+   typingr   r   r   r   torchr   	namespacer	   r
   r,   r.   r   r?   rB   r0   r'   r   <module>rF      sK    ? . .   c ,  , ^4D$7 4J 4r'   