Ë
    g^(h­  ã                   ó>  — d dl Z d dlZd dlZd dlmZmZmZmZmZ d dl	Z	d dl
mZ d dlmc mZ d dlmZ d dlmZ ddlmZ 	 d dlmZ  e	j6                  «       rd„ Zn	 d d	lmZ 	 	 	 ee!e"   e!e!e"      ejF                  ee$de"f   e%f   Z&	 d„ Z'dpde	jP                  de"de&de%fd„Z)dpde	jP                  de%de&de%fd„Z*	 dpde	jP                  de"de&de%de	jP                  f
d„Z+	 dpde	jP                  de"de&de%fd„Z,	 dpde	jP                  de%de"de&de%f
d„Z-	 dpde	jP                  de%de"de&de%f
d„Z.	 dpde!e	jP                     de%de&de%de!e	jP                     f
d„Z/	 dpde!e	jP                     de&de%de!e	jP                     fd„Z0	 dpde!e	jP                     de%de!e"   de&de%de!e	jP                     fd„Z1d „ Z2	 dpde	jP                  d!ee!e"      d"ee!e"      de&de%de	jP                  fd#„Z3	 dpde	jP                  d!ee!e"      d"ee!e"      de&de%de	jP                  fd$„Z4	 dpde	jP                  d%e!e"   de&de%de	jP                  f
d&„Z5 G d'„ d(e	jP                  «      Z6	 dpde&de%de$e%e!e"   e"f   fd)„Z7dpde&de%de%fd*„Z8 G d+„ d,e	jr                  jt                  «      Z;de<fd-„Z=de	jP                  fd.„Z>e j~                  dqd/e<fd0„«       Z@d1„ ZAd2„ ZBd3„ ZCd4„ ZDd5„ ZEd6„ ZFd7„ ZGd8„ ZHd9„ ZId:„ ZJd;„ ZKd<„ ZLd=„ ZMd>„ ZNd?„ ZOd@„ ZPdA„ ZQ e	j6                  «       �sPe	j¤                  j§                  dBdC«      ZTeTj«                  dDeCdE«       eTj«                  dFeHdE«       eTj«                  dGeGdE«       eTj«                  dHeJdE«       eTj«                  dIeDdE«       eTj«                  dJeMdE«       eTj«                  dKeNdE«       eTj«                  dLeOdE«       eTj«                  dMePdE«       eTj«                  dNeQdE«       eTj«                  dOeLdE«       eTj«                  dPeBdE«       eTj«                  dQeIdE«       e	j¬                  j®                  j±                  e	j²                  j´                  jN                  j¶                  «       e	j¬                  j®                  j±                  e	j²                  j´                  jN                  «       e	j¤                  j§                  dRdS«      Z\e	j¤                  j§                  dRdC«      Z]g dT¢Z^ej¾                  e`   Zae^D ]\  Zbebd ebjÇ                  dU«       Zd eeedVed› �«      Zfe\jÏ                  ebe	jÐ                  jÒ                  ¬W«       e]j«                  edefdX«       Œ^ n ej@                  dY«       	 	 	 	 	 drdZe	jP                  d[e	jP                  d\e<de%de"f
d]„Zj	 	 	 	 	 dsd_e	jP                  d`e	jP                  dae%d\e<de"de%fdb„ZkejØ                  jÚ                  d^ejØ                  jÜ                  dcejØ                  jÞ                  ddejØ                  jà                  deejØ                  jâ                  dfejØ                  jä                  dgejØ                  jæ                  dhejØ                  jè                  diiZu	 	 	 	 dtdje	jP                  dae%d\e<de%fdk„Zv	 	 	 	 	 dud_e	jP                  d`e	jP                  de%fdl„Zw	 	 	 dvdme!e	jP                     dje	jP                  de%fdn„Zxd dolmyZzm{Z|m}Z~mZ€m*Z�m3Z‚m-Zƒ e€ejeƒeke�eve‚ewe~exe|ekezejiZ„y# e$ r
 d dlmZ Y �Œ³w xY w# e$ r  ej@                  d
«       d„ ZY �Œ¸w xY w)wé    N)ÚAnyÚcastÚOptionalÚTYPE_CHECKINGÚUnion)Ú
DeviceMesh)Úget_proxy_modeé   )Ú_functional_collectives_impl)Útree_map_onlyc                   ó   — y)z9Can't import torchdynamo in torchdeploy builds currently.F© r   ó    úg/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/distributed/_functional_collectives.pyÚis_torchdynamo_compilingr      s   € àr   )Úis_dynamo_compilingzdUnable to import torchdynamo util `is_torchdynamo_compiling`, so won't support torchdynamo correctlyc                   ó   — y)NFr   r   r   r   r   r   $   s   € Ør   zdist.tensor.DeviceMeshc                 óT   — t         j                  j                  j                  | «      S )z¡
    Wait on a tensor returned by the collectives ops.

    Waiting follows device semantics, which means blocking on CPU and synchronizing streams on CUDA.
    )ÚtorchÚopsÚ_c10d_functionalÚwait_tensor)Útensors    r   r   r   ‡   s   € ô �9‰9×%Ñ%×1Ñ1°&Ó9Ð9r   ÚselfÚsrcÚgroupÚtagc                 ó†   — t        ||«      }t        j                  j                  j	                  | ||«      }t        |«      S )a  
    Broadcasts the tensor to all processes in the given process group.

    Args:
        src (int): Source rank
        group (ProcessGroup or List[int]): The process group to work on.
        tag (str, optional): A unique identifier for the collective. Default: empty string
    )Ú_resolve_group_namer   r   r   Ú	broadcastÚ_maybe_wrap_tensor)r   r   r   r   Ú
group_namer   s         r   r    r    �   s9   € ô % U¨CÓ0€JÜ�Y‰Y×'Ñ'×1Ñ1°$¸¸ZÓH€FÜ˜fÓ%Ð%r   ÚreduceOpc                 ó¢   — t        ||«      }t        j                  j                  j	                  | |j                  «       |«      }t        |«      S )aø  
    Reduces the tensor data across all machines in such a way that all get
    the final result.

    The input tensor is left unmodified.

    Group can be one of:
        List[int]: ranks participating in the collective.
        List[List[int]]: 2D mesh of ranks taking part of this collective in MPMD.
        ProcessGroup: Will perform a collective using the ranks and tag of the PG.
        DeviceMesh: Do a SPMD collective over all ranks of the mesh
        (DeviceMesh, int): Do a MPMD collective over one dimension of the DeviceMesh

    :: N.B. If you pass a PG or a 1D list to perform a MPMD collective, the compiler won't be able to recover
    that information and perform collective algebraic optimization. Use other forms of input for that.
    )r   r   r   r   Ú
