
    7h)                        S SK r S SKJrJr  S SKJr  S SKJr  S SKrS SK	J
s  Jr  S SKJrJrJrJrJrJrJrJrJr  S SKJr    " S S\5      r\ R4                  S	 5       r\ R4                  S
 5       r\ R4                  S 5       r " S S\5      r\ R4                  S 5       r " S S\5      r  " S S\5      r! " S S\5      r"S\S\4S jr#S\4S jr$S\%\   4S jr&S\%\'\S4      S\(4S jr)S r*g)    N)ABCabstractmethod)cached_property)Any)	CFunctionalizeInterpreterPtrCGradInterpreterPtrCInterpreterCJvpInterpreterPtrCVmapInterpreterPtrpop_dynamic_layer_stackpush_dynamic_layer_stackRandomnessTypeTransformType)_set_fwd_grad_enabledc                   V    \ rS rSrS\4S jr\S 5       rS rS r	S r
S rS	 rS
 rSrg)FuncTorchInterpreter7   cptrc                     Xl         g N_cptr)selfr   s     V/var/www/fran/franai/venv/lib/python3.13/site-packages/torch/_functorch/pyfunctorch.py__init__FuncTorchInterpreter.__init__8   s    
    c                     g r    )r   opargskwargss       r   processFuncTorchInterpreter.process=   s    r   c                     [        5       $ r   )!temporarily_pop_interpreter_stackr   s    r   lowerFuncTorchInterpreter.lowerD   s    022r   c                 6    U R                   R                  5       $ r   )r   levelr'   s    r   r+   FuncTorchInterpreter.levelG   s    zz!!r   c                 6    U R                   R                  5       $ r   )r   keyr'   s    r   r.   FuncTorchInterpreter.keyJ   s    zz~~r   c                     [         er   )NotImplementedErrorr'   s    r   	get_stateFuncTorchInterpreter.get_stateM   s    !!r   c                 &    XR                  5       :H  $ r   )r2   r   states     r   check_state FuncTorchInterpreter.check_stateP   s    (((r   c                 ^    U R                   R                  5       nUR                  SS 5        U$ )Nr   )__dict__copypopr5   s     r   __getstate__!FuncTorchInterpreter.__getstate__S   s'    ""$		'4 r   r   N)__name__
__module____qualname____firstlineno__r   r   r   r#   r(   r+   r.   r2   r7   r=   __static_attributes__r   r   r   r   r   7   s@    S 
  3" ")r   r   c               #   `   #     [        5       n S v   [        U 5        g ! [        W 5        f = f7fr   )r   r   )saveds    r   r&   r&   Y   s&     (') ' 's   . .+.c               #     #    / n  [         R                  R                  R                  5       bD  U R	                  [        5       5        [         R                  R                  R                  5       b  MD  [        U 5      v   U (       a#  [        U R                  5       5        U (       a  M"  g g ! U (       a#  [        U R                  5       5        U (       a  M"  f f = f7fr   )	torch_C
_functorchpeek_interpreter_stackappendr   listr   r<   )stacks    r   #temporarily_clear_interpreter_stackrN   b   s     E2hh!!88:FLL023 hh!!88:F5k$UYY[1 ee$UYY[1 es/   CA+B+ 3B+  'C)C+(CCCc              #      #    / n [        U 5       H  n[        U5        UR                  U5        M!     S v   [        U5       H  n[        5         M     g ! [        U5       H  n[        5         M     f = f7fr   )reversedr   rK   r   )rM   pushedss      r   %temporarily_restore_interpreter_stackrS   n   sd     F	&%A$Q'MM! ! 	&!A $% "&!A $% "s   A62A A6A33A6c                   J    \ rS rSrS\4S jr\S 5       rS rS r	S r
S rS	rg
)VmapInterpreter}   cdatac                 X    UR                  5       [        R                  :X  d   eXl        g r   )r.   r   Vmap_cdatar   rW   s     r   r   VmapInterpreter.__init__~   s#    yy{m00000 r   c                 ,    [        U R                  5      $ r   )r   rZ   r'   s    r   r   VmapInterpreter._cptr       "4;;//r   c                 T    UR                   [        R                     nU" U /UQ70 UD6$ r   )functorch_tabler   rY   r   r    r!   r"   kernels        r   r#   VmapInterpreter.process   s-    ##M$6$67d,T,V,,r   c                 6    U R                   R                  5       $ r   )r   	batchSizer'   s    r   
batch_sizeVmapInterpreter.batch_size   s    zz##%%r   c                     U R                   R                  5       nU[        R                  :X  a  gU[        R                  :X  a  gU[        R
                  :X  a  g[        SU 35      e)Nerrorsame	differentzUnknown RandomnessType: )r   
