+
    –°³j¾  ã                   óì   € ^ RI t ^ RIt^ RIHtHt ^ RIHtHt ^ RI	H
t
 ^ RIHtHt ^ RIHtHt ]! R4      t ! R R	4      t ! R
 R]4      t]
RR R ll4       t]
RR R ll4       tRR R lltR R ltR# )é    N)ÚCallableÚIterable)ÚEmptyÚQueue)Úoverload)ÚTypeVarTupleÚUnpack)ÚDeviceContextÚget_device_contextÚ_Tsc                   óV   a € ] tR t^t o V 3R lR ltV 3R lR ltV 3R lR ltRtV tR# )	ÚClosureHandlerc                ó   <€ V ^8„  d   QhRR/# ©é   ÚreturnN© )ÚformatÚ__classdict__s   "€ÚT/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/_lazy/closure.pyÚ__annotate__ÚClosureHandler.__annotate__   s   ø€ ÷ ñ ˜$ñ ó    c                ó   € R # ©Nr   )Úselfs   &r   Ú__init__ÚClosureHandler.__init__   s   € Ùr   c                ó8   <€ V ^8„  d   QhRS[ . S[3,          RR/# ©r   Úclosurer   N©r   Úobject)r   r   s   "€r   r   r      s$   ø€ ÷ ñ ™8 B© JÕ/ð °Dñ r   c                ó   € V! 4        R# )z>Run closure function

Args:
closure: callable function to run
Nr   )r   r!   s   &&r   ÚrunÚClosureHandler.run   s	   € ñ 	Ž	r   c                óH   <€ V ^8„  d   QhRS[ S[. S[3,          ,          RR/# )r   Úclosuresr   N)r   r   r#   )r   r   s   "€r   r   r      s)   ø€ ÷ ñ ¡©(°2±v°:Õ*>Õ!?ð ÀDñ r   c                ó:   € V F  pV P                  V4       K  	  R # r   )r%   )r   r(   r!   s   && r   Ú__call__ÚClosureHandler.__call__   s   € ÛˆGØ�H‰H�WÖó  r   r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r%   r*   Ú__static_attributes__Ú__classdictcell__)r   s   @r   r   r      s#   ø‡ € ÷ð ÷ð ÷ö r   r   c                   ój   a a€ ] tR t^t oRtR	V3R lV 3R llltV3R lR ltV3R lR ltRtVt	V ;t
# )
ÚAsyncClosureHandleraM  Handler for Asynchronous Step Closures
Args:
    max_queue_size: The maximum length of the closure queue after which
    the training loop will block until closures are evaluated.
    By default, a reasonable limit of a maximum of 100 on the queue.
    This value can be set using the `XLA_MAX_ASYNC_QUEUE` environment
    variable.
c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   Úmax_queue_sizer   N)Úint)r   r   s   "€r   r   Ú AsyncClosureHandler.__annotate__)   s   ø€ ÷ Añ A¡sð A°Tñ Ar   c                ó&  <€ \         SV `  4        \        \        \        P
                  P                  R V4      4      4      V n        \        4       V n        \        P                  ! 4       V n        \        P                  ! 4       V n        RV n        R# )ÚLTC_MAX_ASYNC_QUEUEN)Úsuperr   r   r6   ÚosÚenvironÚgetÚ_closure_queueÚ_closure_exceptionÚ	threadingÚLockÚ_closure_lockÚEventÚ_closure_event_loop_finishedÚ_closure_event_loop)r   r5   Ú	__class__s   &&€r   r   ÚAsyncClosureHandler.__init__)   se   ø€ Ü‰ÑÔÜ;@Ü”—
‘
—‘Ð4°nÓEÓFó<
ˆÔô 5:³GˆÔÜ&Ÿ^š^Ó-ˆÔÜ,5¯OªOÓ,=ˆÔ)Ø<@ˆÖ r   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r7   3   s   ø€ ÷ -ñ - $ñ -r   c                ó¦   a € S P                   fB   R V 3R llp\        P                  ! VR7      S n         S P                   P                  4        R# R# )z'Start closure event loop if not startedNc                ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   Ú:AsyncClosureHandler.start_event_loop.<locals>.__annotate__7   s   € ÷ ñ  ñ r   c                  óü  <€   SP                   P                  R ^R7      p V ! 4        SP                   P                  4        KB    \         d~    SP                  ;_uu_ 4        SP                   P                  4       '       d'   SP                  P                  4         RRR4        R#  RRR4        K´    + '       g   i      KÆ  ; i\         d'   pSP                  P                  T4        Rp?R# Rp?ii ; i)T)ÚblockÚtimeoutN)r>   r=   Ú	task_doneÚ
EmptyQueuerB   ÚemptyrD   ÚsetÚ	Exceptionr?   Úput)r!   Úer   s     €r   Ú
event_loopÚ8AsyncClosureHandler.start_event_loop.<locals>.event_loop7   s¾   ø€ àðØ"&×"5Ñ"5×"9Ñ"9ÀÈaÐ"9Ó"P˜Ùœ	Ø×+Ñ+×5Ñ5Ö7øÜ%ô 'Ø!×/×/Ó/Ø#×2Ñ2×8Ñ8×:Ò:Ø $× AÑ A× EÑ EÔ GØ &÷ 0Ò/Ø:÷ 0×/×/Ô/úô %ô Ø×/Ñ/×3Ñ3°AÔ6ÝûðúsA   „>A ÁC;Á#<B6ÂC;Â+C;Â6CÃC;ÃC;ÃC;ÃC6Ã6C;)Útarget)rE   r@   ÚThreadÚstart)r   rV   s   f r   Ústart_event_loopÚ$AsyncClosureHandler.start_event_loop3   sE   ø€ à×#Ñ#Ò+÷ð ô  (1×'7Ò'7¸zÔ'JˆDÔ$Ø×$Ñ$×*Ñ*Ö,ñ' ,r   c                ó8   <€ V ^8„  d   QhRS[ . S[3,          RR/# r    r"   )r   r   s   "€r   r   r7   J   s$   ø€ ÷ ,ñ ,™8 B© JÕ/ð ,°Dñ ,r   c                ó   € V P                   ;_uu_ 4        V P                  P                  VR R7       V P                  e!   V P                  P	                  4       '       g*    V P
                  P                  RR7      p\        R4      VhRRR4       R#   \         d    RT n        T P                  4         L.i ; i  + '       g   i     R# ; i)T)rM   NFzBCannot run asynchronous closure due to previously raised exception)