all_reduceÚlowerr!   )r   r#   r   r   r"   r   s         r   r%   r%   ž   s@   € ô" % U¨CÓ0€JÜ�Y‰Y×'Ñ'×2Ñ2°4¸¿¹Ó9IÈ:ÓV€FÜ˜fÓ%Ð%r   Ú
gather_dimÚreturnc                 ó|  — | j                  «       sJ ‚t        ||«      }t        j                  |«      }t        j
                  j                  j                  | ||«      }t        |«      }|dk7  rMt        |t        «      r|j                  «       }t	        j                  t	        j                  ||d¬«      |¬«      }|S )a%  
    Gather tensor data across from all machines and concatenate over ``gather_dim``.

    Note that it currently only supports gather_dim = 0.

    The input tensor is left unmodified.
    Group can be one of:
        List[int]: ranks participating in the collective.
        List[List[int]]: 2D mesh of ranks taking part of this collective in MPMD.
        ProcessGroup: Will perform a collective using the ranks and tag of the PG.
        DeviceMesh: Do a SPMD collective over all ranks of the mesh
        (DeviceMesh, int): Do a MPMD collective over one dimension of the DeviceMesh

    :: N.B. If you pass a PG or a 1D list to perform a MPMD collective, the compiler won't be able to recover
    that information and perform collective algebraic optimization. Use other forms of input for that.
    r   ©Údim)Úis_contiguousr   Úc10dÚ_get_group_size_by_namer   r   r   Úall_gather_into_tensorr!   Ú
isinstanceÚAsyncCollectiveTensorÚwaitÚcatÚchunk©r   r'   r   r   r"   Ú
group_sizer   Úress           r   Úall_gather_tensorr8   ´   s    € ð, ×ÑÔÐÐÜ$ U¨CÓ0€JÜ×-Ñ-¨jÓ9€JÜ�Y‰Y×'Ñ'×>Ñ>Øˆj˜*ó€Fô ˜VÓ
$€Cà�Q‚ô �cÔ0Ô1Ø—(‘(“*ˆCÜ�i‰iœŸ™ C¨¸Ô;ÀÔLˆØ€Jr   c                 ól  — t        ||«      }t        j                  |«      }t        j                  j
                  j                  | ||«      }t        j                  |«      }|dk7  rMt        |t        «      r|j                  «       }t        j                  t        j                  ||d¬«      |¬«      }|S )a<  
    Gather tensor data across from all machines and concatenate over ``gather_dim``.

    Note that it currently only supports gather_dim = 0.

    This function is the same as all_gather_tensor but will propagate the
    backwards gradient across workers.

    See all_gather_tensor for more details on usage.
    r   r*   )r   r-   r.   r   r   Ú_c10d_functional_autogradr/   Ú_FromTorchTensorÚapplyr0   r1   r2   r3   r4   r5   s           r   Úall_gather_tensor_autogradr=   Û   s”   € ô  % U¨CÓ0€JÜ×-Ñ-¨jÓ9€Jä�Y‰Y×0Ñ0×GÑGØˆj˜*ó€Fô ×
 Ñ
  Ó
(€Cà�Q‚ô �cÔ0Ô1Ø—(‘(“*ˆCÜ�i‰iœŸ™ C¨¸Ô;ÀÔLˆØ€Jr   Úscatter_dimc                 óœ  — t        ||«      }t        j                  |«      }| j                  |«      |z  dk(  sJ d| j                  d«      › d|› �«       ‚|dk7  r-t	        j
                  | ||¬«      }t	        j                  |«      } t        j                  j                  j                  | |j                  «       ||«      }t        |«      }	|	S )a(  
    Reduces the tensor data across all machines in such a way that all get
    the final result, then scatter the results to corresponding ranks.


    The input tensor is left unmodified.
    Group can be one of:
        List[int]: ranks participating in the collective.
        List[List[int]]: 2D mesh of ranks taking part of this collective in MPMD.
        ProcessGroup: Will perform a collective using the ranks and tag of the PG.
        DeviceMesh: Do a SPMD collective over all ranks of the mesh
        (DeviceMesh, int): Do a MPMD collective over one dimension of the DeviceMesh
    :: N.B. If you pass a PG or a 1D list to perform a MPMD collective, the compiler won't be able to recover
    that information and perform collective algebraic optimization. Use other forms of input for that.
    r   úinput dimension 0 (ú" must be a multiple of group_size r*   )r   r-   r.   Úsizer   r4   r3   r   r   Úreduce_scatter_tensorr&   r!   ©
r   r#   r>   r   r   r"   r6   Útensor_listr   r7   s
             r   rC   rC   ü   sÄ   € ô, % U¨CÓ0€JÜ×-Ñ-¨jÓ9€Jà�9‰9�[Ó! JÑ.°!Ò3ð Ø
˜dŸi™i¨›l˜^Ð+MÈjÈ\ÐZóÐ3ð �aÒÜ—k‘k $¨
¸ÔDˆÜ�y‰y˜Ó%ˆä�Y‰Y×'Ñ'×=Ñ=ØØ�‰ÓØØó	€Fô ˜VÓ
$€CØ€Jr   c                 ó°  — t        ||«      }t        j                  |«      }| j                  |«      |z  dk(  sJ d| j                  d«      › d|› �«       ‚|dk7  r-t	        j
                  | ||¬«      }t	        j                  |«      } t        j                  j                  j                  | |j                  «       ||«      }t        j                  |«      }	|	S )a|  
    Reduces the tensor data across all machines in such a way that all get
    the final result, then scatter the results to corresponding ranks.

    This function is the same as reduce_scatter_tensor but will propagate the
    backwards gradient across workers.

    Currently only the "sum" reduceOp is supported.

    See reduce_scatter_tensor for more details on usage.
    r   r@   rA   r*   )r   r-   r.   rB   r   r4   r3   r   r:   rC   r&   r;   r<   rD   s
             r   Úreduce_scatter_tensor_autogradrG   &  sÊ   € ô& % U¨CÓ0€JÜ×-Ñ-¨jÓ9€Jà�9‰9�[Ó! JÑ.°!Ò3ð Ø
˜dŸi™i¨›l˜^Ð+MÈjÈ\ÐZóÐ3ð �aÒÜ—k‘k $¨
¸ÔDˆÜ�y‰y˜Ó%ˆä�Y‰Y×0Ñ0×FÑFØØ�‰ÓØØó	€Fô ×
 Ñ
  Ó
(€CØ€Jr   c                 ó¾   — t        ||«      }t        j                  j                  j	                  | |j                  «       |«      }t        t        t        |«      «      S )a  
    Reduces a list of tensors across all machines in such a way that all get
    the final result.

    The all tensors in the input list are left unmodified.

    Group can be one of:
        List[int]: ranks participating in the collective.
        List[List[int]]: 2D mesh of ranks taking part of this collective in MPMD.
        ProcessGroup: Will perform a collective using the ranks and tag of the PG.
        DeviceMesh: Do a SPMD collective over all ranks of the mesh
        (DeviceMesh, int): Do a MPMD collective over one dimension of the DeviceMesh

    :: N.B. If you pass a PG or a 1D list to perform a MPMD collective, the compiler won't be able to recover
    that information and perform collective algebraic optimization. Use other forms of input for that.
    )	r   r   r   r   Úall_reduce_coalescedr&   ÚlistÚmapr!   )r   r#   r   r   r"   rE   s         r   rI   rI   M  sO   € ô& % U¨CÓ0€JÜ—)‘)×,Ñ,×AÑAØØ�‰ÓØó€Kô
 ”Ô&¨Ó4Ó5Ð5r   c                 óÌ   — t        ||«      }t        j                  |«      }t        j                  j
                  j                  | ||«      }t        t        t        |«      «      S )a  
    Gather a list of tensors across from all machines.

    Note that it currently only supports gather_dim = 0.

    The input tensor is left unmodified.
    Group can be one of:
        List[int]: ranks participating in the collective.
        List[List[int]]: 2D mesh of ranks taking part of this collective in MPMD.
        ProcessGroup: Will perform a collective using the ranks and tag of the PG.
        DeviceMesh: Do a SPMD collective over all ranks of the mesh
        (DeviceMesh, int): Do a MPMD collective over one dimension of the DeviceMesh

    :: N.B. If you pass a PG or a 1D list to perform a MPMD collective, the compiler won't be able to recover
    that information and perform collective algebraic optimization. Use other forms of input for that.
    )
