§
    N�’jr  ã                   óâ   — d Z ddlZddlmZ ddlmZ ddlmZmZ 	 dej	        de
fd„Zdej	        deee         eej	                 f         fd„Zdej	        dee         fd	„Zdej	        defd
„ZdS )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                 ó0   — t          | ¦  «        }|€dS d|vS )zA
    Returns if ``module`` can compose with ``fully_shard``.
    NTÚ	replicater   )r   Úregistrys     úUC:\Projects\DSCons\.venv\Lib\site-packages\torch\distributed\fsdp\_traversal_utils.pyÚ_composabler   "   s'   € õ
 ˜VÑ$Ô$€HØÐØˆtØ˜hÐ&Ð&ó    c                 ó*  — g }g }t          ¦   «         }t          ¦   «         }t          j        | g¦  «        }|rÙ|                     ¦   «         }|                     |¦  «         t          |¦  «        sŒ;t          t          |                     ¦   «         ¦  «        ¦  «        D ]}||vr| 	                    |¦  «         Œt          |¦  «        }|�C||vr?|                     |¦  «         |                     |¦  «         |                     |¦  «         |°Ù||fS )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   s1  € ð& %'€KØ$&€Lõ ,/©5¬5Ðõ '*¡e¤e€Oõ
 +6Ô*;¸V¸HÑ*EÔ*E€EØ
ð +Ø—M’M‘O”Oˆ	Ø×Ò˜IÑ&Ô&Ð&Ý˜9Ñ%Ô%ð 	ØÝ$¥T¨)×*<Ò*<Ñ*>Ô*>Ñ%?Ô%?Ñ@Ô@ð 	/ð 	/ˆLØ ?Ð2Ð2Ø× Ò  Ñ.Ô.Ð.øÝ/°	Ñ:Ô:ˆØÐ%¨.Ð@SÐ*SÐ*SØ×#Ò# NÑ3Ô3Ð3Ø×Ò˜~Ñ.Ô.Ð.Ø×Ò 	Ñ*Ô*Ð*ð ð +ð ˜Ð$Ð$r   c                 ó*   — t          | ¦  «        \  }}|S )z*See :func:`_get_fsdp_states_with_modules`.)r!   )r   r   Ú_s      r   Ú_get_fsdp_statesr$   `   s   € å2°6Ñ:Ô:�N€K�ØÐr   c                 ó8   — d„ t          | ¦  «        D ¦   «         }|S )z‡
    Returns all ``FlatParamHandle`` s in the module tree rooted at ``module``
    following the rules in :func:`_get_fsdp_state`.
    c                 ó*   — g | ]}|j         ®	|j         ‘ŒS )N)Ú_handle)Ú.0Ú
fsdp_states     r   ú
<listcomp>z%_get_fsdp_handles.<locals>.<listcomp>k   s.   € ð ð ð àØÔÐ)ð 	Ôà)Ð)Ð)r   )r$   )r   Úhandless     r   Ú_get_fsdp_handlesr,   f   s/   € ð
ð å*¨6Ñ2Ô2ðñ ô €Gð
 €Nr   )Ú__doc__r   Útorch.nnÚnnÚ&torch.distributed._composable.contractr   Ú$torch.distributed.fsdp._common_utilsr   r   ÚModuleÚboolr   Útupler   r!   r$   r,   © r   r   ú<module>r6      s  ððð ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø @Ð @Ð @Ð @Ð @Ð @Ø SÐ SÐ SÐ SÐ SÐ SÐ SÐ Sðð&'˜œ	ð ' dð 'ð 'ð 'ð 'ð-%ØŒIð-%à
ˆ4�
Ô˜T "¤)œ_Ð,Ô-ð-%ð -%ð -%ð -%ð`˜RœYð ¨4°
Ô+;ð ð ð ð ð
˜bœið 
¨Dð 
ð 
ð 
ð 
ð 
ð 
r   