+
    &jG                        ^ RI t ^ RIt^ RIHt ^ RIHt ^ RIHtHt RR/R lt	R t
]P                  3R lt^ ]P                  3R lt^ ]P                  3R	 lt]P                  ]P                  3R
 lt]P                  ]P                  3R lt]P                  3R lt]P                  3R lt]P                  3R ltRR]P                  3R lt]P                  ]P                  3R lt ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R ]4      t ! R! R"]4      t ! R# R$]4      t R# )%    N)Function)groupReduceOp
suggestionc                N    R V  R2pV'       d   VRV R2,          p\        V4      h) torch.distributed.nn.functional.z& is not supported under torch.compile.z Use 	 instead.)RuntimeError)namer   msgs   &$ w/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/distributed/nn/functional.py_not_supported_under_compiler      s7    
*4&0VW  zl),,
s
    c                 N    \         P                  ! R V  RV R2\        ^R7       R# )r   z is deprecated, use r	   )category
stacklevelN)warningswarnFutureWarning)r   r   s   &&r   _deprecatedr      s,    MM
*4& 1l)	%	r   c                    \         P                  P                  4       '       d   \        RRR7       \	        RR4       \
        P                  WV 4      # )a  
Broadcasts the tensor to the whole group.

``tensor`` must have the same number of elements in all processes
participating in the collective.

Arguments:
    tensor (Tensor): Data to be sent if ``src`` is the rank of current
        process.
    src (int): Source rank.
    group (ProcessGroup, optional): The process group to work on.

Returns:
    Tensor: Received tensor from the broadcast op.

	broadcastz3torch.distributed._functional_collectives.broadcastr   )torchcompileris_compilingr   r   
_Broadcastapply)tensorsrcr   s   &&&r   r   r       sE    " ~~""$$$L	
 RSC//r   c                    \         P                  P                  4       '       d   \        R4       \        P                  WV 4      # )a4  
Gathers a list of tensors in a single process.

Arguments:
    tensor (Tensor): Input tensor.
    dst (int, optional): Destination rank (default is 0).
    group (ProcessGroup, optional): The process group to work on.

Returns:
    tuple[Tensor]: List of appropriately-sized tensors with the gathered data.
gather)r   r   r   r   _Gatherr   )r   dstr   s   &&&r   r"   r"   :   s0     ~~""$$$X.==V,,r   c                    \         P                  P                  4       '       d   \        R4       \        P
                  ! W.V O5!  # )a  
Scatters a list of tensors to all processes in a group.

Each process will receive exactly one tensor and store its data in the
``tensor`` argument.

