Ë
    g^(h~4  ã                   ó
  — d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZ d dlZd dlmZ d dlmZ d dlmZ g Zdeded	eeed
f   eed
f   f   fd„Zde	ej.                     deded	eeef   fd„Zdeed
f   deed
f   d	eeed
f   eeef   f   fd„Z edeee«      Z edej:                  e«      Ze
dedej>                  de d	ee   fd„«       Z!e
dedej>                  de d	ee   fd„«       Z!d„ Z!d=dedede d	dfd„Z"dej:                  dejF                  d	dfd„Z$dej:                  fd „Z% ed!«      Z& ed"eeee'eee«      Z(e
d#eej:                  ge&f   d$ej:                  d	e&fd%„«       Z)e
d#eej:                  gef   d$e(d	e(fd&„«       Z)d'„ Z)deed
f   de	eeef      dej>                  de d	eeed
f   eeeef   d
f   f   f
d(„Z*	 d>d)ejV                  d*eej:                     d+e	d,   fd-„Z,	 d=d.ejZ                  d)ejV                  d/e.d0e.d1ee   d2e d	dfd3„Z/d)ejV                  d4eej:                     d/e.d0e.d	df
d5„Z0d6eeef   d7ed8ed	dfd9„Z1dej:                  d	e fd:„Z2d;eejZ                     d	eejZ                     fd<„Z3y)?é    N)ÚOrderedDict)Ú	Container)ÚAnyÚCallableÚOptionalÚoverloadÚTypeVar)Únn)ÚPackedSequenceÚargsÚkwargsÚreturn.c                  ó¼   — g }t        | «      }|j                  «       D ]'  \  }}|j                  |«       |j                  |«       Œ) t        |«      t        |«      fS )aŠ  
    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         úU/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/distributed/utils.pyÚ_pack_kwargsr      s^   € ð( €JÜ ›:€IØ—‘“ò ‰ˆˆ1Ø×Ñ˜!ÔØ×Ñ˜Õðô �ÓœU :Ó.Ð.Ð.ó    Údtypec                 óŒ   ‡ — ‰ €||fS dt         j                  dt         j                  fˆ fd„}t        ||«      t        ||«      fS )z–
    Cast floating point tensors in ``args`` and ``kwargs`` to ``input_dtype``.

    This respects the existing ``requires_grad`` on the tensors.
    Úxr   c                 ór   •— t        j                  | «      r| j                  ‰k(  r| S | j                  ‰«      S ©N)ÚtorchÚis_floating_pointr   Úto)r   r   s    €r   Úcast_fnz%_cast_forward_inputs.<locals>.cast_fn;   s/   ø€ Ü×&Ñ& qÔ)¨Q¯W©W¸Ò-=ØˆHØ�t‰t�E‹{Ðr   )r    ÚTensorÚ_apply_to_tensors)r   r   r   r#   s   `   r   Ú_cast_forward_inputsr&   .   sK   ø€ ð €}Ø�Vˆ|Ðð”5—<‘<ð ¤E§L¡Lõ ô
 ˜g tÓ,Ô.?ÀÈÓ.PÐQÐQr   r   r   c           	      óü   — t        |«      t        | «      k  sJ dt        |«      › dt        | «      › �«       ‚t        |«      dk(  r| i fS | dt        |«        }t        t        || t        |«       d «      «      }||fS )zSee _pack_kwargs.ztoo many keys z vs. r   N)ÚlenÚdictÚzip)r   r   r   r   s       r   Ú_unpack_kwargsr+   C   s‘   € ô ˆz‹?œc )›nÒ,ð Ø
œ˜Z›Ð)¨¬s°9«~Ð.>Ð?óÐ,ô ˆ:ƒ˜!ÒØ˜"ˆ}ÐØÐ'œ˜J›Ð'Ð(€DÜ”#�j )¬S°«_Ð,<Ð,>Ð"?Ó@ÓA€FØ�ˆ<Ðr   ÚSÚTÚinputsÚtarget_deviceÚ!use_side_stream_for_tensor_copiesc                  ó   — y r   © ©r.   r/   r0   s      r   Ú_recursive_tor4   U   s   € ð r   c                  ó   — y r   r2   r3   s      r   r4   r4   [   s   € ð r   c                 ó>   ‡‡‡— ˆˆˆfd„Š	  ‰| «      }dŠ|S # dŠw xY w)z-Recursively moves input to the target_device.c                 ó–  •— t        | t        j                  t        f«      �rft        | t        «      r| j                  j
                  n| j
                  }|‰
