ó
    oM‡jo  ã                   óü  • S SK r S SKJs  Jr  S SK Jr  SSKJr  SSKJrJ	r	  \" 5       (       a  S SK
r
\R                  \R                  \R                  \R                  \R                  S.rS\S\R"                  4S	 jr " S
 S\R"                  5      r " S S\R"                  5      r " S S\R"                  5      r " S S\R"                  5      r " S S\R"                  5      r " S S\R"                  5      rg)é    N)Únné   )Ú	deprecate)Úis_torch_npu_availableÚis_torch_version)ÚswishÚsiluÚmishÚgeluÚreluÚact_fnÚreturnc           	      óª   • U R                  5       n U [        ;   a  [        U    " 5       $ [        SU  S[        [        R	                  5       5       35      e)zœHelper function to get activation function from string.

Args:
    act_fn (str): Name of activation function.

Returns:
    nn.Module: Activation function.
zactivation function z not found in ACT2FN mapping )ÚlowerÚACT2CLSÚ
ValueErrorÚlistÚkeys)r   s    ÚªC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\diffusers/models/activations.pyÚget_activationr   $   sO   € ð �\‰\‹^€FØ”ÓÜ�vŠÓ Ð äÐ/°¨xÐ7TÔUYÔZa×ZfÑZfÓZhÓUiÐTjÐkÓlÐló    c                   óf   ^ • \ rS rSrSrU 4S jrS\R                  S\R                  4S jrSr	U =r
$ )ÚFP32SiLUé5   z@
SiLU activation function with input upcasted to torch.float32.
c                 ó"   >• [         TU ]  5         g ©N)ÚsuperÚ__init__)ÚselfÚ	__class__s    €r   r   ÚFP32SiLU.__init__:   s   ø€ Ü‰ÑÕr   Úinputsr   c                 óz   • [         R                  " UR                  5       SS9R                  UR                  5      $ )NF)Úinplace)ÚFr	   ÚfloatÚtoÚdtype)r   r"   s     r   ÚforwardÚFP32SiLU.forward=   s(   € Ü�vŠv�f—l‘l“n¨eÑ4×7Ñ7¸¿¹ÓEÐEr   © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚtorchÚTensorr)   Ú__static_attributes__Ú__classcell__©r    s   @r   r   r   5   s1   ø† ñõðF˜eŸl™lð F¨u¯|©|÷ Fò Fr   r   c            	       ó„   ^ • \ rS rSrSrSS\S\S\S\4U 4S jjjrS\	R                  S	\	R                  4S
 jrS rSrU =r$ )ÚGELUéA   a†  
GELU activation function with tanh approximation support with `approximate="tanh"`.

Parameters:
    dim_in (`int`): The number of channels in the input.
    dim_out (`int`): The number of channels in the output.
    approximate (`str`, *optional*, defaults to `"none"`): If `"tanh"`, use tanh approximation.
    bias (`bool`, defaults to True): Whether to use a bias in the linear layer.
Údim_inÚdim_outÚapproximateÚbiasc                 ób   >• [         TU ]  5         [        R                  " XUS9U l        X0l        g ©N©r<   )r   r   r   ÚLinearÚprojr;   )r   r9   r:   r;   r<   r    s        €r   r   ÚGELU.__init__L   s&   ø€ Ü‰ÑÔÜ—I’I˜f°DÑ9ˆŒ	Ø&Õr   Úgater   c                 ó6  • UR                   R                  S:X  ab  [        SS5      (       aQ  [        R                  " UR                  [        R                  S9U R                  S9R                  UR                  S9$ [        R                  " XR                  S9$ )NÚmpsÚ<ú2.0.0©r(   )r;   )
ÚdeviceÚtyper   r%   r   r'   r1   Úfloat32r;   r(   ©r   rC   s     r   r   Ú	GELU.geluQ   sq   € Ø�;‰;×Ñ˜uÓ$Ô)9¸#¸w×)GÑ)Gä—6’6˜$Ÿ'™'¬¯©˜'Ð6ÀD×DTÑDTÑU×XÑXÐ_c×_iÑ_iÐXÐjÐjÜ�vŠv�d×(8Ñ(8Ñ9Ð9r   c                 óJ   • U R                  U5      nU R                  U5      nU$ r   )rA   r   ©r   Úhidden_statess     r   r)   ÚGELU.forwardW   s$   € ØŸ	™	 -Ó0ˆØŸ	™	 -Ó0ˆØÐr   )r;   rA   )ÚnoneT)r,   r-   r.   r/   r0   ÚintÚstrÚboolr   r1   r2   r   r)   r3   r4   r5   s   @r   r7   r7   A   sT   ø† ññ'˜sð '¨Sð '¸sð 'ÐSW÷ 'ð 'ð
:˜Ÿ™ð :¨%¯,©,ô :÷ð r   r7   c                   ó€   ^ • \ rS rSrSrSS\S\S\4U 4S jjjrS\R                  S\R                  4S	 jr
S
 rSrU =r$ )ÚGEGLUé]   a6  
