ó
    EñiBY  ã                   óä  • % S r SSKrSSKrSSKrSSKrSSKJrJrJr  SSK	J
r
Jr  SSKJr  SSKJr  SSKJrJrJrJrJr  SSKrSSKJr  SSKJs  Js  Jr  SSKJr  SSK J!r!J"r"  SS	K#J$r$  SS
K%J&r&  SSK'J(r(  SSK)J*r*J+r+J,r,J-r-J.r.J/r/  \(       a  SSK0J1r1  SSK2J3r3  SSKJ4r4  Sr5\5S-   r6Sr7\Rp                  " 5       r9\Rp                  \:S'    " S S5      r; " S S\;5      r< " S S\"5      r=S\R|                  S\=S-  4S jr?S\R|                  S\=S-  4S jr@ " S S \5      rA " S! S"\5      rBS#\=4S$ jrC\S#\=S\R|                  S\S%   4S& j5       rD\S#\=S\R|                  S\E4S' j5       rFS( rGS)\HS\H4S* jrIS+\R”                  SS4S, jrKS+\R”                  S\E4S- jrLS\R|                  S.\S\M\N\H\Rž                  4      4S/ jrP SGS0\R>                  R|                  S1\ES\Q\Rž                  \M\H   4   4S2 jjrR\S#\=S3S%S4\R¦                  SS4S5 j5       rT\S#\=S3S%S\M\H   S-  4S6 j5       rU SHS7\R>                  R|                  S8\S9\S:\M\H   S-  4S; jjrV\S#\=S<\M\A   SS4S= j5       rWS>\X\R|                     S\X\R|                     4S? jrYS@S04SA\R>                  R|                  SB\\Z\R|                        SC\Q\H\4   S\X\Z\R|                        4SD jjr[S+\R”                  SE\R¸                  SS4SF jr]g)Iz7
This file includes private common utilities for FSDP.
é    N)ÚCallableÚ	GeneratorÚIterable)ÚautoÚEnum)Úpartial)Úchain)ÚAnyÚcastÚno_type_checkÚOptionalÚTYPE_CHECKING)Ú_get_module_stateÚ_State)Ú_CHECKPOINT_PREFIX)Ú_apply_to_tensors)Úno_dispatché   )ÚFullOptimStateDictConfigÚFullStateDictConfigÚOptimStateDictConfigÚShardingStrategyÚStateDictConfigÚStateDictType)Ú
DeviceMesh)ÚFSDPExtensions)ÚFlatParamHandleÚ_fsdp_wrapped_moduleÚ.Ú_fsdp_flattenedÚ_MODULE_TO_INP_DTYPEc                   ó„   • \ rS rSrSrSS\R                  S\4S jjr\	S\R                  SS 4S j5       r
S	\S\4S
 jrSrg)Ú_FSDPDeviceHandleé9   z—
This is a simple abstraction for FSDP computing devices,
which enables custom backends that implement CUDA-like
semantics to be integrated with FSDP.
NÚdeviceÚbackendc                 óÂ   • Uc'   [        [        UR                  5      U l        Xl        g X l        g ! [
         a"  n[        SU SUR                   S35      UeS nAff = f)NzDevice 'z=' does not have a corresponding backend registered as 'torch.z'.)ÚgetattrÚtorchÚtypeÚ_FSDPDeviceHandle__backendÚ_FSDPDeviceHandle__deviceÚAttributeError)Úselfr%   r&   Úexcs       Úa/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/distributed/fsdp/_common_utils.pyÚ__init__Ú_FSDPDeviceHandle.__init__@   sh   € Ø‰?ðÜ!(¬°·±Ó!<�”à &•ð %�Nøô "ó Ü$Ø˜v˜hÐ&cÐdj×doÑdoÐcpÐprÐsóàðûðús   …%2 ²
