
    [Th$                        S SK r S SKJrJrJrJr  S SKJr  S SKrS SKJ	r	  S SK
JrJrJr  \\\4   r\\\\S4   4   rS\\\      S\S	\4S
 jrS\\	\\	S4   4   S	\4S jrS\S\S\/ \4   S	\4S jrS\S\S\S\S	\\\4   4
S jr S"S\\	\\	S4   4   S\S\S\S\S\S	\4S jjrS\S\S	S4S jrS\S\S	S4S jrS\4S jr\" S\S9S#S\S\S\S	\4S  jj5       r   S$S\S\S\S\S	\4
S! jjrg)%    N)AnyCallableOptionalUnion)
deprecated)Tensor)_broadcast_to_and_flattentree_flattentree_unflatten.flat_in_dims	flat_argsreturnc                    ^ [        X5       VVs/ s H  u  p#Uc  M
  UR                  U5      PM     snnmT(       a)  [        U4S jT 5       5      (       a  [        ST S35      eTS   $ s  snnf )Nc              3   2   >#    U  H  oTS    :g  v   M     g7f)r   N ).0sizebatch_sizess     M/var/www/auris/envauris/lib/python3.13/site-packages/torch/_vmap_internals.py	<genexpr>/_validate_and_get_batch_size.<locals>.<genexpr>   s     Jkd;q>1ks   zTvmap: Expected all tensors to have the same size in the mapped dimension, got sizes z for the mapped dimensionr   )zipr   any
ValueError)r   r   in_dimargr   s       @r   _validate_and_get_batch_sizer      s}     |77KF 	7K
 sJkJJJ$$/=0IK
 	
 q>s
   	A+A+batched_outputsc                 D    [        U [        5      (       a  [        U 5      $ g)N   )
isinstancetuplelen)r   s    r   _num_outputsr$   !   s    /5))?##    valuenum_elementserror_message_lambdac                 z    [        U [        5      (       d  U 4U-  $ [        U 5      U:w  a  [        U" 5       5      eU $ N)r!   r"   r#   r   )r&   r'   r(   s      r   	_as_tupler+   )   s>    
 eU##x,&&
