§
    Ý˜ºhƒP  ã                   ó  — d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	 d dl
Zd dlZd dlmZmZ d dlmZ ddlmZmZ dd	lmZ dd
lmZ  e j        e¦  «        Z G d„ dej        j        ¦  «        Z G d„ dej        j        ¦  «        Z dS )é    N)ÚPath)Úsleep)ÚCallableÚOptionalÚUnion)Ú
RepositoryÚcreate_repo)Úparseé   )ÚIntervalStrategyÚPreTrainedTokenizerBase)ÚTrainingSummary)Úkerasc                   óþ   ‡ — e Zd ZdZ	 	 	 	 	 	 ddedeej        j        e	j
        ej        eef         deee                  deee                  dee         d	ed
edee         fˆ fd„Zedd„¦   «         Zd„ Zdd„Zˆ xZS )ÚKerasMetricCallbacka[  
    Callback to compute metrics at the end of every epoch. Unlike normal Keras metrics, these do not need to be
    compilable by TF. It is particularly useful for common NLP metrics like BLEU and ROUGE that require string
    operations or generation loops that cannot be compiled. Predictions (or generations) will be computed on the
    `eval_dataset` before being passed to the `metric_fn` in `np.ndarray` format. The `metric_fn` should compute
    metrics and return a dict mapping metric names to metric values.

    We provide an example of a suitable metric_fn that computes ROUGE scores for a summarization model below. Note that
    this example skips some post-processing for readability and simplicity, and should probably not be used as-is!

    ```py
    from datasets import load_metric

    rouge_metric = load_metric("rouge")


    def rouge_fn(predictions, labels):
        decoded_predictions = tokenizer.batch_decode(predictions, skip_special_tokens=True)
        decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)
        result = rouge_metric.compute(predictions=decoded_predictions, references=decoded_labels)
        return {key: value.mid.fmeasure * 100 for key, value in result.items()}
    ```

    The above function will return a dict containing values which will be logged like any other Keras metric:

    ```
    {'rouge1': 37.4199, 'rouge2': 13.9768, 'rougeL': 34.361, 'rougeLsum': 35.0781
    ```

    Args:
        metric_fn (`Callable`):
            Metric function provided by the user. It will be called with two arguments - `predictions` and `labels`.
            These contain the model's outputs and matching labels from the dataset. It should return a dict mapping
            metric names to numerical values.
        eval_dataset (`tf.data.Dataset` or `dict` or `tuple` or `np.ndarray` or `tf.Tensor`):
            Validation data to be used to generate predictions for the `metric_fn`.
        output_cols (`list[str], *optional*):
            A list of columns to be retained from the model output as the predictions. Defaults to all.
        label_cols ('`list[str]`, *optional*'):
            A list of columns to be retained from the input dataset as the labels. Will be autodetected if this is not
            supplied.
        batch_size (`int`, *optional*):
            Batch size. Only used when the data is not a pre-batched `tf.data.Dataset`.
        predict_with_generate (`bool`, *optional*, defaults to `False`):
            Whether we should use `model.generate()` to get outputs for the model.
        use_xla_generation (`bool`, *optional*, defaults to `False`):
            If we're generating, whether to compile model generation with XLA. This can massively increase the speed of
            generation (up to 100X speedup) but will require a new XLA compilation for each input shape. When using XLA
            generation, it's a good idea to pad your inputs to the same size, or to use the `pad_to_multiple_of`
            argument in your `tokenizer` or `DataCollator`, which will reduce the number of unique input shapes and
            save a lot of compilation time. This option has no effect is `predict_with_generate` is `False`.
        generate_kwargs (`dict`, *optional*):
            Keyword arguments to pass to `model.generate()` when generating. Has no effect if `predict_with_generate`
            is `False`.

    NFÚ	metric_fnÚeval_datasetÚoutput_colsÚ
label_colsÚ
batch_sizeÚpredict_with_generateÚuse_xla_generationÚgenerate_kwargsc	                 óÞ  •— t          ¦   «                              ¦   «          || _        || _        t	          |t
          j        j        ¦  «        sJ|€t          d¦  «        ‚t
          j        j         	                    |¦  «         
                    |d¬¦  «        }|| _        || _        || _        t	          |j        t          ¦  «        r#t!          |j        ¦  «        dk    r|j        \  }	}
n	|j        }	d }
|�+|D ]}||	vrt          d|› d�¦  «        ‚Œ|| _        d| _        nu|
�d | _        d| _        ndd|	v r$dg| _        d| _        t'          j        d	¦  «         n<d
|	v r)d|	v r%d
dg| _        d| _        t'          j        d¦  «         nt          d¦  «        ‚t+          t
          j        ¦  «        t+          d¦  «        k     rt'          j        d¦  «         || _        |€i n|| _        d | _        d S )NzwWhen passing data to KerasMetricCallback that is not a pre-batched tf.data.Dataset the batch_size argument must be set.F)Údrop_remainderé   zLabel z? is in label_cols but could not be found in the dataset inputs!TÚlabelszTNo label_cols specified for KerasMetricCallback, assuming you want the 'labels' key.Ústart_positionsÚend_positionsznNo label_cols specified for KerasMetricCallback, assuming you want the start_positions and end_positions keys.zMCould not autodetect label_cols for KerasMetricCallback, please specify them!z2.7zHTF versions less than 2.7 may encounter issues with KerasMetricCallback!)ÚsuperÚ__init__r   r   Ú
isinstanceÚtfÚdataÚDatasetÚ
ValueErrorÚfrom_tensor_slicesÚbatchr   r   r   Úelement_specÚtupleÚlenr   Úuse_keras_labelÚloggingÚwarningr
   Ú__version__r   r   Úgeneration_function)Úselfr   r   r   r   r   r   r   r   Ú
input_specÚ
label_specÚlabelÚ	__class__s               €úd/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/transformers/keras_callbacks.pyr!   zKerasMetricCallback.__init__N   s4  ø€ õ 	‰Œ×ÒÑÔÐØ"ˆŒØ$ˆŒÝ˜,­¬¬Ñ8Ô8ð 	tØÐ!Ý ð;ñô ð õ
 œ7œ?×=Ò=¸lÑKÔK×QÒQÐR\ÐmrÐQÑsÔsˆLØ(ˆÔØ%:ˆÔ"Ø&ˆÔõ �lÔ/µÑ7Ô7ð 	½CÀÔ@YÑ<ZÔ<ZÐ^_Ò<_Ð<_Ø%1Ô%>Ñ"ˆJ˜
˜
à%Ô2ˆJØˆJØÐ!Ø#ð vð v�Ø 
Ð*Ð*Ý$Ð%t¨eÐ%tÐ%tÐ%tÑuÔuÐuð +à(ˆDŒOØ#(ˆDÔ Ð ØÐ#ð #ˆDŒOØ#'ˆDÔ Ð Ø˜Ð#Ð#Ø'˜jˆDŒOØ#(ˆDÔ ÝŒOÐrÑsÔsÐsÐsØ *Ð,Ð,°ÀJÐ1NÐ1NØ0°/ÐBˆDŒOØ#(ˆDÔ ÝŒOð:ñô ð ð õ
 ÐlÑmÔmÐmÝ•”Ñ Ô ¥5¨¡<¤<Ò/Ð/ÝŒOÐfÑgÔgÐgà"4ˆÔØ%4Ð%<˜r˜rÀ/ˆÔà#'ˆÔ Ð Ð ó    éœÿÿÿc           
      óò  ‡ — ‰ d         j         dk    st          ˆ fd„‰ D ¦   «         ¦  «        rt          j        ‰ d¬¦  «        S t	          d„ ‰ D ¦   «         ¦  «        }t          d„ ‰ D ¦   «         ¦  «        }t          j        ‰ d         |||gt          ‰ d         j        dd …         ¦  «        z   ¬¦  «        }d}‰ D ]:}||||t          |¦  «        z   …d |j        d         …f<   |t          |¦  «        z  }Œ;|S )	Nr   r   c              3   ó\   •K  — | ]&}|j         d          ‰d         j         d          k    V — Œ'dS )r   r   N©Úshape)Ú.0r(   Úbatchess     €r6   ú	<genexpr>z;KerasMetricCallback._concatenate_batches.<locals>.<genexpr>’   s;   øè è € Ð&bÐ&bÐQV u¤{°1¤~¸À¼Ô9IÈ!Ô9LÒ'LÐ&bÐ&bÐ&bÐ&bÐ&bÐ&br7   )Úaxisc                 ó(   — g | ]}|j         d          ‘ŒS )r   r;   ©r=   r(   s     r6   ú
<listcomp>z<KerasMetricCallback._concatenate_batches.<locals>.<listcomp>–   s   € Ð;Ð;Ð;¨%�u”{ 1”~Ð;Ð;Ð;r7   c                 ó(   — g | ]}|j         d          ‘ŒS )r   r;   rB   s     r6   rC   z<KerasMetricCallback._concatenate_batches.<locals>.<listcomp>—   s   € Ð?Ð?Ð?¨e˜5œ; qœ>Ð?Ð?Ð?r7   r   )Ú
fill_valuer<   )
ÚndimÚallÚnpÚconcatenateÚmaxÚsumÚ	full_likeÚlistr<   r+   )r>   Úpadding_indexÚmax_lenÚnum_samplesÚoutputÚir(   s   `      r6   Ú_concatenate_batchesz(KerasMetricCallback._concatenate_batches�   s(  ø€ ð �1Œ:Œ?˜aÒÐ¥3Ð&bÐ&bÐ&bÐ&bÐZaÐ&bÑ&bÔ&bÑ#bÔ#bÐÝ”> '°Ð2Ñ2Ô2Ð2õ Ð;Ð;°7Ð;Ñ;Ô;Ñ<Ô<ˆÝÐ?Ð?°wÐ?Ñ?Ô?Ñ@Ô@ˆÝ”Ø�AŒJ =¸ÀgÐ8NÕQUÐV]Ð^_ÔV`ÔVfÐghÐgiÐgiÔVjÑQkÔQkÑ8kð
ñ 
ô 
ˆð ˆØð 	ð 	ˆEØ;@ˆF�1�q�3˜u™:œ:‘~Ð%Ð'7¨¬°Q¬Ð'7Ð7Ñ8Ø•�U‘”‰OˆAˆAØˆr7   c                 ó8  ‡— t          |d         t          ¦  «        rmi }|d         D ]&Š|                      ˆfd„|D ¦   «         ¦  «        |‰<   Œ't          |¦  «        dk    r't	          |                     ¦   «         ¦  «        d         }�nt          |d         t          t          f¦  «        rRg }t          |Ž D ]*}|                     |                      |¦  «        ¦  «         Œ+t          |¦  «        dk    r|d         }nœt          |d         t          j
        ¦  «        r|                      |¦  «        }nft          |d         t          j        ¦  «        r |                      d„ |D ¦   «         ¦  «        }n&t          dt          |d         ¦  «        › d�¦  «        ‚|S )Nr   c                 ó    •— g | ]
}|‰         ‘ŒS © rV   )r=   r(   Úkeys     €r6   rC   zJKerasMetricCallback._postprocess_predictions_or_labels.<locals>.<listcomp>¦   s   ø€ Ð9YÐ9YÐ9YÈ¸%À¼*Ð9YÐ9YÐ9Yr7   r   c                 ó6   — g | ]}|                      ¦   «         ‘ŒS rV   ©Únumpy)r=   Útensors     r6   rC   zJKerasMetricCallback._postprocess_predictions_or_labels.<locals>.<listcomp>³   s    € Ð0UÐ0UÐ0UÀF°·²±´Ð0UÐ0UÐ0Ur7   zCouldn't handle batch of type ú!)r"   ÚdictrS   r+   rM   Úvaluesr*   ÚzipÚappendrH   Úndarrayr#   ÚTensorÚ	TypeErrorÚtype)r1   ÚinputsÚoutputsÚ
input_listrW   s       @r6   Ú"_postprocess_predictions_or_labelsz6KerasMetricCallback._postprocess_predictions_or_labels¢   s˜  ø€ Ý�f˜Q”i¥Ñ&Ô&ð 	QØˆGØ˜a”yð [ð [�Ø#×8Ò8Ð9YÐ9YÐ9YÐ9YÐRXÐ9YÑ9YÔ9YÑZÔZ�˜‘�å�7‰|Œ|˜qÒ Ð Ý˜wŸ~š~Ñ/Ô/Ñ0Ô0°Ô3�ùÝ˜˜qœ	¥E­4 =Ñ1Ô1ð 	QØˆGÝ! 6˜lð Fð F�
Ø—’˜t×8Ò8¸ÑDÔDÑEÔEÐEÐEÝ�7‰|Œ|˜qÒ Ð Ø! !œ*�øÝ˜˜qœ	¥2¤:Ñ.Ô.ð 	QØ×/Ò/°Ñ7Ô7ˆGˆGÝ˜˜qœ	¥2¤9Ñ-Ô-ð 	QØ×/Ò/Ð0UÐ0UÈfÐ0UÑ0UÔ0UÑVÔVˆGˆGåÐO½TÀ&ÈÄ)¹_¼_ÐOÐOÐOÑPÔPÐPØˆr7   c                 ó¨  ‡ ‡‡‡— t          ‰ j        d¦  «        rt          ‰ j        j        dg ¦  «        Šng Šd }‰ j        r…t          ‰ j        d¦  «        r,t          ‰ j        j        d¦  «        r‰ j        j        j        }nt          ‰ j        dd¦  «        }‰ j        r'‰ j        € ˆ fd„}t          j
        |d¬¦  «        ‰ _        g }g }‰ j        D �]Št          ‰t          ¦  «        r‰\  Š}nd }‰ j        rrt          ‰t          ¦  «        r‰|         }‰                     d	d ¦  «        }	n‰}d }	‰ j        r‰                      ||	¬
