ó
    Eñiq*  ã            
       óØ  • S SK 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
  S SKJrJr  S SKrS SKJr  S SKJr  S SKJr  \" S	S
S9r\" S5      rSS jr\" 5       r\" 5       r " S S5      r\" SSS
S9r\" S\R8                  \\R8                     5      r " S S\
\	\\\4   5      r\4S\ \   S\\\\\4   \4   /\\\\4   \\4   4   4S jjr!S\R8                  S\"\#\4   S-  4S jr$g)é    N)ÚOrderedDict)ÚCallable)Úwraps)ÚConcatenateÚGenericÚProtocol)Ú	ParamSpecÚTypeVar)Ú_State)Ú_get_root_modulesÚ_TT)Ú	covariantÚ_Pc                 óH   • U  S[        [        R                  " 5       5       3$ )NÚ_)ÚstrÚuuidÚuuid4)Ústrings    Úc/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/distributed/_composable/contract.pyÚgenerate_state_keyr      s   € ØˆX�Q”sœ4Ÿ:š:›<Ó(Ð)Ð*Ð*ó    c                   ó   • \ rS rSrSrg)ÚRegistryItemé   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   r   r   r   r      s   † Úr   r   Ú_TStater   )Úboundr   Ú_Mc                   óx   • \ rS rSrS\R
                  S\R                  S\4S jrS\	R                  S\4S jrSrg	)
