§
    “©ºj[   ã                   óê   — d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	 ddl
mZ ddlZddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ  ej        e¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZdS )z
Timer
^^^^^
é    N)Ú	timedelta)ÚAnyÚOptionalÚUnion)Úoverride)ÚCallback©ÚRunningStage)ÚLightningEnum)ÚMisconfigurationException)Úrank_zero_infoc                   ó   — e Zd ZdZdZdS )ÚIntervalÚstepÚepochN)Ú__name__Ú
__module__Ú__qualname__r   r   © ó    úq/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/pytorch_lightning/callbacks/timer.pyr   r   %   s   € € € € € Ø€DØ€E€E€Er   r   c            	       ó|  ‡ — e Zd ZdZdej        dfdeeee	e
eef         f                  dededdfˆ fd„Zej        fd	edee         fd
„Zej        fd	edee         fd„Zej        fd	edefd„Zej        fd	edee         fd„Zed!d„¦   «         Zed!d„¦   «         Zed!d„¦   «         Zed!d„¦   «         Zed!d„¦   «         Zed!d„¦   «         Zedddededdfd„¦   «         Zedddededdfd„¦   «         Zedddededdfd„¦   «         Zede
eef         fd„¦   «         Z ede
eef         ddfd„¦   «         Z!d"d „Z"ˆ xZ#S )#ÚTimeraß  The Timer callback tracks the time spent in the training, validation, and test loops and interrupts the Trainer
    if the given time limit for the training loop is reached.

    Args:
        duration: A string in the format DD:HH:MM:SS (days, hours, minutes seconds), or a :class:`datetime.timedelta`,
            or a dict containing key-value compatible with :class:`~datetime.timedelta`.
        interval: Determines if the interruption happens on epoch level or mid-epoch.
            Can be either ``"epoch"`` or ``"step"``.
        verbose: Set this to ``False`` to suppress logging messages.

    Raises:
        MisconfigurationException:
            If ``duration`` is not in the expected format.
        MisconfigurationException:
            If ``interval`` is not one of the supported choices.

    Example::

        from pytorch_lightning import Trainer
        from pytorch_lightning.callbacks import Timer

        # stop training after 12 hours
        timer = Timer(duration="00:12:00:00")

        # or provide a datetime.timedelta
        from datetime import timedelta
        timer = Timer(duration=timedelta(weeks=1))

        # or provide a dictionary
        timer = Timer(duration=dict(weeks=4, days=2))

        # force training to stop after given time limit
        trainer = Trainer(callbacks=[timer])

        # query training/validation/test time (in seconds)
        timer.time_elapsed("train")
        timer.start_time("validate")
        timer.end_time("test")

    NTÚdurationÚintervalÚverboseÚreturnc           
      óè  •— t          ¦   «                              ¦   «          t          |t          ¦  «        rÐt	          j        d|                     ¦   «         ¦  «        }|st          d|›d�¦  «        ‚t          t          | 
                    d¦  «        ¦  «        t          | 
                    d¦  «        ¦  «        t          | 
                    d¦  «        ¦  «        t          | 
                    d¦  «        ¦  «        ¬¦  «        }n!t          |t          ¦  «        rt          di |¤Ž}|t          t          ¦  «        vr:t          d	|› d