¦  «        Šn” ‰ j        j        |fd	|	i‰ j        ¤ŽŠny‰ j                             ‰¦  «        Št          ‰t          ¦  «        rJt          ‰¦  «        Š‰ j        �ˆfd„‰ j        D ¦   «         Šn ˆfd„‰                     ¦   «         D ¦   «         Š|                     ‰¦  «         ‰ j        sˆfd„‰ j        D ¦   «         }n«t          |t          ¦  «        rd„ |                     ¦   «         D ¦   «         }nwt          |t0          t          f¦  «        rd„ |D ¦   «         }nNt          |t          j        ¦  «        r|                     ¦   «         }nt7          dt9          |¦  «        › �¦  «        ‚|                     |¦  «         �Œ‰                      |¦  «        }
‰                      |¦  «        }‰                      |
|f¦  «        }t          |t          ¦  «        st7          d|› �¦  «        ‚|                     |¦  «         d S )NÚconfigÚkeys_to_ignore_at_inferenceÚencoderÚmain_input_nameÚ	input_idsc                 ó8   •—  ‰j         j        | fd|i‰j        ¤ŽS )NÚattention_mask)ÚmodelÚgenerater   )re   rp   r1   s     €r6   r0   z=KerasMetricCallback.on_epoch_end.<locals>.generation_functionÉ   s)   ø€ Ø.˜4œ:Ô.¨vÐmÐmÀnÐmÐX\ÔXlÐmÐmÐmr7   T)Újit_compilerp   )rp   c                 ó"   •— i | ]}|‰|         “ŒS rV   rV   )r=   rW   Úpredictionss     €r6   ú
<dictcomp>z4KerasMetricCallback.on_epoch_end.<locals>.<dictcomp>ë   s    ø€ Ð&YÐ&YÐ&YÀ s¨K¸Ô,<Ð&YÐ&YÐ&Yr7   c                 ó,   •— i | ]\  }}|‰d gz   v¯||“ŒS )ÚlossrV   )r=   rW   ÚvalÚignore_keyss      €r6   rv   z4KerasMetricCallback.on_epoch_end.<locals>.<dictcomp>í   s:   ø€ ð 'ð 'ð 'Ù)1¨¨cÈCÐWbÐflÐemÑWmÐLmÐLm˜C ÐLmÐLmÐLmr7   c                 óF   •— i | ]}|‰|                               ¦   «         “ŒS rV   rY   )r=   rW   r(   s     €r6   rv   z4KerasMetricCallback.on_epoch_end.<locals>.<dictcomp>ò   s+   ø€ ÐMÐMÐM°c˜#˜u Sœz×/Ò/Ñ1Ô1ÐMÐMÐMr7   c                 ó>   — i | ]\  }}||                      ¦   «         “ŒS rV   rY   )r=   rW   Úarrays      r6   rv   z4KerasMetricCallback.on_epoch_end.<locals>.<dictcomp>ô   s&   € ÐNÐNÐN±°°e˜#˜uŸ{š{™}œ}ÐNÐNÐNr7   c                 ó6   — g | ]}|                      ¦   «         ‘ŒS rV   rY   )r=   r}   s     r6   rC   z4KerasMetricCallback.on_epoch_end.<locals>.<listcomp>ö   s    € Ð<Ð<Ð<¨E˜%Ÿ+š+™-œ-Ð<Ð<Ð<r7   zConfused by labels of type zSmetric_fn should return a dict mapping metric names to values but instead returned ) Úhasattrrq   Úgetattrrj   r   rl   rm   r   r0   r#   Úfunctionr   r"   r*   r]   Úgetrr   r   Úpredict_on_batchr   Úitemsr`   r,   r   rM   rb   rZ   rc   rd   rh   r   Úupdate)r1   ÚepochÚlogsrm   r0   Úprediction_listÚ
label_listr   Úgeneration_inputsrp   Ú	all_predsÚ
all_labelsÚmetric_outputr(   rz   ru   s   `            @@@r6   Úon_epoch_endz KerasMetricCallback.on_epoch_end¸   sØ  øøøø€ Ý�4”:˜xÑ(Ô(ð 	Ý! $¤*Ô"3Ð5RÐTVÑWÔWˆKˆKàˆKàˆØÔ%ð 	^õ �t”z 9Ñ-Ô-ð Vµ'¸$¼*Ô:LÐN_Ñ2`Ô2`ð VØ"&¤*Ô"4Ô"D��å")¨$¬*Ð6GÈÑ"UÔ"U�àÔ&ð ^¨4Ô+CÐ+Kðnð nð nð nð nõ ,.¬;Ð7JÐX\Ð+]Ñ+]Ô+]�Ô(àˆØˆ
ð Ô&ð )	&ñ )	&ˆEÝ˜%¥Ñ'Ô'ð Ø %‘��v�và�ØÔ)ð Ý˜e¥TÑ*Ô*ð *Ø(-¨oÔ(>Ð%Ø%*§Y¢YÐ/?ÀÑ%FÔ%F�N�Nà(-Ð%Ø%)�NØÔ*ð Ø"&×":Ò":Ð;LÐ]kÐ":Ñ"lÔ"l�K�Kà"5 $¤*Ô"5Ø)ð#ð #Ø:Hð#ØLPÔL`ð#ð #�K�Kð #œj×9Ò9¸%Ñ@Ô@�Ý˜k­4Ñ0Ô0ð 	õ #' {Ñ"3Ô"3�KØÔ'Ð3Ø&YÐ&YÐ&YÐ&YÈÔHXÐ&YÑ&YÔ&Y˜˜ð'ð 'ð 'ð 'Ø5@×5FÒ5FÑ5HÔ5Hð'ñ 'ô '˜ð ×"Ò" ;Ñ/Ô/Ð/ØÔ'ð 	NØMÐMÐMÐM¸T¼_ÐMÑMÔM��Ý˜F¥DÑ)Ô)ð NØNÐN¸v¿|º|¹~¼~ÐNÑNÔN��Ý˜F¥T­5 MÑ2Ô2ð NØ<Ð<°VÐ<Ñ<Ô<��Ý˜F¥B¤IÑ.Ô.ð NØŸš™œ��åÐ L½dÀ6¹l¼lÐ LÐ LÑMÔMÐMØ×Ò˜fÑ%Ô%Ð%Ñ%à×;Ò;¸OÑLÔLˆ	Ø×<Ò<¸ZÑHÔHˆ
àŸš¨	°:Ð'>Ñ?Ô?ˆÝ˜-­Ñ.Ô.ð 	ÝØuÐfsÐuÐuñô ð ð 	�Š�MÑ"Ô"Ð"Ð"Ð"r7   )NNNFFN)r8   ©N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   r$   r%   rH   ra   rb   r*   r]   r   rM   ÚstrÚintÚboolr!   ÚstaticmethodrS   rh   rŽ   Ú__classcell__©r5   s   @r6   r   r      s-  ø€ € € € € ð7ð 7ðz ,0Ø*.Ø$(Ø&+Ø#(Ø*.ð?(ð ?(àð?(ð ˜BœGœO¨R¬Z¸¼ÀEÈ4ÐOÔPð?(ð ˜d 3œiÔ(ð	?(ð
 ˜T #œYÔ'ð?(ð ˜S”Mð?(ð  $ð?(ð !ð?(ð " $œð?(ð ?(ð ?(ð ?(ð ?(ð ?(ðB ðð ð ñ „\ðð$ð ð ð,Q#ð Q#ð Q#ð Q#ð Q#ð Q#ð Q#ð Q#r7   r   c                   ó¾   ‡ — e Zd ZdZ	 	 	 	 	 	 ddeeef         deeef         dee	         dee
         d	ee         d
ee         defˆ fd„Zdd„Zdd„Zdd„Zdd„Zˆ xZS )ÚPushToHubCallbackaC	  
    Callback that will save and push the model to the Hub regularly. By default, it pushes once per epoch, but this can
    be changed with the `save_strategy` argument. Pushed models can be accessed like any other model on the hub, such
    as with the `from_pretrained` method.

    ```py
    from transformers.keras_callbacks import PushToHubCallback

    push_to_hub_callback = PushToHubCallback(
        output_dir="./model_save",
        tokenizer=tokenizer,
        hub_model_id="gpt5-7xlarge",
    )

    model.fit(train_dataset, callbacks=[push_to_hub_callback])
    ```

    Args:
        output_dir (`str`):
            The output directory where the model predictions and checkpoints will be written and synced with the
            repository on the Hub.
        save_strategy (`str` or [`~trainer_utils.IntervalStrategy`], *optional*, defaults to `"epoch"`):
            The checkpoint save strategy to adopt during training. Possible values are:

                - `"no"`: Save is done at the end of training.
                - `"epoch"`: Save is done at the end of each epoch.
                - `"steps"`: Save is done every `save_steps`
        save_steps (`int`, *optional*):
            The number of steps between saves when using the "steps" `save_strategy`.
        tokenizer (`PreTrainedTokenizerBase`, *optional*):
            The tokenizer used by the model. If supplied, will be uploaded to the repo alongside the weights.
        hub_model_id (`str`, *optional*):
            The name of the repository to keep in sync with the local `output_dir`. It can be a simple model ID in
            which case the model will be pushed in your namespace. Otherwise it should be the whole repository name,
            for instance `"user_name/model"`, which allows you to push to an organization you are a member of with
            `"organization_name/model"`.

            Will default to the name of `output_dir`.
        hub_token (`str`, *optional*):
            The token to use to push the model to the Hub. Will default to the token in the cache folder obtained with
            `hf auth login`.
        checkpoint (`bool`, *optional*, defaults to `False`):
            Whether to save full training checkpoints (including epoch and optimizer state) to allow training to be
            resumed. Only usable when `save_strategy` is `"epoch"`.
    r†   NFÚ
