ó
    pyüi;†  ã                   óf  • S r SSKrSSKrSSKrSSKJr  SSKrSSKJr  SSK	J
r
JrJr  SSKJr  SSKJr  \R"                  " \5      r\ " S	 S
5      5       r " S S5      r\ " S S\5      5       r " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\\5      rg)zJ
Callbacks to use with the Trainer class and customize the training loop.
é    N)Ú	dataclass)Útqdmé   )ÚIntervalStrategyÚSaveStrategyÚ
has_length)ÚTrainingArguments)Úloggingc                   óÆ  • \ rS rSr% SrSr\\S'   Sr\	\S'   Sr
\	\S'   Sr\	\S'   Sr\	\S	'   Sr\	\S
'   Sr\	S-  \S'   Sr\	\S'   Sr\	\S'   Sr\\S'   Sr\\\\4      \S'   Sr\S-  \S'   Sr\	S-  \S'   Sr\S-  \S'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\S-  \S'   Sr\\\\-  \	-  \-  4   S-  \S'   Sr\S   S-  \S'   S r S\4S jr!\"S\4S  j5       r#S! r$S" r%S#r&g)$ÚTrainerStateé"   aË  
A class containing the [`Trainer`] inner state that will be saved along the model and optimizer when checkpointing
and passed to the [`TrainerCallback`].

<Tip>

In all this class, one step is to be understood as one update step. When using gradient accumulation, one update
step may require several forward and backward passes: if you use `gradient_accumulation_steps=n`, then one update
step requires going through *n* batches.

</Tip>

Args:
    epoch (`float`, *optional*):
        Only set during training, will represent the epoch the training is at (the decimal part being the
        percentage of the current epoch completed).
    global_step (`int`, *optional*, defaults to 0):
        During training, represents the number of update steps completed.
    max_steps (`int`, *optional*, defaults to 0):
        The number of update steps to do during the current training.
    logging_steps (`int`, *optional*, defaults to 500):
        Log every X updates steps
    eval_steps (`int`, *optional*):
        Run an evaluation every X steps.
    save_steps (`int`, *optional*, defaults to 500):
        Save checkpoint every X updates steps.
    train_batch_size (`int`, *optional*):
        The batch size for the training dataloader. Only needed when
        `auto_find_batch_size` has been used.
    num_input_tokens_seen (`int`, *optional*, defaults to 0):
        When tracking the inputs tokens, the number of tokens seen during training (number of input tokens, not the
        number of prediction tokens).
    total_flos (`float`, *optional*, defaults to 0):
        The total number of floating operations done by the model since the beginning of training (stored as floats
        to avoid overflow).
    log_history (`list[dict[str, float]]`, *optional*):
        The list of logs done since the beginning of training.
    best_metric (`float`, *optional*):
        When tracking the best model, the value of the best metric encountered so far.
    best_global_step (`int`, *optional*):
        When tracking the best model, the step at which the best metric was encountered.
        Used for setting `best_model_checkpoint`.
    best_model_checkpoint (`str`, *optional*):
        When tracking the best model, the value of the name of the checkpoint for the best model encountered so
        far.
    is_local_process_zero (`bool`, *optional*, defaults to `True`):
        Whether or not this process is the local (e.g., on one machine if training in a distributed fashion on
        several machines) main process.
    is_world_process_zero (`bool`, *optional*, defaults to `True`):
        Whether or not this process is the global main process (when training in a distributed fashion on several
        machines, this is only going to be `True` for one process).
    is_hyper_param_search (`bool`, *optional*, defaults to `False`):
        Whether we are in the process of a hyper parameter search using Trainer.hyperparameter_search. This will
        impact the way data will be logged in TensorBoard.
    stateful_callbacks (`list[StatefulTrainerCallback]`, *optional*):
        Callbacks attached to the `Trainer` that should have their states be saved or restored.
        Relevant callbacks should implement a `state` and `from_state` function.
