
    eThQ                     F   S SK r S SKrS SKJr   S SKrS rS rS rS rS	 rS
 rSS jr\" \R&                  R(                  5      \" S5      :  a  S r\R,                  R.                  r\rO\r\r\\\\\\\\R,                  R2                  \R,                  R4                  \R,                  R6                  \R,                  R6                  \R,                  R8                  S.rS rg! \\4 a0    S SKr\" \R                  5      R                  S:  a  \" S5      e GNf = f)    N)parse   zYour currently installed version of Keras is Keras 3, but this is not yet supported in Transformers. Please install the backwards-compatible tf-keras package with `pip install tf-keras`.c           
          [         R                  " U 5      n SS[         R                  R                  U [         R                  " [         R
                  " S5      U R                  5      -  5      -   -  nX-  $ )ab  
Gaussian Error Linear Unit. Original Implementation of the gelu activation function in Google Bert repo when
initially created. For information: OpenAI GPT's gelu is slightly different (and gives slightly different results):
0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) Also see
https://arxiv.org/abs/1606.08415
      ?      ?       @)tfconvert_to_tensormatherfcastsqrtdtype)xcdfs     S/var/www/auris/envauris/lib/python3.13/site-packages/transformers/activations_tf.py_gelur   "   sS     	QA
rww{{1rwwrwws|QWW'E#EFF
GC7N    c                 v   [         R                  " U 5      n [         R                  " [        R                  U R
                  5      n[         R                  " SU R
                  5      nSS[         R                  " [         R                  " SU-  5      X[         R                  " U S5      -  -   -  5      -   -  nX-  $ )z
Gaussian Error Linear Unit. This is a smoother version of the GELU. Original paper: https://arxiv.org/abs/1606.0841

Args:
    x: float Tensor to perform activation

Returns:
    `x` with the GELU activation applied.
Hm?r   r   r      )	r	   r
   r   r   pir   tanhr   pow)r   r   coeffr   s       r   	_gelu_newr   /   s     	QA	!''	"BGGHagg&E
rwwrwwsRx0Aq!8L4LMNN
OC7Nr   c                     [         R                  " U 5      n U [         R                  " [         R                  R	                  U 5      5      -  $ )N)r	   r
   r   r   softplusr   s    r   mishr    A   s5    
QArwwrww''*+++r   c                 
   [         R                  " U 5      n [         R                  " SU R                  5      n[         R                  " SU R                  5      nSU -  S[         R                  " X-  SX-  U -  -   -  5      -   -  $ )Nr   g3E?r   r   )r	   r
   r   r   r   )r   coeff1coeff2s      r   	gelu_fastr$   G   si    
QAWWXqww'FWW\177+F7cBGGAJ#
Q2F$GHHIIr   c                     [         R                  " U 5      n [         R                  " SU R                  5      nU [         R                  R                  X-  5      -  $ )NgZd;?)r	   r
   r   r   r   sigmoid)r   r   s     r   
quick_gelur'   O   s@    
QAGGE177#Erwwuy)))r   c                 D    [         R                  " [        U 5      SS5      $ )ax  
Clip the range of possible GeLU outputs between [-10, 10]. This is especially useful for quantization purpose, as
it allows mapping 2 negatives values in the GeLU spectrum. For more information on this trick, please refer to
https://arxiv.org/abs/2004.09602

Gaussian Error Linear Unit. Original Implementation of the gelu activation function in Google Bert repo when
initially created. For information: OpenAI GPT's gelu is slightly different (and gives slightly different results):
0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) Also see
https://arxiv.org/abs/1606.08415 :param x: :return:
i
   )r	   clip_by_valuer   r   s    r   gelu_10r+   U   s     E!Hc2..r   c                 v    [         R                  " U SUS9u  p#U[         R                  R                  U5      -  $ )a  
Gated Linear Unit. Implementation as defined in the original paper (see https://arxiv.org/abs/1612.08083), where
the input `x` is split in two halves across a dimension (`axis`), A and B, returning A * sigmoid(B).

Args:
    `x`: float Tensor to perform activation
    `axis`: dimension across which `x` be split in half

Returns:
    `x` with the GLU activation applied (with its size halved across the dimension `axis`).
r   )axis)r	   splitr   r&   )r   r-   abs       r   glur1   c   s0     88Aqt$DArwwq!!!r   z2.4c                 >    [         R                  R                  U SS9$ )NT)approximate)kerasactivationsgelur   s    r   approximate_gelu_wrapr7   u   s      %%aT%::r   )r6   r+   r$   gelu_newr1   r    r'   relur&   siluswishr   c           	          U [         ;   a	  [         U    $ [        SU  S[        [         R                  5       5       35      e)Nz	function z not found in ACT2FN mapping )ACT2FNKeyErrorlistkeys)activation_strings    r   get_tf_activationrB      sB    F"'((#4"55RSWX^XcXcXeSfRghiir   ))r   
tensorflowr	   packaging.versionr   tf_kerasr4   ModuleNotFoundErrorImportError__version__major
ValueErrorr   r   r    r$   r'   r+   r1   versionVERSIONr7   r5   r6   r8   r9   r&   r;   r   r=   rB    r   r   <module>rO      s9     #


$,J*/"  			e,; !!D$HDH ""  ((##$$""
 jq 	[) 
U%%)&
 	
 *
s   C( (4D D 