a
    d.                     @   sl   d dl Z d dl mZ zd dlmZmZ dZW n( eyT   dZdd
dZdd ZY n0 G dd dejZdS )    N)nn)inplace_abninplace_abn_syncTF皙?h㈵>
leaky_relu{Gz?c
           
      C   s   t dd S )Nz`Please install InplaceABN:'pip install git+https://github.com/mapillary/inplace_abn.git@v1.0.12')ImportError)
xweightbiasrunning_meanrunning_vartrainingmomentumepsZ
activationZactivation_param r   `/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/timm/layers/inplace_abn.pyr   
   s    r   c                  K   s   t f i |  d S )N)r   )kwargsr   r   r   r      s    r   c                       s2   e Zd ZdZd fdd		Zd
d Zdd Z  ZS )
InplaceAbna  Activated Batch Normalization

    This gathers a BatchNorm and an activation function in a single module

    Parameters
    ----------
    num_features : int
        Number of feature channels in the input and output.
    eps : float
        Small constant to prevent numerical issues.
    momentum : float
        Momentum factor applied to compute running statistics.
    affine : bool
        If `True` apply learned scale and shift transformation after normalization.
    act_layer : str or nn.Module type
        Name or type of the activation functions, one of: `leaky_relu`, `elu`
    act_param : float
        Negative slope for the `leaky_relu` activation.
    r   r   Tr   r   Nc	           	         s&  t t|   || _|| _|| _|| _|rt|trP|dv s@J |rH|nd| _	q|t
jkrbd| _	q|t
jkrtd| _	q|d u s|t
jkrd| _	qdsJ d|j dnd| _	|| _| jrt
t|| _t
t|| _n| dd  | d	d  | d
t| | dt| |   d S )N)r   eluidentity r   r   r   FzInvalid act layer z	 for IABNr   r   r   r   )superr   __init__num_featuresaffiner   r   
isinstancestract_namer   ZELUZ	LeakyReLUZIdentity__name__	act_param	ParametertorchZonesr   zerosr   Zregister_parameterZregister_bufferreset_parameters)	selfr   r   r   r   Z	apply_actZ	act_layerr!   Z
drop_layer	__class__r   r   r   (   s4    


zInplaceAbn.__init__c                 C   sJ   t j| jd t j| jd | jrFt j| jd t j| jd d S )Nr      )r   initZ	constant_r   r   r   r   r   )r&   r   r   r   r%   J   s
    zInplaceAbn.reset_parametersc                 C   sB   t || j| j| j| j| j| j| j| j| j	
}t
|tr>|d }|S )Nr   )r   r   r   r   r   r   r   r   r   r!   r   tuple)r&   r
   outputr   r   r   forwardQ   s    
zInplaceAbn.forward)r   r   TTr   r   N)r    
__module____qualname____doc__r   r%   r-   __classcell__r   r   r'   r   r      s     "r   )Tr   r   r   r   )	r#   r   Zinplace_abn.functionsr   r   Zhas_iabnr	   Moduler   r   r   r   r   <module>   s    
