ó
    EñiU5  ã                   ó2  • S SK r S SKrS SKJr  S SKJrJr  S SKJrJ	r	J
r
Jr  S SKrS SKJr  S SKJr  S SKJr  / rS\S\S	\\\S
4   \\S
4   4   4S jrS\R.                  S-  S\S\S	\\\4   4S jrS\\S
4   S\\S
4   S	\\\S
4   \\\4   4   4S jr\" S\\\5      r\" S\R:                  \5      r\
S\S\R>                  S\ S	\\   4S j5       r!\
S\S\R>                  S\ S	\\   4S j5       r!S r!S=S\S\S\ S	S4S jjr"S\R:                  S\RF                  S	S4S jr$S\R:                  4S  jr%\" S!5      r&\" S"\\\\'\\\5      r(\
S#\\R:                  /\&4   S$\R:                  S	\&4S% j5       r)\
S#\\R:                  /\4   S$\(S	\(4S& j5       r)S' r)S\\S
4   S\\\4   S-  S\R>                  S\ S	\\\S
4   \\\\4   S
4   4   4
S( jr* S>S)\RV                  S*\\R:                     S+\	S,   4S- jjr, S=S.\RZ                  S)\RV                  S/\.S0\.S1\\   S2\ S	S4S3 jjr/S)\RV                  S4\\R:                     S/\.S0\.S	S4
S5 jr0S6\\\4   S7\S8\S	S4S9 jr1S\R:                  S	\ 4S: jr2S;\\RZ                     S	\\RZ                     4S< jr3g)?é    N)ÚOrderedDict)ÚCallableÚ	Container)ÚAnyÚOptionalÚoverloadÚTypeVar)Únn)ÚPackedSequenceÚargsÚkwargsÚreturn.c                  ó¾   • / n[        U 5      nUR                  5        H'  u  pEUR                  U5        UR                  U5        M)     [        U5      [        U5      4$ )aJ  
Turn argument list into separate key list and value list (unpack_kwargs does the opposite).

Inspiration: https://github.com/facebookresearch/fairscale/blob/eeb6684/fairscale/internal/containers.py#L70
Usage::

    kwarg_keys, flat_args = pack_kwargs(1, 2, a=3, b=4)
    assert kwarg_keys == ("a", "b")
    assert flat_args == (1, 2, 3, 4)
    args, kwargs = unpack_kwargs(kwarg_keys, flat_args)
    assert args == (1, 2)
    assert kwargs == {"a": 3, "b": 4}
Returns:
    Tuple[Tuple[Any, ...], Tuple[str, ...]]: The first tuple element gives
    gives both positional args and kwarg values, where the positional args
    proceed kwarg values and kwarg values are ordered consistently with the
    kwarg keys. The second tuple element gives the kwarg keys.
    The second tuple element's length is at most the first tuple element's length.
)ÚlistÚitemsÚappendÚtuple)r   r   Ú
kwarg_keysÚ	flat_argsÚkÚvs         ÚT/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/distributed/utils.pyÚ_pack_kwargsr      sW   € ð( €JÜ ›:€IØ—‘–‰ˆØ×Ñ˜!ÔØ×Ñ˜Öñ ô �ÓœU :Ó.Ð.Ð.ó    Údtypec                 óŒ   ^ • T c  X4$ S[         R                  S[         R                  4U 4S jjn[        X15      [        X25      4$ )zŠ
Cast floating point tensors in ``args`` and ``kwargs`` to ``input_dtype``.

This respects the existing ``requires_grad`` on the tensors.
Úxr   c                 ó€   >• [         R                  " U 5      (       a  U R                  T:X  a  U $ U R                  T5      $ ©N)ÚtorchÚis_floating_pointr   Úto)r   r   s    €r   Úcast_fnÚ%_cast_forward_inputs.<locals>.cast_fn;   s2   ø€ Ü×&Ò& q×)Ñ)¨Q¯W©W¸Ó-=ØˆHà�t‰t�E‹{Ðr   )r    ÚTensorÚ_apply_to_tensors)r   r   r   r#   s   `   r   Ú_cast_forward_inputsr'   .   sE   ø€ ð �}Øˆ|Ðð”5—<‘<ð ¤E§L¡L÷ ô ˜gÓ,Ô.?ÀÓ.PÐQÐQr   r   r   c           	      ó  • [        U5      [        U 5      :”  a#  [        S[        U5       S[        U 5       35      e[        U5      S:X  a  U 0 4$ U S[        U5      *  n[        [        X[        U5      * S 5      5      nX#4$ )zSee _pack_kwargs.ztoo many keys z vs. r   N)ÚlenÚAssertionErrorÚdictÚzip)r   r   r   r   s       r   Ú_unpack_kwargsr-   D   s†   € ô ˆ:ƒœ˜Y›Ó'Ü˜~¬c°*«oÐ->¸eÄCÈ	ÃNÐCSÐTÓUÐUÜ
ˆ:ƒ˜!ÓØ˜"ˆ}ÐØÐ'œ˜J›Ð'Ð(€DÜ”#�j¬S°«_Ð,<Ð,>Ð"?Ó@ÓA€FØˆ<Ðr   ÚSÚTÚinputsÚtarget_deviceÚ!use_side_stream_for_tensor_copiesc                 ó   • g r   © ©r0   r1   r2   s      r   Ú_recursive_tor6   U   s   € ð r   c                 ó   • g r   r4   r5   s      r   r6   r6   [   s   € ð r   c                 ó@   ^^^• UUU4S jm T" U 5      nSmU$ ! Smf = f)z-Recursively moves input to the target_device.c                 ó  >• [        U [        R                  [        45      (       Gau  [        U [        5      (       a  U R                  R
                  OU R
                  nUT	:X  a  U 4$ T(       d  U R                  T	5      4$ UR                  S:X  a  U R                  T	5      4$ SSKJ	n  U" T	5      nU   U R                  T	5      nS S S 5        [        R                  R                  T	R                  5         [        R                  R                  5       nUR                  U5        [        U [        5      (       a  WR                  R                  U5        O;[        W[        R                  5      (       d  [!        S5      eUR                  U5        S S S 5        U4$ SSKJn  U" U 5      (       a/  ['        [)        T
U 5      6  Vs/ s H  n[        U 5      " U6 PM     sn$ [        U [*        5      (       a*  [-        U 5      S:”  a  [/        ['        [)        T
U 5      6 5      $ [        U [.        5      (       a;  [-        U 5      S:”  a,  ['        [)        T
U 5      6  Vs/ s H  n[/        U5      PM     sn$ [        U [0        5      (       aO  [-        U 5      S:”  a@  ['        [)        T
U R3                  5       5      6  Vs/ s H  n[        U 5      " U5      PM     sn$ U /$ ! , (       d  f       GN= f! , (       d  f       W4$ = fs  snf s  snf s  snf )NÚcpur   )Ú_get_streamzoutput must be a torch.Tensor©Ú_is_namedtuple)Ú
isinstancer    r%   r   ÚdataÚdevicer"   ÚtypeÚtorch.nn.parallel._functionsr;   ÚacceleratorÚdevice_indexÚindexÚcurrent_streamÚwait_streamÚrecord_streamr*   Ú torch.nn.parallel.scatter_gatherr=   r,   Úmapr   r)   r   r+   r   )Úobjr@   r;   ÚstreamÚoutputrF   r=   r   Úir1   Úto_mapr2   s            €€€r   rO   Ú_recursive_to.<locals>.to_mapd   s\  ø€ Ü�cœEŸL™L¬.Ð9×:Ò:Ü(2°3¼×(GÑ(G�S—X‘X—_’_ÈSÏZÉZˆFØ˜Ó&Ø�v�Þ4ØŸ™˜}Ó-Ð/Ð/ð —;‘; %Ó'ØŸF™F =Ó1Ð3Ð3åDñ % ]Ó3�ÚØ ŸV™V MÓ2�F÷ ô ×&Ñ&×3Ñ3°M×4GÑ4GÕHÜ%*×%6Ñ%6×%EÑ%EÓ%G�Nà"×.Ñ.¨vÔ6ô " #¤~×6Ñ6ØŸ™×1Ñ1°.ÕAä)¨&´%·,±,×?Ñ?Ü"0Ð1PÓ"QÐQØ×,Ñ,¨^Ô<÷ Ið �yÐ åCá˜#×Ñä14´c¸&À#Ó6FÑ1GÓHÒ1G¨”D˜”I˜tÓ$Ñ1GÑHÐHÜ�cœ5×!Ñ!¤c¨#£h°£läœœS ¨Ó-Ð.Ó/Ð/Ü�cœ4× Ñ ¤S¨£X°£\ä%(¬#¨f°cÓ*:Ñ%;Ó<Ò%; ”D˜–GÑ%;Ñ<Ð<Ü�cœ4× Ñ ¤S¨£X°£\ä*-¬s°6¸3¿9¹9»;Ó/GÑ*HÓIÒ*H Q”D˜”I˜a–LÑ*HÑIÐIØˆuˆ÷? –Vú÷ IÔHð �yÐ üò Iùò =ùò Js+   Â3KÃ6BK'ÇK:ÉK?Ê4LË
K$Ë'
K7Nr4   )r0   r1   r2   ÚresrO   s    `` @r   r6   r6   a   s*   ú€ ÷0ðfÙ�V‹nˆàˆØ€Jøð ‰ús   � ™ÚcondÚsÚraise_assertion_errorc                 óx   • U (       d3  [        U5        [        R                  " 5         U(       a  [        U5      egg)zwAlternate to ``assert`` when in the backward context to print the error message ``s`` since otherwise, it is swallowed.N)ÚprintÚ	tracebackÚprint_stackr*   )rR   rS   rT   s      r   Ú	_p_assertrY   ž   s0   € æÜˆaŒÜ×ÒÔÞ Ü  Ó#Ð#ð !ð r   ÚtensorÚsizec                 óÜ  • [         R                  " 5          [         R                  R                  R	                  5       (       d�  U R                  5       R                  5       UR                  5       :H  nU(       dZ  U R                  5       R                  5       n[        US:H  S5        U R                  5       R                  UR                  5       5        SSS5        g! , (       d  f       g= f)z¬
Allocate storage for ``tensor`` with the given size.

Returns:
    bool: ``True`` if this method allocated storage and ``False`` if the
    storage was already allocated.
r   zCTensor storage should have been resized to be 0 but got PLACEHOLDERN)
r    Úno_gradÚdistributedÚ_functional_collectivesÚis_torchdynamo_compilingÚ_typed_storageÚ_sizeÚnumelrY   Ú_resize_)rZ   r[   Úalready_allocatedÚtensor_storage_sizes       r   Ú_alloc_storagerg   §   s¢   € ô 
�Š�Ü× Ñ ×8Ñ8×QÑQ×SÑSØ &× 5Ñ 5Ó 7× =Ñ =Ó ?À4Ç:Á:Ã<Ñ OÐÞ$Ø&,×&;Ñ&;Ó&=×&CÑ&CÓ&EÐ#ÜØ'¨1Ñ,ØYôð ×%Ñ%Ó'×0Ñ0°·±³Ô>÷ 
�Žús   –B>CÃ
C+c           
      óþ  • [         R                  " 5          [         R                  R                  R	                  5       (       d¡  U R                  5       R                  5       S:H  nU(       dy  [        U R                  5       S:H  SU R                  5        SU R                  5       R                  5        SU R                   35        U R                  5       R                  S5        SSS5        g! , (       d  f       g= f)zž
Frees the underlying storage of ``tensor``.

Returns:
    bool: ``True`` if the method freed the storage and ``False`` if the
    storage was already freed.
r   zVFreeing a tensor's storage is unsafe when it is not the sole occupant
storage offset: z
storage size: z
tensor shape: N)r    r]   r^   r_   r`   ra   rb   rY   Ústorage_offsetÚshaperd   )rZ   Úalready_freeds     r   Ú_free_storagerl   »   sÉ   € ô 
�Š�Ü× Ñ ×8Ñ8×QÑQ×SÑSØ"×1Ñ1Ó3×9Ñ9Ó;¸qÑ@ˆMÞ ÜØ×)Ñ)Ó+¨qÑ0ð'Ø'-×'<Ñ'<Ó'>Ð&?ð @%Ø%+×%:Ñ%:Ó%<×%BÑ%BÓ%DÐ$Eð F%Ø%+§\¡\ Nð4ôð ×%Ñ%Ó'×0Ñ0°Ô3÷ 
�Žús   –CC.Ã.
C<ÚQÚRÚfnÚ	containerc                 ó   • g r   r4   ©ro   rp   s     r   r&   r&   Õ   s   € ð 	r   c                 ó   • g r   r4   rr   s     r   r&   r&   Û   s   € ØMPr   c                 ó$   ^ ^• UU 4S jmT" U5      $ )zFRecursively apply to all tensor in different kinds of container types.c           
      ó²  >• SSK Jn  [        U [        R                  5      (       a  T
" U 5      $ [        U S5      (       av  [        R                  " U 5      n[        R                  " U5       Vs0 s H(  o3R                  T	" [        X#R                  5      5      _M*     nn[        R                  " U40 UD6$ [        U [        5      (       a5  U R                  5       nU R                  5        H  u  pgT	" U5      XV'   M     U$ [        U [        5      (       a  T	" U R                  5        U $ [        U [         5      (       a,  U R                  5        VVs0 s H  u  pgUT	" U5      _M     snn$ U" U 5      (       a  U	4S jU  5       n[#        U 5      " U6 $ [        U [$        [&        [(        45      (       a  [#        U 5      " U	4S jU  5       5      $ U $ s  snf s  snnf )Nr   r<   Ú__dataclass_fields__c              3   ó4   >#   • U  H  nT" U5      v •  M     g 7fr   r4   ©Ú.0ÚelÚapplys     €r   Ú	<genexpr>Ú3_apply_to_tensors.<locals>.apply.<locals>.<genexpr>ø   s   øé € Ð)¢q ‘5˜—9�9¢qùó   ƒc              3   ó4   >#   • U  H  nT" U5      v •  M     g 7fr   r4   rx   s     €r   r|   r}   û   s   øé € Ð1ªq¨™5 Ÿ9˜9ªqùr~   )rI   r=   r>   r    r%   ÚhasattrÚdataclassesÚreplaceÚfieldsÚnameÚgetattrr   Ú	__class__r   r   r?   r+   rA   r   r   Úset)r   r=   ÚdcÚfÚchangesÚodÚkeyÚvaluerQ   r{   ro   s            €€r   r{   Ú _apply_to_tensors.<locals>.applyâ   sy  ø€ ÝCä�aœŸ™×&Ñ&Ù�a“5ˆLÜ�QÐ.×/Ñ/Ü×$Ò$ QÓ'ˆBä<G×<NÒ<NÈrÔ<RóÚ<R°q—‘™œg b¯&©&Ó1Ó2Ò2Ñ<Rð ð ô ×&Ò& rÑ5¨WÑ5Ð5Ü˜œ;×'Ñ'Ø—‘“ˆBØŸg™gži‘
�Ù ›,�“ñ (àˆIÜ˜œ>×*Ñ*Ù�!—&‘&ŒMØˆHÜ˜œ4× Ñ Ø89¿¹¼	ÔBº	©*¨#�C™˜u›Ò%¹	ÒBÐBÙ˜A×ÑÜ)¡qÓ)ˆCÜ˜”7˜C�=Ð Ü˜œD¤%¬Ð-×.Ñ.Ü˜”7Ô1©qÓ1Ó1Ð1àˆHùò)ùó Cs   Á./GÅGr4   )ro   rp   r{   s   ` @r   r&   r&   ß   s   ù€ öñ: �ÓÐr   c                 óø  • U (       a  [        XU5      O/ nU(       a  [        XU5      O/ n[        U5      [        U5      :  aA  UR                  [        [        U5      [        U 5      -
  5       Vs/ s H  nSPM     sn5        OX[        U5      [        U5      :  a@  UR                  [        [        U5      [        U5      -
  5       Vs/ s H  n0 PM     sn5        [	        U5      [	        U5      4$ s  snf s  snf )Nr4   )r6   r)   ÚextendÚranger   )r0   r   r1   r2   Úmoved_inputsÚmoved_kwargsÚ_s          r   Ú
_to_kwargsr•     sß   € ö ô 	�fÐ-NÔOàð ö ô 	�fÐ-NÔOàð ô
 ˆ<Óœ3˜|Ó,Ó,Ø×Ñ¬¬s°<Ó/@Ä3ÀvÃ;Ñ/NÔ)OÓPÒ)O A›RÑ)OÑPÕQÜ	ˆ\Ó	œS Ó.Ó	.Ø×Ñ¬¬s°<Ó/@Ä3À|ÓCTÑ/TÔ)UÓVÒ)U A›RÑ)UÑVÔWÜ�Ó¤ lÓ 3Ð3Ð3ùò QùâVs   Á0C2Ã	C7Úprocess_groupÚtensorsÚloggerzdist.Loggerc                 ó0   • [         R                  " XU5      $ r   )ÚdistÚ_verify_params_across_processes)r–   r—   r˜   s      r   Ú$_verify_param_shape_across_processesrœ     s   € ô
 ×/Ò/°ÈÓOÐOr   ÚmoduleÚbroadcast_bucket_sizeÚsrcÚparams_and_buffers_to_ignoreÚbroadcast_buffersc                 ó*  • / nU R                  5        H+  u  pxXt;  d  M  UR                  UR                  5       5        M-     U(       a?  U R                  5        H+  u  pyXt;  d  M  UR                  U	R                  5       5        M-     [	        XX#5        g)aO  
Sync ``module``'s parameters and buffers state.

Syncs ``module``'s parameters and buffers state so that all ranks contain
the same module state across all ranks. Note that this API assumes that all
parameter shapes are consistent before running the synchronization. This can
be checked with ``_verify_param_shape_across_processes``.
N)Únamed_parametersr   ÚdetachÚnamed_buffersÚ_sync_params_and_buffers)
r�   r–   rž   rŸ   r    r¡   Úmodule_statesr„   ÚparamÚbuffers
             r   Ú_sync_module_statesrª   !  sy   € ð  )+€MØ×.Ñ.Ö0‰ˆØÕ3Ø× Ñ  §¡£Ö0ñ 1ö Ø"×0Ñ0Ö2‰LˆDØÕ7Ø×$Ñ$ V§]¡]£_Ö5ñ 3ô ˜]Ð;PÕVr   r§   c                 óR   • [        U5      S:”  a  [        R                  " XX#5        gg)zfSynchronize ``module_states`` (list of tensors) across all processes by broadcasting them from rank 0.r   N)r)   rš   Ú_broadcast_coalesced)r–   r§   rž   rŸ   s       r   r¦   r¦   >  s*   € ô ˆ=Ó˜AÓÜ×!Ò!ØÐ*?õ	
ð r   Ú
state_dictÚ
old_prefixÚ
new_prefixc                 óÄ   • X:X  a  [        S5      e[        U R                  5       5       H3  nUR                  U5      (       d  M  X#[	        U5      S -   nX   X'   X	 M5     g)a  
Replace all keys that match a given old_prefix with a new_prefix (in-place).

Usage::

    state_dict = {"layer.xyz": torch.tensor(1)}
    replace_by_prefix_(state_dict, "layer.", "module.layer.")
    assert state_dict == {"module.layer.xyz": torch.tensor(1)}
z*old_prefix and new_prefix must be distinctN)Ú
ValueErrorr   ÚkeysÚ
startswithr)   )r­   r®   r¯   rŒ   Únew_keys        r   Ú_replace_by_prefixrµ   K  sa   € ð ÓÜÐEÓFÐFÜ�J—O‘OÓ%Ö&ˆØ�~‰~˜j×)Ñ)ÙØ¤3 z£?Ð#4Ð5Ñ5ˆØ(™oˆ
ÑØŠOò 'r   c                 óD   • U R                  5       R                  5       S:„  $ )Nr   )Úuntyped_storageÚdata_ptr)rZ   s    r   Ú_data_ptr_allocatedr¹   c  s   € Ø×!Ñ!Ó#×,Ñ,Ó.°Ñ2Ð2r   Úmodulesc                 ó  • / 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 )zâ
Returns the modules in ``modules`` that are root modules (i.e.
parent-less) with respect to the set ``modules``. In other words, these
are the modules in ``modules`` that are the not child of any other
module in ``modules``.
TF)r‡   rº   r   r   )rº   Úroot_modulesr�   Úmodule_to_modulesÚcandidate_moduleÚis_root_moduleÚ_modulesÚis_child_modules           r   Ú_get_root_modulesrÂ   g  s¢   € ð %'€Lá4;ó:Ú4;¨&”�F—N‘NÓ$Ó%Ò%±Gð ð :ó $ÐØˆØ 1× 7Ñ 7Ö 9ÑˆFà Ð.×OÐ3CÑ3Oð ÷ ˆØ!&�Ùñ !:÷ ˆ>Ø×ÑÐ 0Ö1ñ $ð Ðùò:s   ‡#B)Tr   )4r�   rW   Úcollectionsr   Úcollections.abcr   r   Útypingr   r   r   r	   r    Útorch.distributedr^   rš   r
   Útorch.nn.utils.rnnr   Ú__all__r   Ústrr   r   r'   r+   r-   r   r.   r%   r/   r@   Úboolr6   rY   ÚSizerg   rl   rm   r‡   rn   r&   r•   ÚProcessGrouprœ   ÚModuleÚintrª   r¦   rµ   r¹   rÂ   r4   r   r   Ú<module>rÏ      s-  ðã Û Ý #ß /ß 3Ó 3ã Ý  Ý Ý -ð €ð/˜ð / sð /¨u°U¸3À¸8±_ÀeÈCÐQTÈHÁoÐ5UÑ/Vô /ð:RØ�;‰;˜ÑðRàðRð ðRð ˆ3�ˆ8�_ô	Rð,
Ø�S˜#�X‰ð
Ø,1°#°s°(©Oð
à
ˆ5��c�‰?˜D  c ™NÐ*Ñ+ô
ñ ˆC��t˜UÓ#€ÙˆC�—‘˜~Ó.€ð 
ðØðØ#Ÿl™lðØOSðà	ˆ!�Wóó 
ðð
 
ðØðØ#Ÿl™lðØOSðà
ˆ1�Xóó 
ðò
:ñz$�Cð $˜Cð $¸ð $Èõ $ð?˜5Ÿ<™<ð ?¨u¯z©zð ?¸dô ?ð(4˜%Ÿ,™,ô 4ñ, ˆCƒL€ÙˆC��t˜U C¨°nÀcÓJ€ð 
ðØ�%—,‘,� Ð"Ñ#ðØ05·±ðàóó 
ðð
 
Ø P˜( E§L¡L >°3Ð#6Ñ7Ð PÀAÐ PÈ!Ó Pó 
Ø Pò ðF4Ø�#�s�(‰Oð4à��c�‰N˜TÑ!ð4ð —<‘<ð4ð (,ð	4ð
 ˆ5��c�‰?˜E $ s¨C x¡.°#Ð"5Ñ6Ð6Ñ7ô4ð4 '+ñPØ×$Ñ$ðPà�%—,‘,ÑðPð �]Ñ#õPð #ñWØ�I‰IðWà×$Ñ$ðWð ðWð 
ð	Wð
 #,¨C¡.ðWð ðWð 
õWð:

Ø×$Ñ$ð

à˜Ÿ™Ñ%ð

ð ð

ð 
ð	

ð
 
ô

ðØ�S˜#�X‘ðàðð ðð 
ô	ð03 §¡ð 3°ô 3ð˜t B§I¡I™ð °4¸¿	¹	±?õ r   