
    sg3
                     >   d dl Z d dlmZ d dlmZmZmZ d dlZd dlmZ  e j                  e
      Zd Zd Z G d de      Zd	 Zd
eeej"                     eej"                  df   f   deeej"                     eej"                  df   f   fdZe G d d             Zy)    N)	dataclass)ListTupleUnion)fxc                 Z    g fd}t         j                  j                  | |      }|fS )z\
    Flatten the args into a list form and detach the tensors from computational graph.
    c                     t        | t        j                        r<| j                         j	                  | j
                        }j                  |       |S j                  |        | S N)
isinstancetorchTensordetachrequires_grad_requires_gradappend)avalflat_detached_argss     V/var/www/html/venv/lib/python3.12/site-packages/torch/distributed/pipelining/_utils.pyextract_tensor_argsz0flatten_args_detach.<locals>.extract_tensor_args   sQ    a&((*++AOO<C%%c*J%%a(H    r   nodemap_aggregate)argsr   new_argsr   s      @r   flatten_args_detachr      s:      ww$$H
 '''r   c                 V    g fd}t         j                  j                  | |       S )z,
    Flatten the args into a list form.
    c                 *    j                  |        | S r
   )r   )r   	flat_argss    r   r   z)flatten_args.<locals>.extract_tensor_args,   s    r   r   )r   r   r    s     @r   flatten_argsr!   &   s1     I
 GG
 r   c                       e Zd ZdZy)PipeliningShapeErrorz5Shape mismatch between configured and runtime values.N)__name__
__module____qualname____doc__ r   r   r#   r#   9   s    ?r   r#   c                    |j                   |j                   k(  s't        |  d|j                    d|j                          |j                  |j                  k(  s't        |  d|j                   d|j                         |j                         |j                         k(  s/t        |  d|j                          d|j                                y )Nz  has a shape mismatch: expected z actual z  has a dtype mismatch: expected z! has a stride mismatch: expected )shaper#   dtypestride)descexpectedgivens      r   validate_tensor_metadatar0   =   s    >>U[[("f4X^^4DHU[[MZ
 	
 >>U[[("f4X^^4DHU[[MZ
 	
 ??."f5hoo6G5HQVQ]Q]Q_P`a
 	
 /r   expected_tensors.actual_tensorsc           	          t        |      t        |      k7  r&t        |  dt        |       dt        |       d      t        t        |            D ]  }t        |  d| ||   ||           y )Nz: Number of values (z") does not match expected number ()z: value )lenr#   ranger0   )r-   r1   r2   is       r   validate_tensors_metadatar8   L   s    
 N 33"f(^)<(==_`cdt`u_vvwx
 	
 3'() 
 fHQC "21"5~a7H	

r   c                   D    e Zd ZU dZej
                  ed<   eed<   eed<   y)PipeInfoz>
    Captures information for a pipeline (`Pipe` object).
    graph
num_stageshas_loss_and_backwardN)	r$   r%   r&   r'   r   Graph__annotations__intboolr(   r   r   r:   r:   [   s     88OOr   r:   )loggingdataclassesr   typingr   r   r   r   r   	getLoggerr$   loggerr   r!   RuntimeErrorr#   r0   r   r8   r:   r(   r   r   <module>rH      s     ! % %   
		8	$(0&@< @

D.ellC6G0HHI
 $u||,eELL#4E.FFG
      r   