k(  r| fS ‰s| j                  ‰
«      fS t        t        |j                  d «      }|j                  dk(  s|€| j                  ‰
«      fS ddl	m
}  |‰
«      }|j                  |«      5  | j                  ‰
«      }d d d «       |j                  ‰
j                  «      5  |j                  «       }|j                  |«       t        | t        «      rj                  j                  |«       n-t        t        j                  «      sJ ‚|j                  |«       d d d «       |fS ddlm}  || «      r,t%        t'        ‰| «      Ž D �cg c]  } t        | «      |Ž ‘Œ c}S t        | t(        «      r)t+        | «      dkD  rt-        t%        t'        ‰| «      Ž «      S t        | t,        «      r7t+        | «      dkD  r)t%        t'        ‰| «      Ž D �	cg c]  }	t-        |	«      ‘Œ c}	S t        | t.        «      rKt+        | «      dkD  r=t%        t'        ‰| j1                  «       «      Ž D �	cg c]  }	 t        | «      |	«      ‘Œ c}	S | gS # 1 sw Y   �ŒÃxY w# 1 sw Y   fS xY wc c}w c c}	w c c}	w )NÚcpur   )Ú_get_stream©Ú_is_namedtuple)Ú
isinstancer    r$   r   ÚdataÚdevicer"   ÚgetattrÚtypeÚtorch.nn.parallel._functionsr9   ÚstreamÚindexÚcurrent_streamÚwait_streamÚrecord_streamÚ torch.nn.parallel.scatter_gatherr;   r*   Úmapr   r(   r   r)   r   )Úobjr>   Ú
device_modr9   rB   ÚoutputrD   r;   r   Úir/   Úto_mapr0   s             €€€r   rM   z_recursive_to.<locals>.to_mapd   sK  ø€ Ü�cœEŸL™L¬.Ð9Õ:Ü(2°3¼Ô(G�S—X‘X—_’_ÈSÏZÉZˆFØ˜Ò&Ø�v�Ù4ØŸ™˜}Ó-Ð/Ð/ô %¤U¨F¯K©K¸Ó>�
Ø—;‘; %Ò'¨:Ð+=ØŸF™F =Ó1Ð3Ð3åDñ % ]Ó3�Ø×&Ñ& vÓ.ñ 3Ø ŸV™V MÓ2�F÷3ð  ×&Ñ& }×':Ñ':Ó;ñ 
=Ø%/×%>Ñ%>Ó%@�Nà"×.Ñ.¨vÔ6ô " #¤~Ô6ØŸ™×1Ñ1°.ÕAä)¨&´%·,±,Ô?Ð?Ð?Ø×,Ñ,¨^Ô<÷
=ð �yÐ åCá˜#ÔÜ14´c¸&À#Ó6FÐ1GÖH¨�I”D˜“I˜tÒ$Ò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 Q�I”D˜“I˜a•LÒIÐIØˆuˆ÷53ñ 3ú÷
=ð �yÐ üò
 Iùò =ùâIs+   ÃJ!ÄA;J.Æ+J<È.KÊKÊ!J+Ê.J9Nr2   )r.   r/   r0   ÚresrM   s    `` @r   r4   r4   a   s*   ú€ ö,ð^Ù�V‹nˆàˆØ€Jøð ‰ús   Œ ˜ÚcondÚsÚraise_assertion_errorc                 ób   — | s-t        |«       t        j                  «        |rt        |«      ‚yy)zwAlternate to ``assert`` when in the backward context to print the error message ``s`` since otherwise, it is swallowed.N)ÚprintÚ	tracebackÚprint_stackÚAssertionError)rO   rP   rQ   s      r   Ú	_p_assertrW   š   s0   € áÜˆaŒÜ×ÑÔÙ Ü  Ó#Ð#ð !ð r   ÚtensorÚsizec                 ó¼  — t        j                  «       5  t         j                  j                  j	                  «       s‹| j                  «       j                  «       |j                  «       k(  }|sZ| j                  «       j                  «       }t        |dk(  d«       | j                  «       j                  |j                  «       «       ddd«       y# 1 sw Y   yxY w)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ÚnumelrW   Ú_resize_)rX   rY   Úalready_allocatedÚtensor_storage_sizes       r   Ú_alloc_storagere   £   sª   € ô 
