+
    –°³jU!  ã                   ó  € ^ RI t ^ RIHt ^ RIHt ^ RIt^ RIHu Ht	 ^ RI
Hu Ht ^ RIHt ^ RIHt ^ RI
Ht ^RIHt R.t] P&                  ! ]4      t ! R R	4      t ! R
 R4      tR tR tR tR R ltR t ! R R4      tR# )é    N)Údefaultdict)ÚLock)ÚTensor)ÚRRef)Úfunctional_optim_mapÚDistributedOptimizerc                   ó8   a € ] tR t^t o R tV 3R lR ltRtV tR# )Ú_FunctionalLocalOptimizerc                óŽ   € V Uu. uF  qUP                  4       NK  	  upV n        V! V P                  .VO5/ VB V n        R # u upi ©N©Úlocal_valueÚ_local_paramsÚoptim©ÚselfÚ	optim_clsÚlocal_params_rrefÚargsÚkwargsÚrrefs   &&&*, Úb/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/distributed/optim/optimizer.pyÚ__init__Ú"_FunctionalLocalOptimizer.__init__   óD   € Ù=NÓOÑ=N°T×.Ñ.Ö0Ñ=NÑOˆÔÙ˜t×1Ñ1ÐC°DÒC¸FÑCˆŽ
ùò Pó   …Ac                ó    <€ V ^8„  d   QhRS[ /# )é   Úautograd_ctx_id)Úint)ÚformatÚ__classdict__s   "€r   Ú__annotate__Ú&_FunctionalLocalOptimizer.__annotate__   s   ø€ ÷ ñ ¡Cñ ó    c                óÄ   € \         P                  ! V4      pV P                   Uu. uF  pW29   d	   W#,          MR NK  	  ppV P                  P	                  V4       R # u upi r   )Údist_autogradÚget_gradientsr   r   Ústep)r   r   Úall_local_gradsÚpÚgradss   &&   r   r)   Ú_FunctionalLocalOptimizer.step   s^   € Ü'×5Ò5°oÓFˆð ×'Ò'ó&
á'�ð #$Ô"6ˆOÖ¸DÒ@Ù'ð 	ð &
ð
 	�
‰
�‰˜Öùò&
s   ¥A©r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r)   Ú__static_attributes__Ú__classdictcell__©r"   s   @r   r
   r
      s   ø‡ € òD÷ö r%   r
   c                   ó:   a € ] tR t^'t o ]! 4       tR tR tRtV t	R# )Ú_LocalOptimizerc                óŽ   € V Uu. uF  qUP                  4       NK  	  upV n        V! V P                  .VO5/ VB V n        R # u upi r   r   r   s   &&&*, r   r   Ú_LocalOptimizer.__init__1   r   r   c                ó  € \         P                  ! V4      p\        P                  ;_uu_ 4        VP	                  4        F  w  r4WCn        K  	  V P                  P                  4        R R R 4       R #   + '       g   i     R # ; ir   )r'   r(   r7   Úglobal_lockÚitemsÚgradr   r)   )r   r   r*   Úparamr=   s   &&   r   r)   Ú_LocalOptimizer.step5   sU   € Ü'×5Ò5°oÓFˆä×(×(Ó(Ø.×4Ñ4Ö6‘�Ø!–