r   r-   r.   r   r   r   Ú all_gather_into_tensor_coalescedrJ   rK   r!   )r   r   r   r"   r6   rE   s         r   rM   rM   i  sX   € ô& % U¨CÓ0€JÜ×-Ñ-¨jÓ9€JÜ—)‘)×,Ñ,×MÑMØØØó€Kô
 ”Ô&¨Ó4Ó5Ð5r   Úinputsc           
      ó:  — t        ||«      }t        j                  |«      }t        |«      t        | «      k(  sJ ‚t	        t        || «      «      D ]w  \  }\  }}	|	j                  |«      |z  dk(  s"J d|› d|	j                  |«      › d|› d|› �«       ‚|dk7  sŒHt        j                  |	||¬«      }
t        j                  |
«      | |<   Œy t        j                  j                  j                  | |j                  «       ||«      }
t        t        t         |
«      «      S )a,  
    Reduces a list of tensors across all machines in such a way that all get
    the final result, then scatter the results to corresponding ranks.

    The input tensors are left unmodified.
    Group can be one of:
        List[int]: ranks participating in the collective.
        List[List[int]]: 2D mesh of ranks taking part of this collective in MPMD.
        ProcessGroup: Will perform a collective using the ranks and tag of the PG.
        DeviceMesh: Do a SPMD collective over all ranks of the mesh
        (DeviceMesh, int): Do a MPMD collective over one dimension of the DeviceMesh

    :: N.B. If you pass a PG or a 1D list to perform a MPMD collective, the compiler won't be able to recover
    that information and perform collective algebraic optimization. Use other forms of input for that.
    r   zinput dimension z (rA   z for tensor at index r*   )r   r-   r.   ÚlenÚ	enumerateÚziprB   r   r4   r3   r   r   Úreduce_scatter_tensor_coalescedr&   rJ   rK   r!   )rN   r#   r>   r   r   r"   r6   Úidxr+   r   rE   s              r   rS   rS   †  s  € ô, % U¨CÓ0€JÜ×-Ñ-¨jÓ9€Jäˆ{Óœs 6›{Ò*Ð*Ð*Ü'¬¨K¸Ó(@ÓAò 1Ñˆ‰]ˆc�6Ø�{‰{˜3Ó *Ñ,°Ò1ð 	
Ø˜s˜e 2 f§k¡k°#Ó&6Ð%7Ð7YÐZdÐYeÐezÐ{~Ðzð  Aó	
Ð1ð �!‹8ÜŸ+™+ f¨j¸cÔBˆKÜŸ)™) KÓ0ˆF�3ŠKð1ô —)‘)×,Ñ,×LÑLØØ�‰ÓØØó	€Kô ”Ô&¨Ó4Ó5Ð5r   c                 ó’  — t        | t        j                  j                  «      sJ ‚t        j                  j                  | j                  «       t        j                  j                  «      ry| j                  }t        |j                  «      dkD  r6|j                  d   }|j                  d uxr |j                  j                   S y )NFr   )r0   r   Ú_opsÚ
OpOverloadÚ_CÚ%_dispatch_has_kernel_for_dispatch_keyÚnameÚDispatchKeyÚCompositeImplicitAutogradÚ_schemarP   Ú	argumentsÚ
alias_infoÚis_write)ÚtgtÚschemaÚ	first_args      r   Ú_is_view_oprd   ´  s¢   € Ü�cœ5Ÿ:™:×0Ñ0Ô1Ð1Ð1ô ‡x�x×5Ñ5Ø�‰‹
”E×%Ñ%×?Ñ?ôð Ø�[‰[€FÜ
ˆ6×ÑÓ˜qÒ Ø×$Ñ$ QÑ'ˆ	à×#Ñ#¨4Ð/ÒU¸	×8LÑ8L×8UÑ8UÐ4UÐUð !r   Úoutput_split_sizesÚinput_split_sizesc                 ól  — |�t        d„ |D «       «      sJ |«       ‚|�t        d„ |D «       «      sJ |«       ‚t        ||«      }t        j                  |«      }|�|€#|€|�J d«       ‚| j                  d   |z  g|z  }|}t
        j                  j                  j                  | |||«      }t        |«      S )aC  
    Each process splits input tensor and then scatters the split list
    to all processes in a group. Then concatenate the received tensors from all
    the processes in the group and return single output tensor.

    Group can be one of:
        List[int]: ranks participating in the collective.
        List[List[int]]: 2D mesh of ranks taking part of this collective in MPMD.
        ProcessGroup: Will perform a collective using the ranks and tag of the PG.
        DeviceMesh: Do a SPMD collective over all ranks of the mesh
        (DeviceMesh, int): Do a MPMD collective over one dimension of the DeviceMesh

    :: N.B. If you pass a PG or a 1D list to perform a MPMD collective, the compiler won't be able to recover
    that information and perform collective algebraic optimization. Use other forms of input for that.
    c              3   ó\   K  — | ]$  }t        |t        t        j                  f«      –— Œ& y ­w©N©r0   Úintr   ÚSymInt©Ú.0rB   s     r   ú	<genexpr>z$all_to_all_single.<locals>.<genexpr>Ú  ó%   è ø€ ò 
