+
    –°³jæD ã                   ó€  € ^ RI t ^ RIt^ RIt^ RIt^ RIHtHt ^ RIHt ^ RI	H
t
 ^ RIt^ RIHu Hu Ht ^ RIHu Hu Ht ^ RIH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$H%t% ^ RI&H't'H(t( ^ RI)H*t*H+t+H,t,H-t-H.t. ^ RI/H0t0H1t1H2t2H3t3H4t4 . R8Ot5]Pl                  Pn                  t7R R lt8 ! R R]Pr                  Pt                  4      t; ! R R]Pr                  Pt                  4      t< ! R R]Pz                  4      t>R9R^ /R R lllt?]
! R4      R:R R ll4       t@R;R R lltA]R 4       tB]R 4       tCR9R  R! lltDR"RR#]PŠ                  R$R%R&RR'R/R( R) lltFR"RR#]PŠ                  R$R%R&RR'R/R* R+ lltGR"RR#]PŠ                  R$R%R&RR'R/R, R- lltHR"RR#]PŠ                  R$R%R&RR'R/R. R/ lltIR<R"RR#]PŠ                  R$R%R&RR'R/R0 R1 llltJR$R%R"RR#]PŠ                  R&RR'R/R2 R3 lltKR$R%R"RR#]PŠ                  R&RR'R/R4 R5 lltLR$R%R"RR#]PŠ                  R&RR'R/R6 R7 lltM]>Pœ                  tN]! 4        R# )=é    N)ÚCallableÚSequence)ÚAny)Ú
deprecated)Ú1mark_subclass_constructor_exportable_experimental)Ú
LazyString)Úmaybe_run_for_local_tensor)Ú_mesh_resourcesÚ"_register_distributed_opaque_typesÚ
DeviceMesh)Úcheck_tensor_metaÚmesh_broadcast)ÚDTensorSpecÚ
TensorMeta)ÚRedistributeÚredistribute_local_tensor)Úassert_no_mixed_partial_typesÚcompute_global_tensor_infoÚ%compute_local_shape_and_global_offsetÚExplicitRedistributionContextÚnormalize_to_torch_size)Ú_StridedShardÚPartialÚ	PlacementÚ	ReplicateÚShardÚDTensorc                ód   € V ^8„  d   QhR\         \        R3,          R\         \        R3,          /# )é   Ú
placements.Úreturn©Útupler   )Úformats   "Ú^/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/distributed/tensor/_api.pyÚ__annotate__r&   ?   s.   € ÷ ñ Ü”i �nÕ%ðä
Œ9�cˆ>Õñó    c                ó²   € . pV  FE  pVP                  4       '       d   VP                  \        4       4       K4  VP                  V4       KG  	  \        V4      # )a  
Normalize gradient placements by converting Partial to Replicate.

See the gradient placement guarantees documented in DTensor.from_local's docstring
for why Partial forward placements map to Replicate gradient placements. We do this
for both from_local and to_local backward.
)Ú
is_partialÚappendr   r#   )r    Ú
normalizedÚps   &  r%   Ú_normalize_placements_for_gradr-   ?   sI   € ð #%€JÛˆØ�<‰<�>Š>Ø×Ñœi›kÖ*à×Ñ˜aÖ ñ	 ô
 �ÓÐr'   c                   óX   a € ] tR t^ft o ]V 3R lR l4       t]V 3R lR l4       tRtV tR# )Ú_ToTorchTensorc                óB   <€ V ^8„  d   QhRRRS[ S[,          R,          /# )r   Úinputr   Úgrad_placementsN)r   r   )r$   Ú__classdict__s   "€r%   r&   Ú_ToTorchTensor.__annotate__h   s)   ø€ ÷ 2ñ 2àð2ñ "¡)Õ,¨tÕ3ñ2r'   c                ó¶   € VP                   V n        W n        V P                  R 4       VP                  pVP                  4       V n        VP                  V4      # )F)Ú_specÚdtensor_specr2   Úset_materialize_gradsÚ_local_tensorÚstrideÚlocal_tensor_strideÚview_as)Úctxr1   r2   Úlocal_tensors   &&& r%   ÚforwardÚ_ToTorchTensor.forwardg   sS   € ð !Ÿ;™;ˆÔØ-ÔØ×!Ñ! %Ô(Ø×*Ñ*ˆØ".×"5Ñ"5Ó"7ˆÔð
 ×#Ñ# LÓ1Ð1r'   c                óB   <€ V ^8„  d   QhRS[ P                  R,          /# )r   Úgrad_outputN)ÚtorchÚTensor)r$   r3   s   "€r%   r&   r4   y   s    ø€ ÷ c
ñ c
¡5§<¡<°$Õ#6ñ c
r'   c           
     óä  aaaaa€ Vf   R# V P                   pVP                  pV P                  pVP                  pVf   \	        VP
                  4      p^ RIHo ^ RIH	o V3R loV3R loV3R loVVV3R lpVV3R lpWBP
                  8X  dÌ   V! VP                  VP                  4       V P                  4      '       dš   V! VP                  V P                  VP                  4      '       dl   V! VP                  VP                  4       V P                  4       V! VP                  V P                  VP                  4       \        P                  ! V4      pMQ\        WVP
                  4      w  rš\        V
4      p
\!        VV\#        VP                  V
VP$                  R7      R	7      p\&        P)                  VVP*                  VP
                  VP                  VP                  R
7      R 3# )N)Úcheck_contiguous_sizes_strides)Úguard_or_falsec                 óÚ   <€ \        V 4      \        V4      8H  ;'       dM    \        ;QJ d(    V3R  l\        W4       4       F  '       d   K   R# 	  R# ! V3R  l\        W4       4       4      # )c              3   ó<   <"  € T F  w  rS! W8H  4      x € K  	  R # 5i©N© ©Ú.0ÚaÚbrG   s   &  €r%   Ú	<genexpr>ÚJ_ToTorchTensor.backward.<locals>.strides_provably_match.<locals>.<genexpr>Œ   s!   øé € ð 5Ù3E©4¨1‘˜q™v×&Ð&Ó3Eùó   ƒFT)ÚlenÚallÚzip©r:   ÚotherrG   s   &&€r%   Ústrides_provably_matchÚ7_ToTorchTensor.backward.<locals>.strides_provably_match‹   sa   ø€ Ü�v“;¤# e£*Ñ,÷ ð ·³ô 5Ü36°vÔ3Eó5·´ð ²ð °ô 5Ü36°vÔ3Eó5ó 2ð r'   c                 óÚ   <€ \        V 4      \        V4      8g  ;'       gM    \        ;QJ d(    V3R  l\        W4       4       F  '       g   K   R# 	  R# ! V3R  l\        W4       4       4      # )c              3   ó<   <"  € T F  w  rS! W8g  4      x € K  	  R # 5irJ   rK   rL   s   &  €r%   rP   ÚK_ToTorchTensor.backward.<locals>.strides_provably_differ.<locals>.<genexpr>‘   s!   øé € ð 4Ù3E©4¨1‘˜q™v×&Ð&Ó3EùrR   TF)rS   ÚanyrU   rV   s   &&€r%   Ústrides_provably_differÚ8_ToTorchTensor.backward.<locals>.strides_provably_differ�   sa   ø€ Ü�v“;¤# e£*Ñ,÷ ð ·³ô 4Ü36°vÔ3Eó4·´ð ²ð °ô 4Ü36°vÔ3Eó4ó 1ð r'   c                 óœ   <€ \        V 4      \        V4      u;8X  d   \        V4      8X  g    R #  R # S! WRR7      ;'       d    S! WRR7      # )FT)Úfalse_if_dde)rS   )Úshaper:   rW   rF   s   &&&€r%   Ú strides_are_contiguous_for_shapeÚA_ToTorchTensor.backward.<locals>.strides_are_contiguous_for_shape•   sP   ø€ Ü˜“J¤# f£+Ö;´°U³Õ;Ùð <ÙÙ1Ø¨Dô÷ Rð Rá0°ÈDÔQðRr'   c                 ó`   <€ S! W4      ;'       g    S! WV4      ;'       g    S! W4      '       * # rJ   rK   )rb   r:   rW   rc   r^   rX   s   &&&€€€r%   Ústrides_may_matchÚ2_ToTorchTensor.backward.<locals>.strides_may_matchœ   s9   ø€ á& vÓ5÷ >ð >Ù3°EÀ5ÓI÷>ð >á.¨vÓ=Ô=ðr'   c                 ó´   <aa€ S! SS4      '       g   S! V SS4      '       d   R # \        SS4       F#  w  r4\        P                  ! W48H  VV3R l4       K%  	  R # )Nc                  ó   <€ R S RS  2# )z-Expected matching DTensor local strides, got z and rK   )rW   r:   s   €€r%   Ú<lambda>ÚG_ToTorchTensor.backward.<locals>.check_stride_matches.<locals>.<lambda>«   s   ø€ ØGÈÀxÈuÐUZÐT[Ñ\r'   )rU   rC   Ú_check)rb   r:   rW   rN   rO   rc   rX   s   &ff  €€r%   Úcheck_stride_matchesÚ5_ToTorchTensor.backward.<locals>.check_stride_matches£   sP   ú€ Ù%Ø˜÷ò á1°%¸À×GÒGÙÜ˜F EÖ*‘�Ü—’Ø‘Fõöó +r'   ©rb   r:   Údtype©Útensor_meta)rb   r:   ©NN)r7   Úmeshr2   rr   r-   r    Útorch._prims_commonrF   Ú%torch.fx.experimental.symbolic_shapesrG   rb   r:   r;   Úcopyr   r#   r   r   rp   r   Ú
from_localÚdevice_mesh)r=   rB   r7   rt   r2   Údtensor_metarf   rm   Ú	grad_specÚ_Útensor_striderF   rG   rc   r^   rX   s   &&         @@@@@r%   ÚbackwardÚ_ToTorchTensor.backwardx   sÅ  ü€ àÒØÐà×'Ñ'ˆØ× Ñ ˆØ×-Ñ-ˆØ#×/Ñ/ˆð Ò"ä<¸\×=TÑ=TÓUˆOåFÝHõ	õ
	õ
	R÷	ö	ð" ×6Ñ6Ô6Ù!Ø×!Ñ! ;×#5Ñ#5Ó#7¸×9PÑ9P÷ò ñ "Ø×"Ñ" C×$;Ñ$;¸\×=PÑ=P÷ò ñ !Ø×!Ñ! ;×#5Ñ#5Ó#7¸×9PÑ9Pôñ !Ø×"Ñ" C×$;Ñ$;¸\×=PÑ=Pôô
 Ÿ	š	 ,Ó/‰Iä9Ø <×#:Ñ#:ó ÑˆAô " -Ó0ˆMÜ#ØØÜ&Ø&×,Ñ,Ø(Ø&×,Ñ,ôôˆIô ×ÑØØ×%Ñ%Ø×$Ñ$Ø—o‘oØ ×'Ñ'ð ó ð ð	
ð 		
r'   rK   N©	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ústaticmethodr?   r~   Ú__static_attributes__Ú__classdictcell__©r3   s   @r%   r/   r/   f   s-   ø‡ € Ø÷2ó ð2ð  ÷c
ó öc
r'   r/   c                   ó\   a € ] tR t^ßt o ]RV 3R lR ll4       t]V 3R lR l4       tRtV tR# )Ú_FromTorchTensorNc                óÖ   <€ V ^8„  d   QhRS[ P                  RS[RS[S[R3,          RS[RS[ P                  R,          RS[S[R3,          R,          R	S[S[R3,          R,          R
R/# )r   r1   ry   r    .Ú	run_checkrb   Nr:   r2   r!   r   )rC   rD   r   r#   r   ÚboolÚSizeÚint)r$   r3   s   "€r%   r&   Ú_FromTorchTensor.__annotate__á   s–   ø€ ÷ Fñ Fá�|‰|ðFñ  ðFñ ™) S˜.Õ)ð	Fñ
 ðFñ �z‰z˜DÕ ðFñ ‘c˜3�h• $Õ&ðFñ ™y¨#˜~Õ.°Õ5ðFð 
