+
    –°³j{  ã                   ó  a € R t0 t ^ RIHtHt ^ RIHt ^ RIt^ RIHt	 ^ RI
Ht ^ RIHt ^ RIHtHtHt ^ RIHtHt  ! R R	]4      tRs] ^ k R
 R ltRR R lltRR R lltRR R lltRR R lltRR R lltRR R lltR# )é    )ÚABCÚabstractmethod)ÚAnyN)ÚShardedTensor)ÚShard)Ú_all_gather_dtensorÚ_create_chunk_dtensorÚ_create_chunk_sharded_tensor)Ú
DeviceMeshÚDTensorc                   óÐ   a € ] tR t^t o Rt]V 3R lR l4       t]V 3R lR l4       t]RV 3R lR ll4       t]V 3R	 lR
 l4       t	]V 3R lR l4       t
]V 3R lR l4       tRtV tR# )ÚFSDPExtensionszÔ
This enables some customizable hooks to enable composability with tensor
parallelism. To activate these hooks, use :func:`_set_fsdp_extensions` to
set a custom :class:`FSDPExtensions` that implements the hooks.
c                ór   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  S[R,          3,          /# )é   ÚtensorÚreturnN)ÚtorchÚTensorÚtupler   )ÚformatÚ__classdict__s   "€Úh/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/distributed/fsdp/_fsdp_extensions.pyÚ__annotate__ÚFSDPExtensions.__annotate__   s5   ø€ ÷ ñ á—‘ðñ 
‰u�|‰|™S 4�ZÐ'Õ	(ñó    c                ó   € R# )z6E.g. converting ``DistributedTensor`` to local tensor.N© ©Úselfr   s   &&r   Úpre_flatten_transformÚ$FSDPExtensions.pre_flatten_transform   s   € ñ 	r   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# )r   r   Úparam_extensionr   )r   r   r   )r   r   s   "€r   r   r       s1   ø€ ÷ ñ á—‘ðñ ðñ 
�‰ñ	r   c                ó   € R# )z6E.g. converting local tensor to ``DistributedTensor``.Nr   )r   r   r#   s   &&&r   Úpost_unflatten_transformÚ'FSDPExtensions.post_unflatten_transform   s   € ñ 	r   Nc                ó¢   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[RS[P                  RS[ P
                  R,          RS[ P                  /# )	r   r   ÚrankÚ
world_sizeÚnum_devices_per_nodeÚpgÚdeviceNr   )r   r   ÚintÚdistÚProcessGroupr,   )r   r   s   "€r   r   r   )   sh   ø€ ÷ 
ñ 
á—‘ð
ñ ð
ñ ð	
ñ
 "ð
ñ ×Ñð
ñ —‘˜tÕ#ð
ñ 
�‰ñ
r   c                ó   € R# )z6Shards a tensor to chunks and returns the local chunk.Nr   )r   r   r(   r)   r*   r+   r,   s   &&&&&&&r   Úchunk_tensorÚFSDPExtensions.chunk_tensor(   ó   € ñ 	r   c                óZ   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[ P                  /# )r   r   r(   Údevice_meshr   )r   r   r-   r   )r   r   s   "€r   r   r   6   s;   ø€ ÷ ñ á—‘ðñ ðñ  ð	ñ
 