Ø6:ŒJ�tœc¤5§<¡<Ð0×1ñ
ùó   ‚*,c              3   ó\   K  — | ]$  }t        |t        t        j                  f«      –— Œ& y ­wri   rj   rm   s     r   ro   z$all_to_all_single.<locals>.<genexpr>Þ  rp   rq   ú^output_split_sizes and input_split_sizes must either be specified together or both set to Noner   )
Úallr   r-   r.   Úshaper   r   r   Úall_to_all_singler!   ©r   re   rf   r   r   r"   r6   r   s           r   rv   rv   Ã  sþ   € ð, Ð%Üñ 
Ø>Pô
ô 
ð 	àó	ð 
ð Ð$Üñ 
Ø>Oô
ô 
ð 	àó	ð 
ô % U¨CÓ0€JÜ×-Ñ-¨jÓ9€JØÐ!Ð%6Ð%>Ø!Ð)Ð.?Ð.Gð 	
ð5ó	
ÐGð #Ÿj™j¨™m¨zÑ9Ð:¸ZÑGÐØ.ÐÜ�Y‰Y×'Ñ'×9Ñ9ØØØØó	€Fô ˜fÓ%Ð%r   c                 ó€  — |�t        d„ |D «       «      sJ |«       ‚|�t        d„ |D «       «      sJ |«       ‚t        ||«      }t        j                  |«      }|�|€#|€|�J d«       ‚| j                  d   |z  g|z  }|}t
        j                  j                  j                  | |||«      }t        j                  |«      S )z:
    Same as all_to_all_single but supports autograd.
    c              3   ó\   K  — | ]$  }t        |t        t        j                  f«      –— Œ& y ­wri   rj   rm   s     r   ro   z-all_to_all_single_autograd.<locals>.<genexpr>þ  rp   rq   c              3   ó\   K  — | ]$  }t        |t        t        j                  f«      –— Œ& y ­wri   rj   rm   s     r   ro   z-all_to_all_single_autograd.<locals>.<genexpr>  rp   rq   rs   r   )rt   r   r-   r.   ru   r   r   r:   rv   r;   r<   rw   s           r   Úall_to_all_single_autogradr{   ó  s  € ð Ð%Üñ 
Ø>Pô
ô 
ð 	àó	ð 
ð Ð$Üñ 
Ø>Oô
ô 
ð 	àó	ð 
ô % U¨CÓ0€JÜ×-Ñ-¨jÓ9€JØÐ!Ð%6Ð%>Ø!Ð)Ð.?Ð.Gð 	
ð5ó	
ÐGð #Ÿj™j¨™m¨zÑ9Ð:¸ZÑGÐØ.ÐÜ�Y‰Y×0Ñ0×BÑBØØØØó	€Fô ×!Ñ! &Ó)Ð)r   Úsrc_dstc                 óZ  — t        ||«      \  }}}t        j                  |||«      }dg|z  }dg|z  }	t        |«      D ]\  \  }
}|
t	        j
                  |«      k(  r| j                  «       |	|<   |t	        j
                  |«      k(  sŒJ| j                  «       ||
<   Œ^ t        | ||	||«      S )a"  
    Permutes the elements of the tensor according to the given source/destination pairs. `src_dst` should
    be defined such that src_dst[m] == n means m sends to n.

    Group can be one of:
        List[int]: ranks participating in the collective.
        List[List[int]]: 2D mesh of ranks taking part of this collective in MPMD.
        ProcessGroup: Will perform a collective using the ranks and tag of the PG.
        DeviceMesh: Do a SPMD collective over all ranks of the mesh
        (DeviceMesh, int): Do a MPMD collective over one
    r   )Ú_expand_groupr-   Ú#_find_or_create_pg_by_ranks_and_tagrQ   ÚdistÚget_rankÚnumelrv   )r   r|   r   r   ÚtÚranksetr6   Úlocal_pgre   rf   r   Údsts               r   Úpermute_tensorr‡     s¹   € ô" +¨5°#Ó6Ñ€A€w�
Ü×7Ñ7¸¸7ÀJÓO€Hà˜˜zÑ)ÐØ˜˜jÑ(ÐÜ˜gÓ&ò 3‰ˆˆSØ”$—-‘- Ó)Ò)Ø%)§Z¡Z£\Ð˜cÑ"Ø”$—-‘- Ó)Ó)Ø&*§j¡j£lÐ˜sÒ#ð	3ô ˜TÐ#5Ð7HÈ%ÐQTÓUÐUr   c                   óò   — e Zd ZU dZej
                  ed<   eed<   ddgZe	dej
                  fd„«       Z
d„ Zd„ Ze	d„ «       Z	 dd	ed
ee   fd„Zdefd„Zd„ Zdej
                  fd„Zd„ Zedd„«       Zd„ Zy)r1   a¸  
    A Tensor wrapper subclass that is used to trigger a call to wait
    prior to first use of the underlying tensor.
    Use it inside functional collective pytorch wrappers like the following:
    def functional_collective(self, group, tag):
        tag, rankset, group_size = _expand_group(group, tag)
        tensor = torch.ops.c10d_functional.{collective}(self, tag, rankset, group_size)
        return _maybe_wrap_tensor(tensor)
    ÚelemÚ	completedc           
      ó  — t         j                  j                  | |j                  «       |j	                  «       |j                  «       |j                  |j                  |j                  |j                  ¬«      }||_
        d|_        |S )N)ÚstridesÚstorage_offsetÚdtypeÚlayoutÚdeviceÚrequires_gradF)r   ÚTensorÚ_make_wrapper_subclassrB   Ústrider�   rŽ   r�   r�   r‘   r‰   rŠ   )Úclsr‰   Úrs      r   Ú__new__zAsyncCollectiveTensor.__new__G  so   € ä�L‰L×/Ñ/ØØ�I‰I‹KØ—K‘K“MØ×.Ñ.Ó0Ø—*‘*Ø—;‘;Ø—;‘;Ø×,Ñ,ð 0ó 	
ˆð ˆŒØˆŒØˆr   c                 ó   — dgd fS ©Nr‰   r   ©r   s    r   Ú__tensor_flatten__z(AsyncCollectiveTensor.__tensor_flatten__W  s   € Øˆx˜ˆ~Ðr   c                 ó>   — | j                  «       j                  «       S ri   )Útrigger_waitÚtolistrš   s    r   rž   zAsyncCollectiveTensor.tolistZ  s   € Ø× Ñ Ó"×)Ñ)Ó+Ð+r   c                 ó*   — |�J ‚| d   }t        |«      S r™   )r1   )Úinner_tensorsÚmetaÚ
outer_sizeÚouter_strider‰   s        r   Ú__tensor_unflatten__z*AsyncCollectiveTensor.__tensor_unflatten__]  s!   € àˆ|Ðˆ|Ø˜VÑ$ˆÜ$ TÓ*Ð*r   NÚexpected_metadataÚexpected_typec                 óH   — |t         j                  ury | j                  «       S ri   )r   r’   r�   )r   r¥   r¦   s      r   Ú#__coerce_same_metadata_as_tangent__z9AsyncCollectiveTensor.__coerce_same_metadata_as_tangent__c  s"   € ð ¤§¡Ñ,Øà× Ñ Ó"Ð"r   r(   c                 ó*   — d| j                  «       › d�S )NzAsyncCollectiveTensor(ú))r�   rš   s    r   Ú__repr__zAsyncCollectiveTensor.__repr__k  s   € Ø'¨×(9Ñ(9Ó(;Ð'<¸AÐ>Ð>r   c                 ón   — | j                   st        | j                  «      }d| _         |S | j                  S ©NT)rŠ   r   r‰   )r   Úouts     r   r�   z"AsyncCollectiveTensor.trigger_waitn  s-   € Ø�~Š~Ü˜dŸi™iÓ(ˆCØ!ˆDŒNØˆJà—9‘9Ðr   c                 ó,   — t        | j                  «      S ri   )r   r‰   rš   s    r   r2   zAsyncCollectiveTensor.waitv  s   € Ü˜4Ÿ9™9Ó%Ð%r   c                 ó   — | j                   S )zOThis method enables  _functional_collectives_impl to test if a tensor is an ACS)r‰   rš   s    r   Ú_get_acs_underlying_tensorz0AsyncCollectiveTensor._get_acs_underlying_tensory  s   € à�y‰yÐr   c                 óš  ‡— |t         j                  j                  j                  j                  k(  r& ||d   j
                  |d   «      }t        |«      }|S t        |«      Šdt        fˆfd„}dt         j                  fd„}t        t        ||«      }	t        t        ||«      }
 ||	i |
¤Ž}‰rt        t         j                  ||«      }|S )Nr   r
   Úec                 ó@   •— ‰s| j                  «       S | j                  S ri   )r�   r‰   )r³   Ú