randomnessr   ErrorSame	DifferentRuntimeError)r   typs     r   rm   VmapInterpreter.randomness   sZ    jj##%.&&&N'''N,,,5cU;<<r   c                 t    U R                  5       R                  U R                  5       U R                  5       4$ r   )r.   namer+   rm   r'   s    r   r2   VmapInterpreter.get_state   s&    
t/@AAr   rZ   N)r?   r@   rA   rB   r	   r   r   r   r#   rg   rm   r2   rC   r   r   r   rU   rU   }   s7    l  0 0-&=Br   rU   c               '      #    [         R                  " 5        nU  H  nUR                  U5        M     U v   S S S 5        g ! , (       d  f       g = f7fr   )
contextlib	ExitStackenter_context)contextsrM   ctxs      r   nestedr~      s;     				5C$  
 		s   AA 	A 
A
Ac                   ^   ^  \ rS rSrS\4S jr\S 5       rS rS r	U 4S jr
S rS	 rS
rU =r$ )GradInterpreter   rW   c                 X    UR                  5       [        R                  :X  d   eXl        g r   )r.   r   GradrZ   r[   s     r   r   GradInterpreter.__init__   s!    yy{m00000r   c                 ,    [        U R                  5      $ r   )r   rZ   r'   s    r   r   GradInterpreter._cptr   r_   r   c                     [         R                  " [        R                  U R                  R
                  X/5      u  pX4$ r   pytreetree_map_onlyrG   Tensorr   liftr   r!   r"   s      r   r   GradInterpreter.lift   3    ++LL$**//D>
 |r   c                 z    UR                   [        R                     nU R                  X#5      u  p#U" U /UQ70 UD6$ r   )ra   r   r   r   rb   s        r   r#   GradInterpreter.process   s=    ##M$6$67yy.d,T,V,,r   c                    > U R                  5       nU(       d+  [        [        R                  " 5       [        TU ]  5       5      $ [        TU ]  5       $ r   )prev_grad_moder~   rG   no_gradsuperr(   )r   r   	__class__s     r   r(   GradInterpreter.lower   s9    ,,.%--/57=?;;w}r   c                 6    U R                   R                  5       $ r   )r   prevGradModer'   s    r   r   GradInterpreter.prev_grad_mode   s    zz&&((r   c                 t    U R                  5       R                  U R                  5       U R                  5       4$ r   )r.   ru   r+   r   r'   s    r   r2   GradInterpreter.get_state   s(    
t/B/B/DEEr   rw   )r?   r@   rA   rB   r	   r   r   r   r   r#   r(   r   r2   rC   __classcell__r   s   @r   r   r      sC    l 
 0 0-)F Fr   r   c                   ^   ^  \ rS rSrS\4S jr\S 5       rS rS r	U 4S jr
S rS	 rS
rU =r$ )JvpInterpreter   rW   c                 X    UR                  5       [        R                  :X  d   eXl        g r   )r.   r   JvprZ   r[   s     r   r   JvpInterpreter.__init__   s!    yy{m/////r   c                 ,    [        U R                  5      $ r   )r
   rZ   r'   s    r   r   JvpInterpreter._cptr   s    !$++..r   c                     [         R                  " [        R                  U R                  R
                  X/5      u  pX4$ r   r   r   s      r   r   JvpInterpreter.lift   r   r   c                 z    UR                   [        R                     nU R                  X#5      u  p#U" U /UQ70 UD6$ r   )ra   r   r   r   rb   s        r   r#   JvpInterpreter.process   s=    ##M$5$56yy.d,T,V,,r   c                    > U R                  5       nU(       d!  [        [        S5      [        TU ]  5       5      $ [        TU ]  5       $ )NF)prev_fwd_grad_moder~   r   r   r(   )r   r   r   s     r   r(   JvpInterpreter.lower   s:    !446!/6HHw}r   c                 6    U R                   R                  5       $ r   )r   prevFwdGradModer'   s    r   r   !JvpInterpreter.prev_fwd_grad_mode   s    zz))++r   c                 t    U R                  5       R                  U R                  5       U R                  5       4$ r   )r.   ru   r+   r   r'   s    r   r2   JvpInterpreter.get_state   s(    
t/F/F/HIIr   rw   )r?   r@   rA   rB   r	   r   r   r   r   r#   r(   r   r2   rC   r   r   s   @r   r   r      sC    l 
 / /-,J Jr   r   c                   D    \ rS rSrS\4S jr\S 5       rS rS r	S r
Srg	)
FunctionalizeInterpreter   rW   c                 X    UR                  5       [        R                  :X  d   eXl        g r   )r.   r   FunctionalizerZ   r[   s     r   r   !FunctionalizeInterpreter.__init__   s!    yy{m99999r   c                 ,    [        U R                  5      $ r   )r   rZ   r'   s    r   r   FunctionalizeInterpreter._cptr   s    +DKK88r   c                 T    UR                   [        R                     nU" U /UQ70 UD6$ r   )ra   r   r   rb   s        r   r#    FunctionalizeInterpreter.process   s-    ##M$?$?@d,T,V,,r   c                 6    U R                   R                  5       $ r   )r   functionalizeAddBackViewsr'   s    r   functionalize_add_back_views5FunctionalizeInterpreter.functionalize_add_back_views   s    zz3355r   c                 V    U R                  5       R                  U R                  5       4$ r   )r.   ru   r+   r'   s    r   r2   "FunctionalizeInterpreter.get_state   s    
..r   rw   N)r?   r@   rA   rB   r	   r   r   r   r#   r   r2   rC   r   r   r   r   r      s1    l  9 9-6/r   r   cinterpreterreturnc                 6   U R                  5       nU[        R                  :X  a  [        U 5      $ U[        R                  :X  a  [        U 5      $ U[        R                  :X  a  [        U 5      $ U[        R                  :X  a  [        U 5      $ [        SU 35      e)Nz2NYI: PyDispatcher has not implemented support for )r.   r   r   r   rY   rU   r   r   r   r   rq   )r   r.   s     r   coerce_cinterpreterr     s    



C
m   |,,
m   |,,
ml++
m)))'55
KC5Q
RRr   c                  r    [         R                  R                  R                  5       n U c   e[	        U 5      $ r   )rG   rH   rI   rJ   r   )interpreters    r   &retrieve_current_functorch_interpreterr     s1    ((%%<<>K"""{++r   c                      [         R                  R                  R                  5       n U c  / $ U  Vs/ s H  n[	        U5      PM     sn$ s  snf r   )rG   rH   rI   get_interpreter_stackr   )ciscis     r   #retrieve_all_functorch_interpretersr     sB    
((


3
3
5C
{	.12c#c222s   A
states.c                 "   [         R                  R                  R                  5       nUc  [	        U 5      S:w  d  Ub  [	        U 5      S:X  a  g[        5       n[	        U5      [	        U 5      :H  =(       a    [        S [        X 5       5       5      $ )Nr   Fc              3   H   #    U  H  u  pUR                  U5      v   M     g 7fr   )r7   ).0r   r6   s      r   	<genexpr>*compare_functorch_state.<locals>.<genexpr>)  s"      +/?)"u/?s    ")rG   rH   rI   rJ   lenr   allzip)r   peekr   s      r   compare_functorch_stater     s{     88557DV)t/?CKSTDT
-
/Cs8s6{" s +/23/?+ ( r   c                     [        5       n[        R                  " [        R                  [        R
                  R                  R                  X45      u  pUR                  XU5      $ r   )	r   r   r   rG   r   rH   rI   unwrap_if_deadr#   )r    r!   r"   r   s       r   dispatch_functorchr   .  sP    8:K ''ehh))884.LD r00r   )+ry   abcr   r   	functoolsr   typingr   rG   torch.utils._pytreeutils_pytreer   torch._C._functorchr   r   r	   r
   r   r   r   r   r   torch.autograd.forward_adr   r   contextmanagerr&   rN   rS   rU   r~   r   r   r   r   r   rL   r   tupleboolr   r   r   r   r   <module>r      sA    # %   $ $
 
 
 <@3 D ( ( 2 2 & &B* BB  "F* "FJ"J) "JJ/3 /(
Sl 
S7K 
S,0D ,3T2F-G 3DsCx$9 d  
1r   