�‰ñr   c                ó   € R# )zAShards a tensor/DTensor to DTensor and returns the local DTensor.Nr   )r   r   r(   r5   s   &&&&r   Úchunk_dtensorÚFSDPExtensions.chunk_dtensor5   s   € ñ 	r   c                ót   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  S[S[,          3,          /# )r   r   r   )r   r   r   Úlistr   )r   r   s   "€r   r   r   @   s5   ø€ ÷ ñ á—‘ðñ 
‰u�|‰|™T¡%�[Ð(Õ	)ñr   c                ó   € R# )z‹
This is to be called before loading a *sharded* model state dict and
should return the tensor and list of shards from which to load data.
Nr   r   s   &&r   Úpre_load_state_dict_transformÚ,FSDPExtensions.pre_load_state_dict_transform?   s   € ñ 	r   c                óN   <€ V ^8„  d   QhRS[ RS[R,          RS[P                  /# )r   r   Úparent_meshNr   )r   r   r   r   )r   r   s   "€r   r   r   K   s2   ø€ ÷ 
ñ 
áð
ñ   $Õ&ð
ñ 
�‰ñ	
r   c                ó   € R# )z“
This is to be called before loading a *sharded* DTensor state dict.
This gathers tensor in FSDP dimension and returns local tensor of
TP DTensor.
Nr   )r   r   r?   s   &&&r   Úall_gather_dtensorÚ!FSDPExtensions.all_gather_dtensorJ   r3   r   r   ©N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r    r%   r1   r7   r<   rA   Ú__static_attributes__Ú__classdictcell__)r   s   @r   r   r      s‡   ø‡ € ñð ÷ó ðð ÷ó ðð ÷
ñ 
ó ð
ð ÷ó ðð ÷ó ðð ÷
ó ö
r   r   c                ó(   € V ^8„  d   QhR\         RR/# )r   Ú	flattenerr   N)r   )r   s   "r   r   r   [   s   € ÷ ñ ¤Nð °tñ r   c                 ó
   € V s R # rC   )Ú_extensions)rL   s   &r   Ú_set_fsdp_extensionsrO   [   s   € à‚Kr   c          	      ó¢   € V ^8„  d   QhR\         P                  R\        R,          R\        \         P                  \        R,          3,          /# ©r   r   Úfsdp_extensionNr   )r   r   r   r   r   )r   s   "r   r   r   `   sA   € ÷ ñ Ü�L‰Lðä" TÕ)ðô Œ5�<‰<œ˜t�Ð#Õ$ñr   c                 óF   € Ve   VP                  V 4      w  r#Ve   W#3# V R 3# rC   )r    )r   rR   Ú
new_tensorr#   s   &&  r   Ú_ext_pre_flatten_transformrU   `   s6   € ð Ò!Ø&4×&JÑ&JÈ6Ó&RÑ#ˆ
ØÒ&ØÐ.Ð.Ø�4ˆ<Ðr   c                ó~   € V ^8„  d   QhR\         P                  R\        R\        R,          R\         P                  /# )r   r   r#   rR   Nr   )r   r   r   r   )r   s   "r   r   r   k   s=   € ÷ ñ Ü�L‰Lðäðô # TÕ)ðô ‡\�\ñ	r   c                 ó8   € Ve   Ve   VP                  W4      # V # rC   )r%   )r   r#   rR   s   &&&r   Ú_ext_post_unflatten_transformrX   k   s%   € ð
 Ò! oÒ&AØ×6Ñ6°vÓOÐOØ€Mr   c                ó¶   € V ^8„  d   QhR\         P                  R\        R\        R\        R\        P                  R\
        R,          R\         P                  /# )	r   r   r(   r)   r*   r+   rR   Nr   )r   r   r-   r.   r/   r   )r   s   "r   r   r   u   sa   € ÷ ñ Ü�L‰Lðä
ðô ðô ð	ô
 	×Ñðô # TÕ)ðô ‡\�\ñr   c                 óF   € Ve   VP                   M\        pV! V VVVV4      # rC   )r1   r
   )r   r(   r)   r*   r+   rR   Úchunk_tensor_fns   &&&&&& r   Ú_ext_chunk_tensorr\   u   s;   € ð Ò%ð 	×#Ò#ä)ð ñ
 ØØØØØ
óð r   c          
      óŠ   € V ^8„  d   QhR\         P                  R\        R\        R\        R,          R\         P                  /# )r   r   r(   r5   rR   Nr   )r   r   r-   r   r   )r   s   "r   r   r   ‹   sG   € ÷ ñ Ü�L‰Lðä
ðô ðô # TÕ)ð	ô
 ‡\�\ñr   c                 óB   € Ve   VP                   M\        pV! V VV4      # rC   )r7   r	   )r   r(   r5   rR   Úchunk_dtensor_fns   &&&& r   Ú_ext_chunk_dtensorr`   ‹   s5   € ð Ò%ð 	×$Ò$ä"ð ñ
 ØØØóð r   c          	      óª   € V ^8„  d   QhR\         P                  R\        R,          R\        \         P                  \        \
        ,          3,          /# rQ   )r   r   r   r   r:   r   )r   s   "r   r   r   �   sA   € ÷ 
ñ 
Ü�L‰Lð
ä" TÕ)ð
ô Œ5�<‰<œœe�Ð$Õ%ñ
r   c                 ó¦   € Ve   VP                  V 4      # \        V 4      \        Jd   \        R\        V 4       24      hV P	                  4       pW3# )NzExpected ShardedTensor, got )r<   Útyper   ÚAssertionErrorÚlocal_shards)r   rR   Úshardss   && r   Ú"_ext_pre_load_state_dict_transformrg   �   sU   € ð Ò!Ø×;Ñ;¸FÓCÐCäˆFƒ|œ=Ó(ÜÐ;¼DÀ»L¸>ÐJÓKÐKØ× Ñ Ó"€FØÐÐr   c                óx   € V ^8„  d   QhR\         R\        R,          R\        R,          R\        P                  /# )r   r   r?   NrR   r   )r   r   r   r   r   )r   s   "r   r   r   ª   s>   € ÷ 
6ñ 
6Üð
6ä˜dÕ"ð
6ô # TÕ)ð
6ô ‡\�\ñ	
6r   c                 ó>   € Ve   VP                   M\        pV! W4      # rC   )rA   r   )r   r?   rR   Úall_gather_dtensor_fns   &&& r   Ú_ext_all_gather_dtensorrk   ª   s*   € ð Ò%ð 	×)Ò)ä ð ñ
 ! Ó5Ð5r   c                óN   € V ^8„  d   Qh/ ^ \         9   d   \        R,          ;R&   # )r   NrN   )Ú__conditional_annotations__r   )r   s   "r   r   r      s!   € × #Ñ #÷n *Ò )Œ^˜dÕ"Ñ )òo $r   rC   )rm   Úabcr   r   Útypingr   r   Útorch.distributedÚdistributedr.   Ú+torch.distributed._shard.sharded_tensor.apir   Ú-torch.distributed._shard.sharded_tensor.shardr   Ú#torch.distributed.fsdp._shard_utilsr   r	   r
   Útorch.distributed.tensorr   r   r   rN   rO   rU   rX   r\   r`   rg   rk   r   )rm   s   @r   Ú<module>rv      sk   øðß #Ô #Ý ã Ý  Ý EÝ ?÷ñ ÷
 9ôE�Sô EðP &*€Ó )õ÷
÷÷÷,÷$
÷
6ñ 
6r   