ñFr'   c           	     óø  € W0n         W n        Wpn        V P                  R 4       V'       d   V'       d   YVr˜MRV'       g8   V'       g0   \	        WV4      w  r«\
        P                  ! V
4      \        V4      r˜M\        RV RV R2R4      hVP                  4       '       g   VP                  ^ VP                  R7      pMsV'       dl   V'       * ;'       d    V'       * p\        WR7       \        V4       F:  w  rÞVP                  4       '       g   K  VP                  4       p\!        WVR7       K<  	  \#        VV\%        VV	VP&                  4      R7      p\)        VP+                  V4      VVP                  R7      pV# )	FzFound shape:z	, stride:Ú.z3Please pass both shape and stride at the same time.©Úrequires_grad)Úcheck_shape_stride)Úmesh_dimrq   )Úforward_input_placementsÚforward_input_device_meshr2   r8   r   rC   rŽ   r#   ÚRuntimeErrorÚ_is_current_rank_part_of_meshÚ	new_emptyr”   r   Ú	enumerateÚis_replicateÚ
contiguousr   r   r   rp   r   r<   )r=   r1   ry   r    rŒ   rb   r:   r2   Útensor_shaper}   Úglobal_shapeÚglobal_strider•   ÚidxÚ	placementÚ	dist_specÚdist_tensors   &&&&&&&&         r%   r?   Ú_FromTorchTensor.forwardà   s\  € ð (2Ô$Ø(3Ô%Ø-ÔØ×!Ñ! %Ô(ç—VØ*/™-ßŸvô +EØ Jó+Ñ'ˆLô +0¯*ª*°\Ó*BÄEÈ-ÓDX™-äØ˜u˜g Y¨v¨h°aÐ8ØEóð ð
 ×8Ñ8×:Ò:ð —O‘O A°U×5HÑ5H�OÓI‰Eßð &+¤×!9Ð!9°6¬zÐÜ˜eÕKô #,¨JÖ"7‘�Ø×)Ñ)×+Ô+ð "×,Ñ,Ó.�EÜ" 5À×Dñ #8ô  ØØÜ"ØØØ—‘óô
ˆ	ô à�M‰M˜%Ó Øð  ×-Ñ-ô
ˆð Ðr'   c                ó   <€ V ^8„  d   QhRR/# )r   rB   zDTensor | NonerK   )r$   r3   s   "€r%   r&   r�   *  s   ø€ ÷ 7Jñ 7JÐ#3ñ 7Jr'   c                ó®  € V P                   pV P                  pV P                  pVf   R# Ve   TpM\        V4      pVP                  V8w  ds   VP
                  p\        VVVP
                  P                  R7      p\        P                  ! VV\        R 4      4       VP                  p\        VVV4      p	V	R R R R R R 3# VP                  4       R R R R R R 3# )Nrq   c                  ó   € R # )z?Implicit redistribution occurred in DTensor.from_local backwardrK   rK   r'   r%   rj   Ú+_FromTorchTensor.backward.<locals>.<lambda>R  s   € Ñ]r'   )NNNNNNN)r—   r˜   r2   r-   r    r6   r   rr   r   Úobserve_redistributionr   r9   r   Úto_local)
r=   rB   r—   r˜   r2   Únormalized_placementsÚcurrent_specÚtarget_specr>   Úoutputs
   &&        r%   r~   Ú_FromTorchTensor.backward)  s   € à#&×#?Ñ#?Ð Ø$'×$AÑ$AÐ!Ø×-Ñ-ˆàÒØ;Ð;ð  Ò&Ø$3Ñ!ä$BØ(ó%Ð!ð ×!Ñ!Ð%:Ô:Ø(3×(9Ñ(9ˆLÜ%Ø)Ø%Ø'×-Ñ-×9Ñ9ôˆKô
 *×@Ò@ØØÜÙ]óôð '×4Ñ4ˆLÜ.ØØØóˆFð ˜4  t¨T°4¸Ð=Ð=ð ×#Ñ#Ó% t¨T°4¸¸tÀTÐIÐIr'   rK   )NNNr€   rˆ   s   @r%   rŠ   rŠ   ß   s6   ø‡ € Ø÷Fñ Fó ðFðP ÷7Jó ö7Jr'   rŠ   c            
       ó  a a€ ] tR tRt oRtRR.t]P                  ! 4       tV3R lR lt	]
P                  P                  t	]
P                  ]V 3R l4       4       tR tR	 t]R
 4       tV3R lR ltR tR-R lt]R.R l4       t]R/RRRRRRRR/V3R lR lll4       tRR/V3R lR lltR/RRRRRR/V3R lR llltRR/V3R lR  llt]V3R! lR" l4       t]V3R# lR$ l4       tV3R% lR& lt V3R' lR( lt!R) t"R* t#V3R+ lt$R,t%Vt&V ;t'# )0r   id  ay  
``DTensor`` (Distributed Tensor) is a subclass of ``torch.Tensor`` that provides single-device like
abstraction to program with multi-device ``torch.Tensor``. It describes the distributed tensor sharding
layout (DTensor Layout) through the :class:`DeviceMesh` and following types of :class:`Placement`:

* :class:`Shard`: Tensor sharded on the tensor dimension ``dim`` on the devices of the ``DeviceMesh`` dimension
* :class:`Replicate`: Tensor replicated on the devices of the ``DeviceMesh`` dimension
* :class:`Partial`: Tensor is pending reduction on the devices of the ``DeviceMesh`` dimension

When calling PyTorch operators, ``DTensor`` overrides the PyTorch operators to perform sharded computation and issue
communications whenever necessary. Along with the operator computation, ``DTensor`` will transform or propagate the
placements (DTensor Layout) properly (based on the operator semantic itself) and generate new ``DTensor`` outputs.

To ensure numerical correctness of the ``DTensor`` sharded computation when calling PyTorch operators, ``DTensor``
requires every Tensor argument of the operator be DTensor.

.. note:: Directly using the Tensor subclass constructor here is not the recommended way to create a ``DTensor``
    (i.e. it does not handle autograd correctly hence is not the public API). Please refer to the `create_dtensor`_
    section to see how to create a ``DTensor``.
r9   r6   c                óD   <€ V ^8„  d   QhRS[ P                  RS[RS[RR/# )r   r>   Úspecr”   r!   r   )rC   rD   r   r�   )r$   r3   s   "€r%   r&   ÚDTensor.__annotate__ƒ  s7   ø€ ÷ ñ á—l‘lðñ ðñ
 ðð 
ñr'   c               ó`   € \         P                  P                  WW#R 7      pW$n        Wn        V# ©r“   )rC   rD   Ú_dtensor__new__r6   r9   )Úclsr>   r´   r”   Úrs   &&&$ r%   Ú__new__ÚDTensor.__new__ƒ  s3   € ô �L‰L×(Ñ(Ø˜tð )ó 
ˆð ŒØ&ŒØˆr'   c                ó$   <€ \         SV `  4        R# )a  
Construct a DTensor from a local tensor, device mesh, and placement and
other tensor properties (i.e. shape, requires_grad, strides, etc).
.. note:: This is not a public API and it's only supposed to be used by the
    operator implementations and internals. If you want to construct a
    DTensor from a local tensor, consider using ``DTensor.from_local``, if
    you want to construct a DTensor from a "global" tensor (where you
    already have tensor initialized and want to shard this tensor),
    consider using ``distribute_tensor``.
N)ÚsuperÚ__init__)ÚselfÚargsÚkwargsÚ	__class__s   &*,€r%   r¿   ÚDTensor.__init__“  s   ø€ ô 	‰ÑÖr'   c                ó~   € R V P                    RV P                  P                   RV P                  P                   R2# )zDTensor(local_tensor=z, device_mesh=z, placements=Ú))r9   r6   rt   r    ©rÀ   s   &r%   Ú__repr__ÚDTensor.__repr__¤  s=   € à& t×'9Ñ'9Ð&:¸.ÈÏÉÏÉÐHYÐYfÐgk×gqÑgq×g|Ñg|Ðf}Ð}~ÐÐr'   c                ó¢   € RR.V P                   P                  V P                   P                  V P                   P                  V P                  33# )zM
protocol to inform how to flatten a DTensor to local tensor
for PT2 tracing
r9   ry   )r6   r    rr   Úshard_orderr”   rÇ   s   &r%   Ú__tensor_flatten__ÚDTensor.__tensor_flatten__¨  sK   € ð
   Ð/Ø�J‰J×!Ñ!Ø�J‰J×"Ñ"Ø�J‰J×"Ñ"Ø×Ñð	2
