
    3j                     `   S SK r S SKrS SKrS SKJr  S\R
                  S\S\S\S\4
S jr    SS\R
                  S\S\S\S\S	\R
                  4S
 jjr    SS\R
                  S\S\S\S\S	\R
                  4S jjr	   SS\R
                  S\S\
S\
4S jjrS\R
                  4S jrg)    N)_calculate_fan_in_and_fan_outtensormeanstdabc                    S[         4S jnXSU-  -
  :  d  XSU-  -   :  a  [        R                  " SSS9  [        R                  " 5          U" X1-
  U-  5      nU" XA-
  U-  5      nU R                  SU-  S-
  SU-  S-
  5        U R                  5         U R                  U[        R                  " S5      -  5        U R                  U5        U R                  X4S9  U sS S S 5        $ ! , (       d  f       g = f)	Nxc                 h    S[         R                  " U [         R                  " S5      -  5      -   S-  $ )N      ?       @)matherfsqrt)r
   s    Z/home/wildlama/miniconda3/lib/python3.13/site-packages/spandrel/util/timm/__weight_init.pynorm_cdf(_no_grad_trunc_normal_.<locals>.norm_cdf   s(    dhhq499S>122c99       zjmean is more than 2 std from [a, b] in nn.init.trunc_normal_. The distribution of values may be incorrect.)
stacklevel   r   )minmax)floatwarningswarntorchno_graduniform_erfinv_mul_r   r   add_clamp_)r   r   r   r   r   r   lus           r   _no_grad_trunc_normal_r&      s    
:E : 	1s7{1s7{ 2;	
 
 ah#%&ah#%& 	A	1q519- 	 	C$))C.()D 	!#+ 
s   BC((
C6returnc                     [        XX#U5      $ )ak  
Fills the input Tensor with values drawn from a truncated
normal distribution. The values are effectively drawn from the
normal distribution :math:`\mathcal{N}(\text{mean}, \text{std}^2)`
with values outside :math:`[a, b]` redrawn until they are within
the bounds. The method used for generating the random values works
best when :math:`a \leq \text{mean} \leq b`.

NOTE: this impl is similar to the PyTorch `trunc_normal_`, the bounds [a, b] are
applied while sampling the normal with mean/std applied, therefore a, b args
should be adjusted to match the range of mean, std args.

Args:
    tensor: an n-dimensional `torch.Tensor`
    mean: the mean of the normal distribution
    std: the standard deviation of the normal distribution
    a: the minimum cutoff value
    b: the maximum cutoff value
Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.trunc_normal_(w)
)r&   r   r   r   r   r   s        r   trunc_normal_r*   0   s    : "&::r   c                     [        U SSX45        [        R                  " 5          U R                  U5      R	                  U5        SSS5        U $ ! , (       d  f       U $ = f)a}  Fills the input Tensor with values drawn from a truncated
normal distribution. The values are effectively drawn from the
normal distribution :math:`\mathcal{N}(\text{mean}, \text{std}^2)`
with values outside :math:`[a, b]` redrawn until they are within
the bounds. The method used for generating the random values works
best when :math:`a \leq \text{mean} \leq b`.

NOTE: this 'tf' variant behaves closer to Tensorflow / JAX impl where the
bounds [a, b] are applied when sampling the normal distribution with mean=0, std=1.0
and the result is subsquently scaled and shifted by the mean and std args.

Args:
    tensor: an n-dimensional `torch.Tensor`
    mean: the mean of the normal distribution
    std: the standard deviation of the normal distribution
    a: the minimum cutoff value
    b: the maximum cutoff value
Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.trunc_normal_(w)
r   r   N)r&   r   r   r!   r"   r)   s        r   trunc_normal_tf_r,   P   sI    8 61c10	Cd# 
M 
Ms   !A
Ascalemodedistributionc                    [        U 5      u  pEUS:X  a  UnOUS:X  a  UnOUS:X  a  XE-   S-  nUW-  nUS:X  a"  [        U [        R                  " U5      S-  S9  g US:X  a$  U R	                  [        R                  " U5      S9  g US	:X  a-  [        R                  " S
U-  5      nU R                  U* U5        g [        SU 35      e)Nfan_infan_outfan_avgr   truncated_normalg۶%?)r   normaluniform   zinvalid distribution )r   r,   r   r   normal_r   
ValueError)	r   r-   r.   r/   r1   r2   denomvariancebounds	            r   variance_scaling_r=   r   s     4F;OFx				!Q&u}H))TYYx%8;N%NO		!499X./		"		!h,'&0?@@r   c                     [        U SSS9  g )Nr1   r4   )r.   r/   )r=   )r   s    r   lecun_normal_r?      s    f8:LMr   )g        r   g       r   )r   r1   r5   )r   r   r   torch.nn.initr   Tensorr   r&   r*   r,   strr=   r?    r   r   <module>rD      s:      7%LL% %%,1%6;%@E%T ;LL;
; 
; 	;
 ; \\;D LL
 
 	
  \\H  	ALLAA A 	A:N%,, Nr   