A [variant](https://huggingface.co/papers/2002.05202) of the gated linear unit activation function.

Parameters:
    dim_in (`int`): The number of channels in the input.
    dim_out (`int`): The number of channels in the output.
    bias (`bool`, defaults to True): Whether to use a bias in the linear layer.
r9   r:   r<   c                 ó\   >• [         TU ]  5         [        R                  " XS-  US9U l        g ©Nr   r?   ©r   r   r   r@   rA   ©r   r9   r:   r<   r    s       €r   r   ÚGEGLU.__init__g   s$   ø€ Ü‰ÑÔÜ—I’I˜f°¡k¸Ñ=ˆ�	r   rC   r   c                 ó  • UR                   R                  S:X  aY  [        SS5      (       aH  [        R                  " UR                  [        R                  S95      R                  UR                  S9$ [        R                  " U5      $ )NrE   rF   rG   rH   )	rI   rJ   r   r%   r   r'   r1   rK   r(   rL   s     r   r   Ú
GEGLU.geluk   s_   € Ø�;‰;×Ñ˜uÓ$Ô)9¸#¸w×)GÑ)Gä—6’6˜$Ÿ'™'¬¯©˜'Ð6Ó7×:Ñ:ÀÇÁÐ:ÐLÐLÜ�vŠv�d‹|Ðr   c                 ó   • [        U5      S:”  d  UR                  SS 5      b  Sn[        SSU5        U R                  U5      n[	        5       (       a  [
        R                  " USSS9S   $ UR                  SSS	9u  pXR                  U5      -  $ )
Nr   ÚscalezðThe `scale` argument is deprecated and will be ignored. Please remove it, as passing it will raise an error in the future. `scale` should directly be passed while calling the underlying pipeline component i.e., via `cross_attention_kwargs`.z1.0.0éÿÿÿÿé   )Údimr;   r   ©rd   )	ÚlenÚgetr   rA   r   Ú	torch_npuÚ	npu_gegluÚchunkr   )r   rP   ÚargsÚkwargsÚdeprecation_messagerC   s         r   r)   ÚGEGLU.forwardq   s�   € Üˆt‹9�q‹=˜FŸJ™J w°Ó5ÑAð #UÐÜ�g˜wÐ(;Ô<ØŸ	™	 -Ó0ˆÜ!×#Ñ#ä×&Ò& }¸"È!ÑLÈQÑOÐOà"/×"5Ñ"5°a¸RÐ"5Ð"@ÑˆMØ §9¡9¨T£?Ñ2Ð2r   ©rA   ©T)r,   r-   r.   r/   r0   rS   rU   r   r1   r2   r   r)   r3   r4   r5   s   @r   rW   rW   ]   sL   ø† ññ>˜sð >¨Sð >¸÷ >ð >ð˜Ÿ™ð ¨%¯,©,ô ÷
3ð 
3r   rW   c                   óF   ^ • \ rS rSrSrS	S\S\S\4U 4S jjjrS rSr	U =r
$ )
ÚSwiGLUé~   au  
A [variant](https://huggingface.co/papers/2002.05202) of the gated linear unit activation function. It's similar to
`GEGLU` but uses SiLU / Swish instead of GeLU.

Parameters:
    dim_in (`int`): The number of channels in the input.
    dim_out (`int`): The number of channels in the output.
    bias (`bool`, defaults to True): Whether to use a bias in the linear layer.
r9   r:   r<   c                 ó�   >• [         TU ]  5         [        R                  " XS-  US9U l        [        R
                  " 5       U l        g rZ   )r   r   r   r@   rA   ÚSiLUÚ
activationr\   s       €r   r   ÚSwiGLU.__init__‰   s1   ø€ Ü‰ÑÔä—I’I˜f°¡k¸Ñ=ˆŒ	ÜŸ'š'›)ˆ�r   c                 ón   • U R                  U5      nUR                  SSS9u  pXR                  U5      -  $ )Nr   rb   re   )rA   rj   rv   )r   rP   rC   s      r   r)   ÚSwiGLU.forward�   s:   € ØŸ	™	 -Ó0ˆØ+×1Ñ1°!¸Ð1Ð<ÑˆØŸ™¨tÓ4Ñ4Ð4r   ©rv   rA   rp   )r,   r-   r.   r/   r0   rS   rU   r   r)   r3   r4   r5   s   @r   rr   rr   ~   s1   ø† ññ$˜sð $¨Sð $¸÷ $ð $÷5ð 5r   rr   c                   óz   ^ • \ rS rSrSrSS\S\S\4U 4S jjjrS\R                  S\R                  4S	 jr
S
rU =r$ )ÚApproximateGELUé•   al  
The approximate form of the Gaussian Error Linear Unit (GELU). For more details, see section 2 of this
[paper](https://huggingface.co/papers/1606.08415).

Parameters:
    dim_in (`int`): The number of channels in the input.
    dim_out (`int`): The number of channels in the output.
    bias (`bool`, defaults to True): Whether to use a bias in the linear layer.
r9   r:   r<   c                 óV   >• [         TU ]  5         [        R                  " XUS9U l        g r>   r[   r\   s       €r   r   ÚApproximateGELU.__init__    s    ø€ Ü‰ÑÔÜ—I’I˜f°DÑ9ˆ�	r   Úxr   c                 ó\   • U R                  U5      nU[        R                  " SU-  5      -  $ )Ng¬Zd;û?)rA   r1   Úsigmoid)r   r€   s     r   r)   ÚApproximateGELU.forward¤   s'   € Ø�I‰I�a‹LˆØ”5—=’= ¨¡Ó+Ñ+Ð+r   ro   rp   )r,   r-   r.   r/   r0   rS   rU   r   r1   r2   r)   r3   r4   r5   s   @r   r|   r|   •   sG   ø† ññ:˜sð :¨Sð :¸÷ :ð :ð,˜Ÿ™ð ,¨%¯,©,÷ ,ò ,r   r|   c            	       óF   ^ • \ rS rSrS	S\S\S\S\4U 4S jjjrS rSr	U =r
$ )
ÚLinearActivationé©   r9   r:   r<   rv   c                 óv   >• [         TU ]  5         [        R                  " XUS9U l        [        U5      U l        g r>   )r   r   r   r@   rA   r   rv   )r   r9   r:   r<   rv   r    s        €r   r   ÚLinearActivation.__init__ª   s,   ø€ Ü‰ÑÔä—I’I˜f°DÑ9ˆŒ	Ü(¨Ó4ˆ�r   c                 óF   • U R                  U5      nU R                  U5      $ r   )rA   rv   rO   s     r   r)   ÚLinearActivation.forward°   s   € ØŸ	™	 -Ó0ˆØ�‰˜}Ó-Ð-r   rz   )Tr	   )r,   r-   r.   r/   rS   rU   rT   r   r)   r3   r4   r5   s   @r   r…   r…   ©   s4   ø† ñ5˜sð 5¨Sð 5¸ð 5ÐQT÷ 5ð 5÷.ð .r   r…   )r1   Útorch.nn.functionalr   Ú
functionalr%   Úutilsr   Úutils.import_utilsr   r   rh   ru   ÚMishr7   ÚReLUr   rT   ÚModuler   r   rW   rr   r|   r…   r+   r   r   Ú<module>r’      sÐ   ðó  ß Ð Ý å ß Iñ ×ÑÛð �W‰WØ�G‰GØ�G‰GØ�G‰GØ�G‰Gñ€ðm˜3ð m 2§9¡9ô mô"	Fˆr�y‰yô 	Fôˆ2�9‰9ô ô83ˆB�I‰Iô 3ôB5ˆR�Y‰Yô 5ô.,�b—i‘iô ,ô(	.�r—y‘yõ 	.r   