ð 
ð 	
r'   c                ó¸   € Vf   \        R4      hV R,          pV R,          pVw  rgr‰\        VVVP                  R7      p
\        VVV
VR7      p\	        VVV	R7      # )NzEExpecting spec to be not None from `__tensor_flatten__` return value!r9   ry   ro   )rr   rË   r“   )ÚAssertionErrorr   rp   r   r   )Úinner_tensorsÚflatten_specÚ
outer_sizeÚouter_strider>   rt   r    Úold_tensor_metarË   r”   Úunflatten_tensor_metaÚunflatten_specs   &&&&        r%   Ú__tensor_unflatten__ÚDTensor.__tensor_unflatten__´  s‚   € àÒÜ ØWóð ð % _Õ5ˆØ˜]Õ+ˆØBNÑ?ˆ
 [Ü *ØØØ!×'Ñ'ô!
Ðô
 %ØØØ-Ø#ô	
ˆô àØà'ô
ð 	
r'   c                ó    <€ V ^8„  d   QhRS[ /# ©r   r!   )Ústr)r$   r3   s   "€r%   r&   rµ   Ñ  s   ø€ ÷ 
Pñ 
P©#ñ 
Pr'   c                ó  € \        V P                  P                  4      pV P                  P	                  4       \        V P
                  4      ,           V,           p\        P                  ! VP                  4       ^R7      P                  4       # )zr
Return a stable hash for AOT autograd caching.
[See note: Tensor subclass stable hashing for AOT autograd cache]
)Údigest_size)
rÛ   r9   Údevicer6   Ú_stable_hashr”   ÚhashlibÚblake2bÚencodeÚ	hexdigest)rÀ   rÞ   Ú
cache_datas   &  r%   Ú_stable_hash_for_cachingÚ DTensor._stable_hash_for_cachingÑ  sd   € ô �T×'Ñ'×.Ñ.Ó/ˆØ—Z‘Z×,Ñ,Ó.´°T×5GÑ5GÓ1HÕHÈ6ÕQˆ
Ü�Š˜z×0Ñ0Ó2ÀÔC×MÑMÓOÐOr'   c                ó\  € \         ;QJ d&    R  V P                   4       F  '       g   K   RM	  RM! R  V P                   4       4      '       g   V # V P                   Uu. uF%  p\        V\        4      '       d   \	        4       MTNK'  	  ppV P                  V P                  VR7      # u upi )c              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5irJ   )Ú
isinstancer   ©rM   r,   s   & r%   rP   Ú6DTensor.__coerce_tangent_metadata__.<locals>.<genexpr>Þ  s   é € ÐC±?¨a”:˜a¤×)Ð)³?ùó   ‚TF©ry   r    )r]   r    ré   r   r   Úredistributery   )rÀ   r,   r    s   &  r%   Ú__coerce_tangent_metadata__Ú#DTensor.__coerce_tangent_metadata__Ý  s†   € ß‹sÑC°4·?²?ÓC�s�sŠsÑC°4·?²?ÓC×CÒCØˆKàBFÇ/Â/ó
ÙBQ¸Qœ: a¬×1Ò1ŒIŒK°qÒ8Á/ð 	ð 
ð × Ñ ¨T×-=Ñ-=È*Ð ÓUÐUùò
s   Á+B)Nc                óV   € Ve   R # Vw  p  pV P                  V P                  VR7      # )Nrí   )rî   ry   )rÀ   rÑ   Úexpected_typer    r|   s   &&&  r%   Ú#__coerce_same_metadata_as_tangent__Ú+DTensor.__coerce_same_metadata_as_tangent__å  s=   € ØÒ$Ùà ,Ñˆ�Q˜˜1Ø× Ñ Ø×(Ñ(Ø!ð !ó 
ð 	
r'   c                óÐ   € R  p\         P                  P                  P                  WS4      p\         P                  P                  P                  YT;'       g    / 4      pV! V/ VB # )c                 ó°   € \        V \        4      '       d@   \        V 4      \        Jd-   \        V P                  V P                  V P
                  R 7      # V # r·   )ré   r   Útyper9   r6   r”   )Úts   &r%   ÚunwrapÚ*DTensor.__torch_dispatch__.<locals>.unwrapö  sC   € Ü˜!œW×%Ò%¬$¨q«'¼Ó*@äà—O‘OØ—G‘Gà"#§/¡/ôð ð ˆHr'   )rC   ÚutilsÚ_pytreeÚtree_map)r¹   ÚfuncÚtypesrÁ   rÂ   rù   s   &&&&& r%   Ú__torch_dispatch__ÚDTensor.__torch_dispatch__ï  sS   € ò
	ô �{‰{×"Ñ"×+Ñ+¨FÓ9ˆÜ—‘×$Ñ$×-Ñ-¨f·l°lÀÓCˆÙ�TÐ$˜VÑ$Ð$r'   rŒ   Frb   r:   r2   c                óê   <€ V ^8„  d   QhRS[ P                  RS[R,          RS[S[,          R,          RS[RS[ P                  R,          RS[S[R3,          R,          R	S[S[,          R,          R
R/# )r   r>   ry   Nr    rŒ   rb   r:   .r2   r!   r   )	rC   rD   r   r   r   r�   rŽ   r#   r�   )r$   r3   s   "€r%   r&   rµ     s–   ø€ ÷ |
ñ |
Ù—l‘lð|
á $Õ&ð|
ñ ™YÕ'¨$Õ.ð|
ñ
 ð|
ñ �z‰z˜DÕ ð|
ñ ‘c˜3�h• $Õ&ð|
ñ "¡)Õ,¨tÕ3ð|
ð 
ñ|
r'   c               ó   € \        V \        4      '       d   \        R\        V 4       R24      hT;'       g    \        P
                  ! 4       pVP                  pWpP                  P                  8w  d$   V P                  '       g   V P                  V4      p Vf.   \        VP                  4       Uu. uF  p\        4       NK  	  ppMÁ\        V4      p\        V4       F§  w  rš\        V
\        \         ,          4      '       g   K(  V
P"                  ^ 8  g   K;  V
P"                  V P                  ,           p\        V
4      \         J d   \!        WºP$                  R7      W)&   K…  \        V
4      \        J g   Kš  \        V4      W)&   K©  	  \'        V4       \(        P+                  T T\-        V4      TTTVe   \-        V4      4      # R4      # u upi )a¡  
Create a :class:`DTensor` from a local torch.Tensor on each rank
according to the ``device_mesh`` and ``placements`` specified.

Args:
    local_tensor (torch.Tensor): local torch.Tensor on each rank.
    device_mesh (:class:`DeviceMesh`, optional): DeviceMesh to place the
        tensor, if not specified, must be called under a DeviceMesh
        context manager, default: None
    placements (List[:class:`Placement`], optional): the placements that
        describes how to place the local torch.Tensor on DeviceMesh, must
        have the same number of elements as ``device_mesh.ndim``.

Keyword args:
    run_check (bool, optional): at a cost of extra communications, perform
        sanity check across ranks to check each local tensor's meta information
        to ensure correctness. If have :class:`Replicate` in ``placements``, the
        data on first rank of the device mesh dimension will be broadcasted
        to other ranks. default: False
    shape (torch.Size, optional): A List of int which specifies the size of
        DTensor which build on top of `local_tensor`. Note this needs to be
        provided if the shape of ``local_tensor`` are different across the ranks.
        If not provided, ``shape`` will be computed assuming the given distributed
        tensor is evenly sharded across ranks. default: None
    stride (tuple, optional): A List of int which specifies the stride of DTensor.
        If not provided, ``stride`` will be computed assuming the given distributed
        tensor is evenly sharded across ranks. default: None
    grad_placements (List[:class:`Placement`], optional): specifies the expected
        input gradient placements. The input gradient (a plain tensor) will be
        redistributed to this placement before exiting DTensor. If not
        specified, follows the default placement guarantees below. default: None

Returns:
    A :class:`DTensor` object

Raises:
    ValueError: If ``placements`` contains mixed :class:`Partial` reduce types
        (e.g., both ``Partial("sum")`` and ``Partial("max")``). All Partial
        placements must use the same reduce operation.

.. note:: When ``run_check=False``, it is the user's responsibility to ensure the
    local tensor passed in is correct across ranks (i.e. the tensor is sharded for
    the ``Shard(dim)`` placement or replicated for the ``Replicate()`` placement).
    If not, the behavior of the created DTensor is undefined.

.. note:: ``from_local`` is differentiable, the `requires_grad` of the created
    `DTensor` object will depend on if `local_tensor` requires_grad or not.

.. note:: During backward, ``from_local`` provides the following gradient placement
    guarantees. For each mesh dimension, the gradient placement maps as follows:

    +---------------------+--------------------+
    | Forward Placement   | Gradient Placement |
    +=====================+====================+
    | ``Shard``           | ``Shard``          |
    +---------------------+--------------------+
    | ``Replicate``       | ``Replicate``      |
    +---------------------+--------------------+
    | ``Partial``         | ``Replicate``      |
    +---------------------+--------------------+

    When the forward placement is :class:`Partial`, we always redistribute the gradient
    to :class:`Replicate` instead of keeping it :class:`Partial`. This may not be the most
    efficient option, but it avoids ambiguity and provides clearer gradient semantics to users.
z<the local_tensor argument only accepts torch.Tensor but got z value.N©Úsplit_factor)ré   r   r™   r÷   r
   Úget_current_meshÚdevice_typerÞ   Úis_metaÚtoÚrangeÚndimr   Úlistrœ   r   r   Údimr  r   rŠ   Úapplyr#   )r>   ry   r    rŒ   rb   r:   r2   r  r|   r¢   r£   Únormalized_dims   &&&$$$$     r%   rx   ÚDTensor.from_local  s’  € ôZ �l¤G×,Ò,ÜØNÌtÐT`ÓOaÐNbÐbiÐjóð ð "×GÐG¤_×%EÒ%EÓ%GˆØ!×-Ñ-ˆð ×-Ñ-×2Ñ2Ô2¸<×;O×;OÐ;OØ'Ÿ?™?¨;Ó7ˆLð ÒÜ/4°[×5EÑ5EÔ/FÓGÑ/F¨!œ)ž+Ñ/FˆJÐGˆJä˜jÓ)ˆJÜ"+¨JÖ"7‘�ä˜i¬´Õ)>×?Ô?Ø —}‘} qÖ(Ø)2¯©¸×9JÑ9JÕ)J˜Ü 	›?¬mÓ;Ü.;Ø .×=SÑ=Sô/˜J›Oô " )›_´Õ5Ü.3°NÓ.C˜J›Oñ #8ô 	& jÔ1ô
  ×%Ñ%ØØÜ�*ÓØØØØ&5Ò&AŒE�/Ó"ó
