§
    “©ºjò  ã                   óz   — d Z ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
mZ ddlmZ ddlmZ  G d	„ d
e¦  «        ZdS )zD
LearningRateFinder
==================

Finds optimal learning rate
é    )ÚOptional)ÚoverrideN)ÚCallback)Ú_lr_findÚ	_LRFinder)Ú_TunerExitException)Úisolate_rngc                   óz   — e Zd ZdZdZ	 	 	 	 	 	 	 dd
ededededee         de	deddfd„Z
dd„Zedd„¦   «         ZdS )ÚLearningRateFindera}  The ``LearningRateFinder`` callback enables the user to do a range test of good initial learning rates, to
    reduce the amount of guesswork in picking a good starting learning rate.

    .. warning::  This is an :ref:`experimental <versioning:Experimental API>` feature.

    Args:
        min_lr: Minimum learning rate to investigate
        max_lr: Maximum learning rate to investigate
        num_training_steps: Number of learning rates to test
        mode: Search strategy to update learning rate after each batch:

            - ``'exponential'`` (default): Increases the learning rate exponentially.
            - ``'linear'``: Increases the learning rate linearly.

        early_stop_threshold: Threshold for stopping the search. If the
            loss at any point is larger than early_stop_threshold*best_loss
            then the search is stopped. To disable, set to None.
        update_attr: Whether to update the learning rate attribute or not.
        attr_name: Name of the attribute which stores the learning rate. The names 'learning_rate' or 'lr' get
            automatically detected. Otherwise, set the name here.

    Example::

        # Customize LearningRateFinder callback to run at different epochs.
        # This feature is useful while fine-tuning models.
        from pytorch_lightning.callbacks import LearningRateFinder


        class FineTuneLearningRateFinder(LearningRateFinder):
            def __init__(self, milestones, *args, **kwargs):
                super().__init__(*args, **kwargs)
                self.milestones = milestones

            def on_fit_start(self, *args, **kwargs):
                return

            def on_train_epoch_start(self, trainer, pl_module):
                if trainer.current_epoch in self.milestones or trainer.current_epoch == 0:
                    self.lr_find(trainer, pl_module)


        trainer = Trainer(callbacks=[FineTuneLearningRateFinder(milestones=(5, 10))])
        trainer.fit(...)

    Raises:
        MisconfigurationException:
            If learning rate/lr in ``model`` or ``model.hparams`` isn't overridden, or if you are using more than
            one optimizer.

    )ÚlinearÚexponentialç:Œ0âŽyE>é   éd   r   ç      @TÚ Úmin_lrÚmax_lrÚnum_training_stepsÚmodeÚearly_stop_thresholdÚupdate_attrÚ	attr_nameÚreturnNc                 óì   — |                      ¦   «         }|| j        vrt          d| j        › �¦  «        ‚|| _        || _        || _        || _        || _        || _        || _	        d| _
        d | _        d S )Nz`mode` should be either of F)ÚlowerÚSUPPORTED_MODESÚ
ValueErrorÚ_min_lrÚ_max_lrÚ_num_training_stepsÚ_modeÚ_early_stop_thresholdÚ_update_attrÚ
_attr_nameÚ_early_exitÚ
optimal_lr)Úselfr   r   r   r   r   r   r   s           úu/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/pytorch_lightning/callbacks/lr_finder.pyÚ__init__zLearningRateFinder.__init__V   s€   € ð �zŠz‰|Œ|ˆØ�tÔ+Ð+Ð+ÝÐQ¸4Ô;OÐQÐQÑRÔRÐRàˆŒØˆŒØ#5ˆÔ ØˆŒ
Ø%9ˆÔ"Ø'ˆÔØ#ˆŒà ˆÔØ/3ˆŒˆˆó    Útrainerú
pl.TrainerÚ	pl_moduleúpl.LightningModulec                 óü   — t          ¦   «         5  t          ||| j        | j        | j        | j        | j        | j        | j        ¬¦	  «	        | _	        d d d ¦  «         n# 1 swxY w Y   | j
        rt          ¦   «         ‚d S )N)r   r   Únum_trainingr   r   r   r   )r	   r   r   r    r!   r"   r#   r$   r%   r'   r&   r   ©r(   r,   r.   s      r)   Úlr_findzLearningRateFinder.lr_findo   sÆ   € Ý‰]Œ]ð 	ð 	Ý&ØØØ”|Ø”|Ø!Ô5Ø”ZØ%)Ô%?Ø Ô-Øœ/ð
ñ 
ô 
ˆDŒOð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð Ôð 	(Ý%Ñ'Ô'Ð'ð	(ð 	(s   �AAÁA Á#A c                 ó2   — |                       ||¦  «         d S )N)r3   r2   s      r)   Úon_fit_startzLearningRateFinder.on_fit_start€   s   € à�Š�W˜iÑ(Ô(Ð(Ð(Ð(r+   )r   r   r   r   r   Tr   )r,   r-   r.   r/   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚfloatÚintÚstrr   Úboolr*   r3   r   r5   © r+   r)   r   r       sÜ   € € € € € ð1ð 1ðf 0€Oð ØØ"%Ø!Ø03Ø Øð4ð 4àð4ð ð4ð  ð	4ð
 ð4ð ' uœoð4ð ð4ð ð4ð 
ð4ð 4ð 4ð 4ð2(ð (ð (ð (ð" ð)ð )ð )ñ „Xð)ð )ð )r+   r   )r9   Útypingr   Útyping_extensionsr   Úpytorch_lightningÚplÚ$pytorch_lightning.callbacks.callbackr   Ú!pytorch_lightning.tuner.lr_finderr   r   Ú&pytorch_lightning.utilities.exceptionsr   Ú pytorch_lightning.utilities.seedr	   r   r>   r+   r)   ú<module>rG      sÍ   ððð ð Ð Ð Ð Ð Ð à &Ð &Ð &Ð &Ð &Ð &à Ð Ð Ð Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø AÐ AÐ AÐ AÐ AÐ AÐ AÐ AØ FÐ FÐ FÐ FÐ FÐ FØ 8Ð 8Ð 8Ð 8Ð 8Ð 8ðb)ð b)ð b)ð b)ð b)˜ñ b)ô b)ð b)ð b)ð b)r+   