+
    "Ý³j<  ã                   óÚ  a € R t0 t ^ RIt^ RIt^ RIHt ^ RIHtHt ^ RIt^ RI	H
t
 ]P                  ! 4       t] ^ k  ! R R]P                  4      t ! R R]P                  4      t] ! R	 R
4      4       t]! 4       t]P$                  t]P&                  t]! RR7       ! R R4      4       t]! RR7       ! R R4      4       t ! R R]P                  4      t]! RR7       ! R R4      4       tR# )é    N)Ú	dataclass)ÚOptionalÚUnion)Úis_MI300c                   ó2   a € ] tR t^t o RtRtRtR tRtV t	R# )ÚScalingTypezç
Defines the type of scaling to use for casting to float8.

Values:

* ``DYNAMIC``: Compute scaling factor dynamically based on the tensor's values.
* ``DISABLED``: Skip scaling for this tensor, leave it in its original precision.
ÚdynamicÚdisabledc                ó^   € V \         P                  J d   R # V \         P                  J g   Q hR# )ÚdynÚdis)r   ÚDYNAMICÚDISABLED©Úselfs   &ÚV/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/float8/config.pyÚ	short_strÚScalingType.short_str"   s*   € Ø”;×&Ñ&Ó&Ùàœ;×/Ñ/Ó/Ð/Ð/Ùó    © N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r   r      s"   ø‡ € ñð €Gð €H÷ð r   r   c                   ó2   a € ] tR t^*t o RtRtRtR tRtV t	R# )ÚScalingGranularityzê
Defines the granularity of scaling strategies for casting to float8.

Values:

* ``TENSORWISE``: A single scaling factor for the entire tensor.
* ``AXISWISE``: Scaling factors computed along one axis of the tensor (rowwise scaling).
Ú
tensorwiseÚaxiswisec                ó^   € V \         P                  J d   R # V \         P                  J g   Q hR# )ÚtenÚaxs)r!   Ú
TENSORWISEÚAXISWISEr   s   &r   r   ÚScalingGranularity.short_str:   s,   € ØÔ%×0Ñ0Ó0ÙàÔ-×6Ñ6Ó6Ð6Ð6Ùr   r   N)
r   r   r   r   r   r'   r(   r   r   r   r   s   @r   r!   r!   *   s"   ø‡ € ñð €Jð €H÷ð r   r!   c                   óZ   a € ] tR t^Bt o Rt]P                  t]P                  t	R t
RtV tR# )ÚFloat8TypeConfigz¾
Configuration for selecting the preferred float8 type pair, either e4m3fn/e5m2 or e4m3fnuz/e5m2fnuz.

Currently, ROCm supports 1. fnuz variants in MI300. 2. OCP F8 variants in MI350/Navi4.
c                ó  € \         P                  P                  '       de   \         P                  P	                  4       '       d?   \        4       '       d-   \         P                  V n        \         P                  V n	        R # R # R # R # )N)
ÚtorchÚversionÚhipÚcudaÚis_availabler   Úfloat8_e4m3fnuzÚ
e4m3_dtypeÚfloat8_e5m2fnuzÚ
e5m2_dtyper   s   &r   Ú__post_init__ÚFloat8TypeConfig.__post_init__P   sQ   € Ü�=‰=××Ð¤§¡×!8Ñ!8×!:Ò!:¼x¿zºzÜ#×3Ñ3ˆDŒOÜ#×3Ñ3ˆDŽOñ @JÑ!:Ñr   )r3   r5   N)r   r   r   r   r   r-   Úfloat8_e4m3fnr3   Úfloat8_e5m2r5   r6   r   r   r   s   @r   r+   r+   B   s.   ø‡ € ñð ×$Ñ$€Jð ×"Ñ"€J÷4ð 4r   r+   T)Úfrozenc                   óp   a € ] tR t^\t o Rt]P                  t]P                  t
RtR tR tV 3R ltRtV tR# )Ú
CastConfiga¾  
Configuration for casting a single tensor to float8.

Args:
    scaling_type: The type of scaling to use. See :class:`ScalingType`.
        Default: ``ScalingType.DYNAMIC``
    scaling_granularity: The granularity of scaling. See :class:`ScalingGranularity`.
        Default: ``ScalingGranularity.TENSORWISE``
    target_dtype: The target float8 dtype (e.g., ``torch.float8_e4m3fn``).
        Default: ``None`` (will be set based on the recipe)