ñ  7à�J‰J�O‰OÔ÷ )×(×(Ò(ús   ¯:A3Á3B	r.   N)
r/   r0   r1   r2   r   r;   r   r)   r3   r4   r5   s   @r   r7   r7   '   s   ø‡ € ñ “&€KòD÷ð r%   r7   c                 óH   € \         P                  ! \        W.VO5/ VB 4      # r   )Úrpcr   r7   )r   r   r   r   s   &&*,r   Ú_new_local_optimizerrB   >   s    € Ü�8Š8”O IÐRÀ4ÒRÈ6ÑRÓSÐSr%   c                 óH   € V P                  4       pVP                  V4       R # r   ©r   r)   ©Úlocal_optim_rrefr   Úlocal_optims   && r   Ú_local_optimizer_steprH   B   s   € Ø"×.Ñ.Ó0€KØ×Ñ�_Ö%r%   c                 óL   € \        W.VO5/ VB p\        P                  ! V4      # r   )r
   rA   r   )r   r   r   r   r   s   &&*, r   Ú_new_functional_local_optimizerrJ   G   s$   € Ü% iÐTÀTÒTÈVÑT€EÜ�8Š8�E‹?Ðr%   c                ó4   € V ^8„  d   QhR\         R\        RR/# )r   rF   r   ÚreturnN)r   r    )r!   s   "r   r#   r#   L   s$   € ÷ &ñ &Üð&Ü-0ð&à	ñ&r%   c                 óH   € V P                  4       pVP                  V4       R # r   rD   rE   s   && r   Ú _functional_local_optimizer_steprN   L   s    € ð #×.Ñ.Ó0€KØ×Ñ�_Ö%r%   c                 óÄ   € R p. pV  F#  p VP                  VP                  4       4       K%  	  Ve   VhV#   \         d   pTP                  T4       Tp R p?KS  R p?ii ; ir   )ÚappendÚwaitÚ	Exception)Úrpc_futsÚ	exceptionÚresultsÚfutÚes   &    r   Ú_wait_for_allrX   S   sb   € à€IØ€GÛˆð	Ø�N‰N˜3Ÿ8™8›:Ö&ñ ð ÒØˆØ€Nøô ô 	Ø�N‰N˜1ÔØŽIûð	ús   ‹6¶AÁAÁAc                   ó0   a € ] tR t^bt o RtR tR tRtV tR# )r   a	  
DistributedOptimizer takes remote references to parameters scattered
across workers and applies the given optimizer locally for each parameter.

This class uses :meth:`~torch.distributed.autograd.get_gradients` in order
to retrieve the gradients for specific parameters.

Concurrent calls to
:meth:`~torch.distributed.optim.DistributedOptimizer.step`,
either from the same or different clients, will
be serialized on each worker -- as each worker's optimizer can only work
on one set of gradients at a time. However, there is no guarantee that
the full forward-backward-optimizer sequence will execute for one client
at a time. This means that the gradients being applied may not correspond
to the latest forward pass executed on a given worker. Also, there is no
guaranteed ordering across workers.

`DistributedOptimizer` uses a functional optimizer internally when one is
available for the given ``optimizer_class``, so that optimizer updates are
not blocked by the Python Global Interpreter Lock (GIL) in the case of
multithreaded training (e.g. Distributed Model Parallel). This feature is
currently enabled for most optimizers.

Args:
    optimizer_class (optim.Optimizer): the class of optimizer to
        instantiate on each worker.
    params_rref (list[RRef]): list of RRefs to local or remote parameters
        to optimize.
    args: arguments to pass to the optimizer constructor on each worker.
    kwargs: arguments to pass to the optimizer constructor on each worker.

Example::
    >>> # xdoctest: +SKIP("distributed")
    >>> import torch.distributed.autograd as dist_autograd
    >>> import torch.distributed.rpc as rpc
    >>> from torch import optim
    >>> from torch.distributed.optim import DistributedOptimizer
    >>>
    >>> with dist_autograd.context() as context_id:
    >>>   # Forward pass.
    >>>   rref1 = rpc.remote("worker1", torch.add, args=(torch.ones(2), 3))
    >>>   rref2 = rpc.remote("worker1", torch.add, args=(torch.ones(2), 1))
    >>>   loss = rref1.to_here() + rref2.to_here()
    >>>
    >>>   # Backward pass.
    >>>   dist_autograd.backward(context_id, [loss.sum()])
    >>>
    >>>   # Optimizer.
    >>>   dist_optim = DistributedOptimizer(
    >>>      optim.SGD,
    >>>      [rref1, rref2],
    >>>      lr=0.05,
    >>>   )
    >>>   dist_optim.step(context_id)