ð 	
ð HLó
ð 	
ùò+ Hs   Â2Gc                óX   <€ V ^8„  d   QhRS[ S[,          R,          RS[P                  /# ©r   r2   Nr!   ©r   r   rC   rD   )r$   r3   s   "€r%   r&   rµ   …  s+   ø€ ÷ ?ñ ?Ù"*©9Õ"5¸Õ"<ð?á	�‰ñ?r'   c               ód  € \         P                  ! 4       '       g   V P                  pM:Ve"   \        V\        4      '       g   \	        V4      p\
        P                  W4      p\        V RR4      '       d;   \        VRR4      '       g(   W P                  J d   VP                  V4      pRVn	        V# )aT  
Get the local tensor of this DTensor on its current rank. For sharding it returns
a local shard of the logical tensor view, for replication it returns the replica on
its current rank.

Keyword args:
    grad_placements (List[:class:`Placement`], optional): the placements describes
        the future layout of any gradient layout of the Tensor returned from this
        function.
        `to_local` converts DTensor to local tensor and the returned local tensor
        might not be used as the original DTensor layout later in the code. This
        argument is the hint that user can give to autograd in case the gradient
        layout of the returned tensor does not match the original DTensor layout.
        If not specified, we will assume the gradient layout remains the same
        as the original DTensor and use that for gradient computation.

Returns:
    A :class:`torch.Tensor` or ``AsyncCollectiveTensor`` object. it represents the
    local tensor on its current rank. When an ``AsyncCollectiveTensor`` object is returned,
    it means the local tensor is not ready yet (i.e. communication is not finished). In this
    case, user needs to call ``wait`` to wait the local tensor to be ready.

.. note:: ``to_local`` is differentiable, the ``requires_grad`` of the local tensor returned
    will depend on if the `DTensor` requires_grad or not.
Ú	_is_paramFT)
rC   Úis_grad_enabledr9   ré   r#   r/   r  Úgetattrr<   r  )rÀ   r2   Úresults   &$ r%   r¬   ÚDTensor.to_local…  sœ   € ô8 ×$Ò$×&Ò&Ø×'Ñ'‰FàÒ*´:¸oÌu×3UÒ3UÜ"'¨Ó"8�Ü#×)Ñ)ØóˆFô* �4˜ e×,Ò,´WØ�K ÷6
ò 6
ð ×+Ñ+Ó+ð  Ÿ™¨Ó/�Ø#ˆFÔàˆr'   Úasync_opÚforward_dtypeÚbackward_dtypec                ó¬   <€ V ^8„  d   QhRS[ R,          RS[S[,          R,          RS[RS[P
                  R,          RS[P
                  R,          RR/# )	r   ry   Nr    r  r  r  r!   r   )r   r   r   r�   rC   rp   )r$   r3   s   "€r%   r&   rµ   Æ  sp   ø€ ÷ v
ñ v
á $Õ&ðv
ñ ™YÕ'¨$Õ.ðv
ñ
 ðv
ñ —{‘{ TÕ)ðv
ñ Ÿ™ dÕ*ðv
ð 
ñv
r'   c               óÄ  € T;'       g    V P                   pVf   \        R4      h\        V4      p\        V4       EFF  w  rgVP	                  4       '       dz   V P
                  V,          V8w  db   V P
                  V,          p\        V\        4      '       d%   \        V4      \        J d   VP                  R8X  g   \        RV RV R24      hK•  \        V\        4      '       d<   VP                  ^ 8  d+   \        VP                  V P                  ,           4      W&&   Kæ  \        V\        4      '       g   Kþ  VP                  ^ 8  g   EK  \        VP                  V P                  ,           VP                  R7      W&&   EKI  	  \        V4      pV P                   P"                  p	T;'       g    T	p\$        P&                  ! T TTTRTRTR	RT;'       g    T	RV	//4      # )
a$  
``redistribute`` performs necessary collective operations that redistribute the current
DTensor from its current placements to a new placements, or from its current DeviceMesh
to a new DeviceMesh. i.e. we can turn a Sharded DTensor to a Replicated DTensor by
specifying a Replicate placement for each dimension of the DeviceMesh.

When redistributing from current to the new placements on one device mesh dimension, we
will perform the following operations including communication collective or local operation:

1. ``Shard(dim)`` -> ``Replicate()``: ``all_gather``
2. ``Shard(src_dim)`` -> ``Shard(dst_dim)``: ``all_to_all``
3. ``Replicate()`` -> ``Shard(dim)``: local chunking (i.e. ``torch.chunk``)
4. ``Partial()`` -> ``Replicate()``: ``all_reduce``
5. ``Partial()`` -> ``Shard(dim)``: ``reduce_scatter``
6. ``Shard(dim)`` -> ``Partial("sum")``: local zero-filling. This
   explicit-only conversion materializes a global-shape local tensor
   on every rank and does not communicate.

Of conversions to ``Partial``, this public API supports only
``Shard(dim)`` -> ``Partial("sum")``. Each rank places its local shard
at the corresponding offset in a zero-filled logical-shape tensor, so
summing across ranks reconstructs the original logical tensor.

``redistribute`` would correctly figure out the necessary redistribute steps for DTensors
that are created either on 1-D or N-D DeviceMesh.

Args:
    device_mesh (:class:`DeviceMesh`, optional): DeviceMesh to place the
        DTensor. If not specified, it would use the current DTensor's DeviceMesh.
        default: None
    placements (List[:class:`Placement`], optional): the new placements that
        describes how to place the DTensor into the DeviceMesh, must
        have the same number of elements as ``device_mesh.ndim``.
        default: replicate on all mesh dimensions

Keyword args:
    async_op (bool, optional): whether to perform the DTensor redistribute operation
        asynchronously or not. Default: False
    forward_dtype (torch.dtype, optional): cast the local tensor to
        ``forward_dtype`` before running the forward collective.
        The result DTensor will be in ``forward_dtype``. If ``None``,
        no conversion is performed. Default: None
    backward_dtype (torch.dtype, optional): cast the gradient to
        ``backward_dtype`` before running the backward collective.
        After the collective the gradient is always cast back to the
        input DTensor's dtype. If ``None``, the backward collective
        runs at the input DTensor's dtype (not ``forward_dtype``).
        Default: None

Returns:
    A :class:`DTensor` object

.. note:: ``redistribute`` is twice-differentiable, which means user do not need to worry about
    the backward formula of the redistribute operation, or its compatibility with autograd for
    second-order gradients. Higher-order differentiation has not been tested (but may work).

.. note:: ``redistribute`` currently only supports redistributing DTensor on the same DeviceMesh,
    Please file an issue if you need to redistribute DTensor to different DeviceMesh.
z&placements is needed for redistribute!ÚsumzCan not redistribute from z to z9, only Shard to Partial(sum) redistribution is supported!r  Úop_dtypeÚ	out_dtypeÚbackward_options)ry   r™   r  rœ   r)   r    ré   r   r÷   r   Ú	reduce_opr  r  r   r  r#   r9   rp   r   r  )
rÀ   ry   r    r  r  r  Úir£   ÚsourceÚinput_dtypes
   &&&$$$    r%   rî   ÚDTensor.redistributeÆ  s¨  € ðR "×5Ð5 T×%5Ñ%5ˆàÒÜÐGÓHÐHä˜*Ó%ˆ
Ü% j×1‰LˆAØ×#Ñ#×%Ò%¨$¯/©/¸!Õ*<À	Ô*IØŸ™¨Õ+�ä˜v¤u×-Ò-Ü˜Y›¬7Ó2Ø!×+Ñ+¨uÔ4ä&Ø4°V°H¸DÀÀð LRð Róð ñ 5ô ˜I¤u×-Ò-°)·-±-À!Ô2Cä % i§m¡m°d·i±iÕ&?Ó @�
“Ü˜I¤}×5Ô5¸)¿-¹-È!×:KÜ -Ø—M‘M D§I¡IÕ-¸I×<RÑ<Rô!�
”ñ! 2ô& ˜:Ó&ˆ
à×(Ñ(×.Ñ.ˆØ%×4Ð4¨ˆä×!Ò!ØØØØà˜MØ˜]Ø"ð  × =Ð =°+Ø ð	%ð	ó
ð 	
r'   c                óX   <€ V ^8„  d   QhRS[ S[,          R,          RS[P                  /# r  r  )r$   r3   s   "€r%   r&   rµ   >  s/   ø€ ÷ Añ AÙ"*©9Õ"5¸Õ"<ðAá	�‰ñAr'   c               óš   € V P                  \        4       .V P                  P                  ,          RR7      p\        P                  W!4      # )aB  
Return the full tensor of this DTensor. It will perform necessary collectives
to gather the local tensors from other ranks in its DeviceMesh and concatenate
them together. It's a syntactic sugar of the following code:

``dtensor.redistribute(placements=[Replicate()] * mesh.ndim).to_local()``

Keyword args:
    grad_placements (List[:class:`Placement`], optional): the placements describes
        the future layout of any gradient layout of the full Tensor returned from this
        function.
        `full_tensor` converts DTensor to a full torch.Tensor and the returned torch.tensor
        might not be used as the original replicated DTensor layout later in the code. This
        argument is the hint that user can give to autograd in case the gradient
        layout of the returned tensor does not match the original replicated DTensor layout.
        If not specified, we will assume the gradient layout of the full tensor be replicated.

Returns:
    A :class:`torch.Tensor` object that represents the full tensor of this DTensor.

.. note:: ``full_tensor`` is differentiable.
F)r    r  )rî   r   ry   r  r/   r  )rÀ   r2   Ú
redist_ress   &$ r%   Úfull_tensorÚDTensor.full_tensor>  sF   € ð4 ×&Ñ&Ü!›�} t×'7Ñ'7×'<Ñ'<Õ<Àuð 'ó 
ˆ
ô ×#Ñ# JÓ@Ð@r'   c                ó    <€ V ^8„  d   QhRS[ /# rÚ   )r   )r$   r3   s   "€r%   r&   rµ   ^  s   ø€ ÷ ñ ™Zñ r'   c                ó.   € V P                   P                  # )z”
The :class:`DeviceMesh` attribute that associates with this DTensor object.

.. note:: ``device_mesh`` is a read-only property, it can not be set.
)r6   rt   rÇ   s   &r%   ry   ÚDTensor.device_mesh]  s   € ð �z‰z�‰Ðr'   c                ó4   <€ V ^8„  d   QhRS[ S[R3,          /# )r   r!   .r"   )r$   r3   s   "€r%   r&   rµ   g  s   ø€ ÷ %ñ %™E¡)¨S .Õ1ñ %r'   c                ó.   € V P                   P                  # )z±
The placements attribute of this DTensor that describes the layout of this
DTensor on the its DeviceMesh.

.. note:: ``placements`` is a read-only property, it can not be set.
)r6   r    rÇ   s   &r%   r    ÚDTensor.placementsf  s   € ð �z‰z×$Ñ$Ð$r'   c                ó   <€ V ^8„  d   QhRR/# )r   r!   NrK   )r$   r3   s   "€r%   r&   rµ   p  s   ø€ ÷ ñ °tñ r'   c                ó‚   € V P                   P                   F$  p\        V\        4      '       g   K  \	        R4      h	  R# )z<
Raise an error if the DTensor contains partial placements.
z[Any checkpointing related operations are not supported for DTensor with partial placements!N)r6   r    ré   r   Ú
ValueError)rÀ   r£   s   & r%   Ú%_raise_if_contains_partial_placementsÚ-DTensor._raise_if_contains_partial_placementsp  s:   € ð Ÿ™×.Ô.ˆIÜ˜i¬×1Ò1Ùäð3óð ó	 /r'   c                ó&   <€ V ^8„  d   QhRS[ RS[/# )r   ÚfqnÚobject)rÛ   r   )r$   r3   s   "€r%   r&   rµ   }  s   ø€ ÷ ;ñ ;©#ð ;±sñ ;r'   c                ó  € V P                  4        ^ RIHp \        V P                  R4      '       d   V P                  P                  W4      # \        V P                  \        P                  4      '       d
   V! W4      .# \        R4      h)r   )Ú_create_write_items_for_dtensorÚ__create_write_items__úUnsupported tensor type!)
r6  Ú,torch.distributed.checkpoint.planner_helpersr<  Úhasattrr9   r=  ré   rC   rD   r™   )rÀ   r9  r:  r<  s   &&& r%   r=  ÚDTensor.__create_write_items__}  sq   € Ø×2Ñ2Ô4õ	
ô �4×%Ñ%Ð'?×@Ò@Ø×%Ñ%×<Ñ<¸SÓIÐIÜ˜×*Ñ*¬E¯L©L×9Ò9Ù3°CÓ@ÐAÐAäÐ9Ó:Ð:r'   c                ó  € V P                  4        ^ RIHp \        V P                  R4      '       d   V P                  P                  4       # \        V P                  \        P                  4      '       d
   V! V 4      .# \        R4      h)a¹  
Return a list of ChunkStorageMetadata, which is a dataclass that describes the size/offset of the local shard/replica
on current rank. For DTensor, each rank will have a single local shard/replica, so the returned list usually only
has one element.

This dunder method is primariy used for distributed checkpoint purpose.

Returns:
    A List[:class:`ChunkStorageMetadata`] object that represents the shard size/offset on the current rank.
)Ú_create_chunk_from_dtensorÚ__create_chunk_list__r>  )
r6  r?  rC  r@  r9   rD  ré   rC   rD   r™   )rÀ   rC  s   & r%   rD  ÚDTensor.__create_chunk_list__Š  sq   € ð 	×2Ñ2Ô4õ	
ô �4×%Ñ%Ð'>×?Ò?Ø×%Ñ%×;Ñ;Ó=Ð=Ü˜×*Ñ*¬E¯L©L×9Ò9Ù.¨tÓ4Ð5Ð5äÐ9Ó:Ð:r'   c                ó  € V P                  4        \        V P                  R 4      '       d   V P                  P                  V4      # \	        V P                  \
        P                  4      '       d   V P                  4       # \        R4      h)Ú__get_tensor_shard__r>  )	r6  r@  r9   rG  ré   rC   rD   r¬   r™   )rÀ   Úindexs   &&r%   rG  ÚDTensor.__get_tensor_shard__¡  sh   € Ø×2Ñ2Ô4Ü�4×%Ñ%Ð'=×>Ò>Ø×%Ñ%×:Ñ:¸5ÓAÐAÜ˜×*Ñ*¬E¯L©L×9Ò9Ø—=‘=“?Ð"äÐ9Ó:Ð:r'   c                óf   <€ V ^8„  d   Qh/ S[ P                  ;R&   S[;R&   S[P                  ;R&   # )r   r9   r6   Ú_op_dispatcher)rC   rD   r   Úop_dispatchÚOpDispatcher)r$   r3   s   "€r%   r&   rµ   d  s6   ø‡ ‚ ñ, —<‘<Ññ- ñ. Ññ/ ñ6  ×,Ñ,ÑIò7 r'   rK   rJ   )rK   Nrs   )(r�   r‚   rƒ   r„   Ú__doc__Ú	__slots__rL  rM  rK  r»   rC   rD   r¸   Ú_disable_dynamor   r¿   rÈ   rÌ   r…   r×   rå   rï   ró   Úclassmethodr   rx   r¬   rî   r+  Úpropertyry   r    r6  r=  rD  rG  Ú__annotate_func__r†   r‡   Ú__classcell__)rÃ   r3   s   @@r%   r   r   d  s˜  ù‡ € ñð. ! 'Ð*€Ið 0;×/GÒ/GÓ/I€N÷ð ð �l‰l×*Ñ*€Gà
×ÑØ6ôó 7ó ðò@ò

ð ñ
ó ð
÷8
Pð 
PòVô
ð ó%ó ð%ð, ñ|
ð
  ð|
