Ë
      çi1	  ã                   óŠ   — d dl mZ d dlmZmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d d	lmZmZ  G d
„ de«      Zy)é    )ÚAbstractContextManager)ÚAnyÚLiteralN)Úapply_to_collection)ÚTensor)ÚModule)Úoverride)Ú	Precision)Ú_convert_fp_tensorÚ_DtypeContextManagerc                   óÎ   — e Zd ZU dZdZed   ed<   dded   ddfd„Zede	de	fd	„«       Z
edefd
„«       Zedefd„«       Zedefd„«       Zededefd„«       Zededefd„«       Zy)ÚHalfPrecisionz¦Plugin for training with half precision.

    Args:
        precision: Whether to use ``torch.float16`` (``'16-true'``) or ``torch.bfloat16`` (``'bf16-true'``).

    ú16-true)ú	bf16-truer   Ú	precisionÚreturnNc                 ór   — || _         |dk(  rt        j                  | _        y t        j                  | _        y )Nr   )r   ÚtorchÚbfloat16Úfloat16Ú_desired_input_dtype)Úselfr   s     ú|/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/lightning_fabric/plugins/precision/half.pyÚ__init__zHalfPrecision.__init__%   s*   € Ø"ˆŒØ6?À;Ò6N¤E§N¡NˆÕ!ÔTY×TaÑTaˆÕ!ó    Úmodulec                 ó:   — |j                  | j                  ¬«      S )N)Údtype)Útor   )r   r   s     r   Úconvert_modulezHalfPrecision.convert_module)   s   € à�y‰y˜t×8Ñ8ˆyÓ9Ð9r   c                 ó,   — t        | j                  «      S ©N)r   r   ©r   s    r   Útensor_init_contextz!HalfPrecision.tensor_init_context-   s   € ä# D×$=Ñ$=Ó>Ð>r   c                 ó"   — | j                  «       S r"   ©r$   r#   s    r   Úmodule_init_contextz!HalfPrecision.module_init_context1   ó   € à×'Ñ'Ó)Ð)r   c                 ó"   — | j                  «       S r"   r&   r#   s    r   Úforward_contextzHalfPrecision.forward_context5   r(   r   Údatac                 óD   — t        |t        t        | j                  ¬«      S ©N)Úfunctionr   Údst_type)r   r   r   r   ©r   r+   s     r   Úconvert_inputzHalfPrecision.convert_input9   s   € ä" 4Ô2DÌFÐ]a×]vÑ]vÔwÐwr   c                 óT   — t        |t        t        t        j                  «       ¬«      S r-   )r   r   r   r   Úget_default_dtyper0   s     r   Úconvert_outputzHalfPrecision.convert_output=   s   € ä" 4Ô2DÌFÔ]b×]tÑ]tÓ]vÔwÐwr   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__annotations__r   r	   r   r    r   r$   r'   r*   r   r1   r4   © r   r   r   r      sø   … ñð 2;€IˆwÐ-Ñ.Ó:ñb 'Ð*@Ñ"Að bÐRVó bð ð: Vð :°ò :ó ð:ð ð?Ð%;ò ?ó ð?ð ð*Ð%;ò *ó ð*ð ð*Ð!7ò *ó ð*ð ðx #ð x¨#ò xó ðxð ðx 3ð x¨3ò xó ñxr   r   )Ú
contextlibr   Útypingr   r   r   Ú#lightning_utilities.core.apply_funcr   r   Útorch.nnr   Útyping_extensionsr	   Ú,lightning_fabric.plugins.precision.precisionr
   Ú(lightning_fabric.plugins.precision.utilsr   r   r   r:   r   r   Ú<module>rB      s0   ðõ .ß ã Ý CÝ Ý Ý &å Bß ]ô$x�Iõ $xr   