o
    i                     @   s&   d dl Z d dlZdd ZdddZdS )    Nc                 C   s8   | j dj}||d k rtdt| d  dS dS )zChecks an early stopping trigger and warns the user if it's the case

    :param trainer: The trainer used for training
    :param epochs: The maximum number of epochs
    main   zHit early stop at epoch z=
You can change the patience or set it to 0 to run all epochsN)updaterget_iteratorepochloggingwarningstr)trainerepochs	end_epoch r   U/home/ubuntu/.local/lib/python3.10/site-packages/espnet/utils/training/train_utils.pycheck_early_stop   s   r   Fc                 C   sX   |j }|j}|r|jn|j}d|v rdnd}|dkr*tjjj||||dfd| _dS dS )zSets the early stop trigger given the program arguments

    :param trainer: The trainer used for training
    :param args: The program arguments
    :param is_lm: If the trainer is for a LM (epoch instead of epochs)
    accmaxminr   r   )monitormodepatientsmax_triggerN)	patienceearly_stop_criterionr   r   chainertrainingtriggersEarlyStoppingTriggerstop_trigger)r
   argsis_lmr   	criterionr   r   r   r   r   set_early_stop   s   r!   )F)r   r   r   r!   r   r   r   r   <module>   s    