Arguments:
    tensors (list[Tensor]): List of tensors to scatter on the source rank.
        Receivers must pass ``None`.
    src (int, optional): Source rank (default is 0).
    group (ProcessGroup, optional): The process group to work on.

Returns:
    Tensor: Output tensor from the scatter operation.

scatter)r   r   r   r   _Scatterr   )tensorsr    r   s   &&&r   r&   r&   K   s3    " ~~""$$$Y/>>#/w//r   c                    \         P                  P                  4       '       d   \        R4       \        P                  WW04      # )a  
Reduces the tensor data across all machines.

Only the process with rank ``dst`` is going to receive the final result.

Arguments:
    tensor (Tensor): Input of the collective.
    dst (int): Destination rank.
    op (optional): One of the values from
        ``torch.distributed.ReduceOp``
        enum.  Specifies an operation used for element-wise reductions.
    group (ProcessGroup, optional): The process group to work on.

Returns:
    Tensor: Output of the collective.

reduce)r   r   r   r   _Reducer   )r   r$   opr   s   &&&&r   r*   r*   a   s0    $ ~~""$$$X.==%00r   c                    \         P                  P                  4       '       d   \        RRR7       \	        RR4       \
        P                  ! W#V .VO5!  # )a  
Reduces, then scatters a list of tensors to all processes in a group.

Arguments:
    output (Tensor): Output tensor.
    input_list (list[Tensor]): List of tensors to reduce and scatter.
    op (optional): One of the values from
        ``torch.distributed.ReduceOp``
        enum.  Specifies an operation used for element-wise reductions.
    group (ProcessGroup, optional): The process group to work on.

Returns:
    Tensor: Output of the collective.

reduce_scatterz?torch.distributed._functional_collectives.reduce_scatter_tensorr   )r   r   r   r   r   _Reduce_Scatterr   )output
input_listr,   r   s   &&&&r   r.   r.   x   sO      ~~""$$$X	
 I   F@Z@@r   c                    \         P                  P                  4       '       d   \        RRR7       \	        RR4       \
        P                  W4      # )z
Gathers tensors from the whole group in a list.

Arguments:
    tensor (Tensor): Tensor to be broadcast from current process.
    group (ProcessGroup, optional): The process group to work on.

Returns:
    tuple([Tensor]): Output of the collective.


all_gatherz;torch.distributed._functional_collectives.all_gather_tensorr   )r   r   r   r   r   
_AllGatherr   )r   r   s   &&r   r3   r3      sH     ~~""$$$T	
 S E**r   c                    \         P                  P                  4       '       d   \        R4       \        P                  WV4      # )av  
Single tensor all gather. Gathers a single tensor from all ranks, and puts them in a single output tensor.

Args:
    output_tensor (Tensor): Output tensor. It should contain
        correctly-sized tensors to be used for output of the collective.
    input_tensor (Tensor): Tensor to be broadcast from current process.
    group (ProcessGroup, optional): The process group to work on. If None,
        the default process group will be used.

Examples:
    >>> # All tensors below are of torch.int64 dtype.
    >>> # We have 2 process groups, 2 ranks.
    >>> # xdoctest: +SKIP("incorrect want text")
    >>> output_tensor = torch.zeros(2, dtype=torch.int64)
    >>> output_tensor
    [tensor([0, 0])] # Rank 0 and 1
    >>> tensor = torch.arange(1, dtype=torch.int64) + 1 + rank
    >>> tensor
    tensor([1]) # Rank 0
    tensor([2]) # Rank 1
    >>> dist.all_gather_base(output_tensor, tensor)
    >>> output_tensor
    tensor([1,2]) # Rank 0
    tensor([1,2]) # Rank 1

.. warning::
    `_all_gather_base` is experimental and subject to change.
    It is the caller's responsibility to ensure the output_tensor
    is correctly sized.

_all_gather_base)r   r   r   r   _AllGatherBaser   )output_tensorinput_tensorr   s   &&&r   r6   r6      s4    B ~~""$$$%78UCCr   c                    \         P                  P                  4       '       d   \        R4       \        P
                  ! W .VO5!  # )a  
Each process scatters list of input tensors to all processes in a group and return gathered list of tensors in output list.

Arguments:
    output_tensor_list (list[Tensor]): list of tensors to gather one per rank.
    input_tensor_list (list[Tensor]): List of tensors to scatter one per rank.
    group (ProcessGroup, optional): The process group to work on.

Returns:
    tuple([Tensor]): Output of the collective.


all_to_all)r   r   r   r   	_AlltoAllr   )output_tensor_listinput_tensor_listr   s   &&&r   r;   r;      s4     ~~""$$$\2??5I7HIIr   c                    \         P                  P                  4       '       d   \        RRR7       \	        RR4       \
        P                  W@W#V4      # )a  
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.

Arguments:
    output (Tensor): Gathered concatenated output tensor.
    input (Tensor): Input tensor to scatter.
    output_split_sizes: (list[Int], optional): Output split sizes for dim 0
        if specified None or empty, dim 0 of ``output`` tensor must divide
        equally by ``world_size``.
    input_split_sizes: (list[Int], optional): Input split sizes for dim 0
        if specified None or empty, dim 0 of ``input`` tensor must divide
        equally by ``world_size``.

Returns:
    Tensor: Output of the collective.

all_to_all_singlez;torch.distributed._functional_collectives.all_to_all_singler   )r   r   r   r   r   _AlltoAllSingler   )r0   inputoutput_split_sizesinput_split_sizesr   s   &&&&&r   r@   r@      sR    4 ~~""$$$T	
 E   )e r   c                    \         P                  P                  4       '       d   \        RRR7       \	        RR4       \
        P                  WV 4      # )a  
Reduces the tensor data across all machines in such a way that all get the final result.

After the call the returned tensor is going to be bitwise
identical in all processes.

Arguments:
    tensor (Tensor): Input of the collective.
    op (optional): One of the values from
        ``torch.distributed.ReduceOp``
        enum.  Specifies an operation used for element-wise reductions.
    group (ProcessGroup, optional): The process group to work on.

Returns:
    Tensor: Output of the collective


all_reducez4torch.distributed._functional_collectives.all_reducer   )r   r   r   r   r   
_AllReducer   )r   r,   r   s   &&&r   rF   rF     sE    $ ~~""$$$M	
 TUBv..r   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )r   i&  c                    Wn         W n        \        P                  ! VR 7      V n        VP                  4       p\        P                  ! W1VR 7       V# r   )r    r   distget_rankrankcloner   )ctxr    r   r   s   &&&&r   forward_Broadcast.forward'  s>     	==u- v%0r   c                    \         P                  V P                  \        P                  V P
                  V4      pV P                  V P                  8w  d   VP                  4        R R V3# N)r+   r   r    r   SUMr   rN   zero_)rP   grad_outputgxs   && r   backward_Broadcast.backward3  sJ     ]]377HLL#))[I77chhHHJdBr    N	__name__
__module____qualname____firstlineno__staticmethodrQ   rY   __static_attributes____classdictcell____classdict__s   @r   r   r   &  s+          r   r   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )r#   i<  c                |   Wn         W n        \        \        P                  ! VR 7      4       Uu. uF  p\
        P                  ! V4      NK  	  ppVP                  4       p\        P                  ! VR 7      V8X  d   \        P                  ! W5WR 7       M\        P                  ! VRWR 7       \        V4      # u upi )rK   N)r$   r   rangerL   get_world_sizer   
zeros_like
contiguousrM   r"   tuple)rP   r$   r   r   itensor_lists   &&&&  r   rQ   _Gather.forward=  s     	 /4D4G4Ge4T.U
.UEV$.U 	 
 ""$==u%,KKS>KKc7[!!
s   B9c                l    R\         P                  ! V P                  V P                  .VO5!  3,           # NNN)r'   r   r$   r   )rP   grad_outputss   &*r   rY   _Gather.backwardQ  s(    x~~cggsyyP<PRRRr   r[   Nr\   rd   s   @r   r#   r#   <  s-     " "$ S Sr   r#   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )r'   iV  c                  a Wn         W n        \        ;QJ d    V3R  lS 4       F  '       d   K   RM	  RM! V3R  lS 4       4      '       g   \        h\        P
                  ! S^ ,          4      p\        P                  ! VR7      V8X  d%   \        P                  ! V\        S4      WR7       V# \        P                  ! VRWR7       V# )c              3   r   <"   T F,  qP                  4       S^ ,          P                  4       8H  x  K.  	  R# 5i)r   N)size).0tr(   s   & r   	<genexpr>#_Scatter.forward.<locals>.<genexpr>\  s%     B'Q668wqz00's   47FTrK   N)
r    r   allAssertionErrorr   rj   rL   rM   r&   list)rP   r    r   r(   r0   s   &&&j r   rQ   _Scatter.forwardW  s     	sB'BsssB'BBB  !!'!*-==u%,LLgA  LLs8r   c                f    R\         P                  V P                  V P                  V4      ,           # rq   )r#   r   r    r   rP   rW   s   &&r   rY   _Scatter.backwarde  s$     gmmCGGSYYLLLr   r[   Nr\   rd   s   @r   r'   r'   V  s-     
 
 M Mr   r'   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )r+   ik  c                n    Wn         W0n        VP                  4       p\        P                  ! WAW#R 7       V# )r,   r   )r    r   rO   rL   r*   )rP   r    r,   r   r   s   &&&&&r   rQ   _Reduce.forwardl  s,     	FB4r   c                h    R\         P                  V P                  V P                  V4      3,           # N)NNN)r   r   r    r   r   s   &&r   rY   _Reduce.backwardu  s)     "Z%5%5cggsyy+%V$XXXr   r[   Nr\   rd   s   @r   r+   r+   k  s-       Y Yr   r+   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )r/   i{  c                    W n         VP                  4       p\        ;QJ d    . R  V 4       F  NK  	  5M! R  V 4       4      p\        P                  ! V\        V4      WR7       V# )c              3   @   "   T F  qP                  4       x  K  	  R # 5irT   rk   ry   rz   s   & r   r{   *_Reduce_Scatter.forward.<locals>.<genexpr>  s     !L:KQ,,..:K   r   )r   rk   rl   rL   r.   r   )rP   r,   r   r   r>   s   &&&&*r   rQ   _Reduce_Scatter.forward|  sU     	""$!E!L:K!LEE!L:K!LLFD):$;Pr   c                P    R\         P                  V P                  V4      ,           # r   )r4   r   r   r   s   &&r   rY   _Reduce_Scatter.backward  s      "J$4$4SYY$LLLr   r[   Nr\   rd   s   @r   r/   r/   {  s-       M Mr   r/   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )r4   i  c                   VP                  4       pWn        \        \        P                  ! VR 7      4       Uu. uF  p\
        P                  ! V4      NK  	  pp\        P                  ! WBVR 7       \        V4      # u upi rJ   )	rk   r   rh   rL   ri   r   
empty_liker3   rl   )rP   r   r   _out_tensor_lists   &&&  r   rQ   _AllGather.forward  so     ""$	.3D4G4Ge4T.U
.UEV$.U 	 
 	u=_%%
s   A=c                   \         P                  ! V P                  R 7      \         P                  P                  \         P                  P
                  39   dt   \         P                  ! V P                  R 7      p\        P                  ! W,          4      p\        P                  ! \        P                  V P                  V.VO5!  pRV3# V Uu. uF  p\        P                  ! V4      NK  	  pp\        P                  ! V P                  V.VO5!  p\        P                  ! \        P                  ! V4      ^ R7      pRV3# u upi )rK   )dimN)rL   get_backendr   BackendNCCLXCCLrM   r   r   r/   r   r   rU   r<   sumstack)rP   rs   rN   rX   r   rn   gxss   &*     r   rY   _AllGather.backward  s    #)),1B1BDLLDUDU0VV==syy1D!!,"45B &&x||SYYR\RB bz COO,5++F3,KO//#))[H<HC5;;s+3Bbz Ps   Er[   Nr\   rd   s   @r   r4   r4     s+     
& 
&  r   r4   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )r7   i  c                ^    W0n         \        P                  ! WP                  4       VR 7       V# rJ   )r   rL   r6   rk   )rP   r8   r9   r   s   &&&&r   rQ   _AllGatherBase.forward  s(     	m-D-D-FeTr   c                   \         P                  ! V P                  R 7      \         P                  P                  \         P                  P
                  39   d   \         P                  ! V P                  R 7      p\        VP                  4       4      pV^ ,          V,          ^ 8w  d   \        RV RV 24      hV^ ,          \         P                  ! V P                  R 7      ,          V^ &   \        P                  ! W1P                  VP                  R7      p\         P                  ! WA\        P                   V P                  4       M\        R4      hRVR3# )rK   zTensor with dimensions: z8 does not have first dimension divisible by world_size: devicedtypezBackend not supported!N)rL   r   r   r   r   r   ri   r   rx   r
   r   emptyr   r   _reduce_scatter_baser   rU   )rP   rW   
world_sizeout_sizerX   s   &&   r   rY   _AllGatherBase.backward  s    #)),1B1BDLLDUDU0VV,,399=JK,,./H{Z'1,".xj 9IISV  #1+)<)<399)MMHQK!3!3;;L;LB %%bx||SYYO788b$r   r[   Nr\   rd   s   @r   r7   r7     s+      
    r   r7   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )r<   i  c                   Wn         \        \        P                  ! VR 7      4       Uu. uF  qCV,          P	                  4       NK  	  upV n        \        P                  ! VR 7      p\        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      p\        P                  ! VR 7      \        P                  P                  J d[   \        \        P                  ! VR 7      4       F5  pRpWE8X  d   \        V4      p\        P                  ! W$,          WdVR 7       K7  	  M"\        P                  ! V\        V4      VR 7       \        V4      # u upi )rK   c              3   @   "   T F  qP                  4       x  K  	  R # 5irT   r   r   s   & r   r{   $_AlltoAll.forward.<locals>.<genexpr>  s     81r   N)r   rh   rL   ri   rx   input_tensor_size_listrM   rl   r   r   GLOOr   r&   r;   )rP   r   r   r(   rm   my_rankto_sends   &&&*   r   rQ   _AlltoAll.forward  s     	',T-@-@u-M'N&
'N!AJOO'N&
" --e,%88%%888%(DLL,=,==4..U;<<"7mG_/5I	 = OOW
 _%%%&
s   Ec           	        V P                    Uu. uF=  p\        P                  ! W!^ ,          P                  V^ ,          P                  R7      NK?  	  ppR\
        P                  ! V P                  V.VO5!  ,           # u upi )r   r   rr   )r   r   r   r   r   r<   r   r   )rP   rs   rx   rn   s   &*  r   rY   _AlltoAll.backward  sv     22	
 3 KK!_33<?;P;P 3	 	 
 ioociiT|TTT
s   AA>r[   Nr\   rd   s   @r   r<   r<     s-     & &, U Ur   r<   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )rA   i  c                    Wn         VP                  4       V n        W@n        W0n        \
        P                  ! VVVVVR 7       V# ))rC   rD   r   )r   rx   
input_sizerC   rD   rL   r@   )rP   r   r0   rC   rD   rB   s   &&&&&&r   rQ   _AlltoAllSingle.forward  sF     	!2 21/	
 r   c           	     
   \         P                  ! V P                  VP                  VP                  R 7      pR\
        P                  V P                  VV P                  V P                  VP                  4       4      3,           # )r   )NNNN)r   r   r   r   r   rA   r   r   rC   rD   rk   )rP   rW   r   s   && r   rY   _AlltoAllSingle.backward  ss     NN;#5#5[=N=N
 (!!		&&%%&&(+
 
 	
r   r[   Nr\   rd   s   @r   rA   rA     s+       
 
r   rA   c                   @   a  ] tR tRt o ]R 4       t]R 4       tRtV tR# )rG   i  c                    W n         Wn        VP                  \        P                  R 7      p\
        P                  ! W1VR7       V# ))memory_formatr   )r   r,   rO   r   contiguous_formatrL   rF   )rP   r,   r   r   s   &&&&r   rQ   _AllReduce.forward  s7     	E,C,CDU3r   c                h    R\         P                  V P                  V P                  V4      3,           # rq   )rG   r   r,   r   r   s   &&r   rY   _AllReduce.backward  s)     z//		;OQQQr   r[   Nr\   rd   s   @r   rG   rG     s-       R Rr   rG   )!r   r   torch.distributeddistributedrL   torch.autogradr   r   r   r   r   WORLDr   r"   r&   rU   r*   r.   r3   r6   r;   r@   rF   r   r#   r'   r+   r/   r4   r7   r<   rA   rG   r[   r   r   <module>r      s[       #
 .T  "' 04  -" %++ 0, $<<u{{ 1. +3,,ekk A8 #[[ +. 9> #DL =BKK J* 
++%P #,,ekk /6   ,Sh S4Mx M*Yh Y Mh M" < X  :!U !UH
h 
DR Rr   