ð $(ð|
ð *.ð|
ð 7;÷|
ò |
ó ð|
ð|?Ø?C÷?ò ?ñBv
ð
 ðv
ð -1ðv
ð .2÷v
ó v
ðpAØ?C÷Aò Að> ÷ó ðð ÷%ó ð%÷ð ÷;ð ;ò;ò.;÷{ … r'   Úsrc_data_rankc          
      ó¨   € V ^8„  d   QhR\         P                  R\        R,          R\        \        ,          R,          R\
        R,          R\        /# )r   Útensorry   Nr    rU  r!   )rC   rD   r   r   r   r�   r   )r$   s   "r%   r&   r&   «  sX   € ÷ kñ kÜ�L‰Lðkä˜dÕ"ðkô œÕ# dÕ*ðkô
 ˜•:ðkô ñkr'   c          
     óØ  € \         P                  P                  R4       T;'       g    \        P                  ! 4       pVP
                  pVR8X  d    ^ RIHp V! WV4      # V P                  '       g   \        R4      hW@P                  P                  8w  d$   V P                  '       g   V P                  V4      p Vf-   \        VP                   4       Uu. uF  p\#        4       NK  	  pp\%        V4      VP                   8w  d&   \'        R\%        V4       RVP                    R	24      h\)        V4       \+        V \,        4      '       df   V P.                  V8w  d   \'        R
V P.                   RV R	24      hV P0                  \3        V4      8w  d   \'        RV P0                   RV R24      hV # V P5                  4       p	\7        V4      p\9        V4       EF_  w  r«\+        V\:        \<        ,          4      '       d¸   VP>                  ^ 8  d   VP>                  V P                   ,           MVP>                  p\+        V\:        4      '       d(   \:        P@                  ! WÉWV4      p	\;        V4      W*&   Kž  \<        P@                  ! VV	VV
VVPB                  R7      p	\=        WËPB                  R7      W*&   KÞ  \+        V\"        4      '       d   \"        PD                  ! W‘W£4      p	EK  \+        V\F        4      '       d-   \"        PD                  ! W‘W£4      p	VPI                  W‘V
4      p	EKP  \        RV RV
 R24      h	  \3        V4      pV	f   \K        R4      h\M        VV\O        V PQ                  4       V PS                  4       V PT                  R7      R7      p\-        V	PW                  V PX                  4      VV PX                  R7      #   \         d   pRp\        T4      ThRp?ii ; iu upi )a
  
Distribute a leaf ``torch.Tensor`` (i.e. nn.Parameter/buffers) to the ``device_mesh`` according
to the ``placements`` specified. The rank of ``device_mesh`` and ``placements`` must be the
same. The ``tensor`` to distribute is the logical or "global" tensor, and the API would use
the ``tensor`` from first rank of the DeviceMesh dimension as the source of truth to preserve
the single-device semantic. If you want to construct a DTensor in the middle of the Autograd
computation, please use :meth:`DTensor.from_local` instead.

Args:
    tensor (torch.Tensor): torch.Tensor to be distributed. Note that if you
        want to shard a tensor on a dimension that is not evenly divisible by
        the number of devices in that mesh dimension, we use ``torch.chunk``
        semantic to shard the tensor and scatter the shards. The uneven sharding
        behavior is experimental and subject to change.
    device_mesh (:class:`DeviceMesh`, optional): DeviceMesh to distribute the
        tensor, if not specified, must be called under a DeviceMesh context
        manager, default: None
    placements (List[:class:`Placement`], optional): the placements that
        describes how to place the tensor on DeviceMesh, must have the same
        number of elements as ``device_mesh.ndim``. If not specified, we will
        by default replicate the tensor across the ``device_mesh`` from the
        first rank of each dimension of the `device_mesh`.

Keyword args:
    src_data_rank (int, optional): the rank of the source data for the logical/global tensor, it is
        used by :meth:`distribute_tensor` to scatter/broadcast the shards/replicas to other ranks.
        By default, we use ``group_rank=0`` on each DeviceMesh dimension as the source data to preserve
        the single-device semantic. If passing ``None`` explicitly, :meth:`distribute_tensor` simply uses
        its local data instead of trying to preserve the single-device semantic via scatter/broadcast.
        Default: 0

Returns:
    A :class:`DTensor` or ``XLAShardedTensor`` object.

Raises:
    ValueError: If ``placements`` contains mixed :class:`Partial` reduce types
        (e.g., both ``Partial("sum")`` and ``Partial("max")``). All Partial
        placements must use the same reduce operation.

.. note::
    When initialize the DeviceMesh with the ``xla`` device_type, ``distribute_tensor``
    return `XLAShardedTensor` instead. see `this issue <https://github.com/pytorch/pytorch/issues/92909>`__
    for more details. The XLA integration is experimental and subject to change.
ztorch.dtensor.distribute_tensorÚxla)Úxla_distribute_tensorúDTo use DTensor API with xla, you must install the torch_xla package!NzY`distribute_tensor` should be used to distribute leaf tensors! but found non-leaf tensor!zW`placements` must have the same length as `device_mesh.ndim`! Found placements length: z, and device_mesh.ndim: r’   z-Cannot distribute a DTensor with device mesh z to a different device mesh z,Cannot distribute a DTensor with placements z to a different placements z-. do you want to call `redistribute` instead?r  z8Trying to distribute tensor with unsupported placements z on device mesh dimension Ú!z(distributing a tensor should not be Nonero   )rt   r    rr   r“   )-rC   Ú_CÚ_log_api_usage_oncer
   r  r  Útorch_xla.distributed.spmdrZ  ÚImportErrorÚis_leafr™   rÞ   r÷   r  r	  r
  r  r   rS   r5  r   ré   r   ry   r    r#   Údetachr  rœ   r   r   r  Ú_make_shard_tensorr  Ú_make_replicate_tensorr   Ú_partition_valuerÏ   r   r   Úsizer:   rp   Úrequires_grad_r”   )rW  ry   r    rU  r  rZ  ÚeÚmsgr|   r>   r¢   r£   Úplacement_dimr´   s   &&&$          r%   Údistribute_tensorrk  «  s¯  € ôh 
‡H�H× Ñ Ð!BÔCð ×CÐC¤×!AÒ!AÓ!C€KØ×)Ñ)€KØ�eÔð
	*õñ )¨¸jÓIÐIð
 �>�>ˆ>ÜØgó