Ú_ContractFné'   ÚargsÚkwargsÚreturnc                 ó   • g ©Nr   )Úselfr(   r)   s      r   Ú__call__Ú_ContractFn.__call__(   s   € À3r   Úmodulec                 ó   • g r,   r   )r-   r0   s     r   ÚstateÚ_ContractFn.state*   s   € °3r   r   N)r   r   r   r    r   r(   r)   r   r.   ÚnnÚModuler"   r2   r!   r   r   r   r&   r&   '   s-   † ØF˜bŸg™gÐF°·±ÐF¸rÔFà6˜BŸI™IÐ6¨'×6r   r&   Ú	state_clsr*   c                 ó¾   ^ • [        T 5      S[        [        [        [        4   [        4   S[
        [        [        [        4   [        [        4   4U 4S jj5       nU$ )a™  
Decorate a function as a composable distributed API, where the first
argument of the function must be an :class:`nn.Module` instance or sequence
of :class:`nn.Module` instances.

The decorator verifies that the decorated function does not modify
fully-qualified names (FQNs) for parameters, buffers, or modules. The
decorated function can return different module instances than the input
modules; the FQN invariant will be enforced following the input order.

When a function ``func`` is decorated by ``@contract()``, a
``.state(module: nn.Module)`` method will be installed to the decorated
function. Then you can retrieve and modify the state on a module by calling
``func.state(module)``.

Example::
    >>> # xdoctest: +SKIP
    >>> import torch.nn as nn
    >>>
    >>> class MyModel(nn.Module):
    >>>     def __init__(self) -> None:
    >>>         super().__init__()
    >>>         self.l1 = nn.Linear(10, 10)
    >>>         self.l2 = nn.Linear(10, 10)
    >>>
    >>>     def forward(self, x):
    >>>         return self.l2(self.l1(x))
    >>>
    >>> @contract()
    >>> def my_feature(module: nn.Module) -> nn.Module:
    >>>     my_feature.state(module).some_state = "any value"
    >>>     return module
    >>>
    >>> model = MyModel()
    >>> my_feature(model.l1)
    >>> assert my_feature.state(model.l1).some_state == "any value"
    >>> my_feature(model.l2)
    >>> model(torch.randn(2, 10)).sum().backward()
Úfuncr*   c           	      óØ   >^ • [        T 5      S[        S[        R                  S[        R                  S[        4U U4S jj5       nS[
        R                  S[        4U 4S jjnX!l        U$ )Nr0   r(   r)   r*   c                 óÐ  >• U n[        U [        R                  5      (       a  U /nO[        [	        U 5      5      nT" 5       n[        5       n/ n/ n/ n	U GHu  n [        5       n
[        5       nU R                  R                  [        U
5      n[        U[        5      (       d  [        SU 35      eU R                  R                  [        U5      n[        U[        5      (       d  [        SU 35      eTU;   d  TR                  U;   a  [        STR                   SU  35      eUR                  TU5        UR                  TR                  U5        UR                  [        U R                  5       5      5        UR                  [        U R!                  5       5      5        U	R                  [        U R#                  5       5      5        GMx     T" U/UQ70 UD6nUc  Un[        U[        R                  5      (       a  U/nO[        [	        U5      5      n/ n/ n/ nU H{  n UR                  [        U R                  5       5      5        UR                  [        U R!                  5       5      5        UR                  [        U R#                  5       5      5        M}     [%        U	5      n[%        U5      nUU:w  a  [        TR                   SU SU S35      eS[        [&           S	[        [&           S
[&        4S jn[)        UU5       H>  u  nnU" [	        UR+                  5       5      [	        UR+                  5       5      S5        M@     [)        UU5       H>  u  nnU" [	        UR+                  5       5      [	        UR+                  5       5      S5        M@     [)        U	U5       H>  u  nnU" [	        UR+                  5       5      [	        UR+                  5       5      S5        M@     U$ )Nz-Distributed composable API states corrupted: z/Distributed composable API registry corrupted: zOEach distinct composable distributed API can only be applied to a module once. z3 has already been applied to the following module:
zB should return the same number of modules as input modulesInputs: z modules
Outputs: z modulesÚ	orig_fqnsÚnew_fqnsÚ	check_keyc                 óÔ   • X:X  a  g [        U 5      [        U5      pCX4-
  nXC-
  n[        U5      (       d  [        U5      (       a  [        U SU SU 35      e[        U SU SU 35      e)NzVComposable distributed API implementations cannot modify FQNs.
FQNs only in original: z
FQNs only in new: z[Composable distributed API implementations cannot modify the order of FQNs.
Original FQNs: z
New FQNs: )ÚsetÚlenÚRuntimeError)r;   r<   r=   Úorig_fqn_setÚnew_fqn_setÚ	orig_onlyÚnew_onlys          r   Ú	check_fqnÚ;contract.<locals>.inner.<locals>.wrapper.<locals>.check_fqnº   s“   € ØÓ(Øä,/°	«N¼CÀ»M˜kØ(Ñ6�	Ø&Ñ5�Ü�y—>‘>¤S¨§]¡]Ü&Ø$˜+ð2Ø2;°ð =-Ø-5¨Jð8óð ô 'Ø$˜+ð*à*3¨ð 5%Ø%- Jð	0óð r   zChecking parameters: zChecking buffers: zChecking modules: )Ú
isinstancer4   r5   r   Úlistr   r   Ú__dict__Ú
setdefaultÚ	STATE_KEYÚdictÚAssertionErrorÚREGISTRY_KEYr   ÚappendÚnamed_parametersÚnamed_buffersÚnamed_modulesr@   r   ÚzipÚkeys)r0   r(   r)   Ú
inp_moduleÚmodulesr2   Úregistry_itemÚall_orig_named_paramsÚall_orig_named_buffersÚall_orig_named_modulesÚdefault_all_stateÚdefault_registryÚ	all_stateÚregistryÚupdatedÚupdated_modulesÚall_new_named_paramsÚall_new_named_buffersÚall_new_named_modulesÚnum_orig_modulesÚnum_new_modulesrF   Úorig_named_paramsÚnew_named_paramsÚorig_named_buffersÚnew_named_buffersÚorig_named_modulesÚnew_named_modulesr8   r6   s                               €€r   ÚwrapperÚ(contract.<locals>.inner.<locals>.wrapper`   sÒ  ø€ ð  ˆJä˜&¤"§)¡)×,Ñ,Ø!˜(‘ô ,¬D°«LÓ9�Ù“KˆEÜ(›NˆMð
 DFÐ!ØDFÐ"ØACÐ"ô "�Ü<G»MÐ!Ü<G»MÐ Ø4:·O±O×4NÑ4NÜÐ0ó5�	ô " )¬T×2Ñ2Ü(ØGÈ	À{ÐSóð ð 5;·O±O×4NÑ4NÜ Ð"2ó5�ô " (¬D×1Ñ1Ü(ØIÈ(ÈÐTóð ð ˜9Ó$¨¯©¸Ó(AÜ(ð(Ø(,¯© ð 7.Ø.4¨Xð7óð ð
 ×$Ñ$ T¨5Ô1Ø×#Ñ# D§M¡M°=ÔAð &×,Ñ,¬[¸×9PÑ9PÓ9RÓ-SÔTà&×-Ñ-¬k¸&×:NÑ:NÓ:PÓ.QÔRà&×-Ñ-¬k¸&×:NÑ:NÓ:PÓ.Q×Rñ? "ñB ˜:Ð7¨Ò7°Ñ7ˆGØ‰Ø$�ä˜'¤2§9¡9×-Ñ-Ø#* )‘ä"3´D¸Ó4DÓ"E�àBDÐ ØCEÐ!Ø@BÐ!ã)�à$×+Ñ+¬K¸×8OÑ8OÓ8QÓ,RÔSà%×,Ñ,¬[¸×9MÑ9MÓ9OÓ-PÔQà%×,Ñ,¬[¸×9MÑ9MÓ9OÓ-PÖQñ *ô  #Ð#9Ó:ÐÜ!Ð"7Ó8ˆOØ ?Ó2Ü$Ø—}‘}�oð &Ø/Ð0ð 1 Ø /Ð0°ð:óð ð¤T¬#¡Yð ¼$¼s¹)ð ÔPSô ô. 8;Ø%Ð';ö8Ñ3Ð!Ð#3ñ ÜÐ*×/Ñ/Ó1Ó2ÜÐ)×.Ñ.Ó0Ó1Ø+öñ8ô :=Ø&Ð(=ö:Ñ5Ð"Ð$5ñ ÜÐ+×0Ñ0Ó2Ó3ÜÐ*×/Ñ/Ó1Ó2Ø(öñ:ô :=Ø&Ð(=ö:Ñ5Ð"Ð$5ñ ÜÐ+×0Ñ0Ó2Ó3ÜÐ*×/Ñ/Ó1Ó2Ø(öñ:ð ˆNr   c                 ób   >• U R                   R                  [        0 5      R                  T5      $ r,   )rJ   rK   rL   Úget)r0   r8   s    €r   Ú	get_stateÚ*contract.<locals>.inner.<locals>.get_stateï   s+   ø€ Ø—?‘?×-Ñ-ÜØó÷ ‰c�$‹iðr   )	r   r$   r   r(   r)   r4   r5   r   r2   )r8   rm   rq   r6   s   `  €r   ÚinnerÚcontract.<locals>.inner\   sq   ù€ ô 
ˆt‹ðL	ÜðL	ä—7‘7ðL	ô —i‘iðL	ô ÷	L	ó 
ðL	ð\	œbŸi™ið 	¬F÷ 	ð "Œàˆr   )r   r   r   r$   r   r&   r"   )r6   rs   s   ` r   Úcontractru   -   sa   ø€ ô^ ˆ9ÓðZÜ”{¤2¤r 6Ñ*¬BÐ.Ñ/ðZä	”[¤¤R Ñ(¬"¬gÐ5Ñ	6öZó ðZðx €Lr   r0   c                 ó$   • [        U [        S5      $ )z¦
Get an ``OrderedDict`` of composable APIs that have been applied to the
``module``, indexed by the API name. If no API has been applied, then this
returns ``None``.
N)ÚgetattrrO   )r0   s    r   Ú_get_registryrx   ü   s   € ô �6œ<¨Ó.Ð.r   )Ú__composable_api_state_key)%r   Úcollectionsr   Úcollections.abcr   Ú	functoolsr   Útypingr   r   r   Útyping_extensionsr	   r
   ÚtorchÚtorch.nnr4   Ú#torch.distributed._composable_stater   Útorch.distributed.utilsr   r   r   r   rL   rO   r   r"   r5   rI   r$   r&   Útyperu   rM   r   rx   r   r   r   Ú<module>r„      s$  ðã Ý #Ý $Ý ß 1Ñ 1ß 0ã Ý Ý 6Ý 5ñ ˆT˜TÑ"€Ùˆtƒ_€ô+ñ Ó €	Ù!Ó#€÷	ñ 	ñ �) 8°tÑ
<€ÙˆT�2—9‘9˜d 2§9¡9™oÓ.€ô7�(˜G B¨¨G OÑ4ô 7ð  &ñLØ�G‰}ðLàØˆk˜"˜b˜&Ñ! 2Ð%Ñ&Ð'Ø�˜B ˜FÑ# R¨Ð0Ñ1ð3ñõLð^/˜"Ÿ)™)ð /¨¨S°,Ð->Ñ(?À$Ñ(Fõ /r   