Nc                ó´   € \         R \        R/V P                  ,          pV P                  P	                  4        RV P
                  P	                  4        RV 2# )Úe4m3Úe5m2Ú_)r3   r5   Útarget_dtypeÚscaling_typer   Úscaling_granularity)r   Údtypes   & r   r   ÚCastConfig.short_strn   sU   € Ü˜V¤Z°Ð8¸×9JÑ9JÕKˆØ×#Ñ#×-Ñ-Ó/Ð0°°$×2JÑ2J×2TÑ2TÓ2VÐ1WÐWXÐY^ÐX_Ð`Ð`r   c                ó(  € V P                   \        P                  J d&   V P                  \        P
                  J g   Q R 4       hV P                  eA   V P                  P                  '       d   V P                  P                  ^8X  g   Q R4       hR# R# )zGonly dynamic scaling type is supported for axiswise scaling granularityNz)must specify a 8-bit floating-point dtype)	rC   r!   r(   rB   r   r   rA   Úis_floating_pointÚitemsizer   s   &r   r6   ÚCastConfig.__post_init__r   s‰   € Ø×#Ñ#Ô'9×'BÑ'BÓBØ×$Ñ$¬×(;Ñ(;Ó;ð ØYóÐ;ð × Ñ Ò(Ø×Ñ×/×/Ð/°D×4EÑ4E×4NÑ4NÐRSÔ4Sð	7à6ó	7ð 
Ù4Sñ )r   c                ób   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   S[S[P                  ,          ;R&   # )é   rB   rC   rA   )r   r!   r   r-   rD   )Úformatr   s   "€r   Ú__annotate__ÚCastConfig.__annotate__\   s5   ø‡ ‚ ñ Ñ3ñ ñ ,ÑKñ ñ  ™5Ÿ;™;Õ'Ñ.ò! r   r   )r   r   r   r   r   r   r   rB   r!   r'   rC   rA   r   r6   Ú__annotate_func__r   r   r   s   @r   r<   r<   \   s:   ø‡ € ñ
ð !,× 3Ñ 3€LØ.@×.KÑ.KÐØ*.€Lòaò7÷- ƒ r   r<   c                   ó4   a € ] tR t^|t o RtRtV 3R ltRtV tR# )ÚFloat8GemmConfigzÓ
Configuration for a float8 gemm.

Args:
    use_fast_accum: If True, use fast accumulation in lower precision.
        This can improve performance but may reduce numerical accuracy.
        Default: ``False``
Fc                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )rK   Úuse_fast_accum)Úbool)rL   r   s   "€r   rM   ÚFloat8GemmConfig.__annotate__|   s   ø‡ ‚ ñ Ñ ò r   r   N)	r   r   r   r   r   rS   rO   r   r   r   s   @r   rQ   rQ   |   s   ø‡ € ñð !€N÷ ƒ r   rQ   c                   ó&   € ] tR t^�tRtRtRtRtRtR# )ÚFloat8LinearRecipeNamea.  
Pre-made recipes for common float8 training configurations.

Values:

* ``TENSORWISE``: Default, dynamic per-tensor scaling with the cuBLAS tensorwise kernel.
  Fastest option.
* ``ROWWISE``: Dynamic rowwise scaling with the CUTLASS rowwise kernel.
  Uses e4m3 for activations, weights, gradients. Scales are rounded (floor) to
  the nearest power of two for increased accuracy.
* ``ROWWISE_WITH_GW_HP``: A modification on rowwise scaling with increased accuracy
  for grad_weight by keeping grad_weight computation in high precision. Most accurate option.
r"   ÚrowwiseÚrowwise_with_gw_hpr   N)	r   r   r   r   r   r'   ÚROWWISEÚROWWISE_WITH_GW_HPr   r   r   r   rW   rW   �   s   † ñð €Jð
 €Gð .Ôr   rW   c                   óÊ   a € ] tR t^³t o Rt]! 4       tRt]! 4       tRt	]! 4       t
Rt]! RR7      t]! 4       t]! 4       tRtRtRtRtRtR t]V 3R lR l4       tV 3R	 ltR
tV tR# )ÚFloat8LinearConfigzQ
Configuration for converting a `torch.nn.Linear` module to float8
for training.
NT)rS   Fc                ó”  € V P                   f"   \        P                  V RV P                  4       V P                  f"   \        P                  V RV P
                  4       V P                  f"   \        P                  V RV P                  4       V P
                  P                  \        P                  8w  d1   V P                  '       d   Q RV P
                  P                   24       hV P                  pV P
                  pV P                  pV P                   pV P                  pV P                  pWR3W5R3WFR33 FN  w  rxp	VP                  \        P                  J p