ð 	
ð
 —m‘m×(Ñ(Ô(°··°Ø—‘˜;Ó'ˆð ÒÜ+0°×1AÑ1AÔ+BÓCÑ+B a”i–kÑ+Bˆ
ÐCä
ˆ:ƒ˜+×*Ñ*Ô*Üð(Ü(+¨J«Ð'8Ð8PÐQ\×QaÑQaÐPbÐbcðeó
ð 	
ô " *Ô-Ü�&œ'×"Ò"ð
 ×Ñ Ô,ÜØ?À×@RÑ@RÐ?Sð T.Ø.9¨]¸!ð=óð ð ×Ñ¤ jÓ 1Ô1ÜØ>¸v×?PÑ?PÐ>Qð R-Ø-7¨Lð 9*ð+óð ð
 ˆà—=‘=“?€Lô �jÓ!€JÜ# J×/‰ˆÜ�i¤¬Õ!6×7Ò7à/8¯}©}¸qÔ/@�	—‘ §¡Ö+ÀiÇmÁmð ô ˜)¤U×+Ò+Ü$×7Ò7Ø!°À=ó �ô #(¨Ó"6�
“ä,×?Ò?Ø!Ø ØØØ!Ø!*×!7Ñ!7ô �ô #0Ø!×0FÑ0Fô#�
“ô ˜	¤9×-Ò-Ü$×;Ò;Ø¨3ó‹Lô ˜	¤7×+Ò+Ü$×;Ò;Ø¨3óˆLð %×5Ñ5°lÐQTÓU‹LäØJÈ9È+ÐUoÐpsÐotÐtuÐvóð ñA 0ôF �zÓ"€JàÒÜÐGÓHÐHô ØØÜØ—+‘+“-Ø—=‘=“?Ø—,‘,ô
ô€Dô à×#Ñ# F×$8Ñ$8Ó9Øà×*Ñ*ôð øôG ô 	*ØXˆCÜ˜cÓ"¨Ð)ûð	*üò Ds   ÁO ÃO'ÏO$ÏOÏO$zAPlease use `distribute_tensor` with `src_data_rank=None` instead.c                óx   € V ^8„  d   QhR\         P                  R\        \        ,          R\        R,          RR/# )r   r+  r    ry   Nr!   r   )rC   rD   r   r   r   )r$   s   "r%   r&   r&   Z  sC   € ÷ "Wñ "WÜ—‘ð"Wäœ•ð"Wô ˜dÕ"ð"Wð ñ	"Wr'   c                ó   € \        WVRR7      # )a4  
Locally shards a full tensor based on indicated sharding arrangement, and
returns a DTensor containing the local shard.

.. warning:: This is a private API that is subject to change. It skips the
    communication otherwise required by `distribute_tensor`. It is only
    applicable to cases where all ranks have the same `full_tensor`. For
    example, in distributed inference all ranks load from the same
    checkpoint. This API will not check for data equality between ranks, it
    is thus user's responsibility to ensure the `full_tensor` is the same
    across ranks.

Args:
    full_tensor (torch.Tensor): the full tensor to be sharded.
    placements (Sequence[:class:`Shard`]): the placements that
        describes how to place the local tensor on DeviceMesh.
    device_mesh (:class:`DeviceMesh`, optional): DeviceMesh to place the
        DTensor.  Must have same dimension as the number of placements.
        If not specified, would be retrieve from current context.

Returns:
    A :class:`DTensor` object with the shard as its local tensor.

Examples:
    >>> # xdoctest: +SKIP("need world_size and rank")
    >>> device_mesh = dist.init_device_mesh("cuda", (world_size,))
    >>> full_tensor = torch.arange(world_size, device=f"cuda:{rank}")
    >>> dtensor = _shard_tensor(full_tensor, [Shard(1)], device_mesh)
N)rU  )rk  )r+  r    ry   s   &&&r%   Ú_shard_tensorrn  Y  s   € ôF ˜[°zÐQUÔVÐVr'   c                óŒ  € V ^8„  d   QhR\         P                  R\        R,          R\        \        \         P                  \        .R3,          R,          R\        \         P                  \
        \        .R3,          R,          R\        \         P                  \
        \        .R3,          R,          R\         P                  /# )r   Úmodulery   NÚpartition_fnÚinput_fnÚ	output_fnr!   )ÚnnÚModuler   r   rÛ   r   )r$   s   "r%   r&   r&     s§   € ÷ mñ mÜ�I‰Iðmä˜dÕ"ðmô œC¤§¡¬JÐ7¸Ð=Õ>ÀÕEðmô œŸ	™	¤3¬
Ð3°TÐ9Õ:¸TÕAð	mô
 œŸ™¤C¬Ð4°dÐ:Õ;¸dÕBðmô ‡Y�Yñmr'   c                ód  aaa€ \         P                  P                  R4       \        V RR4      pV'       d   \	        R4      hS;'       g    \
        P                  ! 4       oSP                  pVR8X  d    ^ RIH	p V! V SVSS4      # R	 R
 lp
Vf"   V P                  4        F  pV
! VS4       K  	  M+V P                  4        F  w  rËV! WËS4       V
! VS4       K  	  Se’   \        \        P                  ! S4      P                   4      pV^8X  d5   \"        P$                  ! R\&        ^R7       V P)                  VV3R l4       M-V^8X  d   V P)                  VV3R l4       M\+        RV R24      hSe’   \        \        P                  ! S4      P                   4      pV^8X  d5   \"        P$                  ! R\&        ^R7       V P-                  VV3R l4       M-V^8X  d   V P-                  VV3R l4       M\+        RV R24      hRV n        V #   \         d   pRp	\        T	4      ThRp?ii ; i)a9  
Convert a module's parameters/buffers to :class:`DTensor` s, and optionally
convert its inputs/outputs at runtime, using the three user-provided callbacks.

The behavior of the three callbacks:

1. ``partition_fn`` shards the module's parameters/buffers *before* runtime
   execution (i.e. it converts plain ``torch.Tensor`` parameters into
   :class:`DTensor` parameters). Any parameter/buffer not converted by
   ``partition_fn`` is replicated across ``device_mesh`` afterwards. If
   ``partition_fn`` is ``None``, *all* parameters/buffers are replicated.
2. ``input_fn`` / ``output_fn`` convert the module's inputs/outputs *during*
   runtime execution (e.g. convert plain tensor inputs into :class:`DTensor`,
   or convert :class:`DTensor` outputs back into plain ``torch.Tensor``).

Args:
    module (:class:`nn.Module`): user module to be partitioned.
    device_mesh (:class:`DeviceMesh`): the device mesh to place the module. If
        ``None``, the current mesh from the ambient mesh context is used.
    partition_fn (Callable): a function with signature
        ``partition_fn(name: str, module: nn.Module, device_mesh: DeviceMesh) -> None``.
        It is called once for *every* submodule (including ``module`` itself),
        where ``name`` is the submodule's fully-qualified name (``""`` for the
        top-level module) as returned by :meth:`nn.Module.named_modules`. The
        function is expected to mutate ``module`` in place, typically by calling
        :func:`distribute_tensor` and :meth:`register_parameter` to replace
        selected parameters with :class:`DTensor` parameters. Its return value
        is ignored. If not specified, all module parameters are replicated
        across ``device_mesh``.
    input_fn (Callable): a function with signature
        ``input_fn(module: nn.Module, inputs: Inputs, device_mesh: DeviceMesh) -> Inputs``,
        where ``Inputs`` is the tuple of positional arguments to ``forward`` (one
        entry per positional argument, e.g. ``(x,)`` for ``forward(self, x)``;
        keyword arguments are not forwarded to ``input_fn``). Installed on the
        top-level ``module`` as a ``forward_pre_hook``, it returns the new
        argument tuple -- the same structure as ``inputs``, typically with each
        ``torch.Tensor`` entry converted to a :class:`DTensor` -- which replaces
        ``inputs`` for the actual ``forward`` call.
    output_fn (Callable): a function with signature
        ``output_fn(module: nn.Module, outputs: Outputs, device_mesh: DeviceMesh) -> Outputs``,
        where ``Outputs`` is the return type of ``module.forward`` (a single
        tensor, or any nested structure of tensors such as a tuple/dict), with the
        tensors typically being :class:`DTensor` s. Installed on the top-level
        ``module`` as a ``forward_hook``, it returns the replacement output of the
        same structure -- typically with each :class:`DTensor` converted back to a
        plain ``torch.Tensor`` via :meth:`DTensor.to_local` or
        :meth:`DTensor.full_tensor`, or redistributed to different placements.

Returns:
    A module whose parameters/buffers are all :class:`DTensor` s (the same
    ``module`` object, mutated in place).

.. warning::
    ``input_fn`` and ``output_fn`` previously took two arguments
    ``(inputs, device_mesh)`` / ``(outputs, device_mesh)``. That form is
    deprecated; use the three-argument form documented above.

Example::

    import torch.nn as nn
    from torch.distributed.tensor import (
        DTensor,
        Replicate,
        Shard,
        distribute_module,
        distribute_tensor,
        init_device_mesh,
    )


    class MyModule(nn.Module):
        def __init__(self) -> None:
            super().__init__()
            self.fc = nn.Linear(8, 8)

        def forward(self, x):
            return self.fc(x)


    mesh = init_device_mesh("cuda", (4,))


    def shard_params(name, mod, mesh):
        if isinstance(mod, nn.Linear):
            for pname, param in mod.named_parameters(recurse=False):
                mod.register_parameter(
                    pname, nn.Parameter(distribute_tensor(param, mesh, [Shard(0)]))
                )


    # Replicate the input across the mesh before forward.
    def to_replicated(mod, inputs, mesh):
        return tuple(
            distribute_tensor(x, mesh, [Replicate()])
            if isinstance(x, torch.Tensor)
            else x
            for x in inputs
        )


    # Convert the DTensor output back to a plain torch.Tensor after forward.
    def to_local(mod, outputs, mesh):
        return outputs.full_tensor() if isinstance(outputs, DTensor) else outputs


    sharded = distribute_module(
        MyModule(),
        mesh,
        partition_fn=shard_params,
        input_fn=to_replicated,
        output_fn=to_local,
    )

.. note::
    When initializing the ``DeviceMesh`` with the ``xla`` device_type,
    ``distribute_module`` returns an ``nn.Module`` with PyTorch/XLA SPMD
    annotated parameters. See
    `this issue <https://github.com/pytorch/pytorch/issues/92909>`__
    for more details. The XLA integration is experimental and subject to change.

ztorch.dtensor.distribute_moduleÚ_distribute_module_appliedFzhdistribute_module should only be called once on a module, but it has already been called on this module!rY  )Úxla_distribute_moduler[  Nc                óH   € V ^8„  d   QhR\         P                  R\        RR/# )r   Úmrt   r!   N)rt  ru  r   )r$   s   "r%   r&   Ú'distribute_module.<locals>.__annotate__  s*   € ÷ Rñ R¬2¯9©9ð R¼Jð RÈ4ñ Rr'   c                 ó   € \        4       .VP                  ,          pV P                  P                  4        Fi  w  r4Vf   K  \	        V\
        4      '       d   K#  V P                  V\        P                  ! \        VP                  W4      VP                  R7      4       Kk  	  V P                  P                  4        F<  w  r5Vf   K  \	        V\
        4      '       d   K#  \        WQV4      V P                  V&   K>  	  R # )Nr“   )r   r  Ú_parametersÚitemsré   r   Úregister_parameterrt  Ú	Parameterrk  Údatar”   Ú_buffers)rz  rt   Úfull_replicateÚkeyÚparamÚbuffers   &&    r%   Úreplicate_module_params_buffersÚ:distribute_module.<locals>.replicate_module_params_buffers  s¶   € ô $›+˜¨¯©Õ2ˆØŸ-™-×-Ñ-Ö/‰JˆCØÔ ¬°E¼7×)CÔ)CØ×$Ñ$ØÜ—L’LÜ)¨%¯*©*°dÓKØ&+×&9Ñ&9ôöñ 0ð Ÿ:™:×+Ñ+Ö-‰KˆCØÔ!¬*°V¼W×*EÔ*EÜ"3°FÀ.Ó"Q�—
‘
˜3“ó .r'   z�Deprecating input_fn that takes two arguments (inputs, device_mesh), please use input_fn that takes in (module, inputs, device_mesh) instead!)Ú
stacklevelc                 ó   <€ S! VS4      # rJ   rK   )r|   Úinputsry   rr  s   &&€€r%   rj   Ú#distribute_module.<locals>.<lambda>I  s   ø€ ¡(¨6°;Ô"?r'   c                 ó   <€ S! WS4      # rJ   rK   )Úmodr‹  ry   rr  s   &&€€r%   rj   rŒ  N  s   ø€ ¡H¨S¸+Ô$Fr'   z-input_fn should take in 3 arguments, but got z arguments!z�Deprecating output_fn that takes two arguments (inputs, device_mesh), please use output_fn that takes in (module, inputs, device_mesh) instead!c                 ó   <€ S! VS4      # rJ   rK   ©rŽ  r‹  Úoutputsry   rs  s   &&&€€r%   rj   rŒ  `  s   ø€ ©Y°wÀÔ-Lr'   c                 ó   <€ S! WS4      # rJ   rK   r�  s   &&&€€r%   rj   rŒ  d  s   ø€ ©Y°sÀ[Ô-Qr'   z.output_fn should take in 3 arguments, but got T)rC   r]  r^  r  r™   r
   r  r  r_  rx  r`  ÚmodulesÚnamed_modulesrS   ÚinspectÚ	signatureÚ
parametersÚwarningsÚwarnÚFutureWarningÚregister_forward_pre_hookr5  Úregister_forward_hookrw  )rp  ry   rq  rr  rs  Úalready_distributedr  rx  rh  ri  r‡  ÚsubmodÚnameÚnum_argss   &f&ff         r%   Údistribute_moduler¡    s+  ú€ ôB 
‡H�H× Ñ Ð!BÔCä! &Ð*FÈÓNÐßÜð=ó
ð 	
ð
 ×CÐC¤×!AÒ!AÓ!C€KØ×)Ñ)€KØ�eÔð	*õñ )Ø˜ \°8¸Yóð õRð, Òð —n‘nÖ&ˆFÙ+¨F°KÖ@ò 'ð #×0Ñ0Ö2‰LˆDÙ˜ {Ô3Ù+¨F°KÖ@ñ 3ð
 Òä”w×(Ò(¨Ó2×=Ñ=Ó>ˆØ�qŒ=ä�MŠMð[äØõ	ð ×,Ñ,Ý?õð ˜Œ]à×,Ñ,ÝFõô Ø?À¸zÈÐUóð ð ÒÜ”w×(Ò(¨Ó3×>Ñ>Ó?ˆØ�qŒ=ä�MŠMð\äØõ	ð ×(Ñ(ÝLõð ˜Œ]Ø×(Ñ(ÝQõô Ø@ÀÀ
È+ÐVóð ð )-€FÔ%Ø€Møôk ô 	*ØXˆCÜ˜cÓ"¨Ð)ûð	*ús   Á6H ÈH/ÈH*È*H/c                 óÆ   € TpTpV^ 8”  dD   V^8”  d=   W!,
          V^,
          ,          p	WV	,          ,           pWyV^,
          ,          ,           pM	V^ 8”  d   TpV ! Wx3RV/VB # )r   ÚstepsrK   )
Úinit_opÚstartÚendÚtotal_stepsÚlocal_stepsÚoffsetrÂ   Úlocal_startÚ	local_endÚsteps
   &&&&&&,   r%   Ú_linspace_local_tensorr­  u  si   € ð €KØ€IØ�Q„˜;¨œ?Ø• ¨a¥Õ0ˆØ t�mÕ+ˆØ¨+¸­/Õ":Õ:‰	Ø	�qŒØˆ	Ù�;ÑG°ÐGÀÑGÐGr'   c                 óÊ   € TpTp	V^ 8”  dD   V^8”  d=   W!,
          V^,
          ,          p
WV
,          ,           pWŠV^,
          ,          ,           p	M	V^ 8”  d   Tp	V ! W‰3RVRV/VB # )r   r£  ÚbaserK   )r¤  r¥  r¦  r¯  r§  r¨  r©  rÂ   rª  r«  r¬  s   &&&&&&&,   r%   Ú_logspace_local_tensorr°  „  sn   € ð €KØ€IØ�Q„˜;¨œ?Ø• ¨a¥Õ0ˆØ t�mÕ+ˆØ¨+¸­/Õ":Õ:‰	Ø	�qŒØˆ	Ù�;ÑR°ÐRÀ4ÐRÈ6ÑRÐRr'   c                óŽ   € V ^8„  d   QhR\         P                  R\        R,          R\        \        ,          R,          R\
        /# )r   rf  ry   Nr    r!   )rC   rŽ   r   r   r   r   )r$   s   "r%   r&   r&   “  sK   € ÷ ^ñ ^ä
�*‰*ð^ô ˜dÕ"ð^ô œÕ# dÕ*ð	^ô ñ^r'   c           
      ó,  € T;'       g    \         P                  ! 4       pVP                  VR &   T;'       gS    \        ;QJ d'    . R \	        VP
                  4       4       F  NK  	  5M ! R \	        VP
                  4       4       4      pVP
                  \        V4      8w  d   \        R4      hVR,          \        P                  8w  d   \        R4      h\        P                  P                  V4      p\        VVVV \        P                  \        P                  39  R7      w  rgV \        P                  J d   VP!                  R4      pV ! Wh3/ VB p	EMêV \        P                  J dK   VP!                  R4      p
VP!                  R4      p\#        V V
VV^ ,          V^ ,          V^ ,          3/ VB p	EMŒV \        P                  J d]   VP!                  R4      p
VP!                  R4      pVP!                  R	4      p\%        V V
VVV^ ,          V^ ,          V^ ,          3/ VB p	EMV \        P&                  J g   V \        P(                  J dì   VP+                  R
\        P,                  ! 4       4      p\/        WV4      p\1        V\        V4      VR7      p\2        P4                  ! V4      '       d6   \2        P6                  '       g    \2        P8                  ! V4      \2        n        \2        P6                  f   \        h\2        P6                  P;                  V4      ;_uu_ 4        V ! V3/ VB p	RRR4       M	V ! V3/ VB p	\1        V\        V4      \/        VVX	P<                  4      R7      p\?        V	VVR,          R7      #   + '       g   i     LQ; i)rÞ   c              3   ó6   "  € T F  p\        4       x € K  	  R # 5irJ   )r   )rM   r|   s   & r%   rP   Ú'_dtensor_init_helper.<locals>.<genexpr>Ÿ  s   é € Ð$RÑ:Q°Q¤Y§[ [Ó:Qùs   ‚z6mesh dimension does not match the length of placementsÚlayoutzlayout value not supported!)Úskip_offsetÚ
fill_valuer¥  r¦  r¯  rp   rq   Nr”   r“   ) r
   r  r  r#   r
  r  rS   rÏ   rC   ÚstridedÚ_prims_commonÚmake_contiguous_strides_forr   ÚlinspaceÚlogspaceÚfullÚpopr­  r°  ÚrandÚrandnÚgetÚget_default_dtyper   r   ÚrandomÚis_rng_supported_meshÚ_rng_trackerÚOffsetBasedRNGTrackerÚ_distribute_regionrp   r   )r¤  rf  ry   r    rÂ   Útorch_strideÚlocal_shapeÚglobal_offsetr·  r>   r¥  r¦  r¯  rp   rr   r´   s   &&&&,           r%   Ú_dtensor_init_helperrË  “  s   € ð ×CÐC¤×!AÒ!AÓ!C€KØ"×.Ñ.€Fˆ8Ñð ×RÐRŸuœuÑ$R¼%À×@PÑ@PÔ:QÓ$RŸu™uÑ$R¼%À×@PÑ@PÔ:QÓ$RÓR€Jð ×Ñœ3˜z›?Ô*ÜÐUÓVÐVàˆhÕœ5Ÿ=™=Ô(ÜÐ:Ó;Ð;Ü×&Ñ&×BÑBÀ4ÓH€Lô "GØØØØ¤E§N¡N´E·N±NÐ#CÑCô	"Ñ€Kð ”%—*‘*ÓØ—Z‘Z Ó-ˆ
Ù˜{ÑA¸&ÑAŠØ	”E—N‘NÓ	"Ø—
‘
˜7Ó#ˆØ�j‰j˜ÓˆÜ-ØØØØ��GØ˜�NØ˜!Õñ
ð ñ
Šð 
”E—N‘NÓ	"Ø—
‘
˜7Ó#ˆØ�j‰j˜ÓˆØ�z‰z˜&Ó!ˆÜ-ØØØØØ��GØ˜�NØ˜!Õñ	
ð ñ	
Šð 
”E—J‘JÓ	 '¬U¯[©[Ó"8à—
‘
˜7¤E×$;Ò$;Ó$=Ó>ˆä  °UÓ;ˆÜ˜;¬¨jÓ(9À{ÔSˆä×'Ò'¨×4Ò4¼V×=P×=PÐ=PÜ"(×">Ò">¸{Ó"KŒFÔä×ÑÒ&Ü Ð Ü× Ñ ×3Ñ3°D×9Õ9Ù" ;Ñ9°&Ñ9ˆL÷ :Ð9ñ ˜{Ñ5¨fÑ5ˆäØÜˆjÓÜØØØ×Ñó
ô€Dô àØà˜_Õ-ôð ÷! :×9ús   Ì&
NÎN	rp   rµ  r”   Fry   r    c                óÈ   € V ^8„  d   QhR\         P                  R,          R\         P                  R\        R\        R,          R\
        \        ,          R,          R\        /# ©r   rp   Nrµ  r”   ry   r    r!   ©rC   rp   rµ  r�   r   r   r   r   )r$   s   "r%   r&   r&   ô  ób   € ÷ (ñ (ä�;‰;˜Õð(ô �L‰Lð(ô ð	(ô
 ˜dÕ"ð(ô œÕ# dÕ*ð(ô ñ(r'   c           
     óX   € \        V4      p\        \        P                  VV VVVVR7      # )a  
Returns a :class:`DTensor` filled with the scalar value 1, with the shape defined
by the variable argument ``size``.

Args:
    size (int...): a sequence of integers defining the shape of the output :class:`DTensor`.
        Can be a variable number of arguments or a collection like a list or tuple.
        E.g.: ones(1,2,3..) or ones([1,2,3..]) or ones((1,2,3..))

Keyword args:
    dtype (:class:`torch.dtype`, optional): the desired data type of returned :class:`DTensor`.
        Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
    layout (:class:`torch.layout`, optional): the desired layout of returned DTensor.
        Default: ``torch.strided``.
    requires_grad (bool, optional): If autograd should record operations on the
        returned :class:`DTensor`. Default: ``False``.
    device_mesh: :class:`DeviceMesh` type, contains the mesh info of ranks
    placements: a sequence of :class:`Placement` type: ``Shard``, ``Replicate``

Returns:
    A :class:`DTensor` object on each rank
©rp   rµ  r”   ry   r    )r   rË  rC   Úones©rp   rµ  r”   ry   r    rf  Ú
torch_sizes   $$$$$* r%   rÒ  rÒ  ô  s4   € ô< )¨Ó.€JäÜ�
‰
ØØØØ#ØØôð r'   c                óÈ   € V ^8„  d   QhR\         P                  R,          R\         P                  R\        R\        R,          R\
        \        ,          R,          R\        /# rÍ  rÎ  )r$   s   "r%   r&   r&     rÏ  r'   c           
     óX   € \        V4      p\        \        P                  VV VVVVR7      # )a0  
Returns a :class:`DTensor` filled with uninitialized data. The shape of the :class:`DTensor`
is defined by the variable argument ``size``.

Args:
    size (int...): a sequence of integers defining the shape of the output :class:`DTensor`.
        Can be a variable number of arguments or a collection like a list or tuple.
        E.g.: empty(1,2,3..) or empty([1,2,3..]) or empty((1,2,3..))

Keyword args:
    dtype (:class:`torch.dtype`, optional): the desired data type of returned :class:`DTensor`.
        Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).        layout (:class:`torch.layout`, optional): the desired layout of returned :class:`DTensor`.
        Default: ``torch.strided``.
    requires_grad (bool, optional): If autograd should record operations on the
        returned :class:`DTensor`. Default: ``False``.
    device_mesh: :class:`DeviceMesh` type, contains the mesh info of ranks
    placements: a sequence of :class:`Placement` type: ``Shard``, ``Replicate``

Returns:
    A :class:`DTensor` object on each rank
rÑ  )r   rË  rC   ÚemptyrÓ  s   $$$$$* r%   r×  r×    s4   € ô< )¨Ó.€JäÜ�‰ØØØØ#ØØôð r'   c                óÈ   € V ^8„  d   QhR\         P                  R,          R\         P                  R\        R\        R,          R\
        \        ,          R,          R\        /# rÍ  rÎ  )r$   s   "r%   r&   r&   J  sd   € ÷ ,ñ ,ô �;‰;˜Õð	,ô
 �L‰Lð,ô ð,ô ˜dÕ"ð,ô œÕ# dÕ*ð,ô ñ,r'   c               óZ   € \        V 4      p\        \        P                  VVVVVVVR7      # )aq  
Returns a :class:`DTensor` filled with ``fill_value`` according to ``device_mesh`` and
``placements``, with the shape defined by the argument ``size``.

Args:
    size (int...): a sequence of integers defining the shape of the output :class:`DTensor`.
        Can be a variable number of arguments or a collection like a list or tuple.
        E.g.: ones(1,2,3..) or ones([1,2,3..]) or ones((1,2,3..))
    fill_value(Scalar): the value to fill the output tensor with.

Keyword args:
    dtype (:class:`torch.dtype`, optional): the desired data type of returned :class:`DTensor`.
        Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
    layout (:class:`torch.layout`, optional): the desired layout of returned DTensor.
        Default: ``torch.strided``.
    requires_grad (bool, optional): If autograd should record operations on the
        returned :class:`DTensor`. Default: ``False``.
    device_mesh: :class:`DeviceMesh` type, contains the mesh info of ranks.
    placements: a sequence of :class:`Placement` type: ``Shard``, ``Replicate``

Returns:
    A :class:`DTensor` object on each rank
)r·  rp   rµ  r”   ry   r    )r   rË  rC   r½  )rf  r·  rp   rµ  r”   ry   r    rÔ  s   &&$$$$$ r%   r½  r½  J  s8   € ôB )¨Ó.€JäÜ�
‰
ØØØØØ#ØØô	ð 	r'   c                óÈ   € V ^8„  d   QhR\         P                  R,          R\         P                  R\        R\        R,          R\
        \        ,          R,          R\        /# rÍ  rÎ  )r$   s   "r%   r&   r&   y  sl   € ÷ Bñ Bô
 �;‰;˜ÕðBô �L‰LðBô ðBô ˜dÕ"ðBô œÕ# dÕ*ðBô ñBr'   c               óT  € VeF   \         ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \        R4      h\        V \        P                  4      '       d:   \        P
                  ! V P                  4       ^ 8H  R 4       V P                  4       p \        V\        P                  4      '       d:   \        P
                  ! VP                  4       ^ 8H  R 4       VP                  4       p\        V34      p\        \        P                  VV VVVVVVR7	      # )a¿  
Returns a :class:`DTensor` of size ``steps`` whose values are evenly spaced from
`start` to `end`.

Args:
    start (float or :class:`DTensor`): the starting value for the set of points. If
       :class:`DTensor`, it must be 0-dimensional
    end (float or :class:`DTensor`): the ending value for the set of points. If
       :class:`DTensor`, it must be 0-dimensional
    steps (int): size of the constructed :class:`DTensor`

Keyword args:
    dtype (:class:`torch.dtype`, optional): the data type to perform the computation
        in. Default: if ``None``, uses the global default dtype
        (see :func:`torch.set_default_dtype`) when both `start` and `end` are real,
        and corresponding complex dtype when either is complex.
    layout (:class:`torch.layout`, optional): the desired layout of returned
        :class:`DTensor`. Default: ``torch.strided``.
    requires_grad (bool, optional): If autograd should record operations on the
        returned :class:`DTensor`. Default: ``False``.
    device_mesh: :class:`DeviceMesh` type, contains the mesh info of ranks
    placements: a sequence of :class:`Placement` type: ``Shard``, ``Replicate``

Returns:
    A :class:`DTensor` object on each rank
c              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5irJ   ©ré   r   rê   s   & r%   rP   Úlinspace.<locals>.<genexpr>ž  ó   é € Ð%WÉJÀq¤j°´M×&BÐ&BËJùrì   TFz2linspace does not support _StridedShard placementsc                  ó   € R # ©z:linspace only supports 0-dimensional start and end tensorsrK   rK   r'   r%   rj   Úlinspace.<locals>.<lambda>¤  ó   € ÑPr'   c                  ó   € R # rá  rK   rK   r'   r%   rj   râ  «  rã  r'   )r¥  r¦  rp   rµ  r”   ry   r    )r]   rÏ   ré   rC   rD   rl   r  Úitemr   rË  r»  )	r¥  r¦  r£  rp   rµ  r”   ry   r    rÔ  s	   &&&$$$$$ r%   r»  r»  y  sä   € ðJ Ò§#£#Ñ%WÉJÓ%W§#§#¢#Ñ%WÉJÓ%W×"WÒ"WÜÐQÓRÐRä�%œŸ™×&Ò&Ü�ŠØ�I‰I‹K˜1ÑÙPô	
ð —
‘
“ˆä�#”u—|‘|×$Ò$Ü�ŠØ�G‰G‹I˜‰NÙPô	
ð �h‰h‹jˆä(¨%¨Ó2€JäÜ�‰ØØØØØØ#ØØô
ð 
r'   c                óÈ   € V ^8„  d   QhR\         P                  R,          R\         P                  R\        R\        R,          R\
        \        ,          R,          R\        /# rÍ  rÎ  )r$   s   "r%   r&   r&   ¾  sl   € ÷ Fñ Fô �;‰;˜ÕðFô �L‰LðFô ðFô ˜dÕ"ðFô œÕ# dÕ*ðFô ñFr'   c               óV  € VeF   \         ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \        R4      h\        V \        P                  4      '       d:   \        P
                  ! V P                  4       ^ 8H  R 4       V P                  4       p \        V\        P                  4      '       d:   \        P
                  ! VP                  4       ^ 8H  R 4       VP                  4       p\        V34      p	\        \        P                  V	V VVVVVVVR7
      # )a`  
Returns a :class:`DTensor` of size ``steps`` whose values are evenly spaced from
``base`` :sup:`start` to ``base`` :sup:`end`, inclusive, on a logarithmic scale
with base ``base``.

Args:
    start (float or :class:`DTensor`): the starting value for the set of points. If
       :class:`DTensor`, it must be 0-dimensional
    end (float or :class:`DTensor`): the ending value for the set of points. If
       :class:`DTensor`, it must be 0-dimensional
    steps (int): size of the constructed :class:`DTensor`

Keyword args:
    base (float, optional): base of the logarithm function. Default: ``10.0``.
    dtype (:class:`torch.dtype`, optional): the data type to perform the computation
        in. Default: if ``None``, uses the global default dtype
        (see :func:`torch.set_default_dtype`) when both `start` and `end` are real,
        and corresponding complex dtype when either is complex.
    layout (:class:`torch.layout`, optional): the desired layout of returned
        :class:`DTensor`. Default: ``torch.strided``.
    requires_grad (bool, optional): If autograd should record operations on the
        returned :class:`DTensor`. Default: ``False``.
    device_mesh: :class:`DeviceMesh` type, contains the mesh info of ranks
    placements: a sequence of :class:`Placement` type: ``Shard``, ``Replicate``

Returns:
    A :class:`DTensor` object on each rank
c              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5irJ   rÝ  rê   s   & r%   rP   Úlogspace.<locals>.<genexpr>æ  rß  rì   TFz2logspace does not support _StridedShard placementsc                  ó   € R # ©z:logspace only supports 0-dimensional start and end tensorsrK   rK   r'   r%   rj   Úlogspace.<locals>.<lambda>ì  rã  r'   c                  ó   € R # rë  rK   rK   r'   r%   rj   rì  ó  rã  r'   )r¥  r¦  r¯  rp   rµ  r”   ry   r    )r]   rÏ   ré   rC   rD   rl   r  rå  r   rË  r¼  )
r¥  r¦  r£  r¯  rp   rµ  r”   ry   r    rÔ  s
   &&&&$$$$$ r%   r¼  r¼  ¾  sç   € ðP Ò§#£#Ñ%WÉJÓ%W§#§#¢#Ñ%WÉJÓ%W×"WÒ"WÜÐQÓRÐRä�%œŸ™×&Ò&Ü�ŠØ�I‰I‹K˜1ÑÙPô	
ð —
‘
“ˆä�#”u—|‘|×$Ò$Ü�ŠØ�G‰G‹I˜‰NÙPô	
ð �h‰h‹jˆä(¨%¨Ó2€JäÜ�‰ØØØØØØØ#ØØôð r'   c                óÈ   € V ^8„  d   QhR\         R\        P                  R,          R\        P                  R\        R,          R\
        \        ,          R,          R\        /# ©r   r”   rp   Nrµ  ry   r    r!   ©r�   rC   rp   rµ  r   r   r   r   )r$   s   "r%   r&   r&     ób   € ÷ )ñ )äð)ô �;‰;˜Õð)ô �L‰Lð	)ô
 ˜dÕ"ð)ô œÕ# dÕ*ð)ô ñ)r'   c           
     óX   € \        V4      p\        \        P                  VVVV VVR7      # )aK  
Returns a :class:`DTensor` filled with random numbers from a uniform distribution
on the interval ``[0, 1)``. The shape of the tensor is defined by the variable
argument ``size``.

Args:
    size (int...): a sequence of integers defining the shape of the output :class:`DTensor`.
        Can be a variable number of arguments or a collection like a list or tuple.
        E.g.: ones(1,2,3..) or ones([1,2,3..]) or ones((1,2,3..))

Keyword args:
    dtype (:class:`torch.dtype`, optional): the desired data type of returned :class:`DTensor`.
        Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
    layout (:class:`torch.layout`, optional): the desired layout of returned DTensor.
        Default: ``torch.strided``.
    requires_grad (bool, optional): If autograd should record operations on the
        returned :class:`DTensor`. Default: ``False``.
    device_mesh: :class:`DeviceMesh` type, contains the mesh info of ranks.
    placements: a sequence of :class:`Placement` type: ``Shard``, ``Replicate``

Returns:
    A :class:`DTensor` object on each rank
rÑ  )r   rË  rC   r¿  ©r”   rp   rµ  ry   r    rf  rÔ  s   $$$$$* r%   r¿  r¿    s4   € ô> )¨Ó.€JäÜ�
‰
ØØØØ#ØØôð r'   c                óÈ   € V ^8„  d   QhR\         R\        P                  R,          R\        P                  R\        R,          R\
        \        ,          R,          R\        /# rï  rð  )r$   s   "r%   r&   r&   3  rñ  r'   c           
     óX   € \        V4      p\        \        P                  VVVV VVR7      # )aJ  