is_view_ops    €r   Úunwrapz8AsyncCollectiveTensor.__torch_dispatch__.<locals>.unwrapˆ  s   ø€ áØ—~‘~Ó'Ð'Ø—6‘6ˆMr   c                 ó@   — t        | t        «      rJ ‚t        | «      }|S ri   )r0   r1   )r³   r7   s     r   Úwrapz6AsyncCollectiveTensor.__torch_dispatch__.<locals>.wrapŽ  s"   € ä! !Ô%:Ô;Ð;Ð;Ü'¨Ó*ˆCØˆJr   )
r   r   ÚatenÚviewÚdefaultr‰   r1   rd   r’   r   )r•   ÚfuncÚtypesÚargsÚkwargsr7   Úwrapper_resr¶   r¸   Úunwrapped_argsÚunwrapped_kwargsr®   rµ   s               @r   Ú__torch_dispatch__z(AsyncCollectiveTensor.__torch_dispatch__}  s¿   ø€ à”5—9‘9—>‘>×&Ñ&×.Ñ.Ò.ñ �t˜A‘w—|‘| T¨!¡WÓ-ˆCÜ/°Ó4ˆKØÐä  Ó&ˆ
ð	Ô+õ 	ð	”E—L‘Ló 	ô 'Ô'<¸fÀdÓKˆÜ(Ô)>ÀÈÓOÐñ �NÐ7Ð&6Ñ7ˆñ Ü¤§¡¨d°CÓ8ˆCàˆ
r   c                 ó>   — | j                  «       j                  «       S ri   )r2   Únumpyrš   s    r   rÅ   zAsyncCollectiveTensor.numpy   s   € Ø�y‰y‹{× Ñ Ó"Ð"r   ri   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r’   Ú__annotations__ÚboolÚ	__slots__Ústaticmethodr—   r›   rž   r¤   r   r   Útyper¨   Ústrr«   r�   r2   r±   ÚclassmethodrÃ   rÅ   r   r   r   r1   r1   7  s½   … ñð �,‰,ÓØƒOà˜Ð%€Iàð˜5Ÿ<™<ò ó ðòò,ð ñ+ó ð+ð GKñ#Ø!$ð#Ø5=¸d±^ó#ð?˜#ó ?òð&�e—l‘ló &òð ò ó ð óD#r   r1   c           	      ó–  — t         rd„ }d„ }nd„ }d„ }t        | t        «      r†t        | d   t        «      r^ || «      }g }d}|D ]K  }|j                  |«       |dk7  r(|t	        |«      k7  rt        d|› dt	        |«      › �«      ‚t	        |«      }ŒM �n1 || «      }t	        |«      }�nt        | t        j                  «      r:t        j                  | «      }t	        |«      }|xs t        j                  | «      }nÈt        | t        «      r5| j                  d	k(  sJ d
«       ‚| j                  d   \  }}}t	        |«      }nƒt        | t        «      rht	        | «      dk(  rOt        | d   t        «      r<t        | d	   t        «      r)| d   }	| d	   }
|	j                  |
   \  }}}t	        |«      }nt        d«      ‚t        d«      ‚|||fS )a5  
    _expand_group desugars the different RANK_TYPES types into a canonical format that is traceable.

    By having this be part of the explicit eager codepath, we avoid having to specialize behavior inside
    torchdynamo and can still interoperate with processgroup objects or other untraceable forms.
    c                 ó>   — t        t        t        t              | «      S ri   ©r   rJ   rk   ©Úxs    r   Úcast_listlistintz'_expand_group.<locals>.cast_listlistintµ  s   € ÜœœT¤#™Y™¨Ó+Ð+r   c                 ó0   — t        t        t           | «      S ri   rÓ   rÔ   s    r   Úcast_listintz#_expand_group.<locals>.cast_listint¸  s   € ÜœœS™	 1Ó%Ð%r   c                 ó   — | S ri   r   rÔ   s    r   rÖ   z'_expand_group.<locals>.cast_listlistint¿  ó   € ØˆHr   c                 ó   — | S ri   r   rÔ   s    r   rØ   z#_expand_group.<locals>.cast_listintÂ  rÚ   r   r   éÿÿÿÿz$group sizes must be identical found z and r
   úJOnly 1D mesh is supported, pass in (DeviceMesh, int) together if mesh > 1Dé   ú1Invalid tuple for group must be (DeviceMesh, int)z[Invalid type for group, must be one of List, Processgroup, DeviceMesh or (DeviceMesh, int).)r   r0   rJ   ÚextendrP   Ú
ValueErrorr€   ÚProcessGroupÚget_process_group_ranksr-   Ú_get_group_tagr   ÚndimÚ_dim_group_infosÚtuplerk   )r   r   rÖ   rØ   Únested_listr„   r6   ÚrsÚ_Údmeshr+   s              r   r~   r~   ©  sË  € õ ò	,ó	&ò	ò	ô �%œÔÜ�e˜A‘h¤Ô%Ù*¨5Ó1ˆKØˆGØˆJØ!ò %�Ø—‘˜rÔ"Ø Ò#¨
´c¸"³gÒ(=Ü$Ø>¸z¸lÈ%ÔPSÐTVÓPWÈyÐYóð ô ! ›W‘
ò%ñ # 5Ó)ˆGÜ˜W›ŠJÜ	�Eœ4×,Ñ,Ô	-Ü×.Ñ.¨uÓ5ˆÜ˜“\ˆ
ØÒ/”T×(Ñ(¨Ó/‰Ü	�Eœ:Ô	&Ø�z‰z˜QŠð 	
ØXó	
ˆð  ×0Ñ0°Ñ3‰ˆˆW�aÜ˜“\‰
Ü	�Eœ5Ô	!ä�‹J˜!ŠOÜ˜5 ™8¤ZÔ0Ü˜5 ™8¤SÔ)à˜!‘HˆEØ˜‘(ˆCØ#×4Ñ4°SÑ9‰OˆC�˜!Ü˜W›‰JäÐPÓQÐQäØió
ð 	
ð �˜*Ð%Ð%r   c                 ó®  — t        | t        j                  «      r| j                  S t        | t        «      r| S t        | t
        «      r(| j                  dk(  sJ d«       ‚| j                  d   d   S t        | t        «      r[t        | «      dk(  rBt        | d   t
        «      r/t        | d   t        «      r| d   }| d   }|j                  |   d   S t        d«      ‚t        | t        «      rQt        «       st        j                  dt         d¬«       t#        j$                  t'        t        t           | «      |«      S t        d	t)        | «      › d
| › �«      ‚)z;
    Given group in RANK_TYPES, return the group name.
    r
   rÝ   r   rÞ   rß   z—The combination of ranks + tag as process group identifier has been deprecated. Please switch to using ProcessGroup, DeviceMesh, or group name instead.é   )Ú
stacklevelzUnsupported group type: z, )r0   r€   râ   r"   rÏ   r   rå   ræ   rç   rP   rk   rá   rJ   r   ÚwarningsÚwarnÚFutureWarningr-   Ú$_resolve_group_name_by_ranks_and_tagr   rÎ   )r   r   rë   r+   s       r   r   r   ô  s8  € ô �%œ×*Ñ*Ô+Ø×ÑÐÜ	�Eœ3Ô	ØˆÜ	�Eœ:Ô	&Ø�z‰z˜QŠð 	
ØXó	
ˆð ×%Ñ% aÑ(¨Ñ+Ð+Ü	�Eœ5Ô	!ä�‹J˜!ŠOÜ˜5 ™8¤ZÔ0Ü˜5 ™8¤SÔ)à˜!‘HˆEØ˜‘(ˆCØ×)Ñ)¨#Ñ.¨qÑ1Ð1äÐPÓQÐQÜ	�Eœ4Ô	 Ü'Ô)Ü�M‰MðIô Øõô ×8Ñ8¼¼dÄ3¹iÈÓ9OÐQTÓUÐUäÐ3´D¸³K°=ÀÀ5À'ÐJÓKÐKr   c                   ó”   — e Zd ZdZedej                  dej                  fd„«       Zedej                  dej                  fd„«       Zy)r;   zm
    _FromTorchTensor allows autograd to propagate from a normal Tensor to an
    AsyncCollectiveTensor.
    Úinputr(   c                 ó   — t        |«      S ri   )r!   )Úctxrô   s     r   Úforwardz_FromTorchTensor.forward"  s   € ô
 " %Ó(Ð(r   Úgrad_outputc                 ó   — |S ri   r   )rö   rø   s     r   Úbackwardz_FromTorchTensor.backward)  s   € àÐr   N)	rÆ   rÇ   rÈ   rÉ   rÍ   r   r’   r÷   rú   r   r   r   r;   r;     s_   „ ñð
 ð)à�|‰|ð)ð 
