ó
    Eñi  ã                   ó  • S r SSKrSSKJr  SSKJr  SSKJrJr   S\R                  S\
4S jrS\R                  S\\\   \\R                     4   4S jrS\R                  S\\   4S	 jrS\R                  S\4S
 jrg)zú
NOTE: This file must be imported like
``import torch.distributed.fsdp._traversal_utils`` and not like
``from torch.distributed.fsdp._traversal_utils import ...`` to avoid circular
imports. For brevity, we may import the file as ``traversal_utils``.
é    N©Ú_get_registry)Ú
_FSDPStateÚ_get_module_fsdp_stateÚmoduleÚreturnc                 ó*   • [        U 5      nUc  gSU;  $ )z9
Returns if ``module`` can compose with ``fully_shard``.
TÚ	replicater   )r   Úregistrys     Úd/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/distributed/fsdp/_traversal_utils.pyÚ_composabler   "   s"   € ô
 ˜VÓ$€HØÑØØ˜hÑ&Ð&ó    c                 óú  • / n/ n[        5       n[        5       n[        R                  " U /5      nU(       aÃ  UR                  5       nUR	                  U5        [        U5      (       d  M:  [        [        UR                  5       5      5       H  nXt;  d  M
  UR                  U5        M     [        U5      nUb8  Xƒ;  a3  UR	                  U5        UR                  U5        UR                  U5        U(       a  MÃ  X4$ )aÃ  
Returns a tuple containing:
1. A list of the ``_FSDPState`` instances in the module tree rooted at
``module`` without any duplicates and following the ``module.modules()``
traversal order (which is assumed to be depth-first).
2. A corresponding list of the modules owning the states in the first list.

For the wrapper code path, both returned lists are the same, each
containing all ``FullyShardedDataParallel`` instances. For the composable
code path, this returns a list of all composable state instances and a list
of the corresponding fully sharded modules. See [Note: Fully Sharded
Module].

NOTE: The traversal does not proceed into any module annotated by an
incompatible API (e.g. ``replicate``).
)ÚsetÚcollectionsÚdequeÚpopleftÚaddr   ÚreversedÚlistÚchildrenÚ
appendleftr   Úappend)	r   Úfsdp_statesÚfsdp_modulesÚvisited_fsdp_statesÚvisited_modulesr   Ú	submoduleÚchild_moduleÚoptional_states	            r   Ú_get_fsdp_states_with_modulesr!   0   sä   € ð& %'€KØ$&€Lô ,/«5Ðô '*£e€Oô
 +6×*;Ò*;¸V¸HÓ*E€EÞ
Ø—M‘M“Oˆ	Ø×Ñ˜IÔ&Ü˜9×%Ñ%ÙÜ$¤T¨)×*<Ñ*<Ó*>Ó%?Ö@ˆLØÕ2Ø× Ñ  Ö.ñ Aô 0°	Ó:ˆØÑ%¨.Ó*SØ×#Ñ# NÔ3Ø×Ñ˜~Ô.Ø×Ñ 	Ô*÷ ˆ%ð Ð$Ð$r   c                 ó    • [        U 5      u  pU$ )z*See :func:`_get_fsdp_states_with_modules`.)r!   )r   r   Ú_s      r   Ú_get_fsdp_statesr$   `   s   € ä2°6Ó:�N€KØÐr   c                 óx   • [        U 5       Vs/ s H  nUR                  c  M  UR                  PM      nnU$ s  snf )z{
Returns all ``FlatParamHandle`` s in the module tree rooted at ``module``
following the rules in :func:`_get_fsdp_state`.
)r$   Ú_handle)r   Ú
fsdp_stateÚhandless      r   Ú_get_fsdp_handlesr)   f   sF   € ô +¨6Ô2óâ2ˆJØ×Ñó 	ˆ
×ÔÙ2ð ð ð
 €Nùòs   Ž7£7)Ú__doc__r   Útorch.nnÚnnÚ&torch.distributed._composable.contractr   Ú$torch.distributed.fsdp._common_utilsr   r   ÚModuleÚboolr   Útupler   r!   r$   r)   © r   r   Ú<module>r3      s˜   ðñó å Ý @ß Sðð&'˜Ÿ	™	ð ' dô 'ð-%Ø�I‰Ið-%à
ˆ4�
Ñ˜T "§)¡)™_Ð,Ñ-ô-%ð`˜RŸY™Yð ¨4°
Ñ+;ô ð
˜bŸi™ið 
¨Dõ 
r   