c                ó~  € \         P                  P                  R 4       \        \        4      pV F(  pWVP                  4       ,          P                  V4       K*  	  V\        9   d8   \        P                  P                  '       d   \        P                  ! V4      pMTpWq8g  V n        V P                  '       d   \        pM\        P                  RV4       \         p. p	VP#                  4        F8  w  r«\$        P&                  ! V
VW{3V,           VR7      pV	P                  V4       K:  	  \)        V	4      V n        R# )z,torch.distributed.optim.DistributedOptimizera3  Creating the optimizer %s without a functional optimizer, this might result in slow computation time in multithreading environment(i.e. Distributed Model Parallel training on CPU) due to the Python's Global Interpreter Lock (GIL). Please file an issue if you need a functional optimizer for this optimizer. )r   r   N)ÚtorchÚ_CÚ_log_api_usage_oncer   ÚlistÚownerrP   r   ÚjitÚ_stateÚ_enabledÚgetÚis_functional_optimrJ   ÚloggerÚwarningrB   r<   rA   Ú	rpc_asyncrX   Úremote_optimizers)r   Úoptimizer_classÚparams_rrefr   r   Úper_worker_params_rrefr>   Ú
optim_ctorÚoptimizer_new_funcÚremote_optim_futsÚworkerÚparam_rrefsÚremote_optim_rref_futs   &&&*,        r   r   ÚDistributedOptimizer.__init__›   s  € Ü�‰×$Ñ$Ð%SÔTÜ!,¬TÓ!2ÐÛ ˆEØ"§;¡;£=Õ1×8Ñ8¸Ö?ñ !ð Ô2Ô2´s·z±z×7J×7JÐ7JÜ-×1Ò1°/ÓB‰Jà(ˆJØ#-Ñ#@ˆÔ à×#×#Ð#Ü!@Ñä�N‰Nð<ð
  ôô "6ÐàÐØ#9×#?Ñ#?Ö#AÑˆFÜ$'§M¢MØØ"Ø Ð.°Õ5Øô	%Ð!ð ×$Ñ$Ð%:Ö;ñ $Bô "/Ð/@Ó!AˆÖr%   c           	     ó  € \         P                  ! V4       V P                  '       d   \        M\        pV P
                   Uu. uF+  p\        P                  ! VP                  4       VW13R7      NK-  	  pp\        V4       R# u upi )aÕ  
Performs a single optimization step.

This will call :meth:`torch.optim.Optimizer.step` on each worker
containing parameters to be optimized, and will block until all workers
return. The provided ``context_id`` will be used to retrieve the
corresponding :class:`~torch.distributed.autograd.context` that
contains the gradients that should be applied to the parameters.

Args:
    context_id: the autograd context id for which we should run the
        optimizer step.
)r   N)
r'   Ú_is_valid_contextrd   rN   rH   rh   rA   rg   r_   rX   )r   Ú
context_idÚoptimizer_step_funcÚ	optimizerrS   s   &&   r   r)   ÚDistributedOptimizer.stepÀ   s„   € ô 	×'Ò'¨
Ô3ð ×'×'Ð'õ -ä&ð 	ð "×3Ò3ó
ñ 4�	ô �MŠMØ—‘Ó!Ø#ØÐ,÷ñ
 4ð 	ð 
ô 	�hÖùò
s   Á1B)rd   rh   N)	r/   r0   r1   r2   Ú__doc__r   r)   r3   r4   r5   s   @r   r   r   b   s   ø‡ € ñ6òp#B÷J ð  r%   )ÚloggingÚcollectionsr   Ú	threadingr   r[   Útorch.distributed.autogradÚdistributedÚautogradr'   Útorch.distributed.rpcrA   Ú	torch.jitr`   r   r   Úutilsr   Ú__all__Ú	getLoggerr/   re   r
   r7   rB   rH   rJ   rN   rX   r   © r%   r   Ú<module>r†      s}   ðã Ý #Ý ã ß 2Ð 2ß #Ð #Ý Ý Ý &å 'ð "Ð
"€à	×	Ò	˜8Ó	$€÷ñ ÷$ñ ò.Tò&ò
õ
&ò÷| ó | r%   