�‰ò)ó ð)ð ð 5§<¡<ð °E·L±Lò ó ñr   r;   c                  ó´   — t        «       ryt        j                  j                  t        j                  j                  j
                  «      �yt        «       d uS r­   )r   r   rX   Ú_get_dispatch_modeÚ_TorchDispatchModeKeyÚFAKEr	   r   r   r   Ú_are_we_tracingrÿ   .  sA   € ÜÔ!Øä‡x�x×"Ñ"¤5§8¡8×#AÑ#A×#FÑ#FÓGÐSØÜÓ 4Ð'Ð'r   c                 óv   — t        «       rt        | «      S t        | «      }t        t        j
                  |«      S ri   )rÿ   r   r1   r   r   r’   )r   r7   s     r   r!   r!   7  s.   € ÜÔÜ˜4Ó Ð Ü
 Ó
%€CÜ”—‘˜cÓ"Ð"r   Úvaluec              #   óf  K  — t         j                  j                  j                  «       }	 t         j                  j                  j	                  | «       d–— t         j                  j                  j	                  |«       y# t         j                  j                  j	                  |«       w xY w­w)aC  
    Context manager to temporarily set whether inflight collectives are allowed as torch.compile graph inputs.
    Common use case is when the collective is issued in eager (with `async_op=True`) but waited in compiled region:
    ```
    def all_reduce_eager(x):
        y = x * x
        req = dist.all_reduce(y, op=dist.ReduceOp.SUM, async_op=True)
        return y


    @torch.compile(fullgraph=True)
    def all_reduce_wait_compiled(y):
        torch.ops.c10d_functional.wait_tensor(y)
        return y * y


    x = torch.ones(1280, 1280, device="cuda") + self.rank
    # the context manager ensures that `wait_tensor(y)` will wait on the correct work object
    with allow_inflight_collective_as_graph_input_ctx():
        y = all_reduce_eager(x)
        z = all_reduce_wait_compiled(y)
    ```
    With this context manager, when a collective is called, under the hood the work object of the collective
    will be registered in the work registry, and the wait_tensor() in compiled region called on
    the output tensor of the collective will wait on the correct work object.
    N)r   rX   Ú_distributed_c10dÚ)_allow_inflight_collective_as_graph_inputÚ-_set_allow_inflight_collective_as_graph_input)r  Úpreviouss     r   Ú,allow_inflight_collective_as_graph_input_ctxr  >  sw   è ø€ ô8 �x‰x×)Ñ)×SÑSÓU€Hð
Ü�‰×"Ñ"×PÑPÐQVÔWÛä�‰×"Ñ"×PÑPØõ	
øŒ�‰×"Ñ"×PÑPØõ	
üs   ‚)B1¬-B Á*B1Â+B.Â.B1c                 óD   ‡— ˆfd„}| D �cg c]
  } ||«      ‘Œ c}S c c}w )Nc                 óv   •— t        | j                  «       «      }|dxx   ‰z  cc<   | j                  |«      }|S ©Nr   ©rJ   rB   Ú	new_empty)ÚshardÚout_sizeÚ
out_tensorr6   s      €r   Úmk_out_tensorz=_all_gather_into_tensor_coalesced_meta.<locals>.mk_out_tensorf  s5   ø€ Ü˜Ÿ
™
›Ó%ˆØ�‹�zÑ!‹Ø—_‘_ XÓ.ˆ
ØÐr   r   )r   r   r„   r6   r  rƒ   s      `  r   Ú&_all_gather_into_tensor_coalesced_metar  e  s#   ø€ ôð '+Ö+ ‰M˜!ÕÒ+Ð+ùÒ+ó   ‹c                 ó,   — t        j                  | «      S ri   ©r   Ú
empty_like©r   r¾   s     r   Ú_broadcast_metar  p  ó   € Ü×Ñ˜DÓ!Ð!r   c                 ó,   — t        j                  | «      S ri   r  r  s     r   Ú_all_reduce_metar  t  r  r   c                 ó,   — t        j                  | «      S ri   r  r  s     r   Ú_wait_tensor_metar  x  r  r   c                 óp   — t        | j                  «       «      }|dxx   |z  cc<   | j                  |«      S r
  r  )r  r   r„   r6   r  s        r   Ú_all_gather_into_tensor_metar  |  s/   € Ü�E—J‘J“LÓ!€HØˆQƒK�:ÑƒKØ�?‰?˜8Ó$Ð$r   c                 óp   — t        | j                  «       «      }|dxx   |z  cc<   | j                  |«      S r
  r  )rô   Ú	reduce_opr   r„   r6   r  s         r   Ú_reduce_scatter_tensor_metar!  ‚  s/   € Ü�E—J‘J“LÓ!€HØˆQƒK�JÑƒKØ�?‰?˜8Ó$Ð$r   c                 óR   — | D �cg c]  }t        j                  |«      ‘Œ c}S c c}w ri   r  )r   r¾   rƒ   s      r   Ú_all_reduce_coalesced_metar#  ˆ  s!   € Ø)-Ö. AŒE×Ñ˜QÕÒ.Ð.ùÒ.s   …$c                 ó   — | S ri   r   ©Úinpr¾   s     r   Ú_all_reduce__metar'  Œ  ó   € Ø€Jr   c                 ó   — | S ri   r   r%  s     r   Ú_broadcast__metar*  �  r(  r   c                 ó   — | S ri   r   )rN   r¾   s     r   Ú_all_reduce_coalesced__metar,  ”  s   € Ø€Mr   c                 óD   ‡— ˆfd„}| D �cg c]
  } ||«      ‘Œ c}S c c}w )Nc                 óv   •— t        | j                  «       «      }|dxx   ‰z  cc<   | j                  |«      }|S r
  r  )rô   r  r  r6   s      €r   r  z<_reduce_scatter_tensor_coalesced_meta.<locals>.mk_out_tensor™  s5   ø€ Ü˜Ÿ
™
›Ó%ˆØ�‹˜
Ñ"‹Ø—_‘_ XÓ.ˆ
ØÐr   r   )rN   r#   r   r„   r6   r  rƒ   s       `  r   Ú%_reduce_scatter_tensor_coalesced_metar/  ˜  s#   ø€ ôð '-Ö- ‰M˜!ÕÒ-Ð-ùÒ-r  c                 óì   — |€| j                  | j                  «       «      S |D ]  }t        j                  |«       Œ t	        | j                  «       «      }t        |«      |d<   | j                  |«      S r
  )r  rB   r   Ú_check_is_sizerJ   Úsum)rô   re   rf   r¾   r¿   Úsr  s          r   Ú_all_to_all_single_metar4  §  sj   € ð Ð!Ø�‰˜uŸz™z›|Ó,Ð,à#ò 	$ˆAÜ× Ñ  Õ#ð	$ä˜Ÿ