rB   r>   rT   rE   Úis_aliver?   r=   ÚRuntimeErrorrP   r[   )r   r!   rU   s   && r   r%   ÚAsyncClosureHandler.runJ   s²   € Ø××ÓØ×Ñ×#Ñ# G°4Ð#Ô8à×(Ñ(Ò0Ø×/Ñ/×8Ñ8×:Ò:ð,Ø×/Ñ/×3Ñ3¸%Ð3Ó@�AÜ&Ø\óàð÷  Ñøô "ô ,Ø/3�DÔ,Ø×)Ñ)Ö+ð,ú÷  ×Ðús*   •AB<Á"(BÂ"B9Â6B<Â8B9Â9B<Â<C	)rE   rD   r?   rB   r>   )éd   )r,   r-   r.   r/   Ú__doc__r   r[   r%   r0   r1   Ú__classcell__)rF   r   s   @@r   r3   r3      s/   ù‡ € ñ÷Aõ A÷-ð -÷.,÷ ,ð ,r   r3   c                óh   € V ^8„  d   QhR\         . \        3,          R\        R,          R\        RR/# )r   r!   ÚargsÚ	run_asyncr   Nr   ©r   r#   ÚtupleÚbool)r   s   "r   r   r   \   s=   € ÷ ñ Ü�bœ&�jÕ!ðä
��)ðô ðð 
ñ	r   c                 ó   € R # r   r   ©r!   rf   rg   s   &&&r   Úadd_step_closurerm   [   ó   € ñ
 r   c                ó¦   € V ^8„  d   QhR\         \        \        ,          .\        3,          R\        \        \        ,          ,          R\
        RR/# )r   r!   rf   rg   r   N)r   r	   r   r#   ri   rj   )r   s   "r   r   r   b   sI   € ÷ ñ Ü”vœc•{�m¤VÐ+Õ,ðä