r   ÚepochÚglobal_stepÚ	max_stepsiô  Úlogging_stepsÚ
eval_stepsÚ
save_stepsNÚtrain_batch_sizeÚnum_train_epochsÚnum_input_tokens_seenÚ
total_flosÚlog_historyÚbest_metricÚbest_global_stepÚbest_model_checkpointTÚis_local_process_zeroÚis_world_process_zeroFÚis_hyper_param_searchÚ
trial_nameÚtrial_paramsÚTrainerCallbackÚstateful_callbacksc                 ó   • U R                   c  / U l         U R                  c  0 U l        g [        U R                  [        5      (       a  g 0 nU R                   H�  n[        U[        5      (       d  [        S[        U5       35      eUR                  R                  nX1;   aA  [        X   [        5      (       d  X   /X'   X   R                  UR                  5       5        M‹  UR                  5       X'   MŸ     Xl        g )NzNAll callbacks passed to be saved must inherit `ExportableState`, but received )r   r"   Ú
isinstanceÚdictÚExportableStateÚ	TypeErrorÚtypeÚ	__class__Ú__name__ÚlistÚappendÚstate)Úselfr"   ÚcallbackÚnames       ÚZ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/trainer_callback.pyÚ__post_init__ÚTrainerState.__post_init__t   sï   € Ø×ÑÑ#Ø!ˆDÔØ×"Ñ"Ñ*Ø&(ˆDÕ#Ü˜×/Ñ/´×6Ñ6àð "$ÐØ ×3Ô3�Ü! (¬_×>Ñ>Ü#ØhÔimÐnvÓiwÐhxÐyóð ð  ×)Ñ)×2Ñ2�ØÓ-ô &Ð&8Ñ&>Ä×EÑEØ4FÑ4LÐ3MÐ*Ñ0Ø&Ñ,×3Ñ3°H·N±NÓ4DÖEà/7¯~©~Ó/?Ð&Ó,ñ 4ð '9Õ#ó    Ú	json_pathc                 óÊ   • [         R                  " [        R                  " U 5      SSS9S-   n[	        USSS9 nUR                  U5        SSS5        g! , (       d  f       g= f)	zDSave the content of this instance in JSON format inside `json_path`.é   T)ÚindentÚ	sort_keysÚ
Úwúutf-8©ÚencodingN)ÚjsonÚdumpsÚdataclassesÚasdictÚopenÚwrite)r.   r5   Újson_stringÚfs       r1   Úsave_to_jsonÚTrainerState.save_to_json�   sK   € ä—j’j¤×!3Ò!3°DÓ!9À!ÈtÑTÐW[Ñ[ˆÜ�)˜S¨7Ò3°qØ�G‰G�KÔ ÷ 4×3Ö3ús   ¹AÁ
A"c                 ó¢   • [        USS9 nUR                  5       nSSS5        U " S0 [        R                  " W5      D6$ ! , (       d  f       N*= f)z3Create an instance from the content of `json_path`.r<   r=   N© )rC   Úreadr?   Úloads)Úclsr5   rF   Útexts       r1   Úload_from_jsonÚTrainerState.load_from_json•   s@   € ô �) gÒ.°!Ø—6‘6“8ˆD÷ /áÑ&”T—Z’Z Ó%Ñ&Ð&÷ /Õ.ús   ‹A Á 
Ac                 ó–   • S HC  n[        X S35      nUc  M  US:  a  [        R                  " X$-  5      n[        X S3U5        ME     g)zt
Calculates and stores the absolute value for logging,
eval, and save steps based on if it was a proportion
or not.
)r
   ÚevalÚsaveÚ_stepsNr   )ÚgetattrÚmathÚceilÚsetattr)r.   Úargsr   Ú	step_kindÚ	num_stepss        r1   Úcompute_stepsÚTrainerState.compute_stepsœ   sN   € ó 5ˆIÜ ¨°6Ð&:Ó;ˆIØÓ$Ø˜q“=Ü $§	¢	¨)Ñ*?Ó @�IÜ˜ ¨6Ð2°IÖ>ò 5r4   c                 ó  • UR                   b-  UR                  b   UR                  UR                  5      U l        SU l        Ub  SSKJn  U" U5      U l        X l        X0l        UR                  5       U l        UR                  5       U l	        g)z9
Stores the initial training references needed in `self`
Nr   )Ú	hp_params)
Úhp_nameÚ_trialr   r    Útransformers.integrationsr_   r   r   r   r   )r.   Útrainerr   r   Útrialr_   s         r1   Úinit_training_referencesÚ%TrainerState.init_training_references©   sx   € ð �?‰?Ñ&¨7¯>©>Ñ+Eð &Ÿo™o¨g¯n©nÓ=ˆDŒOØ ˆÔØÑÝ;á )¨%Ó 0ˆDÔà"ŒØ 0ÔØ%,×%BÑ%BÓ%DˆÔ"Ø%,×%BÑ%BÓ%DˆÕ"r4   )r   r   r   r   r   r"   r   r    )'r*   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚfloatÚ__annotations__r   Úintr   r   r   r   r   r   r   r   r   r+   r%   Ústrr   r   r   r   Úboolr   r   r   r    r"   r2   rG   ÚclassmethodrO   r\   re   Ú__static_attributes__rJ   r4   r1   r   r   "   s\  ‡ ñ9ðv €Eˆ5ÓØ€K�ÓØ€IˆsÓØ€M�3ÓØ€J�ÓØ€J�ÓØ#'Ð�c˜D‘jÓ'ØÐ�cÓØ!"Ð˜3Ó"Ø€J�ÓØ*.€K��d˜3 ˜:Ñ&Ñ'Ó.Ø $€K�˜‘Ó$Ø#'Ð�c˜D‘jÓ'Ø(,Ð˜3 ™:Ó,Ø"&Ð˜4Ó&Ø"&Ð˜4Ó&Ø"'Ð˜4Ó'Ø!€J��d‘
Ó!Ø?C€L�$�s˜C %™K¨#Ñ-°Ñ4Ð4Ñ5¸Ñ<ÓCØ9=Ð˜Ð.Ñ/°$Ñ6Ó=ò9ð6! cô !ð ð' só 'ó ð'ò?õEr4   r   c                   ó6   • \ rS rSrSrS\4S jr\S 5       rSr	g)r&   é½   a  
A class for objects that include the ability to have its state
be saved during `Trainer._save_checkpoint` and loaded back in during
`Trainer._load_from_checkpoint`.

These must implement a `state` function that gets called during the respective
Trainer function call. It should only include parameters and attributes needed to
recreate the state at a particular time, to avoid utilizing pickle/maintain standard
file IO writing.

Example:

```python
class EarlyStoppingCallback(TrainerCallback, ExportableState):
    def __init__(self, early_stopping_patience: int = 1, early_stopping_threshold: Optional[float] = 0.0):
        self.early_stopping_patience = early_stopping_patience
        self.early_stopping_threshold = early_stopping_threshold
        # early_stopping_patience_counter denotes the number of times validation metrics failed to improve.
        self.early_stopping_patience_counter = 0

    def state(self) -> dict:
        return {
            "args": {
                "early_stopping_patience": self.early_stopping_patience,
                "early_stopping_threshold": self.early_stopping_threshold,
            },
            "attributes": {
                "early_stopping_patience_counter": self.early_stopping_patience_counter,
            }
        }
```Úreturnc                 ó   • [        S5      e)Nz<You must implement a `state` function to utilize this class.)ÚNotImplementedError©r.   s    r1   r-   ÚExportableState.stateÞ   s   € Ü!Ð"`ÓaÐar4   c                 ól   • U " S0 US   D6nUS   R                  5        H  u  p4[        X#U5        M     U$ )NrY   Ú
attributesrJ   )ÚitemsrX   )rM   r-   ÚinstanceÚkÚvs        r1   Ú
from_stateÚExportableState.from_stateá   s<   € áÑ'˜˜v™Ñ'ˆØ˜,Ñ'×-Ñ-Ö/‰DˆAÜ�H Ö#ñ 0àˆr4   rJ   N)
r*   rg   rh   ri   rj   r%   r-   rp   r   rq   rJ   r4   r1   r&   r&   ½   s*   † ñð@b�tô bð ñó ór4   r&   c                   ó€   • \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   Sr
\\S'   Sr\\S'   S	 rS
 rS rS\4S jrSrg)ÚTrainerControléé   aõ  