VP                  \        P                  J pW«8X  d   KF  Q RV	 24       h	  WR	\        3W%R
\        3W6R\         33 Fu  w  rxrÍVP"                  f   \        P                  VRV4       VP"                  f   \        P                  VRV4       VP"                  VP"                  8X  d   Km  Q V R24       h	  V P$                  '       d   \&        P)                  R4       R # R # )NÚ!cast_config_input_for_grad_weightÚ!cast_config_weight_for_grad_inputÚ'cast_config_grad_output_for_grad_weightzPenable_fsdp_float8_all_gather only supports tensorwise scaling granularity, got ÚoutputÚ
grad_inputÚgrad_weightz#incompatible operand precision for ÚinputÚweightÚgrad_outputrA   z< must be cast to the same dtype in both matmuls it's used inz¨`config.force_recompute_fp8_weight_in_bwd` is deprecated and will be removed in a future release. Please see https://github.com/pytorch/ao/issues/2251 for more details.)r_   ÚobjectÚ__setattr__Úcast_config_inputr`   Úcast_config_weightra   Úcast_config_grad_outputrC   r!   r'   Úenable_fsdp_float8_all_gatherrB   r   r   r3   r5   rA   Ú!force_recompute_fp8_weight_in_bwdÚloggerÚwarning)r   Úcc_iÚcc_wÚcc_goÚcc_i_gwÚcc_w_giÚcc_go_gwÚcc1Úcc2Ú	gemm_nameÚis_disabled_1Úis_disabled_2Úoperand_nameÚdefault_dtypes   &             r   r6   Ú Float8LinearConfig.__post_init__ø   sX  € ð ×1Ñ1Ò9Ü×ÑØÐ9¸4×;QÑ;Qôð ×1Ñ1Ò9Ü×ÑØÐ9¸4×;RÑ;Rôð ×7Ñ7Ò?Ü×ÑØØ9Ø×,Ñ,ôð ×"Ñ"×6Ñ6Ô:L×:WÑ:WÔWØ×9×9Ð9ð ØbÐcg×czÑcz÷  dOñ  dOð  cPð  QóÐ9ð
 ×%Ñ%ˆØ×&Ñ&ˆØ×,Ñ,ˆØ×8Ñ8ˆØ×8Ñ8ˆØ×?Ñ?ˆð
 ˜Ð"Ø˜\Ð*Ø Ð.ó$