””s•Õ
ðô ðð 
ñ	r   c                 ó   € R # r   r   rl   s   &&&r   rm   rm   a   rn   r   c                ót   € V ^8„  d   QhR\         R\        3,          R\        \        R3,          R\        RR/# )r   r!   .rf   rg   r   Nrh   )r   s   "r   r   r   g   sB   € ÷ !5ñ !5Ü�cœ6�kÕ"ð!5ä
”˜�Õ
ð!5ô ð!5ð 
ñ	!5r   c                ó    a € \        4       pV'       d   RMRp\        W4R4      pVf   . p\        W4V4       VP                  V3V 3R ll4       R# )a�  Adds a closure to the list of the ones to be run at the end of the step.
Many times during model training there is the need to print/report (print to
console, post to tensorboard, etc...) information which require the content of
intermediary tensors to be inspected.
Inspecting different tensors content in different points of the model code
requires many executions and typically causes performance issues.
Adding a step closure will ensure that it will be run after the barrier, when
all the live tensors will be already materialized to device data.
Live tensors which will include the ones captured by the closure arguments.
So using `add_step_closure()` will ensure a single execution will be
performed, even when multiple closures are queued, requiring multiple tensors
to be inspected.
Step closures will be run sequentially in the order they have been queued.
Note that even though using this API the execution will be optimized, it is
advised to throttle the printing/reporting events once every N steps.
Args:
  closure (callable): The function to be called.
  args (tuple): The arguments to be passed to the closure.
  run_async: If True, run the closure asynchronously.
Úasync_step_closuresÚstep_closuresNc                 ó   <€ S! V !  # r   r   )Úar!   s   &€r   Ú<lambda>Ú"add_step_closure.<locals>.<lambda>ˆ   s	   ø€ ©°ªr   )r   ÚgetattrÚsetattrÚappend)r!   rf   rg   ÚdevctxÚclosures_typert   s   f&&   r   rm   rm   g   sN   ø€ ô2  Ó!€Fß-6Ñ)¸O€MÜ7>Ø˜tó8€Mð ÒØˆÜ� }Ô5Ø×Ñ $Ö3Ö4r   c                ó$   € V ^8„  d   QhR\         /# )r   r   )r
   )r   s   "r   r   r   ‹   s   € ÷ ñ œ=ñ r   c                  ó  € \        4       p \        V R R4      pVe1   . V n        \        V RR4      pVf   \        4       pW n        V! V4       \        V RR4      pVe1   . V n        \        V RR4      pVf   \        4       pW@n        V! V4       V # )rs   NÚasync_closure_handlerrt   Úclosure_handler)r   ry   rs   r3   r€   rt   r   r�   )r|   rs   r€   rt   r�   s        r   Úrun_step_closuresr‚   ‹   s¢   € ÜÓ!€FÜ! &Ð*?ÀÓFÐØÒ&Ø%'ˆÔ"Ü '¨Ð0GÈÓ NÐØ Ò(Ü$7Ó$9Ð!Ø+@Ô(ÙÐ1Ô2ä˜F O°TÓ:€MØÒ Ø!ˆÔÜ! &Ð*;¸TÓBˆØÒ"Ü,Ó.ˆOØ%4Ô"Ù˜Ô&Ø€Mr   )r   F)F)r;   r@   Úcollections.abcr   r   Úqueuer   rP   r   Útypingr   Útyping_extensionsr   r	   Útorch._lazy.device_contextr
   r   r   r   r3   rm   r‚   r   r   r   Ú<module>rˆ      sp   ðÛ 	Û ß .ß ,Ý ß 2ç Hñ �5Ó€÷ñ ô"9,˜.ô 9,ðx 
öó 
ðð
 
öó 
ð÷
!5÷Hr   