�‰‹ñ 	?Ü× Ñ ×8Ñ8×QÑQÔSØ &× 5Ñ 5Ó 7× =Ñ =Ó ?À4Ç:Á:Ã<Ñ OÐÙ$Ø&,×&;Ñ&;Ó&=×&CÑ&CÓ&EÐ#ÜØ'¨1Ñ,ØYôð ×%Ñ%Ó'×0Ñ0°·±³Ô>÷	?÷ 	?ñ 	?ús   •B4CÃCc           
      óÞ  — t        j                  «       5  t         j                  j                  j	                  «       sœ| j                  «       j                  «       dk(  }|syt        | j                  «       dk(  d| j                  «       › d| j                  «       j                  «       › d| j                  › �«       | j                  «       j                  d«       ddd«       y# 1 sw Y   yxY w)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^   r_   r`   rW   Ústorage_offsetÚshaperb   )rX   Úalready_freeds     r   Ú_free_storagerj   ·   sÑ   € ô 
�‰‹ñ 4Ü× Ñ ×8Ñ8×QÑQÔSØ"×1Ñ1Ó3×9Ñ9Ó;¸qÑ@ˆMÙ ÜØ×)Ñ)Ó+¨qÑ0ð'Ø'-×'<Ñ'<Ó'>Ð&?ð @%Ø%+×%:Ñ%:Ó%<×%BÑ%BÓ%DÐ$Eð F%Ø%+§\¡\ Nð4ôð ×%Ñ%Ó'×0Ñ0°Ô3÷4÷ 4ñ 4ús   •CC#Ã#C,ÚQÚRÚfnÚ	containerc                  ó   — y r   r2   ©rm   rn   s     r   r%   r%   Ñ   s   € ð 	r   c                  ó   — y r   r2   rp   s     r   r%   r%   ×   s   € ØMPr   c                 ó"   ‡ ‡— ˆˆ fd„Š ‰|«      S )zFRecursively apply to all tensor in different kinds of container types.c           
      ó\  •— ddl m} t        | t        j                  «      r ‰
| «      S t        | d«      rrt        j                  | «      }t        j                  |«      D �ci c])  }|j                   ‰	t        ||j                  «      «      “Œ+ }}t        j                  |fi |¤ŽS t        | t        «      r5| j                  «       }| j                  «       D ]  \  }} ‰	|«      ||<   Œ |S t        | t        «      r ‰	| j                  «       | S t        | t         «      r*| j                  «       D ��ci c]  \  }}| ‰	|«      “Œ c}}S  || «      rˆ	fd„| D «       } t#        | «      |Ž S t        | t$        t&        t(        f«      r t#        | «      ˆ	fd„| D «       «      S | S c c}w c c}}w )Nr   r:   Ú__dataclass_fields__c              3   ó.   •K  — | ]  } ‰|«      –— Œ y ­wr   r2   ©Ú.0ÚelÚapplys     €r   ú	<genexpr>z3_apply_to_tensors.<locals>.apply.<locals>.<genexpr>ô   s   øè ø€ Ò) ‘5˜—9Ñ)ùó   ƒc              3   ó.   •K  — | ]  } ‰|«      –— Œ y ­wr   r2   rv   s     €r   rz   z3_apply_to_tensors.<locals>.apply.<locals>.<genexpr>÷   s   øè ø€ Ò1¨™5 Ÿ9Ñ1ùr{   )rG   r;   r<   r    r$   ÚhasattrÚdataclassesÚreplaceÚfieldsÚnamer?   r   Ú	__class__r   r   r=   r)   r@   r   r   Úset)r   r;   ÚdcÚfÚchangesÚodÚkeyÚvaluerN   ry   rm   s            €€r   ry   z _apply_to_tensors.<locals>.applyÞ   sp  ø€ ÝCä�aœŸ™Ô&Ù�a“5ˆLÜ�QÐ.Ô/Ü×$Ñ$ QÓ'ˆBä<G×<NÑ<NÈrÓ<RöØ78�—‘™œg b¨!¯&©&Ó1Ó2Ñ2ðˆGð ô ×&Ñ& rÑ5¨WÑ5Ð5Ü˜œ;Ô'Ø—‘“ˆBØŸg™g›iò '‘
��UÙ ›,��3’ð'àˆIÜ˜œ>Ô*Ù�!—&‘&ŒMØˆHÜ˜œ4Ô Ø89¿¹»	×B©*¨#¨u�C™˜u›Ñ%ÓBÐBÙ˜AÔÛ) qÔ)ˆCØ”4˜“7˜C�=Ð Ü˜œD¤%¬Ð-Ô.Ø”4˜“7Ó1¨qÔ1Ó1Ð1àˆHùò)ùó Cs   Á".F#Ä4F(r2   )rm   rn   ry   s   ` @r   r%   r%   Û   s   ù€ õñ: �ÓÐr   c                 óØ  — | rt        | ||«      ng }|rt        |||«      ng }t        |«      t        |«      k  r>|j                  t        t        |«      t        | «      z
  «      D �cg c]  }d‘Œ c}«       nTt        |«      t        |«      k  r=|j                  t        t        |«      t        |«      z
  «      D �cg c]  }i ‘Œ c}«       t	        |«      t	        |«      fS c c}w c c}w )Nr2   )r4   r(   ÚextendÚranger   )r.   r   r/   r0   Úmoved_inputsÚmoved_kwargsÚ_s          r   Ú
