+
    "Ý³j¼(  ã                   óÆ   € ^ RI t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	H
t
 ^ RIHtHt ^ RIHt ^ RIHtHt ^ RIHt R	 t ! R
 R]4      t ! R R]
4      t ! R R]	4      tR# )é    N)ÚDTensor)Ú
DeviceMesh)ÚColwiseParallelÚPrepareModuleInputÚRowwiseParallel)ÚScalingTypeÚ
e4m3_dtype)Útensor_already_casted_to_fp8)ÚNoopFwToFloat8BwDynamicÚhp_tensor_to_float8_dynamic)ÚGemmInputRolec                 ó†   € V P                   \        P                  8H  ;'       d    V P                  \        P                  8H  # )N)Úscaling_type_inputr   ÚDYNAMICÚscaling_type_grad_output)Úms   &Úf/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/float8/float8_tensor_parallel.pyÚ(_float8_linear_supports_float8_allgatherr   "   s;   € ð 	
×Ñ¤× 3Ñ 3Ñ3÷ 	>ð 	>Ø×&Ñ&¬+×*=Ñ*=Ñ=ðó    c                   ób   a a€ ] tR t^*t oRt]R 4       t]R 4       tV3R lV 3R lltRt	Vt
V ;t# )ÚFloat8ColwiseParallelzc
Like `ColwiseParallel`, but with all-gather in float8. This
currently assumes tensorwise scaling.
c                óT  € V^ ,          p\        V\        4      '       g   \        P                  ! WTV RR7      p\        V4      '       gF   \	        VVP
                  P                  P                  VP                  \        P                  R7      pW8w  d   VP                  VRR7      pV# ©r   F©Ú	run_check©Úgemm_input_roleT©Ú
placementsÚasync_op©Ú
isinstancer   Ú
from_localr
   r   ÚconfigÚcast_config_inputÚtarget_dtypeÚlinear_mm_configr   ÚINPUTÚredistribute©Úinput_layoutsÚdesired_input_layoutsÚmodÚinputsÚdevice_meshÚinput_tensors   &&&&& r   Ú_prepare_input_fnÚ'Float8ColwiseParallel._prepare_input_fn0   sš   € ð
 ˜a•yˆÜ˜,¬×0Ò0Ü"×-Ò-Ø¨=ÀEôˆLô ,¨L×9Ò9Ü6ØØ—
‘
×,Ñ,×9Ñ9Ø×$Ñ$Ü -× 3Ñ 3ô	ˆLð Ô1Ø'×4Ñ4Ø0¸4ð 5ó ˆLð Ðr   c                óþ   € VP                   V 8w  d   VP                  V R R7      p\        P                  ! VVP                  VP
                  P                  P                  4      pV'       d   VP                  4       # T# ©Tr   ©	r   r)   r   Úapplyr'   r$   Úcast_config_grad_outputr&   Úto_local©Úoutput_layoutsÚuse_local_outputr-   Úoutputsr/   s   &&&&&r   Ú_prepare_output_fnÚ(Float8ColwiseParallel._prepare_output_fnJ   su   € ð ×Ñ Ô/Ø×*Ñ*Ø)°Dð +ó ˆGô
 *×/Ò/ØØ× Ñ Ø�J‰J×.Ñ.×;Ñ;ó
ˆ÷ &6ˆw×ÑÓ!ÐB¸7ÐBr   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# ©é   Úmoduler/   Úreturn©ÚnnÚModuler   )ÚformatÚ__classdict__s   "€r   Ú__annotate__Ú"Float8ColwiseParallel.__annotate__\   ó*   ø€ ÷ 3ñ 3™RŸY™Yð 3±Zð 3ÁBÇIÁIñ 3r   c                óØ   <€ ^ RI Hp \        W4      '       g   \        R\	        V4       24      h\        W4      '       d   \        V4      '       g   \        R4      h\        SV `!  W4      # ©r   ©ÚFloat8Linearz.Expecting module to be Float8Linear but found Úunsupported©	Útorchao.float8.float8_linearrO   r"   Ú
ValueErrorÚtyper   ÚAssertionErrorÚsuperÚ_apply©ÚselfrB   r/   rO   Ú	__class__s   &&& €r   rW   ÚFloat8ColwiseParallel._apply\   óc   ø€ Ý=ä˜&×/Ò/ÜØ@ÄÀfÃÀÐOóð ô Ø÷
ò 
ä:¸6×BÒBÜ  Ó/Ð/ä‰w‰~˜fÓ2Ð2r   © ©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ústaticmethodr1   r=   rW   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©rZ   rH   s   @@r   r   r   *   sC   ù‡ € ñð
 ñó ðð2 ñCó ðC÷"3÷ 3ó 3r   r   c                   ób   a a€ ] tR t^kt oRt]R 4       t]R 4       tV3R lV 3R lltRt	Vt