A class that handles the [`Trainer`] control flow. This class is used by the [`TrainerCallback`] to activate some
switches in the training loop.

Args:
    should_training_stop (`bool`, *optional*, defaults to `False`):
        Whether or not the training should be interrupted.

        If `True`, this variable will not be set back to `False`. The training will just stop.
    should_epoch_stop (`bool`, *optional*, defaults to `False`):
        Whether or not the current epoch should be interrupted.

        If `True`, this variable will be set back to `False` at the beginning of the next epoch.
    should_save (`bool`, *optional*, defaults to `False`):
        Whether or not the model should be saved at this step.

        If `True`, this variable will be set back to `False` at the beginning of the next step.
    should_evaluate (`bool`, *optional*, defaults to `False`):
        Whether or not the model should be evaluated at this step.

        If `True`, this variable will be set back to `False` at the beginning of the next step.
    should_log (`bool`, *optional*, defaults to `False`):
        Whether or not the logs should be reported at this step.

        If `True`, this variable will be set back to `False` at the beginning of the next step.
FÚshould_training_stopÚshould_epoch_stopÚshould_saveÚshould_evaluateÚ
should_logc                 ó   • SU l         g)z<Internal method that resets the variable for a new training.FN)r„   rw   s    r1   Ú_new_trainingÚTrainerControl._new_training  s
   € à$)ˆÕ!r4   c                 ó   • SU l         g)z9Internal method that resets the variable for a new epoch.FN)r…   rw   s    r1   Ú
_new_epochÚTrainerControl._new_epoch  s
   € à!&ˆÕr4   c                 ó.   • SU l         SU l        SU l        g)z8Internal method that resets the variable for a new step.FN)r†   r‡   rˆ   rw   s    r1   Ú	_new_stepÚTrainerControl._new_step  s   € à ˆÔØ$ˆÔØˆ�r4   rt   c                 ó|   • U R                   U R                  U R                  U R                  U R                  S.0 S.$ )N©r„   r…   r†   r‡   rˆ   ©rY   rz   r“   rw   s    r1   r-   ÚTrainerControl.state  sC   € ð )-×(AÑ(AØ%)×%;Ñ%;Ø#×/Ñ/Ø#'×#7Ñ#7Ø"Ÿo™oñð ñ	
ð 		
r4   )r…   r‡   rˆ   r†   r„   N)r*   rg   rh   ri   rj   r„   ro   rl   r…   r†   r‡   rˆ   rŠ   r�   r�   r%   r-   rq   rJ   r4   r1   r‚   r‚   é   sX   ‡ ñð6 "'Ð˜$Ó&Ø#Ð�tÓ#Ø€K�ÓØ!€O�TÓ!Ø€J�Óò*ò'ò ð

�t÷ 

r4   r‚   c                   óx  • \ rS rSrSrS\S\S\4S jrS\S\S\4S jr	S\S\S\4S jr
S\S\S\4S	 jrS\S\S\4S
 jrS\S\S\4S jrS\S\S\4S jrS\S\S\4S jrS\S\S\4S jrS\S\S\4S jrS\S\S\4S jrS\S\S\4S jrS\S\S\4S jrS\S\S\4S jrS\S\S\4S jrS\S\S\4S jrSrg)r!   i'  a�  
A class for objects that will inspect the state of the training loop at some events and take some decisions. At
each of those events the following arguments are available:

Args:
    args ([`TrainingArguments`]):
        The training arguments used to instantiate the [`Trainer`].
    state ([`TrainerState`]):
        The current state of the [`Trainer`].
    control ([`TrainerControl`]):
        The object that is returned to the [`Trainer`] and can be used to make some decisions.
    model ([`PreTrainedModel`] or `torch.nn.Module`):
        The model being trained.
    processing_class ([`PreTrainedTokenizer` or `BaseImageProcessor` or `ProcessorMixin` or `FeatureExtractionMixin`]):
        The processing class used for encoding the data. Can be a tokenizer, a processor, an image processor or a feature extractor.
    optimizer (`torch.optim.Optimizer`):
        The optimizer used for the training steps.
    lr_scheduler (`torch.optim.lr_scheduler.LambdaLR`):
        The scheduler used for setting the learning rate.
    train_dataloader (`torch.utils.data.DataLoader`, *optional*):
        The current dataloader used for training.
    eval_dataloader (`torch.utils.data.DataLoader`, *optional*):
        The current dataloader used for evaluation.
    metrics (`dict[str, float]`):
        The metrics computed by the last evaluation phase.

        Those are only accessible in the event `on_evaluate`.
    logs  (`dict[str, float]`):
        The values to log.

        Those are only accessible in the event `on_log`.

The `control` object is the only one that can be changed by the callback, in which case the event that changes it
should return the modified version.

The argument `args`, `state` and `control` are positionals for all events, all the others are grouped in `kwargs`.
You can unpack the ones you need in the signature of the event using them. As an example, see the code of the
simple [`~transformers.PrinterCallback`].

Example:

```python
class PrinterCallback(TrainerCallback):
    def on_log(self, args, state, control, logs=None, **kwargs):
        _ = logs.pop("total_flos", None)
        if state.is_local_process_zero:
            print(logs)
```rY   r-   Úcontrolc                 ó   • g)zC
Event called at the end of the initialization of the [`Trainer`].
NrJ   ©r.   rY   r-   r—   Úkwargss        r1   Úon_init_endÚTrainerCallback.on_init_endZ  ó   � r4   c                 ó   • g)z,
Event called at the beginning of training.
NrJ   r™   s        r1   Úon_train_beginÚTrainerCallback.on_train_begin_  r�   r4   c                 ó   • g)z&
Event called at the end of training.
NrJ   r™   s        r1   Úon_train_endÚTrainerCallback.on_train_endd  r�   r4   c                 ó   • g)z,
Event called at the beginning of an epoch.
NrJ   r™   s        r1   Úon_epoch_beginÚTrainerCallback.on_epoch_begini  r�   r4   c                 ó   • g)z&
Event called at the end of an epoch.
NrJ   r™   s        r1   Úon_epoch_endÚTrainerCallback.on_epoch_endn  r�   r4   c                 ó   • g)z€
Event called at the beginning of a training step. If using gradient accumulation, one training step might take
several inputs.
NrJ   r™   s        r1   Úon_step_beginÚTrainerCallback.on_step_begins  r�   r4   c                 ó   • g)zf
Event called before the optimizer step but after gradient clipping. Useful for monitoring gradients.
NrJ   r™   s        r1   Úon_pre_optimizer_stepÚ%TrainerCallback.on_pre_optimizer_stepy  r�   r4   c                 ó   • g)zm
Event called after the optimizer step but before gradients are zeroed out. Useful for monitoring gradients.
NrJ   r™   s        r1   Úon_optimizer_stepÚ!TrainerCallback.on_optimizer_step~  r�   r4   c                 ó   • g)zE
Event called at the end of an substep during gradient accumulation.
NrJ   r™   s        r1   Úon_substep_endÚTrainerCallback.on_substep_endƒ  r�   r4   c                 ó   • g)zz
Event called at the end of a training step. If using gradient accumulation, one training step might take
several inputs.
NrJ   r™   s        r1   Úon_step_endÚTrainerCallback.on_step_endˆ  r�   r4   c                 ó   • g)z)
Event called after an evaluation phase.
NrJ   r™   s        r1   Úon_evaluateÚTrainerCallback.on_evaluateŽ  r�   r4   c                 ó   • g)z-
Event called after a successful prediction.
NrJ   ©r.   rY   r-   r—   Úmetricsrš   s         r1   Ú
on_predictÚTrainerCallback.on_predict“  r�   r4   c                 ó   • g)z'
Event called after a checkpoint save.
NrJ   r™   s        r1   Úon_saveÚTrainerCallback.on_save˜  r�   r4   c                 ó   • g)z+
Event called after logging the last logs.
NrJ   r™   s        r1   Úon_logÚTrainerCallback.on_log�  r�   r4   c                 ó   • g)z'
Event called after a prediction step.
NrJ   r™   s        r1   Úon_prediction_stepÚ"TrainerCallback.on_prediction_step¢  r�   r4   c                 ó   • g)z~
Event called before pushing the model to the hub, at the beginning of Trainer.push_to_hub and Trainer._push_from_checkpoint.
NrJ   r™   s        r1   Úon_push_beginÚTrainerCallback.on_push_begin§  r�   r4   rJ   N)r*   rg   rh   ri   rj   r	   r   r‚   r›   rŸ   r¢   r¥   r¨   r«   r®   r±   r´   r·   rº   r¿   rÂ   rÅ   rÈ   rË   rq   rJ   r4   r1   r!   r!   '  sÆ  † ñ/ðbÐ 1ð ¸,ð ÐQ_ô ð
Ð#4ð ¸\ð ÐTbô ð
Ð!2ð ¸<ð ÐR`ô ð
Ð#4ð ¸\ð ÐTbô ð
Ð!2ð ¸<ð ÐR`ô ð
Ð"3ð ¸Lð ÐSaô ðÐ*;ð ÀLð Ð[iô ð
Ð&7ð Àð ÐWeô ð
Ð#4ð ¸\ð ÐTbô ð
Ð 1ð ¸,ð ÐQ_ô ðÐ 1ð ¸,ð ÐQ_ô ð
Ð0ð ¸ð ÐP^ô ð
Ð-ð °lð È^ô ð
Ð,ð °\ð ÈNô ð
Ð'8ð Àð ÐXfô ð
Ð"3ð ¸Lð ÐSa÷ r4   r!   c                   ó¦  • \ rS rSrSrS rS rS rS r\	S 5       r
S\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS\S	\S
\4S jrS rSrg)ÚCallbackHandleri­  z>Internal class that just calls the list of callbacks in order.c                 ó  • / U l         U H  nU R                  U5        M     X l        X0l        X@l        XPl        S U l        S U l        [        S U R                    5       5      (       d#  [        R                  SU R                  -   5        g g )Nc              3   óB   #   • U  H  n[        U[        5      v •  M     g 7f©N)r$   ÚDefaultFlowCallback©Ú.0Úcbs     r1   Ú	<genexpr>Ú+CallbackHandler.__init__.<locals>.<genexpr>»  s   é € ÐPÂ¸2”:˜bÔ"5×6Ð6Âùs   ‚zÔThe Trainer will not work properly if you don't have a `DefaultFlowCallback` in its callbacks. You
should add one before training with `trainer.add_callback(DefaultFlowCallback). The current list ofcallbacks is
:)Ú	callbacksÚadd_callbackÚmodelÚprocessing_classÚ	optimizerÚlr_schedulerÚtrain_dataloaderÚeval_dataloaderÚanyÚloggerÚwarningÚcallback_list)r.   rØ   rÚ   rÛ   rÜ   rÝ   rÕ   s          r1   Ú__init__ÚCallbackHandler.__init__°  sƒ   € ØˆŒÛˆBØ×Ñ˜bÖ!ñ àŒ
Ø 0ÔØ"ŒØ(ÔØ $ˆÔØ#ˆÔäÑPÀÇÂÓP×PÑPÜ�N‰Nð$ð ×$Ñ$ñ%õð Qr4   c                 ój  • [        U[        5      (       a  U" 5       OUn[        U[        5      (       a  UOUR                  nX0R                   Vs/ s H  oDR                  PM     sn;   a)  [        R                  SU S3S-   U R                  -   5        U R                  R                  U5        g s  snf )NzYou are adding a zH to the callbacks of this Trainer, but there is already one. The currentzlist of callbacks is
:)r$   r(   r)   rØ   rá   râ   rã   r,   )r.   r/   rÕ   Úcb_classÚcs        r1   rÙ   ÚCallbackHandler.add_callbackÃ  s“   € Ü% h´×5Ñ5‰XŒZ¸8ˆÜ)¨(´D×9Ñ9‘8¸x×?QÑ?QˆØ¯^ª^Ó<ª^¨Ÿœ©^Ñ<Ó<Ü�N‰NØ# H :Ð-uÐvØ+ñ,à×$Ñ$ñ%ôð
 	�‰×Ñ˜bÕ!ùò =s   ÁB0c                 ó"  • [        U[        5      (       aC  U R                   H2  n[        X!5      (       d  M  U R                  R                  U5        Us  $    g U R                   H'  nX!:X  d  M
  U R                  R                  U5        Us  $    g rÑ   ©r$   r(   rØ   Úremove©r.   r/   rÕ   s      r1   Úpop_callbackÚCallbackHandler.pop_callbackÎ  sk   € Ü�h¤×%Ñ%Ø—n”n�Ü˜b×+Ó+Ø—N‘N×)Ñ)¨"Ô-Ø’Iò %ð
 —n”n�Ø•>Ø—N‘N×)Ñ)¨"Ô-Ø’Iò %r4   c                 óæ   • [        U[        5      (       aA  U R                   H0  n[        X!5      (       d  M  U R                  R                  U5          g    g U R                  R                  U5        g rÑ   rë   rí   s      r1   Úremove_callbackÚCallbackHandler.remove_callbackÚ  sQ   € Ü�h¤×%Ñ%Ø—n”n�Ü˜b×+Ó+Ø—N‘N×)Ñ)¨"Ô-Ùò %ð
 �N‰N×!Ñ! (Õ+r4   c                 óF   • SR                  S U R                   5       5      $ )Nr:   c              3   óL   #   • U  H  oR                   R                  v •  M     g 7frÑ   )r)   r*   rÓ   s     r1   rÖ   Ú0CallbackHandler.callback_list.<locals>.<genexpr>å  s   é € ÐHº°2Ÿ™×.Ö.ºùs   ‚"$)ÚjoinrØ   rw   s    r1   rã   ÚCallbackHandler.callback_listã  s   € à�y‰yÑH¸¿ºÓHÓHÐHr4   rY   r-   r—   c                 ó,   • U R                   " SXU40 UD6$ )Nr›   ©Ú
call_eventr™   s        r1   r›   ÚCallbackHandler.on_init_endç  ó   € Ø�Š˜}¨d¸7ÑMÀfÑMÐMr4   c                 ó:   • SUl         U R                  " SXU40 UD6$ )NFrŸ   )r„   rú   r™   s        r1   rŸ   ÚCallbackHandler.on_train_beginê  s#   € Ø',ˆÔ$Ø�ŠÐ/°¸gÑPÈÑPÐPr4   c                 ó,   • U R                   " SXU40 UD6$ )Nr¢   rù   r™   s        r1   r¢   ÚCallbackHandler.on_train_endî  ó   € Ø�Š˜~¨t¸GÑNÀvÑNÐNr4   c                 ó:   • SUl         U R                  " SXU40 UD6$ )NFr¥   )r…   rú   r™   s        r1   r¥   ÚCallbackHandler.on_epoch_beginñ  s#   € Ø$)ˆÔ!Ø�ŠÐ/°¸gÑPÈÑPÐPr4   c                 ó,   • U R                   " SXU40 UD6$ )Nr¨   rù   r™   s        r1   r¨   ÚCallbackHandler.on_epoch_endõ  r  r4   c                 óV   • SUl         SUl        SUl        U R                  " SXU40 UD6$ )NFr«   )rˆ   r‡   r†   rú   r™   s        r1   r«   ÚCallbackHandler.on_step_beginø  s2   € Ø"ˆÔØ"'ˆÔØ#ˆÔØ�Š˜°¸WÑOÈÑOÐOr4   c                 ó,   • U R                   " SXU40 UD6$ )Nr®   rù   r™   s        r1   r®   Ú%CallbackHandler.on_pre_optimizer_stepþ  s   € Ø�ŠÐ6¸ÀWÑWÐPVÑWÐWr4   c                 ó,   • U R                   " SXU40 UD6$ )Nr±   rù   r™   s        r1   r±   Ú!CallbackHandler.on_optimizer_step  s   € Ø�ŠÐ2°DÀÑSÈFÑSÐSr4   c                 ó,   • U R                   " SXU40 UD6$ )Nr´   rù   r™   s        r1   r´   ÚCallbackHandler.on_substep_end  s   € Ø�ŠÐ/°¸gÑPÈÑPÐPr4   c                 ó,   • U R                   " SXU40 UD6$ )Nr·   rù   r™   s        r1   r·   ÚCallbackHandler.on_step_end  rü   r4   c                 ó>   • SUl         U R                  " SXU4SU0UD6$ )NFrº   r¾   )r‡   rú   r½   s         r1   rº   ÚCallbackHandler.on_evaluate
  s(   € Ø"'ˆÔØ�Š˜}¨d¸7Ñ^ÈGÐ^ÐW]Ñ^Ð^r4   c                 ó0   • U R                   " SXU4SU0UD6$ )Nr¿   r¾   rù   r½   s         r1   r¿   ÚCallbackHandler.on_predict  s    € Ø�Š˜|¨T¸'Ñ]È7Ð]ÐV\Ñ]Ð]r4   c                 ó:   • SUl         U R                  " SXU40 UD6$ )NFrÂ   )r†   rú   r™   s        r1   rÂ   ÚCallbackHandler.on_save  s"   € Ø#ˆÔØ�Š˜y¨$°wÑIÀ&ÑIÐIr4   c                 ó>   • SUl         U R                  " SXU4SU0UD6$ )NFrÅ   Úlogs)rˆ   rú   )r.   rY   r-   r—   r  rš   s         r1   rÅ   ÚCallbackHandler.on_log  s'   € Ø"ˆÔØ�Š˜x¨°gÑSÀDÐSÈFÑSÐSr4   c                 ó,   • U R                   " SXU40 UD6$ )NrÈ   rù   r™   s        r1   rÈ   Ú"CallbackHandler.on_prediction_step  s   € Ø�ŠÐ3°TÀ'ÑTÈVÑTÐTr4   c                 ó,   • U R                   " SXU40 UD6$ )NrË   rù   r™   s        r1   rË   ÚCallbackHandler.on_push_begin  s   € Ø�Š˜°¸WÑOÈÑOÐOr4   c                 óè   • U R                    Ha  n[        Xa5      " UUU4U R                  U R                  U R                  U R
                  U R                  U R                  S.UD6nUc  M_  UnMc     U$ )N)rÚ   rÛ   rÜ   rÝ   rÞ   rß   )rØ   rU   rÚ   rÛ   rÜ   rÝ   rÞ   rß   )r.   ÚeventrY   r-   r—   rš   r/   Úresults           r1   rú   ÚCallbackHandler.call_event  s   € ØŸœˆHÜ˜XÔ-ØØØðð —j‘jØ!%×!6Ñ!6ØŸ.™.Ø!×.Ñ.Ø!%×!6Ñ!6Ø $× 4Ñ 4ñð ñˆFð Ó!Ø ’ñ 'ð  ˆr4   )rØ   rß   rÝ   rÚ   rÜ   rÛ   rÞ   N) r*   rg   rh   ri   rj   rä   rÙ   rî   rñ   Úpropertyrã   r	   r   r‚   r›   rŸ   r¢   r¥   r¨   r«   r®   r±   r´   r·   rº   r¿   rÂ   rÅ   rÈ   rË   rú   rq   rJ   r4   r1   rÎ   rÎ   ­  s2  † ÙHòò&	"ò
ò,ð ñIó ðIðNÐ 1ð N¸,ð NÐQ_ô NðQÐ#4ð Q¸\ð QÐTbô QðOÐ!2ð O¸<ð OÐR`ô OðQÐ#4ð Q¸\ð QÐTbô QðOÐ!2ð O¸<ð OÐR`ô OðPÐ"3ð P¸Lð PÐSaô PðXÐ*;ð XÀLð XÐ[iô XðTÐ&7ð TÀð TÐWeô TðQÐ#4ð Q¸\ð QÐTbô QðNÐ 1ð N¸,ð NÐQ_ô Nð_Ð 1ð _¸,ð _ÐQ_ô _ð^Ð0ð ^¸ð ^ÐP^ô ^ðJÐ-ð J°lð JÈ^ô JðTÐ,ð T°\ð TÈNô TðUÐ'8ð UÀð UÐXfô UðPÐ"3ð P¸Lð PÐSaô Põr4   rÎ   c                   óD   • \ rS rSrSrS\S\S\4S jrS\S\S\4S jr	Sr
g	)
rÒ   i3  zp
A [`TrainerCallback`] that handles the default flow of the training loop for logs, evaluation and checkpoints.
rY   r-   r—   c                 óz  • UR                   S:X  a  UR                  (       a  SUl        UR                  [        R
                  :X  a$  UR                   UR                  -  S:X  a  SUl        UR                  [        R
                  :X  a>  UR                   UR                  -  S:X  a!  UR                  UR                   ::  a  SUl
        UR                  [        R
                  :X  a4  UR                  S:”  a$  UR                   UR                  -  S:X  a  SUl        UR                   UR                  :¼  aˆ  SUl        UR                  [        R
                  :X  a>  UR                   UR                  -  S:w  a!  UR                  UR                   ::  a  SUl
        UR                  [        R
                  :X  a  SUl        U$ )Nr   Tr   )r   Úlogging_first_steprˆ   Úlogging_strategyr   ÚSTEPSr   Úeval_strategyr   Ú
eval_delayr‡   Úsave_strategyr   r   r†   r   r„   r™   s        r1   r·   ÚDefaultFlowCallback.on_step_end8  sm  € à×Ñ Ó! d×&=×&=Ø!%ˆGÔØ× Ñ Ô$4×$:Ñ$:Ó:¸u×?PÑ?PÐSX×SfÑSfÑ?fÐjkÓ?kØ!%ˆGÔð ×ÑÔ"2×"8Ñ"8Ó8Ø×!Ñ! E×$4Ñ$4Ñ4¸Ó9Ø—‘ 5×#4Ñ#4Ó4à&*ˆGÔ#ð ×Ñ¤,×"4Ñ"4Ó4Ø× Ñ  1Ó$Ø×!Ñ! E×$4Ñ$4Ñ4¸Ó9à"&ˆGÔð ×Ñ §¡Ó/Ø+/ˆGÔ(ð ×"Ñ"Ô&6×&<Ñ&<Ó<Ø×%Ñ%¨×(8Ñ(8Ñ8¸AÓ=Ø—O‘O u×'8Ñ'8Ó8à*.�Ô'à×!Ñ!¤\×%7Ñ%7Ó7Ø&*�Ô#àˆr4   c                 ó  • UR                   [        R                  :X  a  SUl        UR                  [        R                  :X  a!  UR
                  UR                  ::  a  SUl        UR                  [        R                  :X  a  SUl
        U$ )NT)r%  r   ÚEPOCHrˆ   r'  r(  r   r‡   r)  r   r†   r™   s        r1   r¨   Ú DefaultFlowCallback.on_epoch_end`  sp   € à× Ñ Ô$4×$:Ñ$:Ó:Ø!%ˆGÔð ×ÑÔ!1×!7Ñ!7Ó7¸D¿O¹OÈuÏ{É{Ó<ZØ&*ˆGÔ#ð ×Ñ¤×!3Ñ!3Ó3Ø"&ˆGÔàˆr4   rJ   N)r*   rg   rh   ri   rj   r	   r   r‚   r·   r¨   rq   rJ   r4   r1   rÒ   rÒ   3  s@   † ñð&Ð 1ð &¸,ð &ÐQ_ô &ðPÐ!2ð ¸<ð ÐR`÷ r4   rÒ   c                   ó\   • \ rS rSrSrSS\4S jjrS rS rSS jr	S	 r
S
 rSS jrS rSrg)ÚProgressCallbackip  z¢
A [`TrainerCallback`] that displays the progress of training or evaluation.
You can modify `max_str_len` to control how long strings are truncated when logging.
Úmax_str_lenc                 ó,   • SU l         SU l        Xl        g)zñ
Initialize the callback with optional max_str_len parameter to control string truncation length.

Args:
    max_str_len (`int`):
        Maximum length of strings to display in logs.
        Longer strings will be truncated with a message.
N)Útraining_barÚprediction_barr0  )r.   r0  s     r1   rä   ÚProgressCallback.__init__v  s   € ð !ˆÔØ"ˆÔØ&Õr4   c                 óf   • UR                   (       a  [        UR                  SS9U l        SU l        g )NT)ÚtotalÚdynamic_ncolsr   )r   r   r   r2  Úcurrent_stepr™   s        r1   rŸ   ÚProgressCallback.on_train_beginƒ  s&   € Ø×&×&Ü $¨5¯?©?È$Ñ OˆDÔØˆÕr4   c                 ó®   • UR                   (       aD  U R                  R                  UR                  U R                  -
  5        UR                  U l        g g rÑ   )r   r2  Úupdater   r8  r™   s        r1   r·   ÚProgressCallback.on_step_endˆ  sC   € Ø×&×&Ø×Ñ×$Ñ$ U×%6Ñ%6¸×9JÑ9JÑ%JÔKØ %× 1Ñ 1ˆDÕð 'r4   Nc                 óä   • UR                   (       a_  [        U5      (       aN  U R                  c%  [        [	        U5      U R
                  S L SS9U l        U R                  R                  S5        g g g )NT)r6  Úleaver7  r   )r   r   r3  r   Úlenr2  r;  )r.   rY   r-   r—   rß   rš   s         r1   rÈ   Ú#ProgressCallback.on_prediction_step�  se   € Ø×&×&¬:°o×+FÑ+FØ×"Ñ"Ñ*Ü&*Ü˜oÓ.°d×6GÑ6GÈ4Ð6OÐ_cñ'�Ô#ð ×Ñ×&Ñ& qÕ)ð ,GÐ&r4   c                 ó„   • UR                   (       a/  U R                  b  U R                  R                  5         S U l        g g rÑ   ©r   r3  Úcloser™   s        r1   rº   ÚProgressCallback.on_evaluate•  ó6   € Ø×&×&Ø×"Ñ"Ñ.Ø×#Ñ#×)Ñ)Ô+Ø"&ˆDÕð 'r4   c                 ó„   • UR                   (       a/  U R                  b  U R                  R                  5         S U l        g g rÑ   rB  r™   s        r1   r¿   ÚProgressCallback.on_predict›  rE  r4   c                 óÄ  • UR                   (       aÏ  U R                  bÁ  0 nUR                  5        Ht  u  px[        U[        5      (       a9  [        U5      U R                  :”  a   S[        U5       SU R                   S3Xg'   MS  [        U[        5      (       a  US Xg'   Mp  X†U'   Mv     UR                  SS 5      n	U R                  R                  [	        U5      5        g g g )Nz%[String too long to display, length: z > z/. Consider increasing `max_str_len` if needed.]ú.4gr   )