output_dirÚsave_strategyÚ
save_stepsÚ	tokenizerÚhub_model_idÚ	hub_tokenÚ
checkpointc                 ó¸  •— t          ¦   «                              ¦   «          |r|dk    rt          d¦  «        ‚t          |t          ¦  «        r!t          |                     ¦   «         ¦  «        }|| _        | j        t
          j        k    r*t          |t          ¦  «        r|dk    rt          d¦  «        ‚|| _
        t          |¦  «        }|€|                     ¦   «         j        }t          |d|¬¦  «        j        | _        || _        t%          t	          | j        ¦  «        | j        |¬¦  «        | _        || _        d | _        || _        d | _        || _        d S )Nr†   z:Cannot save checkpoints when save_strategy is not 'epoch'!r   zWPlease supply a positive integer argument for save_steps when save_strategy == 'steps'!T)Úrepo_idÚexist_okÚtoken)Ú
clone_fromr¦   )r    r!   r&   r"   r”   r   Úlowerr�   ÚSTEPSr•   rž   r   ÚabsoluteÚnamer	   r¤   r    rœ   r   ÚreporŸ   Úlast_jobr¢   Útraining_historyÚmodel_card_args)
r1   rœ   r�   rž   rŸ   r    r¡   r¢   r¯   r5   s
            €r6   r!   zPushToHubCallback.__init__;  sO  ø€ õ 	‰Œ×ÒÑÔÐØð 	[˜-¨7Ò2Ð2ÝÐYÑZÔZÐZÝ�m¥SÑ)Ô)ð 	DÝ,¨]×-@Ò-@Ñ-BÔ-BÑCÔCˆMØ*ˆÔØÔÕ!1Ô!7Ò7Ð7ÅÈJÕX[ÑA\ÔA\Ð7Ð`jÐnoÒ`oÐ`oÝÐvÑwÔwÐwØ$ˆŒÝ˜*Ñ%Ô%ˆ
ð ÐØ%×.Ò.Ñ0Ô0Ô5ˆLÝ'°ÀtÐS\Ð]Ñ]Ô]ÔeˆÔà$ˆŒÝ�s 4¤?Ñ3Ô3ÀÔ@QÐYbÐcÑcÔcˆŒ	à"ˆŒØˆŒØ$ˆŒØ $ˆÔØ.ˆÔÐÐr7   c                 ó   — g | _         d S r�   )r®   )r1   r‡   s     r6   Úon_train_beginz PushToHubCallback.on_train_begin_  s   € ð !#ˆÔÐÐr7   c                 ó\  — | j         t          j        k    r”|dz   | j        z  dk    r…| j        �| j        j        sd S | j                             | j        ¦  «         | j	        �| j	                             | j        ¦  «         | j
                             d|› �d¬¦  «        \  }| _        d S d S d S )Nr   r   zTraining in progress steps F©Úcommit_messageÚblocking)r�   r   r©   rž   r­   Úis_donerq   Úsave_pretrainedrœ   rŸ   r¬   Úpush_to_hub)r1   r(   r‡   Ú_s       r6   Úon_train_batch_endz$PushToHubCallback.on_train_batch_endd  s»   € ØÔÕ!1Ô!7Ò7Ð7¸UÀQ¹YÈ$Ì/Ñ<YÐ]^Ò<^Ð<^ØŒ}Ð(°´Ô1FÐ(Ø�ØŒJ×&Ò& t¤Ñ7Ô7Ð7ØŒ~Ð)Ø”×.Ò.¨t¬Ñ?Ô?Ð?Ø#œy×4Ò4ØD¸UÐDÐDÈuð  5ñ  ô  ÑˆAˆtŒ}ˆ}ˆ}ð 8Ð7Ð<^Ð<^r7   c                 óB  — |                      ¦   «         }d|vr||d<   | j                             |¦  «         | j        t          j        k    �rQ| j        �| j        j        sd S | j         	                    | j
        ¦  «         | j        �| j         	                    | j
        ¦  «         | j        r@t          j                             | j
        d¦  «        }| j                             ||¦  «         t#          j        d	| j        | j        | j        dœ| j        ¤Ž}|                     ¦   «         }| j
        dz                       d¦  «        5 }|                     |¦  «         d d d ¦  «         n# 1 swxY w Y   | j                             d|› �d¬¦  «        \  }| _        d S d S )
Nr†   r¢   ©rq   Ú
model_nameÚkeras_historyú	README.mdÚwzTraining in progress epoch Fr³   rV   )Úcopyr®   r`   r�   r   ÚEPOCHr­   r¶   rq   r·   rœ   rŸ   r¢   ÚosÚpathÚjoinÚ_save_checkpointr   Ú
from_kerasr    r¯   Úto_model_cardÚopenÚwriter¬   r¸   )r1   r†   r‡   Úcheckpoint_dirÚtrain_summaryÚ
model_cardÚfr¹   s           r6   rŽ   zPushToHubCallback.on_epoch_endo  sÝ  € Ø�yŠy‰{Œ{ˆØ˜$ÐÐØ!ˆD�‰MØÔ×$Ò$ TÑ*Ô*Ð*ØÔÕ!1Ô!7Ò7Ñ7ØŒ}Ð(°´Ô1FÐ(Ø�ØŒJ×&Ò& t¤Ñ7Ô7Ð7ØŒ~Ð)Ø”×.Ò.¨t¬Ñ?Ô?Ð?ØŒð CÝ!#¤§¢¨d¬o¸|Ñ!LÔ!L�Ø”
×+Ò+¨N¸EÑBÔBÐBÝ+Ô6ð Ø”jØÔ,Ø"Ô3ðð ð Ô&ð	ð ˆMð '×4Ò4Ñ6Ô6ˆJØ”/ KÑ/×5Ò5°cÑ:Ô:ð $¸aØ—’˜
Ñ#Ô#Ð#ð$ð $ð $ñ $ô $ð $ð $ð $ð $ð $ð $øøøð $ð $ð $ð $à#œy×4Ò4ØD¸UÐDÐDÈuð  5ñ  ô  ÑˆAˆtŒ}ˆ}ˆ}ð% 8Ð7s   Å	E+Å+E/Å2E/c                 óz  — | j         �K| j         j        s?t          j        d¦  «         | j         j        st	          d¦  «         | j         j        ¯d S d S | j                             | j        ¦  «         | j        �| j                             | j        ¦  «         t          j
        d	| j        | j        | j        dœ| j        ¤Ž}|                     ¦   «         }| j        dz                       d¦  «        5 }|                     |¦  «         d d d ¦  «         n# 1 swxY w Y   | j                             dd¬¦  «         d S )