™
›Ó%ˆÜÐ,Ó-ˆ�‰Ø�‰˜xÓ(Ð(r   c                óp   — t        | j                  «       «      }|dxx   |z  cc<   | j                  |«      S r
  r  )rô   r6   r"   r®   ru   s        r   Ú'_all_gather_into_tensor_out_native_metar6  ´  ó/   € Ü�—‘“Ó€EØ	ˆ!ƒH�
ÑƒHØ�?‰?˜5Ó!Ð!r   c                 óp   — t        | j                  «       «      }|dxx   |z  cc<   | j                  |«      S r
  r  )rô   r6   r"   ru   s       r   Ú#_all_gather_into_tensor_native_metar9  º  r7  r   c                 óB   — | D �cg c]  }t        |||«      ‘Œ c}S c c}w ri   )r9  )rN   r6   r"   rô   s       r   Ú-_all_gather_into_tensor_coalesced_native_metar;  À  s-   € ð öàô 	,¨E°:¸zÕJòð ùò s   …c                 óp   — t        | j                  «       «      }|dxx   |z  cc<   | j                  |«      S r
  r  )r&  r   r6   r"   ru   s        r   Ú"_reduce_scatter_tensor_native_metar=  Ç  s/   € Ü�—‘“Ó€EØ	ˆ!ƒH�ÑƒHØ�=‰=˜ÓÐr   c           	      óD   — | D �cg c]  }t        ||||«      ‘Œ c}S c c}w ri   )r=  )rN   r   r6   r"   r&  s        r   Ú,_reduce_scatter_tensor_coalesced_native_metar?  Í  s/   € ð
 öàô 	+¨3°	¸:ÀzÕRòð ùò s   …r   ÚIMPLr%   ÚMetaÚall_reduce_rI   Úall_reduce_coalesced_r   Úall_gather_into_tensor_outr/   rM   rC   rS   rv   r    Ú
broadcast_Úc10d_functionalÚDEF)	zObroadcast(Tensor self, int src, str tag, int[] ranks, int group_size) -> TensorzUall_reduce(Tensor self, str reduceOp, str tag, int[] ranks, int group_size) -> Tensorzcall_reduce_coalesced(Tensor[] self, str reduceOp, str tag, int[] ranks, int group_size) -> Tensor[]z"wait_tensor(Tensor self) -> TensorzTall_gather_into_tensor(Tensor shard, str tag, int[] ranks, int group_size) -> Tensorzball_gather_into_tensor_coalesced(Tensor[] input, str tag, int[] ranks, int group_size) -> Tensor[]zareduce_scatter_tensor(Tensor input, str reduceOp, str tag, int[] ranks, int group_size) -> Tensorzpreduce_scatter_tensor_coalesced(Tensor[] inputs, str reduceOp, str tag, int[] ranks, int group_size) -> Tensor[]zŠall_to_all_single(Tensor input, SymInt[]? output_split_sizes, SymInt[]? input_split_sizes, str tag, int[] ranks, int group_size) -> Tensorú(rê   )Útagsr\   zJPyTorch Distributed functional collectives do not work with torch::deploy.Úoutput_tensorÚinput_tensorÚasync_opc                 ó’   — |rJ d«       ‚|xs t         j                  j                  }|€J ‚| j                  t	        ||||«      «      S ©Nú@Can't remap async version of inplace op to functional collective)r€   r   ÚWORLDÚcopy_r8   )rJ  rK  r   rL  r   r'   s         r   Úall_gather_tensor_inplacerR    sV   € ñ ð ØJóˆ<ð Ò%”T—Z‘Z×%Ñ%€EØÐÐÐà×ÑÔ0°¸zÈ5ÐRUÓVÓWÐWr   r2  Úoutputrô   Úopc           	      ó”   — |rJ d«       ‚|xs t         j                  j                  }|€J ‚| j                  t	        |||||«      «      S rN  )r€   r   rP  rQ  rC   )rS  rô   rT  r   rL  r>   r   s          r   Úreduce_scatter_tensor_inplacerV  1  sU   € ñ ð ØJóˆ<ð Ò%”T—Z‘Z×%Ñ%€EØÐÐÐà�<‰<Ô-¨e°R¸ÀeÈSÓQÓRÐRr   ÚavgÚproductÚminÚmaxÚbandÚborÚbxorr   c                 ó’   — |rJ d«       ‚|xs t         j                  j                  }|€J ‚| j                  t	        | |||«      «      S rN  )r€   r   rP  rQ  r%   )r   rT  r   rL  r   s        r   Úall_reduce_inplacer_  P  sR   € ñ ð ØJóˆ<ð Ò%”T—Z‘Z×%Ñ%€EØÐÐÐà�<‰<œ
 6¨2¨u°cÓ:Ó;Ð;r   c           	      ó”   — |rJ d«       ‚|xs t         j                  j                  }|€J ‚| j                  t	        |||||«      «      S rN  )r€   r   rP  rQ  rv   )rS  rô   re   rf   r   rL  r   s          r   Úall_to_all_inplacera  a  s`   € ñ ð ØJóˆ<ð Ò%”T—Z‘Z×%Ñ%€EØÐÐÐà�<‰<ÜØØØØØó	
óð r   rE   c           	      ó„  ‡— |rJ d«       ‚t        ˆfd„| D «       «      sJ d«       ‚|xs t        j                  j                  }|€J ‚t	        ‰d||«      }g }d}| D ]<  }|j                  ||||j                  d«      z    «       ||j                  d«      z  }Œ> t        | |«      D ]  \  }	}
|	j                  |
«       Œ | S )NrO  c              3   ód   •K  — | ]'  }|j                  d «      ‰j                  d «      k(  –— Œ) y­w)r   N)rB   )rn   rƒ   r   s     €r   ro   z%all_gather_inplace.<locals>.<genexpr>†  s&   øè ø€ Ò@¨qˆq�v‰v�a‹y˜FŸK™K¨›NÕ*Ñ@ùs   ƒ-0z7Remapping variable size all_gather is not yet supportedr   )	rt   r€   r   rP  r8   ÚappendrB   rR   rQ  )rE   r   r   rL  r   rS  Úoutput_splitsÚoffsetrƒ   r†   r   s    `         r   Úall_gather_inplacerg  |  så   ø€ ñ ð ØJóˆ<ô Ó@°KÔ@Ô@ð ØAóÐ@ð Ò%”T—Z‘Z×%Ñ%€EØÐÐÐä˜v q¨%°Ó5€Fð €MØ€FØò ˆØ×Ñ˜V F¨V°a·f±f¸Q³iÑ-?Ð@ÔAØ�!—&‘&˜“)Ñ‰ðô ˜ ]Ó3ò ‰ˆˆSØ�	‰	�#�ðàÐr   )Ú_all_gather_baseÚ_reduce_scatter_baseÚ
all_gatherr/   r%   rv   rC   )Ú )T)NFrk  r   )r2  NFr   rk  )r2  NFrk  )NNNFrk  )NFrk  )…Ú
contextlibÚsysrï   Útypingr   r   r   r   r   r   Útorch.distributedÚdistributedr€   Ú"torch.distributed.distributed_c10dÚdistributed_c10dr-   Útorch.distributed.device_meshr   Ú"torch.fx.experimental.proxy_tensorr	   rk  r   Úfun_col_implÚtorch.utils._cxx_pytreer   ÚImportErrorÚtorch.utils._pytreeÚ_running_with_deployr   Útorch.compilerr   Ú	Exceptionrð   rJ   rk   râ   rç   rÏ   Ú
RANK_TYPESr   r’   r    r%   r8   r=   rC   rG   rI   rM   rS   rd   rv   r{   r‡   r1   r~   r   ÚautogradÚFunctionr;   rË   rÿ   r!   Úcontextmanagerr  r  r  r  r  r  r!  r#  r'  r*  r,  r/  r4  r6  r9  r;  r=  r?  ÚlibraryÚLibraryÚlib_implÚimplÚfxÚnodeÚhas_side_effectr   r   r»   Ú
legacy_libÚlegacy_lib_implÚops_defsÚmodulesrÆ   Ú	my_moduleÚop_defÚindexÚop_nameÚgetattrÚbackend_implÚdefineÚTagÚpt2_compliant_tagrR  rV  ÚReduceOpÚSUMÚAVGÚPRODUCTÚMINÚMAXÚBANDÚBORÚBXORÚREDUCE_OP_TO_STRr_  ra  rg  rh  Úlegacy_all_gather_baseri  Úlegacy_reduce_scatter_baserj  Úlegacy_all_gatherr/   Úlegacy_allgatherÚlegacy_allreduceÚlegacy_all_to_all_singleÚlegacy_reducescatterÚtraceable_collective_remapsr   r   r   ú<module>r¦     se	  ðã Û 
Û ß <Õ <ã Ý  ß 1Ð 1Ý 4Ý =å :ð2Ý5ð
 €5×ÑÔóð
ÝRðð#ðJð
 Øˆ�IØˆˆc‰�OØ×ÑØØ	Ð
" CÐ
'Ñ(Øð	ñ€
ðò::ñ&�E—L‘Lð & sð &°:ð &ÀCó &ñ&�U—\‘\ð &¨Sð &¸ð &È#ó &ð4 ñ	$Ø
�,‰,ð$àð$ð ð$ð 
ð	$ð
 ‡\�\ó$ðV ñ	Ø
�,‰,ðàðð ðð 
ó	ðL ñ'Ø
�,‰,ð'àð'ð ð'ð ð	'ð
 
ó'ð^ ñ$Ø
�,‰,ð$àð$ð ð$ð ð	$ð
 
ó$ðP LNñ6Ø
ˆu�|‰|Ñ
ð6Ø(+ð6Ø4>ð6ØEHð6à	ˆ%�,‰,Ñó6ð: =?ñ6Ø
ˆu�|‰|Ñ
ð6Ø%/ð6Ø69ð6à	ˆ%�,‰,Ñó6ðD ñ)6Ø�—‘Ñð)6àð)6ð �c‘ð)6ð ð	)6ð
 