Returns a :class:`DTensor` filled with random numbers from a normal distribution
with mean 0 and variance 1. The shape of the tensor is defined by the variable
argument ``size``.

Args:
    size (int...): a sequence of integers defining the shape of the output :class:`DTensor`.
        Can be a variable number of arguments or a collection like a list or tuple.
        E.g.: ones(1,2,3..) or ones([1,2,3..]) or ones((1,2,3..))

Keyword args:
    dtype (:class:`torch.dtype`, optional): the desired data type of returned :class:`DTensor`.
        Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
    layout (:class:`torch.layout`, optional): the desired layout of returned DTensor.
        Default: ``torch.strided``.
    requires_grad (bool, optional): If autograd should record operations on the
        returned :class:`DTensor`. Default: ``False``.
    device_mesh: :class:`DeviceMesh` type, contains the mesh info of ranks.
    placements: a sequence of :class:`Placement` type: ``Shard``, ``Replicate``

Returns:
    A :class:`DTensor` object on each rank
rÑ  )r   rË  rC   rÀ  ró  s   $$$$$* r%   rÀ  rÀ  3  s4   € ô> )¨Ó.€JäÜ�‰ØØØØ#ØØôð r'   c                óÈ   € V ^8„  d   QhR\         R\        P                  R,          R\        P                  R\        R,          R\
        \        ,          R,          R\        /# rï  rð  )r$   s   "r%   r&   r&   _  sb   € ÷ &ñ &äð&ô �;‰;˜Õð&ô �L‰Lð	&ô
 ˜dÕ"ð&ô œÕ# dÕ*ð&ô ñ&r'   c           
     óX   € \        V4      p\        \        P                  VVVV VVR7      # )aÜ  