V ;t# )ÚFloat8RowwiseParallelzc
Like `RowwiseParallel`, but with all-gather in float8. This
currently assumes tensorwise scaling.
c                óT  € V^ ,          p\        V\        4      '       g   \        P                  ! WTV RR7      p\        V4      '       gF   \	        VVP
                  P                  P                  VP                  \        P                  R7      pW8w  d   VP                  VRR7      pV# r   r!   r*   s   &&&&& r   r1   Ú'Float8RowwiseParallel._prepare_input_fnq   sš   € ð ˜a•yˆÜ˜,¬×0Ò0Ü"×-Ò-Ø¨=ÀEôˆLô ,¨L×9Ò9Ü6ØØ—
‘
×,Ñ,×9Ñ9Ø×$Ñ$Ü -× 3Ñ 3ô	ˆLð Ô1Ø'×4Ñ4Ø0¸4ð 5ó ˆLð Ðr   c                óþ   € VP                   V 8w  d   VP                  V R R7      p\        P                  ! VVP                  VP
                  P                  P                  4      pV'       d   VP                  4       # T# r4   r5   r9   s   &&&&&r   r=   Ú(Float8RowwiseParallel._prepare_output_fn‰   sp   € ð
 ×Ñ Ô/Ø×*Ñ*°nÈtÐ*ÓTˆGô *×/Ò/ØØ× Ñ Ø�J‰J×.Ñ.×;Ñ;ó
ˆ÷ &6ˆw×ÑÓ!ÐB¸7ÐBr   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# r@   rD   )rG   rH   s   "€r   rI   Ú"Float8RowwiseParallel.__annotate__›   rK   r   c                óØ   <€ ^ RI Hp \        W4      '       g   \        R\	        V4       24      h\        W4      '       d   \        V4      '       g   \        R4      h\        SV `!  W4      # rM   rQ   rX   s   &&& €r   rW   ÚFloat8RowwiseParallel._apply›   r\   r   r]   r^   rh   s   @@r   rj   rj   k   sC   ù‡ € ñð
 ñó ðð. ñCó ðC÷"3÷ 3ó 3r   rj   c                   óˆ   a a€ ] tR t^ªt oRtRRRRRRRRRRR	]P                  R
R/V 3R lltR tV3R lV 3R llt	Rt
VtV ;t# )ÚPrepareFloat8ModuleInputaÀ  
Like `PrepareModuleInput`, but with all-gather in float8. This
currently assumes tensorwise scaling.

The only difference from `PrepareModuleInput` is that
after we prepare the input DTensor, we cast the input to DTensor(Float8TrainingTensor)
This is to ensure the float8 cast happens before the all-gather (i.e. Shard -> Replicate)
so that if there are multiple float8 users of the input activation, we perform fp8 allgather
only once.
FP8 Args:
  float8_dtype (torch.dtype, optional): control what float8 dtype to cast to when prepare the module input,
      we currently only support torch.float8_e4m3fn. default: torch.float8_e4m3fn
  fwd_config_submodule_fqn (str, optional): the fqn of the submodule that contains the forward config used
      for the float8 cast. If not specified, we will search for the Float8Linear in the submodules
      and use the forward config from that module, in this case all module's forward config must be
      the same.