ÑˆC�ið
  ×,Ñ,´×0DÑ0DÐDˆMØ×,Ñ,´×0DÑ0DÐDˆMØ Ö1ð Ø5°i°[ÐAóÐ1ñ$
ð ˜G¤ZÐ0Ø˜H¤jÐ1Ø˜m¬ZÐ8ó6
Ñ1ˆC�lð ×ÑÒ'Ü×"Ñ" 3¨¸ÔFØ×ÑÒ'Ü×"Ñ" 3¨¸ÔFØ×#Ñ# s×'7Ñ'7Ö7ð Ø�.Ð \Ð]óÐ7ñ6
ð ×1×1Ð1Ü�N‰Nð {öñ 2r   c                ó:   <€ V ^8„  d   QhRS[ S[S[3,          RR/# )rK   Úrecipe_nameÚreturnr]   )r   rW   Ústr)rL   r   s   "€r   rM   ÚFloat8LinearConfig.__annotate__=  s0   ø€ ÷ @Gñ @GÙÑ1±3Ð6Õ7ð@Gà	ñ@Gr   c           
     óœ  € \        V 4      \        8X  d=   \         Uu. uF  qP                  NK  	  ppW9   g   Q RV  RV 24       h\        V 4      p V \        P                  J d   \        4       # V \        P                  J dm   \        \        P                  \        R7      p\        \        P                  \        R7      p\        \        P                  \        R7      p\        VVVRR7      # V \        P                  J d¹   \        \        P                  R7      p\        \        P                  R7      p\        \        P                  \        R7      p\        \        P                  R7      p\        \        P                  R7      p\        \        P                  \        R7      p\        VVVVVVRR	7      # \        R
V  24      hu upi )z®
Input: `Float8LinearRecipeName` value, or a string representing a `Float8LinearRecipeName` value
Output: a `Float8LinearConfig` configured to implement the specified recipe
zrecipe_name z not in valid names )rC   rA   T)rj   rk   rl   Úround_scales_to_power_of_2)rC   )rB   )rB   rA   )rj   rk   rl   r_   r`   ra   r…   zunknown recipe_name )Útyper‚   rW   Úvaluer'   r]   rZ   r<   r!   r(   r3   r[   r   r   ÚAssertionError)	r€   ÚnÚvalid_namesrq   rr   rs   ru   rt   rv   s	   &        r   Úfrom_recipe_nameÚ#Float8LinearConfig.from_recipe_name<  s¢  € ô �Ó¤Ô#Ý,BÓCÑ,B qŸ7œ7Ñ,BˆKÐCØÔ-ð Ø˜{˜mÐ+?À¸}ÐMóÐ-ô 1°Ó=ˆKàÔ0×;Ñ;Ó;Ü%Ó'Ð'àÔ2×:Ñ:Ó:ÜÜ$6×$?Ñ$?ÌjôˆDô Ü$6×$?Ñ$?ÌjôˆDô Ü$6×$?Ñ$?ÌjôˆEô &Ø"&Ø#'Ø(-à+/ôð ð Ô2×EÑEÓEäÔ2D×2MÑ2MÔNˆDÜÔ2D×2MÑ2MÔNˆDô Ü$6×$?Ñ$?ÌjôˆEô !Ô5G×5RÑ5RÔSˆGô !¬k×.BÑ.BÔCˆGÜ!Ü(×1Ñ1Ä
ôˆHô &Ø"&Ø#'Ø(-Ø29Ø29Ø8@Ø+/ôð ô !Ð#7¸°}Ð!EÓFÐFùòq Ds   �G	c                óò   <€ V ^8„  d   Qh/ S[ ;R&   S[S[ ,          ;R&   S[ ;R&   S[S[ ,          ;R&   S[ ;R&   S[S[ ,          ;R&   S[;R&   S[;R&   S[;R	&   S[;R
&   S[;R&   S[;R&   S[;R&   S[;R&   # )rK   rj   r_   rk   r`   rl   ra   Úgemm_config_outputÚgemm_config_grad_inputÚgemm_config_grad_weightrm   Úpad_inner_dimÚemulatern   r…   )r<   r   rQ   rT   )rL   r   s   "€r   rM   rƒ   ³   sÚ   ø‡ ‚ ñ. "Ñ0ñ/ ñ0 (0±
Õ';ÑBñ1 ñ4 #Ñ1ñ5 ñ6 (0±
Õ';ÑBñ7 ñ: (Ñ6ñ; ñ< .6±jÕ-AÑHñ= ñH )ÑPñI ñJ -ÑAñK ñL .ÑBñM ñ\ $(Ñ/ñ] ñh Ññi ñn Ñño ñx (,Ñ3ñy ñF !%Ñ,òG r   r   )r   r   r   r   r   r<   rj   r_   rk   r`   rl   ra   rQ   rŽ   r�   r�   rm   r‘   r’   rn   r…   r6   Ústaticmethodr‹   rO   r   r   r   s   @r   r]   r]   ³   s¢   ø‡ € ññ* %/£LÐØ>BÐ%á%/£\ÐØ>BÐ%á*4«,ÐØDHÐ+ñ ,<È4Ô+PÐÙ/?Ó/AÐÙ0@Ó0BÐð +0Ð!ð  €Mð €Gð
 /4Ð%ð (-ÐòBðH ÷@Gó ð@G÷U ƒ r   r]   c                óT   € V ^8„  d   Qh/ ^ \         9   d   \        P                  ;R&   # )rK   ro   )Ú__conditional_annotations__ÚloggingÚLogger)rL   s   "r   rM   rM      s   € ‡�÷ -Ò ,Œ�‰Ñ ,ò r   )r•   Úenumr–   Údataclassesr   Útypingr   r   r-   Útorchao.utilsr   Ú	getLoggerro   ÚEnumr   r!   r+   Útype_configr3   r5   r<   rQ   rW   r]   rM   )r•   s   @r   Ú<module>rŸ      s÷   øð÷ €Û Ý !ß "ã å "à ×*Ò*Ó,€Ó ,ô�$—)‘)ô ô.˜Ÿ™ô ð0 ÷4ð 4ó ð4ñ( Ó €Ø×#Ñ#€
Ø×#Ñ#€
ñ �$Ô÷7ð 7ó ð7ñ> �$Ô÷!ð !ó ð!ô #.˜TŸY™Yô #.ñL �$Ô÷IGð IGó òIGr   