5z\!-/00Lr%   in_dimsargs
vmap_levelfuncc                 (   [        U [        5      (       d<  [        U [        5      (       d'  [        S[	        U5       SU  S[        U 5       S35      e[        U5      S:X  a  [        S[	        U5       S35      e[        U5      u  pE[        X5      nUc-  [        S[	        U5       SU  S[        U 5      S    S	U S3	5      e[        XF5       H  u  px[        U[        5      (       d!  Ub  [        S[	        U5       SU  S
U S35      e[        U[        5      (       a?  [        U[        5      (       d*  [        S[	        U5       SU  S
U S[        U5       S3	5      eUc  M  US:  d  XR                  5       :  d  M  [        S[	        U5       SU  S
U SUR                  5        SUR                  5        S35      e   [        Xd5      n	[        Xd5       VVs/ s H!  u  pUc  UO[        R                  " XxU5      PM#     n
nn[        X5      U	4$ s  snnf )Nvmap(z
, in_dims=zv, ...)(<inputs>): expected `in_dims` to be int or a (potentially nested) tuple matching the structure of inputs, got: .r   z)(<inputs>): got no inputs. Maybe you forgot to add inputs, or you are trying to vmap over a function with no inputs. The latter is unsupported.zb, ...)(<inputs>): in_dims is not compatible with the structure of `inputs`. in_dims has structure r    z but inputs has structure z, ...)(<inputs>): Got in_dim=zE for an input but in_dim must be either an integer dimension or None.z' for an input but the input is of type zT. We cannot vmap over non-Tensor arguments, please use None as the respective in_dimz> for some input, but that input is a Tensor of dimensionality z- so expected in_dim to satisfy 0 <= in_dim < )r!   intr"   r   	_get_nametyper#   r
   r	   r   r   dimr   torch_add_batch_dimr   )r,   r-   r.   r/   r   	args_specr   r   r   
batch_sizebatched_inputss              r   _create_batched_inputsr<   7   sc    gs##Jw,F,FIdO$Jwi 866:7m_AG
 	

 4yA~IdO$ %) *
 	
 (-I,W@LIdO$Jwi 8%%1'%:1%=$> ?&Kq*
 	
 93&#&&6+=	$(
7) <$X &01 
 fc"":c6+B+B	$(
7) <$X%L9+ ;<  6A:7791D	$(
7) <$X &%%(WWYK 0!!$1.  4, .lFJ |77KF ~5#7#7Z#PP7   .4j@@	s   (Hout_dimsr:   allow_none_pass_throughc                 8  ^^^^^ [        U 5      m[        TTUUU4S j5      n[        U [        5      (       a  US   n[        R
                  " U TTU5      $ U(       a  [        UU4S j[        X5       5       5      $ [        UU4S j[        X5       5       5      $ )Nc            
      F   > S[        T 5       ST ST S[        T 5       S3	$ )Nr1   , ..., out_dims=z0): `out_dims` must have one dim per output (got z outputs) of r2   )r4   )r/   num_outputsr=   s   r   <lambda>!_unwrap_batched.<locals>.<lambda>   s4    %	$((8
 C((3}M)D/ARRSUr%   r   c              3   d   >#    U  H%  u  pUb  [         R                  " UTTU5      OS v   M'     g 7fr*   r7   _remove_batch_dimr   outout_dimr:   r.   s      r   r   "_unwrap_batched.<locals>.<genexpr>   s@      
 !H ? ''ZWM !Hs   -0c              3   Z   >#    U  H   u  p[         R                  " UTTU5      v   M"     g 7fr*   rF   rH   s      r   r   rK      s.      
 G ##CZII Gs   (+)r$   r+   r!   r   r7   rG   r"   r   )	r   r=   r.   r:   r/   r>   out_dims_as_tuplerJ   rB   s	    ````   @r   _unwrap_batchedrN   t   s     /K!	U /6**#A&&&
JPWXX 
 !$O G
 
 	
  
 #O G
 
 	
r%   outputsc                 r   [        U [        5      (       a  g [        U [        5      (       d0  [        S[	        U5       S[	        U5       S[        U 5       S35      e[        U 5       HM  u  p#[        U[        5      (       a  M  [        S[	        U5       S[	        U5       S[        U5       SU S3	5      e   g )Nr1   z	, ...): `z%` must only return Tensors, got type z as the return.z for return r2   )r!   r   r"   r   r4   r5   	enumerate)rO   r/   idxoutputs       r   _validate_outputsrT      s    '6""gu%%IdO$Iio-> ?!!%g@
 	
 !)ff%%IdO$Iio-> ?!!%fl3%qB
 	
 *r%   c                     [        U [        5      (       a  g [        U [        5      (       a  [        S U  5       5      (       d  [	        S[        U5       SU  S35      eg )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fr*   )r!   r3   )r   rJ   s     r   r   6_check_out_dims_is_int_or_int_tuple.<locals>.<genexpr>   s      208W
7C  s   r1   rA   zu): `out_dims` must be an int or a tuple of int representing where in the outputs the vmapped dimension should appear.)r!   r3   r"   allr   r4   )r=   r/   s     r   #_check_out_dims_is_int_or_int_tuplerY      si    (C  h&&c 2082 / / IdO$$4XJ ?/ 0
 	
/r%   c                 R    [        U S5      (       a  U R                  $ [        U 5      $ )N__name__)hasattrr[   repr)r/   s    r   r4   r4      s%    tZ  }}
 :r%   z@Please use `torch.vmap` instead of `torch._vmap_internals.vmap`.)categoryc                     [        XU5      $ )z,
Please use torch.vmap instead of this API.
)_vmap)r/   r,   r=   s      r   vmapra      s     ))r%   c                 R   ^ ^^^ [         R                  " T 5      UU UU4S j5       nU$ )Nc            	      F  > [        TT5        [        R                  R                  5       n [	        TXT5      u  p#T" U6 nT(       d  [        UT5        [        UTUUTTS9[        R                  R                  5         $ ! [        R                  R                  5         f = f)N)r>   )rY   r7   _C_vmapmode_increment_nestingr<   rT   rN   _vmapmode_decrement_nesting)	r-   r.   r;   r:   r   r>   r/   r,   r=   s	        r   wrapped_vmap.<locals>.wrapped   s    +Hd;XX99;
	3)?4*&N #N3O*!/48"(? HH002EHH002s   4B    B )	functoolswraps)r/   r,   r=   r>   rg   s   ```` r   r`   r`      s'     __T3 3* Nr%   )F)r   r   )r   r   F) ri   typingr   r   r   r   typing_extensionsr   r7   r   torch.utils._pytreer	   r
   r   r3   r"   	in_dims_t
out_dims_tlistr   r$   strr+   r<   boolrN   rT   rY   r4   FutureWarningra   r`   r   r%   r   <module>rt      s!    1 1 (   W W #u*	3c3h'(
x}% 	"%fck0B(B"C  			 #2s7+	 		9A9A
9A 9A 	9A
 5#:9AF %*#
65#556#
#
 #
 	#

 #
 "#
 #
T
s 
( 
t 
"

* 

H 

QU 

H  F*x *) *: *h *	* $)	 
     "	 
  r%   