A¼AÁAÚreturnc                 óÊ   • UR                   S:X  a  [        [        [        R                  5      $ UR                   S:X  a  [        [        [        R
                  5      $ U " U5      $ )aC  
Return a device handle corresponding to the device, and through this handle,
operations with the same semantics as CUDA can be performed on the device.
Just return torch.cuda if the device is cuda to make attribute-access faster.
Custom backend must first register a module with the same name with {device.type} on torch.
ÚcudaÚmtia)r*   r   r#   r)   r5   r6   )Úclsr%   s     r0   Úfrom_deviceÚ_FSDPDeviceHandle.from_deviceM   sJ   € ð �;‰;˜&Ó ÜÔ)¬5¯:©:Ó6Ð6Ø�[‰[˜FÓ"ÜÔ)¬5¯:©:Ó6Ð6Ù�6‹{Ðó    Únamec          
      óÐ   •  [        U R                  U5      $ ! [         aC  n[        SU R                  R                   SU R                  R                   SU S35      UeS nAff = f)NzCustom backend 'z' not implement 'torch.r   Ú')r(   r+   r-   r,   r*   )r.   r;   r/   s      r0   Ú__getattr__Ú_FSDPDeviceHandle.__getattr__[   sk   € ð	Ü˜4Ÿ>™>¨4Ó0Ð0øÜó 	Ü Ø" 4§=¡=×#5Ñ#5Ð"6Ð6MÈdÏmÉm×N`ÑN`ÐMaÐabÐcgÐbhÐhiÐjóàðûð	ús   ‚ ˜
A%¢>A Á A%)Ú	__backendÚ__device©N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r)   r%   r
   r1   Úclassmethodr8   Ústrr>   Ú__static_attributes__© r:   r0   r#   r#   9   sX   † ññ%˜uŸ|™|ð %°cõ %ð ð §¡ð Ð2Eó ó ðð ð ¨3÷ r:   r#   c                   ó0   • \ rS rSrSS jrS\S\4S jrSrg)	Ú_UninitializedDeviceHandleéd   r3   Nc                 ó   • g rB   rK   ©r.   s    r0   r1   Ú#_UninitializedDeviceHandle.__init__e   s   € Ør:   r;   c                ó   • [        S5      e)Nz-Trying to use an uninitialized device handle.)ÚRuntimeError)r.   r;   s     r0   Ú__getattribute__Ú+_UninitializedDeviceHandle.__getattribute__h   s   € ÜÐJÓKÐKr:   rK   ©r3   N)	rC   rD   rE   rF   r1   rI   r
   rT   rJ   rK   r:   r0   rM   rM   d   s   † ôðL Sð L°÷ Lr:   rM   c                   ó   • \ rS rSrSS jrSrg)Ú
_FSDPStateél   Nc                 ó2  • [        5       U l        [        5       U l        [        5       U l        S U l        SU l        SU l        S U l        [        R                  U l
        SU l        [        R                  U l        0 U l        [         R"                  U l        ['        5       U l        [+        5       U l        S U l        S U l        0 U l        S U l        SU l        SU l        S U l        S U l        S U l        [A        5       U l!        / U l"        / U l#        S U l$        g )NéÿÿÿÿFr   )%ÚsetÚ_ignored_modulesÚ_ignored_paramsÚ_ignored_buffer_namesÚprocess_groupÚrankÚ
world_sizeÚ_device_meshr   Ú
FULL_SHARDÚsharding_strategyÚ_use_orig_paramsÚTrainingStateÚIDLEÚtraining_stateÚ_unshard_params_ctxr   ÚFULL_STATE_DICTÚ_state_dict_typer   Ú_state_dict_configr   Ú_optim_state_dict_configÚ_is_rootÚ_handleÚ_fully_sharded_module_to_handleÚcompute_deviceÚ_gradient_predivide_factorÚ_gradient_postdivide_factorÚ
_comm_hookÚ_comm_hook_stateÚ_unshard_eventrM   Ú_device_handleÚ_all_fsdp_statesÚ_all_handlesÚ_fsdp_extensionrP   s    r0   r1   Ú_FSDPState.__init__m   s  € ô 14³ˆÔÜ25³%ˆÔä/2«uˆÔ"Ø7;ˆÔØˆŒ	Ø!ˆŒØ/3ˆÔÜ!1×!<Ñ!<ˆÔØ&+ˆÔÜ+×0Ñ0ˆÔØ?AˆÔ Ü/<×/LÑ/LˆÔÜ3FÓ3HˆÔÜ>VÓ>XˆÔ%Ø%)ˆŒØ?CˆŒð ð 	Ô,ð 48ˆÔØ/0ˆÔ'Ø01ˆÔ(Ø+/ˆŒØ,0ˆÔØ26ˆÔô 2LÓ1MˆÔð 35ˆÔØCEˆÔØ6:ˆÕr:   )ry   rz   ru   rv   rx   rc   r{   rq   rt   rs   rp   r_   r]   r^   ro   rn   rm   rl   rw   rj   rf   rr   r`   ra   re   ri   rb   rV   )rC   rD   rE   rF   r1   rJ   rK   r:   r0   rX   rX   l   s   † ÷$;r:   rX   Úmoduler3   c                 óN   • [        U 5      nUb  [        U[        5      (       d  g U$ rB   )r   Ú
isinstancerX   ©r}   Ústates     r0   Ú_get_module_fsdp_stater‚   ”   s%   € Ü˜fÓ%€EØ�}œJ u¬j×9Ñ9ØØ€Lr:   c                 óR   • [        U 5      nUc  g X:X  a  U$ XR                  ;   a  U$ g rB   )r‚   rq   r€   s     r0   Ú._get_module_fsdp_state_if_fully_sharded_moduler„   ›   s4   € ô # 6Ó*€EØ�}ØØƒØˆØ×6Ñ6Ó6ØˆØr:   c                   óB   • \ rS rSrSr\" 5       r\" 5       r\" 5       rSr	g)rg   é¨   zM
An enum that indicates the state of a ``FullyShardedDataParallel` instance.
rK   N)
rC   rD   rE   rF   rG   r   rh   ÚFORWARD_BACKWARDÚSUMMON_FULL_PARAMSrJ   rK   r:   r0   rg   rg   ¨   s    † ññ ‹6€DÙ“vÐÙ›Ór:   rg   c                   ó^   • \ rS rSrSr\" 5       r\" 5       r\" 5       r\" 5       r	\" 5       r
Srg)ÚHandleTrainingStateé²   z;
An enum that indicates the state of a ``FlatParamHandle`.
rK   N)rC   rD   rE   rF   rG   r   rh   ÚFORWARDÚBACKWARD_PREÚBACKWARD_POSTrˆ   rJ   rK   r:   r0   rŠ   rŠ   ²   s-   † ññ ‹6€DÙ‹f€GÙ“6€LÙ“F€MÙ›Ór:   rŠ   r�   c                 ó@   • [        U [        R                  5      (       + $ rB   )r   ÚnnÚModule)r�   s    r0   Ú_is_composabler’   ¾   s   € ä˜%¤§¡Ó+Ô+Ð+r:   r   c                 óÈ   • [        U 5      (       aG  U R                  c  gXR                  ;  a  [        SU SU R                   35      eU R                  U   $ UR                  $ )z
Returns the ``FlatParamHandle`` s corresponding to ``module``. This is
the handle that contains some parameter in ``module``.
Nz'Expects a fully sharded module but got z	 on rank )r’   rp   rq   ÚAssertionErrorra   ©r�   r}   s     r0   Ú_module_handler–   Ã   sj   € ô �e×Ñð �=‰=Ñ ØØ×>Ñ>Ó>Ü Ø9¸&¸ÀÈ5Ï:É:È,ÐWóð ð ×4Ñ4°VÑ<Ð<ð �~‰~Ðr:   c                 ó   • [        X5      SL$ )z5Returns if ``module`` has parameters managed by FSDP.N)r–   r•   s     r0   Ú_has_fsdp_paramsr˜   Ø   s   € ô ˜%Ó(°Ð4Ð4r:   c                 ó,   • U (       a  U R                   $ S$ )z.
Returns the sharding strategy of the handle.
N)Ú_sharding_strategy)Úhandles    r0   Ú_get_sharding_strategyrœ   Þ   s   € ö )/ˆ6×$Ñ$Ð8°DÐ8r:   Útensor_namec                 ó^   • U R                  [        S5      n U R                  [        S5      n U $ )zN
Cleans the parameter or buffer name by removing any module wrapper
prefixes.
Ú )ÚreplaceÚFSDP_PREFIXr   )r�   s    r0   Úclean_tensor_namer¢   å   s1   € ð
 ×%Ñ%¤k°2Ó6€Kð ×%Ñ%Ô&8¸"Ó=€KØÐr:   Útensorc                 ó&   • [        U [        S5        g)z€
Sets an attribute on ``tensor`` to mark it as flattened by FSDP. This is to
avoid re-flattening it during nested construction.
TN)ÚsetattrÚFSDP_FLATTENED©r£   s    r0   Ú_set_fsdp_flattenedr¨   ò   s   € ô
 ˆF”N DÕ)r:   c                 ó$   • [        U [        S5      $ )z;Returns if ``tensor`` has been marked as flattened by FSDP.F)r(   r¦   r§   s    r0   Ú_is_fsdp_flattenedrª   ú   s   € ä�6œ>¨5Ó1Ð1r:   Úkwargsc                 óä   • SU;   a  [        S5      eSUS'    [        U R                  " S0 UD65      nU$ ! [          a0    UR                  S5        [        U R                  " S0 UD65      n U$ f = f)zl
This API is required as some modules overwrite `named_parameters()` but do not support
`remove_duplicate`.
Úremove_duplicatezR_named_parameters_with_duplicates cannot be used with `remove_duplicate` argument.FrK   )r”   ÚlistÚnamed_parametersÚpop)r}   r«   Úrets      r0   Ú!_named_parameters_with_duplicatesr²   ÿ   sˆ   € ð ˜VÓ#ÜØ`ó
ð 	
ð "'€FÐÑð6Ü�6×*Ò*Ñ4¨VÑ4Ó5ˆð €Jøô ó 6Ø�
‰
Ð%Ô&Ü�6×*Ò*Ñ4¨VÑ4Ó5‰Ø€Jð6ús   ˜5 µ6A/Á.A/ÚmodelÚdedup_shared_paramsc                 ó€   ^• U4S jnS n0 n[        U UU[        U 5       VVs/ s H  u  pVUPM	     snnU5      $ s  snnf )aù  
Constructs a mapping from parameter to a list of its "canonical" FQNs. Here,
we use canonical to mean the fully-qualified name assigned to the parameter
based on its position in the original nn.Module hierarchy before any wrapper
or parallelism has been applied to it. This is in contrast to FQNs that may be
generated after parallelisms or wrappers have been applied to the model.

Each normal parameter maps to a singleton list containing its FQN, while each
``FlatParameter`` maps to a list of its original parameter FQNs, which may
have length greater than one.  All FQNs are prefixed starting from ``model``.

In the case where FSDP was applied with ``use_orig_params=True``, there should be no
``FlatParameter`` s registered to the model's modules and this mapping will only
contain mappings from ``nn.Parameter`` s to singleton FQN lists.

It is only in the case where FSDP was applied with ``use_orig_params=False`` where
a ``FlatParameter`` will be registered in place of the original parameters and there
will be mappings from each ``FlatParameter`` to lists of FQNs corresponding to the
original parameters.

Args:
    model (torch.nn.Module): Root module (which may or may not be a
        :class:`FullyShardedDataParallel` instance).
    dedup_shared_params (bool): For shared parameters, if ``True``, only
        includes the FQNs corresponding to the first encounter of the
        shared parameter in the module traversal; if ``False``, then
        includes the FQNs across all encounters. (Default: ``True``)
c                 óš  >• [        U SS9 H·  u  pE[        U[        R                  5      (       a  UR                  OU/nU Vs/ s H  n[        X-   5      PM     nnXS;   n	U	(       d  XƒU'   Ma  [        U[        R                  5      (       a  [        R                  " SSS9  XƒU'   M›  T
(       a  M¤  X5   R                  U5        M¹     g s  snf )NF)Úrecursez�FlatParameter is being traversed more than once. This case should only happen when using DistributedModelParallel with FullyShardedDataParallel.é   )Ú
stacklevel)	r²   r   Úflat_param_fileÚFlatParameterÚ_fqnsr¢   ÚwarningsÚwarnÚextend)r}   ÚprefixÚ
tree_levelÚparam_to_fqnsÚ
param_nameÚparamÚ
local_fqnsr;   Úglobal_fqnsÚis_shared_paramr´   s             €r0   Ú	module_fnÚ%_get_param_to_fqns.<locals>.module_fn4  sÑ   ø€ Ü!BØ˜Eô"
ÑˆJô
 ˜e¤_×%BÑ%B×CÑCð —’à �\ð ñ >HóÚ=G°TÔ! &¡-Ö0¹Zð ð ð $Ñ4ˆOÞ"Ø'2˜eÓ$ä˜e¤_×%BÑ%B×CÑCô —M’MðRð $%ò	ð ,7 %Ó(ß,Ð,Ø!Ñ(×/Ñ/°Ö<òG"
ùòs   ÁCc                 ó   • U $ rB   rK   )rÂ   s    r0   Ú	return_fnÚ%_get_param_to_fqns.<locals>.return_fnZ  s   € ØÐr:   )Ú_apply_to_modulesr²   )r³   r´   rÈ   rË   Úparam_to_unflat_param_namesÚkeyÚ_s    `     r0   Ú_get_param_to_fqnsrÑ     sS   ø€ õB$=òLð HJÐÜØØØÜ<¸UÔCÔDÒC‘�‹ÑCÒDØ#óð ùó 	Es   £:r›   Úloggerc                 ó´   • U R                   (       aG  UR                  [        R                  R                  :X  a  [        X5      nUR                  SU5        g g g )Nz1FSDP firing post-backward hooks for parameters %s)rf   Ú_debug_levelÚdistÚ
DebugLevelÚINFOÚ_get_handle_fqns_from_rootÚwarning)r�   r›   rÒ   Ú
param_fqnss       r0   Ú_log_post_backward_hookrÛ   g  sF   € ð ×× &×"5Ñ"5¼¿¹×9MÑ9MÓ"MÜ/°Ó>ˆ
Ø�‰ÐJÈJÕWð #NÐr:   c                 ó¬   ^• Uc  g U R                   R                  mUR                  R                  n/ [        R
                  " U4S jU 5       5      QnU$ )Nc              3   ó.   >#   • U  H
  nTU   v •  M     g 7frB   rK   )Ú.0ÚpÚparam_to_fqns     €r0   Ú	<genexpr>Ú-_get_handle_fqns_from_root.<locals>.<genexpr>{  s   øé € Ð&NÂ¸1 |°A¦Âùs   ƒ)Ú_exec_order_datarà   Ú
flat_paramÚ_paramsr	   Úfrom_iterable)r�   r›   Úhandle_paramsrÚ   rà   s       @r0   rØ   rØ   s  sP   ø€ ð �~ØØ×)Ñ)×6Ñ6€LØ×%Ñ%×-Ñ-€MØO”5×&Ò&Ô&NÁÓ&NÓNÐO€JØÐr:   Úroot_modulerÈ   rË   Úfilter_fqnsc                 ó^  ^^^	• Sm	Ub`  [        5       m	U HP  nUR                  S5      nUS:w  d  M  T	R                  USUS-    5        UR                  SUS-   5      nUS:w  a  M4  MR     S[        R                  R
                  S[        S[        4UU	U4S jjmT" U S	S
/UQ70 UD6  U" U0 UD6$ )aþ  
Performs a pre-order traversal of the modules in the hierarchy rooted at
``root_module``, applying ``module_fn`` at each module and finally
returning a value using ``return_fn``. The traversal constructs the full
module prefix name (e.g. "module.submodule." just like in model state dict)
and makes that available to ``module_fn``.

``filter_fqns`` is used because some module may have its own prefix similar
to ``FullyShardedDataParallel`` and the ``named_parameters()`` is overwritten
to remove the prefix.
Nr   r[   r   r}   rÀ   rÁ   c                 óÎ   >• T" XU/UQ70 UD6  U R                  5        HC  u  pVUc  M
  X-   S-   nUS-   nT
b  UT
;  a  US:X  d  US:X  a  UnOUS:X  a  UnT	" XgU/UQ70 UD6  ME     g )Nr   r   r   Ú_dmp_wrapped_moduler}   )Únamed_children)r}   rÀ   rÁ   Úargsr«   Úsubmodule_nameÚ	submoduleÚ
new_prefixÚnew_tree_levelÚfÚfilter_prefixesrÈ   s            €€€r0   ró   Ú_apply_to_modules.<locals>.fž  s•   ø€ á�& *Ð>¨tÒ>°vÒ>Ø)/×)>Ñ)>Ö)@Ñ%ˆNØÑ ÙØÑ0°3Ñ6ˆJØ'¨!™^ˆNØÑ*Ø _Ó4ð 'Ð*@Ó@Ø)Ð-BÓBà%+™
Ø'¨8Ó3Ø%+˜
Ùˆi ^ÐE°dÒE¸fÔEò) *Ar:   rŸ   r   )r\   ÚfindÚaddr)   r�   r‘   rI   Úint)
rè   rÈ   rË   ré   rî   r«   ÚfqnÚiró   rô   s
    `      @@r0   rÍ   rÍ     s¾   ú€ ð, (,€OØÑÜ›%ˆÛˆCØ—‘˜“ˆAØ�r•'Ø×#Ñ# C¨¨!¨a©% LÔ1Ø—H‘H˜S ! a¡%Ó(�ð �r—'ñ ðF”%—(‘(—/‘/ð F¬3ð F¼C÷ Fñ Fñ2 €k�2�qÐ*˜4Ò* 6Ò*Ù�dÐ%˜fÑ%Ð%r:   Útraining_statesc                 ó  • U R                   U;  a}  SU SU R                    3nU R                  S:X  aP  [        U [        R                  5      (       a  [        SU  35        [        SU 35        [        R                  " 5         [        U5      eg)z8Asserts that FSDP is in the states ``_training_states``.zexpected to be in states z but current state is r   zAsserting FSDP instance is: zERROR: N)	ri   ra   r   r�   r‘   ÚprintÚ	tracebackÚprint_stackÚ
ValueError)r�   rû   Úmsgs      r0   Ú_assert_in_training_statesr  »  sŠ   € ð ×Ñ ?Ó2à'¨Ð'8Ð8NØ×#Ñ#Ð$ð&ð 	ð
 �:‰:˜‹?Ü˜%¤§¡×+Ñ+ÜÐ4°U°GÐ<Ô=Ü�G˜C˜5�/Ô"Ü×!Ò!Ô#Ü˜‹oÐð 3r:   Úmodulesc                 ó$  • [        5       nU  Vs0 s H  o"[        UR                  5       5      _M     nnU  HQ  nSnUR                  5        H  u  p&XBL=(       a    XF;   nU(       d  M  Sn  O   U(       d  M@  UR                  U5        MS     U$ s  snf )a  
Returns:
    Set[nn.Module]: The subset of ``modules`` that are root modules (i.e.
    parent-less) with respect to the modules in the set itself. In other
    words, these are the modules in ``modules`` that are not the child of
    any other module in ``modules``.
TF)r\   r  Úitemsr÷   )r  Úroot_modulesr}   Úmodule_to_submodulesÚcandidate_moduleÚis_root_moduleÚ
submodulesÚis_child_modules           r0   Ú_get_root_modulesr  Ñ  sœ   € ô $'£5€LÙHOÓPÊ¸f¤C¨¯©Ó(8Ó$9Ò9ÉÐÐPÛ#ÐØˆØ"6×"<Ñ"<Ö">ÑˆFà Ð.×QÐ3CÑ3Qð ÷ ˆØ!&�Ùñ #?÷ ˆ>Ø×ÑÐ-Ö.ñ $ð Ðùò Qs   �#BÚmixed_precisionÚrootÚmodule_classes_to_overrideÚwrap_override_dictc           	      ó¸  ^• [        [        U5      5      n[        5       nU R                  5        H¦  n[        XA5      (       d  M  UR	                  [        U5      5        X$l        S[        R                  S[        R                  S[        R                  S[        R                  4S jmU4S jnU4S jnUR                  USS	9  UR                  USS	9  M¨     U$ )
NÚdtyper}   Úxr3   c                 ó¤   • [         R                  " U5      (       a  UR                  U :X  a  U$ UR                  [        U'   UR	                  U 5      $ rB   )r)   Úis_floating_pointr  r!   Úto)r  r}   r  s      r0   Úcast_fnÚ1_override_module_mixed_precision.<locals>.cast_fnü  sB   € ô ×.Ò.¨q×1Ñ1°Q·W±WÀÓ5EØ�HØ/0¯w©wÔ$ VÑ,Ø—t‘t˜E“{Ð"r:   c                 óN   >• [        [        T[        R                  U 5      U5      $ rB   )r   r   r)   Úfloat32)r}   rî   r  s     €r0   Úforward_pre_hookÚ:_override_module_mixed_precision.<locals>.forward_pre_hook  s   ø€ Ü(¬°¼%¿-¹-ÈÓ)PÐRVÓWÐWr:   c                 óX   >• U [         ;   a  [         U    n[        [        TX05      U5      $ g rB   )r!   r   r   )r}   rî   ÚoutputÚ	old_dtyper  s       €r0   Úforward_post_hookÚ;_override_module_mixed_precision.<locals>.forward_post_hook  s6   ø€ ð Ô1Ó1Ü 4°VÑ <�IÜ,Ü ¨Ó;¸Vóð ð 2r:   F)Úprepend)Útupler\   r  r   r÷   r*   Ú_wrap_overridesr)   r  r�   r‘   ÚTensorÚregister_forward_pre_hookÚregister_forward_hook)r  r  r  Úoverridden_module_classesÚmodr  r   r  s          @r0   Ú _override_module_mixed_precisionr*  é  sÅ   ø€ ô
 "'¤sÐ+EÓ'FÓ!GÐä69³eÐØ�|‰|Ž~ˆÜ�c×6Ó6Ø%×)Ñ)¬$¨s«)Ô4Ø"4Ôð#Ü—{‘{ð#Ü,.¯I©Ið#Ü:?¿,¹,ð#ä—‘ô#õXõð ×)Ñ)Ð*:ÀEÐ)ÑJØ×%Ñ%Ð&7ÀÐ%ÓGñG ðH %Ð$r:   Ústreamc                 ó@  • U R                   R                  SSS[        R                  R	                  5       4;  a  g [        R
                  R                  R                  5       (       a  g [        5          U R                  U5        S S S 5        g ! , (       d  f       g = f)Nr5   r6   Úxpu)
r%   r*   r)   Ú_CÚ_get_privateuse1_backend_nameÚdistributedÚ_functional_collectivesÚis_torchdynamo_compilingÚrecord_streamr   )r£   r+  s     r0   Ú_no_dispatch_record_streamr4    st   € à‡}�}×ÑØØØÜ�‰×.Ñ.Ó0ð	"ó ð 	ä×Ñ×0Ñ0×IÑI×KÑKØô �]Ø× Ñ  Ô(÷ �]Ž]ús   Á4BÂ
B)TrB   )^rG   Úloggingrþ   r½   ÚweakrefÚcollections.abcr   r   r   Úenumr   r   Ú	functoolsr   Ú	itertoolsr	   Útypingr
   r   r   r   r   r)   Útorch.distributedr0  rÕ   Ú"torch.distributed.fsdp._flat_paramÚfsdpÚ_flat_paramrº   Útorch.nnr�   Ú#torch.distributed._composable_stater   r   Ú;torch.distributed.algorithms._checkpoint.checkpoint_wrapperr   Útorch.distributed.utilsr   Útorch.utils._mode_utilsr   Úapir   r   r   r   r   r   Útorch.distributed.device_meshr   Ú'torch.distributed.fsdp._fsdp_extensionsr   r   ÚFSDP_WRAPPED_MODULEr¡   r¦   ÚWeakKeyDictionaryr!   Ú__annotations__r#   rM   rX   r‘   r‚   r„   rg   rŠ   r’   r–   Úboolr˜   rœ   rI   r¢   r%  r¨   rª   r®   r#  Ú	Parameterr²   ÚdictrÑ   ÚLoggerrÛ   rØ   rÍ   r  r\   r  r*   r*  ÚStreamr4  rK   r:   r0   Ú<module>rP     sÀ  ðòó Û Û Û ß 9Ñ 9ß Ý Ý ß DÕ Dã Ý  ß <Ó <Ý ß Iõõ 6Ý /÷÷ ö Ý8ÝFå,à,Ð Ø! CÑ'€Ø"€ð 3:×2KÒ2KÓ2MÐ �g×/Ñ/Ó M÷(ñ (ôVLÐ!2ô Lô%;�ô %;ðP 2§9¡9ð °¸dÑ1Bô ð
Ø�I‰Ið
à�$Ñô
ô �Dô  ô	 ˜$ô 	 ð,˜*ô ,ð
 ð˜*ð ¨b¯i©ið ¸HÐEVÑ<Wó ó ðð( ð5˜Jð 5°·	±	ð 5¸dó 5ó ð5ò
9ð
 3ð 
¨3ô 
ð* §¡ð *°ô *ð2˜uŸ|™|ð 2°ô 2ð
Ø�I‰IðØ!$ðà	ˆ%��R—\‘\Ð!Ñ
"Ñ#ôð, !%ñQØ�8‰8�?‰?ðQàðQð 
ˆ"�,‰,˜˜S™	Ð
!Ñ"õQðh ðXØðXØ0ðXØ:A¿.¹.ðXà	óXó ðXð ðØðØ0ðà	ˆ#�Y�Ñóó ðð %)ñ	9&Ø—‘—‘ð9&àð9&ð ð9&ð �c‘˜TÑ!õ	9&ðx ðØðà˜-Ñ(ðð 
óó ðð*˜s 2§9¡9™~ð °#°b·i±i±.ô ð6 +<¸TÐ)Bñ,%Ø
�(‰(�/‰/ð,%à (¨¨b¯i©i©Ñ 9ð,%ð ˜S #˜X™ð,%ð 	ˆˆb�i‰i‰Ñõ	,%ð^) u§|¡|ð )¸U¿\¹\ð )Èdõ )r:   