d                     t          t          ¦  «        ¦  «        › �¦  «        ‚|�|                     ¦   «         nd | _        || _        || _        t                               t(          ¦  «        | _        t                               t(          ¦  «        | _        d| _        d S )Nz(\d+):(\d\d):(\d\d):(\d\d)z`Timer(duration=zH)` is not a valid duration. Expected a string in the format DD:HH:MM:SS.é   é   é   é   )ÚdaysÚhoursÚminutesÚsecondsz,Unsupported parameter value `Timer(interval=z)`. Possible choices are: z, r   r   )ÚsuperÚ__init__Ú
isinstanceÚstrÚreÚ	fullmatchÚstripr   r   ÚintÚgroupÚdictÚsetr   ÚjoinÚtotal_secondsÚ	_durationÚ	_intervalÚ_verboseÚfromkeysr
   Ú_start_timeÚ	_end_timeÚ_offset)Úselfr   r   r   Úduration_matchÚ	__class__s        €r   r(   zTimer.__init__T   sÒ  ø€ õ 	‰Œ×ÒÑÔÐÝ�h¥Ñ$Ô$ð 	-Ýœ\Ð*GÈÏÊÑIYÔIYÑZÔZˆNØ!ð Ý/ðC xð Cð Cð Cñô ð õ !Ý˜×-Ò-¨aÑ0Ô0Ñ1Ô1Ý˜.×.Ò.¨qÑ1Ô1Ñ2Ô2Ý˜N×0Ò0°Ñ3Ô3Ñ4Ô4Ý˜N×0Ò0°Ñ3Ô3Ñ4Ô4ð	ñ ô ˆHˆHõ ˜¥$Ñ'Ô'ð 	-Ý Ð,Ð, 8Ð,Ð,ˆHØ�3�x™=œ=Ð(Ð(Ý+ð/¸xð /ð /Ø—I’I�c¥(™mœmÑ,Ô,ð/ð /ñô ð ð 6>Ð5I˜×/Ò/Ñ1Ô1Ð1ÈtˆŒØ!ˆŒØˆŒÝ@DÇÂÍlÑ@[Ô@[ˆÔÝ>B¿mºmÍLÑ>YÔ>YˆŒØˆŒˆˆr   Ústagec                 ó:   — t          |¦  «        }| j        |         S )z8Return the start time of a particular stage (in seconds))r
   r8   ©r;   r>   s     r   Ú
start_timezTimer.start_timev   s   € å˜UÑ#Ô#ˆØÔ Ô&Ð&r   c                 ó:   — t          |¦  «        }| j        |         S )z6Return the end time of a particular stage (in seconds))r
   r9   r@   s     r   Úend_timezTimer.end_time{   s   € å˜UÑ#Ô#ˆØŒ~˜eÔ$Ð$r   c                 óÖ   — |                       |¦  «        }|                      |¦  «        }|t          j        k    r| j        nd}|€|S |€t          j        ¦   «         |z
  |z   S ||z
  |z   S )z;Return the time elapsed for a particular stage (in seconds)r   )rA   rC   r
   ÚTRAININGr:   ÚtimeÚ	monotonic)r;   r>   ÚstartÚendÚoffsets        r   Útime_elapsedzTimer.time_elapsed€   sr   € à—’ Ñ&Ô&ˆØ�mŠm˜EÑ"Ô"ˆØ!&­,Ô*?Ò!?Ð!?�”�ÀQˆØˆ=ØˆMØˆ;Ý”>Ñ#Ô# eÑ+¨fÑ4Ð4Ø�U‰{˜VÑ#Ð#r   c                 óN   — | j         �| j         |                      |¦  «        z
  S dS )z=Return the time remaining for a particular stage (in seconds)N)r4   rK   r@   s     r   Útime_remainingzTimer.time_remaining‹   s*   € àŒ>Ð%Ø”> D×$5Ò$5°eÑ$<Ô$<Ñ<Ð<Øˆtr   Útrainerú
pl.TrainerÚ	pl_moduleúpl.LightningModulec                 óP   — t          j        ¦   «         | j        t          j        <   d S ©N)rF   rG   r8   r
   rE   ©r;   rN   rP   s      r   Úon_train_startzTimer.on_train_start‘   s    € å26´.Ñ2BÔ2BˆÔ�Ô.Ñ/Ð/Ð/r   c                 óP   — t          j        ¦   «         | j        t          j        <   d S rS   )rF   rG   r9   r
   rE   rT   s      r   Úon_train_endzTimer.on_train_end•   s   € å04´Ñ0@Ô0@ˆŒ•|Ô,Ñ-Ð-Ð-r   c                 óP   — t          j        ¦   «         | j        t          j        <   d S rS   )rF   rG   r8   r
   Ú
VALIDATINGrT   s      r   Úon_validation_startzTimer.on_validation_start™   s    € å48´NÑ4DÔ4DˆÔ�Ô0Ñ1Ð1Ð1r   c                 óP   — t          j        ¦   «         | j        t          j        <   d S rS   )rF   rG   r9   r
   rY   rT   s      r   Úon_validation_endzTimer.on_validation_end�   s   € å26´.Ñ2BÔ2BˆŒ•|Ô.Ñ/Ð/Ð/r   c                 óP   — t          j        ¦   «         | j        t          j        <   d S rS   )rF   rG   r8   r
   ÚTESTINGrT   s      r   Úon_test_startzTimer.on_test_start¡   s    € å15´Ñ1AÔ1AˆÔ�Ô-Ñ.Ð.Ð.r   c                 óP   — t          j        ¦   «         | j        t          j        <   d S rS   )rF   rG   r9   r
   r^   rT   s      r   Úon_test_endzTimer.on_test_end¥   s   € å/3¬~Ñ/?Ô/?ˆŒ•|Ô+Ñ,Ð,Ð,r   ÚargsÚkwargsc                 óB   — | j         €d S |                      |¦  «         d S rS   )r4   Ú_check_time_remaining©r;   rN   rb   rc   s       r   Úon_fit_startzTimer.on_fit_start©   s+   € ð Œ>Ð!ØˆFØ×"Ò" 7Ñ+Ô+Ð+Ð+Ð+r   c                 ól   — | j         t          j        k    s| j        €d S |                      |¦  «         d S rS   )r5   r   r   r4   re   rf   s       r   Úon_train_batch_endzTimer.on_train_batch_end±   s7   € àŒ>�Xœ]Ò*Ð*¨d¬nÐ.DØˆFØ×"Ò" 7Ñ+Ô+Ð+Ð+Ð+r   c                 ól   — | j         t          j        k    s| j        €d S |                      |¦  «         d S rS   )r5   r   r   r4   re   rf   s       r   Úon_train_epoch_endzTimer.on_train_epoch_end·   s7   € àŒ>�Xœ^Ò+Ð+¨t¬~Ð/EØˆFØ×"Ò" 7Ñ+Ô+Ð+Ð+Ð+r   c                 ó.   ‡ — dˆ fd„t           D ¦   «         iS )NrK   c                 óF   •— i | ]}|j         ‰                     |¦  «        “ŒS r   )ÚvaluerK   )Ú.0r>   r;   s     €r   ú