_to_kwargsr�   þ   s×   € ñ ô 	�f˜mÐ-NÔOàð ñ ô 	�f˜mÐ-NÔOàð ô
 ˆ<Óœ3˜|Ó,Ò,Ø×Ñ¬¬s°<Ó/@Ä3ÀvÃ;Ñ/NÓ)OÖP AšRÒPÕQÜ	ˆ\Ó	œS Ó.Ò	.Ø×Ñ¬¬s°<Ó/@Ä3À|ÓCTÑ/TÓ)UÖV AšRÒVÔWÜ�Ó¤ lÓ 3Ð3Ð3ùò QùâVs   Á'	C"Â<	C'Úprocess_groupÚtensorsÚloggerzdist.Loggerc                 ó0   — t        j                  | ||«      S r   )ÚdistÚ_verify_params_across_processes)r‘   r’   r“   s      r   Ú$_verify_param_shape_across_processesr—     s   € ô
 ×/Ñ/°¸wÈÓOÐOr   ÚmoduleÚbroadcast_bucket_sizeÚsrcÚparams_and_buffers_to_ignoreÚbroadcast_buffersc                 ó  — g }| j                  «       D ])  \  }}||vsŒ|j                  |j                  «       «       Œ+ |r<| j                  «       D ])  \  }}	||vsŒ|j                  |	j                  «       «       Œ+ t	        ||||«       y)ag  
    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¥     s’   € ð  )+€MØ×.Ñ.Ó0ò 1‰ˆˆeØÐ3Ò3Ø× Ñ  §¡£Õ0ð1ñ Ø"×0Ñ0Ó2ò 	6‰LˆD�&ØÐ7Ò7Ø×$Ñ$ V§]¡]£_Õ5ð	6ô ˜]¨MÐ;PÐRUÕVr   r¢   c                 óR   — t        |«      dkD  rt        j                  | |||«       yy)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                 ó¼   — ||k(  rt        d«      ‚t        | j                  «       «      D ]0  }|j                  |«      sŒ||t	        |«      d z   }| |   | |<   | |= Œ2 y)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°   G  sm   € ð �ZÒÜÐEÓFÐFÜ�J—O‘OÓ%Ó&ò ˆØ�~‰~˜jÔ)ØØ˜s¤3 z£?Ð#4Ð5Ñ5ˆØ(¨™oˆ
�7ÑØ�s‰Oñr   c                 óD   — | j                  «       j                  «       dkD  S )Nr   )Úuntyped_storageÚdata_ptr)rX   s    r   Ú_data_ptr_allocatedr´   _  s   € Ø×!Ñ!Ó#×,Ñ,Ó.°Ñ2Ð2r   Úmodulesc                 óì   — g }| D �ci c]  }|t        |j                  «       «      “Œ }}| D ]@  }d}|j                  «       D ]  \  }}||uxr ||v }|sŒd} n |sŒ0|j                  |«       ŒB |S c c}w )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½   c  s¯   € ð %'€Là4;ö:Ø*0ˆ”�F—N‘NÓ$Ó%Ñ%ð:Ðð :ð $ò 
2ÐØˆØ 1× 7Ñ 7Ó 9ò 	ÑˆF�Hà ¨Ð.ÒOÐ3CÀxÐ3Oð ò Ø!&�Ùð	ò Ø×ÑÐ 0Õ1ð
2ð Ðùò:s   ‡!A1)Tr   )4r~   rT   Úcollectionsr   Úcollections.abcr   Útypingr   r   r   r   r	   r    Útorch.distributedr\   r•   r
   Útorch.nn.utils.rnnr   Ú__all__r   Ústrr   r   r&   r)   r+   r   r,   r$   r-   r>   Úboolr4   rW   ÚSizere   rj   rk   rƒ   rl   r%   r�   ÚProcessGroupr—   ÚModuleÚintr¥   r¡   r°   r´   r½   r2   r   r   ú<module>rÊ      s-  ðã Û Ý #Ý %ß =Õ =ã Ý  Ý Ý -ð €ð/˜ð / sð /¨u°U¸3À¸8±_ÀeÈCÐQTÈHÁoÐ5UÑ/Vó /ð:RØ�E—K‘KÑ ð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òó 
ðò
6ñr$�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à�T˜#˜s˜(‘^Ñ$ð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   