r+   Nr,   Úinput_kwarg_layoutsÚdesired_input_kwarg_layoutsr;   FÚfloat8_dtypeÚfwd_config_submodule_fqnc               óª   <€ \         SV `  VVVVVR 7       W`n        RV n        Wpn        V P                  \
        P                  8w  d   \        R4      hR# ))r+   r,   ru   rv   r;   NzFPrepareFloat8ModuleInput only support casting to float8_e4m3fn for now)rV   Ú__init__rw   r'   rx   ÚtorchÚfloat8_e4m3fnÚNotImplementedError)	rY   r+   r,   ru   rv   r;   rw   rx   rZ   s	   &$$$$$$$€r   rz   Ú!PrepareFloat8ModuleInput.__init__½   se   ø€ ô 	‰ÑØ'Ø"7Ø 3Ø(CØ-ð 	ô 	
ð )ÔØ $ˆÔØ(@Ô%à×Ñ¤× 3Ñ 3Ô3Ü%ØXóð ñ 4r   c                óš  € VeÇ   \        V\        4      '       d   TpMA\        V\        P                  4      '       g   Q R4       h\        P                  ! WV3RR7      p\        V\        V P                  \        P                  R7      pVe   W48w  d   VP                  V3R7      pV P                  '       d   VP                  4       # T# V# )Nz%expecting input to be a torch.Tensor!Fr   r   )r   )r"   r   r{   ÚTensorr#   r   r	   r'   r   r(   r)   r;   r8   )rY   ÚinputÚmeshÚinput_layoutÚdesired_layoutÚdt_inps   &&&&& r   Ú_prepare_input_argÚ+PrepareFloat8ModuleInput._prepare_input_argÚ   sÁ   € ØÒ#Ü˜%¤×)Ò)ð ‘ä! %¬¯©×6Ò6ð Ø;óÐ6ô !×+Ò+Ø , ¸Eô�ô 1ØÜØ×%Ñ%Ü -× 3Ñ 3ô	ˆFð Ò)¨lÔ.LØ×,Ñ,¸Ð8IÐ,ÓJ�à(,×(=×(=Ð(=�6—?‘?Ó$ÐIÀ6ÐIàˆLr   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# r@   rD   )rG   rH   s   "€r   rI   Ú%PrepareFloat8ModuleInput.__annotate__õ   s*   ø€ ÷ ñ ™RŸY™Yð ±Zð ÁBÇIÁIñ r   c                óÈ  <€ ^ RI Hp V P                  eA   VP                  V P                  4      p\	        WC4      '       g   Q hVP
                  V n        MmVP                  4        FY  p\	        WS4      '       g   K  V P
                  f   VP
                  V n        K7  V P
                  VP
                  8X  d   KT  Q R4       h	  V P
                  f   Q h\        SV `!  W4       V# )r   rN   z?All the Float8Linear modules should have same linear_mm_config!)	rR   rO   rx   Úget_submoduler"   r'   ÚmodulesrV   rW   )rY   rB   r/   rO   Ú
fwd_linearr-   rZ   s   &&&   €r   rW   ÚPrepareFloat8ModuleInput._applyõ   sÈ   ø€ Ý=à×(Ñ(Ò4Ø×-Ñ-¨d×.KÑ.KÓLˆJÜ˜j×7Ò7Ð7Ð7Ø$.×$?Ñ$?ˆDÕ!ð —~‘~Ö'�Ü˜c×0Ô0Ø×,Ñ,Ò4Ø03×0DÑ0D˜Ö-à#×4Ñ4¸×8LÑ8LÖLð Ø]óÐLñ (ð ×$Ñ$Ò0Ð0Ð0Ü‰‰�vÔ+Øˆr   )rw   rx   r'   )r_   r`   ra   rb   rc   r{   r|   rz   r†   rW   re   rf   rg   rh   s   @@r   rt   rt   ª   so   ù‡ € ñð$ð ðð #ð	ð
 !ðð %)ðð ðð ×(Ñ(ðð "&÷ò:÷6÷ ó r   rt   )r{   Útorch.nnrE   Útorch.distributed._tensorr   Útorch.distributed.device_meshr   Ú!torch.distributed.tensor.parallelr   r   r   Útorchao.float8.configr   r	   Ú torchao.float8.distributed_utilsr
   Ú#torchao.float8.float8_scaling_utilsr   r   Ú%torchao.float8.float8_training_tensorr   r   r   rj   rt   r]   r   r   Ú<module>r—      s^   ðó Ý Ý -Ý 4÷ñ ÷ :Ý I÷õ @òô>3˜Oô >3ôB<3˜Oô <3ô~_Ð1ö _r   