Nz;Pushing the last epoch to the Hub, this may take a while...r   r¼   r¿   rÀ   zEnd of trainingTr³   rV   )r­   r¶   r-   Úinfor   rq   r·   rœ   rŸ   r   rÇ   r    r®   r¯   rÈ   rÉ   rÊ   r¬   r¸   )r1   r‡   rÌ   rÍ   rÎ   s        r6   Úon_train_endzPushToHubCallback.on_train_endŠ  sˆ  € àŒ=Ð$¨T¬]Ô-BÐ$ÝŒLÐVÑWÔWÐWØ”mÔ+ð Ý�a‘”�ð ”mÔ+ð ð ð ð ð ð ŒJ×&Ò& t¤Ñ7Ô7Ð7ØŒ~Ð)Ø”×.Ò.¨t¬Ñ?Ô?Ð?Ý+Ô6ð Ø”jØÔ,Ø"Ô3ðð ð Ô&ð	ð ˆMð '×4Ò4Ñ6Ô6ˆJØ”/ KÑ/×5Ò5°cÑ:Ô:ð $¸aØ—’˜
Ñ#Ô#Ð#ð$ð $ð $ñ $ô $ð $ð $ð $ð $ð $ð $øøøð $ð $ð $ð $àŒI×!Ò!Ð1BÈTÐ!ÑRÔRÐRÐRÐRs   Ã2DÄDÄD)r†   NNNNFr�   )r�   r‘   r’   r“   r   r”   r   r   r   r•   r   r–   r!   r±   rº   rŽ   rÑ   r˜   r™   s   @r6   r›   r›     s$  ø€ € € € € ð,ð ,ðb 7>Ø$(Ø7;Ø&*Ø#'Ø ð"/ð "/à˜#˜t˜)Ô$ð"/ð ˜SÐ"2Ð2Ô3ð"/ð ˜S”Mð	"/ð
 Ð3Ô4ð"/ð ˜s”mð"/ð ˜C”=ð"/ð ð"/ð "/ð "/ð "/ð "/ð "/ðH#ð #ð #ð #ð
	ð 	ð 	ð 	ðð ð ð ð6Sð Sð Sð Sð Sð Sð Sð Sr7   r›   )!r-   rÃ   Úpathlibr   Útimer   Útypingr   r   r   rZ   rH   Ú
tensorflowr#   Úhuggingface_hubr   r	   Úpackaging.versionr
   Ú r   r   Ú	modelcardr   Úmodeling_tf_utilsr   Ú	getLoggerr�   ÚloggerÚ	callbacksÚCallbackr   r›   rV   r7   r6   ú<module>rß      sp  ðØ €€€Ø 	€	€	€	Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,à Ð Ð Ð Ø Ð Ð Ð Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø #Ð #Ð #Ð #Ð #Ð #à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø &Ð &Ð &Ð &Ð &Ð &Ø $Ð $Ð $Ð $Ð $Ð $ð 
ˆÔ	˜8Ñ	$Ô	$€ðu#ð u#ð u#ð u#ð u#˜%œ/Ô2ñ u#ô u#ð u#ðpQSð QSð QSð QSð QS˜œÔ0ñ QSô QSð QSð QSð QSr7   