Returns a :class:`DTensor` filled with the scalar value 0.

Args:
    size (int...): a sequence of integers defining the shape of the output :class:`DTensor`.
        Can be a variable number of arguments or a collection like a list or tuple.
        E.g.: zeros(1,2,3..) or zeros([1,2,3..]) or zeros((1,2,3..))
Keyword args:
    requires_grad (bool, optional): If autograd should record operations on the
        returned :class:`DTensor`. Default: ``False``.
    dtype (:class:`torch.dtype`, optional): the desired data type of returned :class:`DTensor`.
        Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
    layout (:class:`torch.layout`, optional): the desired layout of returned :class:`DTensor`.
        Default: ``torch.strided``.
    device_mesh: :class:`DeviceMesh` type, contains the mesh info of ranks
    placements: a sequence of :class:`Placement` type: ``Shard``, ``Replicate``

Returns:
    A :class:`DTensor` object on each rank
rÑ  )r   rË  rC   Úzerosró  s   $$$$$* r%   rø  rø  _  s4   € ô8 )¨Ó.€JäÜ�‰ØØØØ#ØØôð r'   )r   rk  r¡  rÒ  r×  r½  r»  r¼  r¿  rÀ  rø  rs   rJ   )NNNN)g      $@)Orw   rà   r•  r˜  Úcollections.abcr   r   Útypingr   Útyping_extensionsr   rC   Ú"torch.distributed.tensor._dispatchÚdistributedrW  Ú	_dispatchrL  Ú torch.distributed.tensor._randomÚ_randomrÃ  Útorch.nnrt  Útorch._export.wrappersr   Útorch._loggingr   Útorch.distributed._local_tensorr	   Útorch.distributed.device_meshr
   r   r   Ú*torch.distributed.tensor._collective_utilsr   r   Ú&torch.distributed.tensor._dtensor_specr   r   Ú&torch.distributed.tensor._redistributer   r   Útorch.distributed.tensor._utilsr   r   r   r   r   Ú(torch.distributed.tensor.placement_typesr   r   r   r   r   Ú__all__ÚopsÚatenr-   ÚautogradÚFunctionr/   rŠ   rD   r   rk  rn  r¡  r­  r°  rË  r¸  rÒ  r×  r½  r»  r¼  r¿  rÀ  rø  rx   rK   r'   r%   Ú<module>r     s1  ðó Û Û Û ß .Ý Ý (ã ß 8Ó 8ß 1Ó 1Ý Ý TÝ %Ý F÷ñ ÷
 Yß J÷÷õ ÷õ ò€ð ‡y�y‡~�~€õôNv
�U—^‘^×,Ñ,ô v
ôrBJ�u—~‘~×.Ñ.ô BJôJD	;ˆe�l‰lô D	;ñNkð
 !"÷kð kñ\ ÐOÓPö"Wó Qð"W÷Jmðl ñHó ðHð ñSó ðS÷^ðB(à $ð(ð !Ÿ=™=ð(ð  ð	(ð
 &*ð(ð .2÷(ðV(à $ð(ð !Ÿ=™=ð(ð  ð	(ð
 &*ð(ð .2÷(ðV,ð !%ð	,ð
 !Ÿ=™=ð,ð  ð,ð &*ð,ð .2÷,ð^Bð
 !%ðBð !Ÿ=™=ðBð  ðBð &*ðBð .2÷BñJFð !%ðFð !Ÿ=™=ðFð  ðFð &*ðFð .2÷Fð FðR)àð)ð !%ð)ð !Ÿ=™=ð	)ð
 &*ð)ð .2÷)ðX)àð)ð !%ð)ð !Ÿ=™=ð	)ð
 &*ð)ð .2÷)ðX&àð&ð !%ð&ð !Ÿ=™=ð	&ð
 &*ð&ð .2÷&ðZ ×Ñ€
á "Ö $r'   