r   r2  r{   r$   rn   r?  r0  rk   ÚpoprD   )
r.   rY   r-   r—   r  rš   Úshallow_logsr}   r~   Ú_s
             r1   rÅ   ÚProgressCallback.on_log¡  sÐ   € Ø×&×&¨4×+<Ñ+<Ñ+Hð ˆLØŸ
™
ž‘�Ü˜a¤×%Ñ%¬#¨a«&°4×3CÑ3CÓ*Cà?ÄÀAÃ¸xÀsÈ4×K[ÑK[ÐJ\ð ]Hð Hð !“Oô   ¤5×)Ñ)à)*¨3¨�L“Oà&' “Oñ %ð × Ñ  ¨tÓ4ˆAØ×Ñ×#Ñ#¤C¨Ó$5Õ6ð! ,IÐ&r4   c                 ój   • UR                   (       a"  U R                  R                  5         S U l        g g rÑ   )r   r2  rC  r™   s        r1   r¢   ÚProgressCallback.on_train_end´  s*   € Ø×&×&Ø×Ñ×#Ñ#Ô%Ø $ˆDÕð 'r4   )r8  r0  r3  r2  )éd   rÑ   )r*   rg   rh   ri   rj   rm   rä   rŸ   r·   rÈ   rº   r¿   rÅ   r¢   rq   rJ   r4   r1   r/  r/  p  s6   † ññ
' Cõ 'òò
2ô
*ò'ò'ô7õ&%r4   r/  c                   ó"   • \ rS rSrSrSS jrSrg)ÚPrinterCallbackiº  z7
A bare [`TrainerCallback`] that just prints the logs.
Nc           	      óð   • UR                  SS 5      nUR                  (       aM  Ub>  UR                  5        VVs0 s H!  u  pxU[        U[        5      (       a  US OU_M#     nnn[        U5        g g s  snnf )Nr   rI  )rJ  r   r{   r$   rk   Úprint)	r.   rY   r-   r—   r  rš   rL  r}   r~   s	            r1   rÅ   ÚPrinterCallback.on_log¿  sh   € Ø�H‰H�\ 4Ó(ˆØ×&×&ØÑØSW×S]ÑS]ÔS_Ô`ÒS_É4È1˜¬*°Q¼×*>Ñ*>˜q ™gÀAÒEÑS_�Ñ`Ü�$�Kð 'ùã`s   º(A2rJ   rÑ   )r*   rg   rh   ri   rj   rÅ   rq   rJ   r4   r1   rR  rR  º  s   † ñ÷r4   rR  c                   óT   • \ rS rSrSrSS\S\S-  4S jjrS rS r	S	 r
S
\4S jrSrg)ÚEarlyStoppingCallbackiÇ  a  
A [`TrainerCallback`] that handles early stopping.

Args:
    early_stopping_patience (`int`):
        Use with `metric_for_best_model` to stop training when the specified metric worsens for
        `early_stopping_patience` evaluation calls.
    early_stopping_threshold(`float`, *optional*):
        Use with TrainingArguments `metric_for_best_model` and `early_stopping_patience` to denote how much the
        specified metric must improve to satisfy early stopping conditions. `

This callback depends on [`TrainingArguments`] argument *load_best_model_at_end* functionality to set best_metric
in [`TrainerState`]. Note that if the [`TrainingArguments`] argument *save_steps* differs from *eval_steps*, the
early stopping will not occur until the next save step.
Úearly_stopping_patienceÚearly_stopping_thresholdNc                 ó*   • Xl         X l        SU l        g )Nr   ©rX  rY  Úearly_stopping_patience_counter)r.   rX  rY  s      r1   rä   ÚEarlyStoppingCallback.__init__Ø  s   € Ø'>Ô$Ø(@Ô%à/0ˆÕ,r4   c                 ó2  • UR                   (       a  [        R                  O[        R                  nUR                  b<  U" XBR                  5      (       a-  [        XBR                  -
  5      U R                  :”  a  SU l        g U =R                  S-  sl        g )Nr   r   )Úgreater_is_betterÚnpÚgreaterÚlessr   ÚabsrY  r\  )r.   rY   r-   r—   Úmetric_valueÚoperators         r1   Úcheck_metric_valueÚ(EarlyStoppingCallback.check_metric_valueÞ  sk   € à!%×!7×!7”2—:’:¼R¿W¹WˆØ×ÑÑ$Ù�\×#4Ñ#4×5Ñ5Ü�L×#4Ñ#4Ñ4Ó5¸×8UÑ8UÓUà34ˆDÕ0à×0Ò0°AÑ5Ö0r4   c                 óÂ   • UR                   (       d  [        R                  S5        UR                  c   S5       eUR                  [
        R                  :w  d   S5       eg )NzŒUsing EarlyStoppingCallback without load_best_model_at_end=True. Once training is finished, the best model will not be loaded automatically.zBEarlyStoppingCallback requires metric_for_best_model to be definedzAEarlyStoppingCallback requires IntervalStrategy of steps or epoch)Úload_best_model_at_endrá   râ   Úmetric_for_best_modelr'  r   ÚNOr™   s        r1   rŸ   Ú$EarlyStoppingCallback.on_train_beginé  sb   € Ø×*×*Ü�N‰Nð^ôð ×)Ñ)Ñ5ð 	
ØPó	
Ð5ð ×!Ñ!Ô%5×%8Ñ%8Ó8ð 	
ØOó	
Ñ8r4   c                 ó  • UR                   nUR                  S5      (       d  SU 3nUR                  U5      nUc  [        R	                  SU S35        g U R                  XX75        U R                  U R                  :¼  a  SUl        g g )NÚeval_z@early stopping required metric_for_best_model, but did not find z so early stopping is disabledT)	rj  Ú
startswithÚgetrá   râ   rf  r\  rX  r„   )r.   rY   r-   r—   r¾   rš   Úmetric_to_checkrd  s           r1   rº   Ú!EarlyStoppingCallback.on_evaluateö  s–   € Ø×4Ñ4ˆØ×)Ñ)¨'×2Ñ2Ø % oÐ%6Ð7ˆOØ—{‘{ ?Ó3ˆàÑÜ�N‰NØRÐSbÐRcð dð ôð à×Ñ ¨WÔCØ×/Ñ/°4×3OÑ3OÓOØ+/ˆGÕ(ð Pr4   rt   c                 óR   • U R                   U R                  S.SU R                  0S.$ )N)rX  rY  r\  r”   r[  rw   s    r1   r-   ÚEarlyStoppingCallback.state  s7   € ð ,0×+GÑ+GØ,0×,IÑ,Iñð
 2°4×3WÑ3Wðñ
ð 	
r4   )rX  r\  rY  )r   g        )r*   rg   rh   ri   rj   rm   rk   rä   rf  rŸ   rº   r%   r-   rq   rJ   r4   r1   rW  rW  Ç  s<   † ññ 1°ð 1ÐSXÐ[_ÑS_õ 1ò	6ò
ò0ð"	
�t÷ 	
r4   rW  )rj   rA   r?   rV   r   Únumpyr`  Ú	tqdm.autor   Útrainer_utilsr   r   r   Útraining_argsr	   Úutilsr
   Ú
get_loggerr*   rá   r   r&   r‚   r!   rÎ   rÒ   r/  rR  rW  rJ   r4   r1   Ú<module>r{     s×   ðñó Û Û Ý !ã Ý ç EÑ EÝ ,Ý ð 
×	Ò	˜HÓ	%€ð ÷WEð WEó ðWE÷t)ñ )ðX ô:
�_ó :
ó ð:
÷zCñ CôLC�oô CôL:˜/ô :ôzG%�ô G%ôT
�oô 
ôI
˜O¨_õ I
r4   