ð)6ð 
ˆ%�,‰,Ñó)6ò\Vð( ñ-&Ø
�,‰,ð-&à   c¡Ñ+ð-&ð    S¡	Ñ*ð-&ð ð	-&ð
 
ð-&ð ‡\�\ó-&ðj ñ"*Ø
�,‰,ð"*à   c¡Ñ+ð"*ð    S¡	Ñ*ð"*ð ð	"*ð
 
ð"*ð ‡\�\ó"*ðR ñ	VØ
�,‰,ðVà�#‰YðVð ðVð 
ð	Vð
 ‡\�\óVô>j#˜EŸL™Lô j#ðZñ
H&˜ð H&¨#ð H&°u¸SÀ$ÀsÁ)ÈSÐ=PÑ7Qó H&ñV%L˜zð %L°ð %L¸Só %LôP�u—~‘~×.Ñ.ô ð$(˜ó (ð# §¡ó #ð ×Ññ#
¸ò #
ó ð#
òL,ò"ò"ò"ò%ò%ò/òòòò.ò
)ò"ò"òò òð "€u×!Ñ!Õ#ð �}‰}×$Ñ$Ð%7¸Ó@€HØ‡M�M�,Ð 0°&Ô9Ø‡M�M�-Ð!2°FÔ;Ø‡M�MÐ(Ð*DÀfÔMØ‡M�MÐ)Ð+FÈÔOØ‡M�M�-Ð!2°FÔ;Ø‡M�MØ$Ð&MÈvôð ‡M�MÐ*Ð,OÐQWÔXØ‡M�MØ*Ø5Øôð
 ‡M�MÐ)Ð+MÈvÔVØ‡M�MØ)Ø4Øôð
 ‡M�MÐ%Ð'>ÀÔGØ‡M�M�+˜°Ô7Ø‡M�M�,Ð 0°&Ô9ð 
‡H�H‡M�M×!Ñ! %§)¡)×"<Ñ"<×"HÑ"H×"PÑ"PÔQØ	‡H�H‡M�M×!Ñ! %§)¡)×"<Ñ"<×"HÑ"HÔIð —‘×&Ñ&Ð'8¸%Ó@€JØ—m‘m×+Ñ+Ð,=¸vÓF€Oò
€Hð —‘˜HÑ%€IØò QˆØ˜˜VŸ\™\¨#Ó.Ð/ˆÙ˜|¨q°°	¨]Ó;ˆØ×Ñ˜& u§y¡y×'BÑ'BÐÔCØ×Ñ˜W lÐ4OÕPñ	Qð €H‡M�MØTôð
ð ØØØñXØ—<‘<ðXà—,‘,ðXð ð	Xð
 
ðXð óXð* Ø
ØØØñSØ�L‰LðSà�<‰<ðSð 	ðSð
 ðSð ðSð 
óSð( 	‡M�M×Ñ�uØ‡M�M×Ñ�uØ‡M�M×Ñ˜9Ø‡M�M×Ñ�uØ‡M�M×Ñ�uØ‡M�M×Ñ˜Ø‡M�M×Ñ�uØ‡M�M×Ñ˜ð	Ð ð Ø
ØØñ<Ø�L‰Lð<àð<ð ð	<ð
 
ó<ð( ØØ
ØØñØ�L‰Lðà�<‰<ðð 
óð< ØØñØ�e—l‘lÑ#ðà�L‰Lðð
 
ó÷>÷ ñ ð Ð/ØÐ7ØÐ(ØÐ0ØÐ)ØÐ =ØÐ5ðÑ øðm$ ò 2ß1Ð1ð2ûð ò Øˆ�‰Ørô	
õ	ðús$   Á[, Á[> Û,[;Û:[;Û>\Ü\