<dictcomp>z$Timer.state_dict.<locals>.<dictcomp>¿   s+   ø€ Ð aÐ aÐ aÈ5 ¤¨d×.?Ò.?ÀÑ.FÔ.FÐ aÐ aÐ ar   r	   )r;   s   `r   Ú
state_dictzTimer.state_dict½   s$   ø€ àÐ aÐ aÐ aÐ aÕT`Ð aÑ aÔ aÐbÐbr   rq   c                 ó†   — |                      di ¦  «        }|                      t          j        j        d¦  «        | _        d S )NrK   r   )Úgetr
   rE   rn   r:   )r;   rq   rK   s      r   Úload_state_dictzTimer.load_state_dictÁ   s6   € à!—~’~ n°bÑ9Ô9ˆØ#×'Ò'­Ô(=Ô(CÀQÑGÔGˆŒˆˆr   c                 óV  — | j         €J ‚|                      ¦   «         | j         k    }|j                             |¦  «        }|j        p||_        |rV| j        rQt          t          |                      t          j	        ¦  «        ¦  «        ¬¦  «        }t          d|› d�¦  «         d S d S d S )N)r&   z$Time limit reached. Elapsed time is z. Signaling Trainer to stop.)r4   rK   ÚstrategyÚ	broadcastÚshould_stopr6   r   r.   r
   rE   r   )r;   rN   rx   Úelapseds       r   re   zTimer._check_time_remainingÆ   sÂ   € ØŒ~Ð)Ð)Ð)Ø×'Ò'Ñ)Ô)¨T¬^Ò;ˆØÔ&×0Ò0°Ñ=Ô=ˆØ%Ô1Ð@°[ˆÔØð 	i˜4œ=ð 	iÝ­¨D×,=Ò,=½lÔ>SÑ,TÔ,TÑ(UÔ(UÐVÑVÔVˆGÝÐgÀ'ÐgÐgÐgÑhÔhÐhÐhÐhð	ið 	ið 	ið 	ir   )rN   rO   rP   rQ   r   N)rN   rO   r   N)$r   r   r   Ú__doc__r   r   r   r   r*   r   r0   r.   Úboolr(   r
   rE   ÚfloatrA   rC   rK   rM   r   rU   rW   rZ   r\   r_   ra   r   rg   ri   rk   rq   rt   re   Ú__classcell__)r=   s   @r   r   r   *   s  ø€ € € € € ð'ð 'ðV EIØ œØð	 ð  à˜5  i°°c¸3°h´Ð!?Ô@ÔAð ð ð ð ð	 ð
 
ð ð  ð  ð  ð  ð  ðD '3Ô&;ð 'ð ' ð 'ÀÈÄð 'ð 'ð 'ð 'ð
 %1Ô$9ð %ð %˜cð %¸hÀu¼oð %ð %ð %ð %ð
 )5Ô(=ð 	$ð 	$ #ð 	$À%ð 	$ð 	$ð 	$ð 	$ð +7Ô*?ð ð  Cð ÀHÈUÄOð ð ð ð ð ðCð Cð Cñ „XðCð ðAð Að Añ „XðAð ðEð Eð Eñ „XðEð ðCð Cð Cñ „XðCð ðBð Bð Bñ „XðBð ð@ð @ð @ñ „Xð@ð ð, Lð ,¸ð ,Èð ,ÐPTð ,ð ,ð ,ñ „Xð,ð ð,¨,ð ,¸sð ,Ècð ,ÐVZð ,ð ,ð ,ñ „Xð,ð
 ð,¨,ð ,¸sð ,Ècð ,ÐVZð ,ð ,ð ,ñ „Xð,ð
 ðc˜D  c œNð cð cð cñ „Xðcð ðH¨$¨s°C¨x¬.ð H¸Tð Hð Hð Hñ „XðHðið ið ið ið ið ið ið ir   r   )rz   Úloggingr+   rF   Údatetimer   Útypingr   r   r   Útyping_extensionsr   Úpytorch_lightningÚplÚ$pytorch_lightning.callbacks.callbackr   Ú pytorch_lightning.trainer.statesr
   Úpytorch_lightning.utilitiesr   Ú&pytorch_lightning.utilities.exceptionsr   Ú%pytorch_lightning.utilities.rank_zeror   Ú	getLoggerr   Úlogr   r   r   r   r   ú<module>r‹      sX  ððð ð
 €€€Ø 	€	€	€	Ø €€€Ø Ð Ð Ð Ð Ð Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à &Ð &Ð &Ð &Ð &Ð &à Ð Ð Ð Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø LÐ LÐ LÐ LÐ LÐ LØ @Ð @Ð @Ð @Ð @Ð @à€gÔ˜Ñ!Ô!€ðð ð ð ð ˆ}ñ ô ð ð
cið cið cið cið ciˆHñ ciô cið cið cið cir   