� ���go���b�dZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z ddl Z ddlZddlmZddlmZdd lmZdd lmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$dd l%m&Z&dd l'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/eeeeeeee e"e#eie�e!�e$ed �Z0e/j1e2��Z3Gd�d��Z4dZ5dZ6idd�dd�dd�dd�dd�dd�dd�d d!�d"d#�d$d%�d&d'�d(d)�d*d+�d,d-�d.d/�d0d1�Z7gd2�Z8d3�Z9d4�Z:d5�Z;d6�Z<d7�Z=d8�Z>eGd9�d:����Z?d;�Z@d<�ZAd=�ZBdEd?�ZCd@�ZDdA�ZEdB�ZFgdC�ZGdD�ZHdS)Fz'Configuration base class and utilities.�N)� dataclass)�Path)�Any�Optional�Union)� model_info)�HFValidationError�)� __version__)�,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES�!MODEL_FOR_CAUSAL_LM_MAPPING_NAMES�MODEL_FOR_CTC_MAPPING_NAMES�,MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES�*MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES�*MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES�!MODEL_FOR_MASKED_LM_MAPPING_NAMES�(MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES�*MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES�,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES�/MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES�(MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES�0MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES�,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES�6MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING_NAMES)� ParallelMode)�MODEL_CARD_NAME� cached_file�is_datasets_available�is_offline_mode�is_tf_available�is_tokenizers_available�is_torch_available�logging)�text-generation�image-classification�image-segmentation� fill-mask�object-detection�question-answering�text2text-generation�text-classification�table-question-answering�token-classification�audio-classification�automatic-speech-recognitionzzero-shot-image-classificationzimage-text-to-textc�~�eZdZdZd�Zd�Zed���Zed���Zed���Z d�Z d�Z d �Z d �Z d �Zd S) � ModelCarda Structured Model Card class. Store model card as well as methods for loading/downloading/saving model cards. Please read the following paper for details and explanation on the sections: "Model Cards for Model Reporting" by Margaret Mitchell, Simone Wu, Andrew Zaldivar, Parker Barnes, Lucy Vasserman, Ben Hutchinson, Elena Spitzer, Inioluwa Deborah Raji and Timnit Gebru for the proposal behind model cards. Link: https://arxiv.org/abs/1810.03993 Note: A model card can be loaded and saved to disk. c ���tjdt��|�di��|_|�di��|_|�di��|_|�di��|_|�di��|_|�di��|_ |�di��|_ |�d i��|_ |�d i��|_ |� ��D]N\}} t|||���#t$r*}t �d |�d |�d |����|�d}~wwxYwdS)NzTThe class `ModelCard` is deprecated and will be removed in version 5 of Transformers� model_details� intended_use�factors�metrics�evaluation_data� training_data�quantitative_analyses�ethical_considerations�caveats_and_recommendationsz Can't set z with value z for )�warnings�warn� FutureWarning�popr3r4r5r6r7r8r9r:r;�items�setattr�AttributeError�logger�error)�self�kwargs�key�value�errs �f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/transformers/modelcard.py�__init__zModelCard.__init__[sw��� � b�dq� � � �$�Z�Z���<�<���"�J�J�~�r�:�:����z�z�)�R�0�0�� ��z�z�)�R�0�0�� �%�z�z�*;�R�@�@���#�Z�Z���<�<���%+�Z�Z�0G��%L�%L��"�&,�j�j�1I�2�&N�&N��#�+1�:�:�6S�UW�+X�+X��(�!�,�,�.�.� � �J�C�� ���c�5�)�)�)�)��!� � � �� � �M�#�M�M�5�M�M�t�M�M�N�N�N�� ����� ���� � s�(D:�: E.�%E)�)E.c���tj�|��r&tj�|t��}n|}|�|��t �d|����dS)zKSave a model card object to the directory or file `save_directory_or_file`.zModel card saved in N)�os�path�isdir�joinr� to_json_filerC�info)rE�save_directory_or_file�output_model_card_files rJ�save_pretrainedzModelCard.save_pretrainedrsp�� �7�=�=�/� 0� 0� <�%'�W�\�\�2H�/�%Z�%Z� "� "�%;� "� ���0�1�1�1�� � �C�+A�C�C�D�D�D�D�D�c ��|�dd��}|�dd��}|�dd��}|�dd��}ddi}|�||d <tj�|��}tj�|��r|} d }n� t |t |||� ��} |rt�d | ����n%t�d t �d | ����|� | ��} n&#ttj f$r |��} YnwxYwg} |� ��D];\} } t| | ��r&t| | | ��| �| ���<| D]} |�| d���t�d| ����|r| |fS| S)a� Instantiate a [`ModelCard`] from a pre-trained model model card. Parameters: pretrained_model_name_or_path: either: - a string, the *model id* of a pretrained model card hosted inside a model repo on huggingface.co. - a path to a *directory* containing a model card file saved using the [`~ModelCard.save_pretrained`] method, e.g.: `./my_model_directory/`. - a path or url to a saved model card JSON *file*, e.g.: `./my_model_directory/modelcard.json`. cache_dir: (*optional*) string: Path to a directory in which a downloaded pre-trained model card should be cached if the standard cache should not be used. kwargs: (*optional*) dict: key/value pairs with which to update the ModelCard object after loading. - The values in kwargs of any keys which are model card attributes will be used to override the loaded values. - Behavior concerning key/value pairs whose keys are *not* model card attributes is controlled by the *return_unused_kwargs* keyword parameter. proxies: (*optional*) dict, default None: A dictionary of proxy servers to use by protocol or endpoint, e.g.: {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request. return_unused_kwargs: (*optional*) bool: - If False, then this function returns just the final model card object. - If True, then this functions returns a tuple *(model card, unused_kwargs)* where *unused_kwargs* is a dictionary consisting of the key/value pairs whose keys are not model card attributes: ie the part of kwargs which has not been used to update *ModelCard* and is otherwise ignored. Examples: ```python # Download model card from huggingface.co and cache. modelcard = ModelCard.from_pretrained("google-bert/bert-base-uncased") # Model card was saved using *save_pretrained('./test/saved_model/')* modelcard = ModelCard.from_pretrained("./test/saved_model/") modelcard = ModelCard.from_pretrained("./test/saved_model/modelcard.json") modelcard = ModelCard.from_pretrained("google-bert/bert-base-uncased", output_attentions=True, foo=False) ```� cache_dirN�proxies�return_unused_kwargsF�_from_pipeline� file_type� model_card�using_pipelineT)�filenamerXrY� user_agentzloading model card file z from cache at z Model card: )r?rMrNrO�isfilerrrCrR�from_json_file�OSError�json�JSONDecodeErrorr@�hasattrrA�append)�cls�pretrained_model_name_or_pathrFrXrYrZ� from_pipeliner`�is_local�resolved_model_card_file� modelcard� to_removerGrHs rJ�from_pretrainedzModelCard.from_pretrained}s��Z�J�J�{�D�1�1� ��*�*�Y��-�-��%�z�z�*@�%�H�H��� � �#3�T�:�:� �!�<�0� � � $�+8�J�'� (��7�=�=�!>�?�?�� �7�>�>�7� 8� 8� "�'D� $��H�H� "�+6�1�,�'�#�)� ,�,�,�(��w��K�K� U�;S� U� U�V�V�V�V��K�K� u�?� u� u�[s� u� u�v�v�v��.�.�/G�H�H� � ���T�1�2� "� "� "��C�E�E� � � � "���� � � �,�,�.�.� &� &�J�C���y�#�&�&� &�� �3��.�.�.�� � ��%�%�%��� "� "�C� �J�J�s�D� !� !� !� !�� � �.�9�.�.�/�/�/� � ��f�$� $�� s�(A3D� D?�>D?c��|di|��S)z@Constructs a `ModelCard` from a Python dictionary of parameters.�rq)rh� json_objects rJ� from_dictzModelCard.from_dict�s���s�!�!�[�!�!�!rVc��t|d���5}|���}ddd��n #1swxYwYtj|��}|di|��S)z8Constructs a `ModelCard` from a json file of parameters.�utf-8��encodingNrq)�open�readrd�loads)rh� json_file�reader�text�dict_objs rJrbzModelCard.from_json_file�s����)�g� .� .� .� !�&��;�;�=�=�D� !� !� !� !� !� !� !� !� !� !� !���� !� !� !� !��:�d�#�#���s���X���s �3�7�7c�"�|j|jkS�N)�__dict__)rE�others rJ�__eq__zModelCard.__eq__�s���}���.�.rVc�D�t|�����Sr�)�str�to_json_string�rEs rJ�__repr__zModelCard.__repr__�s���4�&�&�(�(�)�)�)rVc�8�tj|j��}|S)z0Serializes this instance to a Python dictionary.)�copy�deepcopyr�)rE�outputs rJ�to_dictzModelCard.to_dict�s����t�}�-�-��� rVc�Z�tj|���dd���dzS)z*Serializes this instance to a JSON string.�T)�indent� sort_keys� )rd�dumpsr�r�s rJr�zModelCard.to_json_string�s&���z�$�,�,�.�.��d�C�C�C�d�J�JrVc��t|dd���5}|�|�����ddd��dS#1swxYwYdS)z"Save this instance to a json file.�wrurvN)rx�writer�)rE�json_file_path�writers rJrQzModelCard.to_json_file�s��� �.�#�� 8� 8� 8� 0�F� �L�L��,�,�.�.� /� /� /� 0� 0� 0� 0� 0� 0� 0� 0� 0� 0� 0� 0���� 0� 0� 0� 0� 0� 0s�(A�A �A N)�__name__� __module__� __qualname__�__doc__rKrU� classmethodrorsrbr�r�r�r�rQrqrVrJr1r1Ps������������. E� E� E��[�[��[�[�z�"�"��[�"�����[��/�/�/�*�*�*���� K�K�K�0�0�0�0�0rVr1z� <!-- This model card has been generated automatically according to the information the Trainer had access to. You should probably proofread and complete it, then remove this comment. --> z� <!-- This model card has been generated automatically according to the information Keras had access to. You should probably proofread and complete it, then remove this comment. --> r'zMasked Language Modelingr%zImage Classificationr&zImage Segmentationzmultiple-choicezMultiple Choicer(zObject Detectionr)zQuestion Answering� summarization� Summarizationr,zTable Question Answeringr+zText Classificationr$zCausal Language Modelingr*z&Sequence-to-sequence Language Modelingr-zToken Classification� translation� Translationzzero-shot-classificationzZero Shot Classificationr/zAutomatic Speech Recognitionr.zAudio Classification) �accuracy�bleu�f1�matthews_correlation�pearsonr� precision�recall�rouge� sacrebleu� spearmanr�werc�>�|�gSt|t��r|gS|Sr�)� isinstancer�)�objs rJ�_listifyr�+s*�� �{�� � �C�� � ���u� �� rVc��|�|St|t��r|g}d�|D��}t|��dkr|S|||<|S)Nc��g|]}|�|��Sr�rq��.0�vs rJ� <listcomp>z*_insert_values_as_list.<locals>.<listcomp>9s�� 1� 1� 1�A�1�=�a�=�=�=rVr)r�r��len)�metadata�name�valuess rJ�_insert_values_as_listr�4s\�� �~����&�#������� 1� 1�� 1� 1� 1�F� �6�{�{�a������H�T�N� �OrVc�0�|�iSi}|���D]z}|����dd��tvr,|||����dd��<�]|���dkr||d<�{|S)N� �_�rouge1r�)�keys�lower�replace� METRIC_TAGS)� eval_results�resultrGs rJ�#infer_metric_tags_from_eval_resultsr�@s������ � �F�� � �"�"�"�"�� �9�9�;�;� � �s�C� (� (�K� 7� 7�47�F�3�9�9�;�;�&�&�s�C�0�0� 1� 1� �Y�Y�[�[�H� $� $�!�F�7�O�� �MrVc��|�|S|||<|Sr�rq)r�r�rHs rJ� _insert_valuer�Ls�� �}����H�T�N� �OrVc�V�t��sdSddlm}m}t |||f��S)NFr)�Dataset�IterableDataset)r�datasetsr�r�r�)�datasetr�r�s rJ� is_hf_datasetr�SsB�� � "� "���u�1�1�1�1�1�1�1�1� �g���9� :� :�:rVc���g}|���D]F}t|ttf��r|t|��z }�1|�|���G|Sr�)r�r��tuple�listrg)�mappingr�r�s rJ�_get_mapping_valuesr�\sb�� �F� �^�^� � ���� �a�%��� '� '� � �d�1�g�g� �F�F� �M�M�!� � � � � �MrVc��eZdZUeed<dZeeeeefed<dZ eeed<dZ eeeeefed<dZ eeed<dZ eeeeefed<dZ eeeeefed<dZeeeeefed <dZeeeeefed <dZeeeefed <dZeeeefed <dZeeeed <dZeeeefed<dZeeed<d�Zd�Zd�Zd�Ze dd���Ze dd���ZdS)�TrainingSummary� model_nameN�language�license�tags�finetuned_from�tasksr�� dataset_tags� dataset_args�dataset_metadatar�� eval_lines�hyperparameters�trainer�sourcec�h�|j��t��s�|j��t|j��dkr} t |j��}|jD]&}|�d��r|dd�|_�'dS#tjj tjj tf$rYdSwxYwdSdSdSdS)Nrzlicense:�) r�rr�r�rr�� startswith�requests� exceptions� HTTPError�ConnectionErrorr )rErR�tags rJ� __post_init__zTrainingSummary.__post_init__ws��� �L� �#�%�%� !��#�/��D�'�(�(�1�,�,� �!�$�"5�6�6���9�/�/�C��~�~�j�1�1�/�'*�1�2�2�w�� ��/�/���'�1�8�3F�3V�Xi�j� � � ���� ���� !� � � �/�/�,�,s�AA:�:+B)�(B)c����d|ji}t|j��}t|j��}t|j��}t|j��}t |��t |��kr&|dgt |��t |��z zz}tt||�����tt||����}tt||����}d�t|j ��D��} g|d<t | ��dkrt ���dkr|gSt | ��dkrddi} t ���dkrddi��fd�| D��} | D]�\} } i} | �| | | d�| d<| �?|� | i��}�| | d�|�| d<|| �|| | dd <t |��dkrIg| d <|� ��D]/\}}| d � |||j |d ����0d| vr$d| vr d | vr|d� | ����t�d | ������|gS) Nr�c�<�i|]}|tv� |t|��Srq)�TASK_TAG_TO_NAME_MAPPING)r��tasks rJ� <dictcomp>z6TrainingSummary.create_model_index.<locals>.<dictcomp>�s3�� � � �59�UY�]u�Uu�Uu�D�*�4�0�Uu�Uu�UurV�resultsrc�"��g|] }�D]}||f��� Srqrq)r��task_tag�ds_tag�dataset_mappings �rJr�z6TrainingSummary.create_model_index.<locals>.<listcomp>�s-���k�k�k�H�[j�k�k�QW�h��/�k�k�k�krV)r��typer�r��argsr6)r�r�rHzLDropping the following result as it does not have all the necessary fields: )r�r�r�r�r�r�r��dict�zipr��getr@rgr�rCrR)rE�metric_mapping� model_index� dataset_namesr�r�r��dataset_arg_mapping�dataset_metadata_mapping� task_mapping�all_possibilitiesr�r�r�r�� metric_tag� metric_namer�s @rJ�create_model_indexz"TrainingSummary.create_model_index�s����t��/� �!���.�.� ��� 1�2�2� ��� 1�2�2� �#�D�$9�:�:�� �|� � �s�<�0�0� 0� 0�'�4�&�C� �4E�4E��L�HY�HY�4Y�*Z�Z�L��s�<��?�?�@�@��"�3�|�\�#B�#B�C�C��#'��L�:J�(K�(K�#L�#L� � � �=E�d�j�=Q�=Q� � � � �"$� �I�� �|� � �� !� !�c�/�&:�&:�a�&?�&?��=� � �|� � �� !� !� �$�<�L� �� � �1� $� $�#�T�l�O�l�k�k�k� �k�k�k�� 1� v� v� �H�f��F��#�*6�x�*@�(�!S�!S��v���!�3�7�7���C�C��+�F�3�"�%�%��%��y�!� '�v�.�:�0C�F�0K�F�9�%�f�-��>�"�"�Q�&�&�$&��y�!�/=�/C�/C�/E�/E���+�J� ��9�%�,�,�$/�$.�%)�%6�{�%C�����������I��$7�$7�I��<O�<O��I�&�-�-�f�5�5�5�5�� � �t�lr�t�t�u�u�u�u��}�rVc�2�t|j��}i}t|dd��}t|d|j��}t|d|j��}|j�Ht|jt��r.t|j��dkrt|d|j��}t|d|j ��}t|d|j ��}t|d t|� ������}|�|��|d <|S) N� library_name� transformersr�r�r� base_modelr�r�r6z model-index)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r)rEr�r�s rJ�create_metadatazTrainingSummary.create_metadata�s���<�T�=N�O�O���� ��>�>�J�J��)�(�J�� �N�N�� ��9�d�l�C�C�� � � *�z�$�:M�s�/S�/S� *�X[�\`�\o�Xp�Xp�st�Xt�Xt�$�X�|�T�=P�Q�Q�H�)�(�F�D�I�F�F��)�(�J��@Q�R�R��)�(�I�t�N�DW�DW�DY�DY�?Z�?Z�[�[��"&�"9�"9�.�"I�"I�����rVc�&�d}tj|���d���}t|��dkrd|�d�}|jdkr |t z }n |t z }|d|j�d�z }|j�|d z }n|d |j�d |j�d �z }|j �2t|j t��rt|j ��dkr|d z }n�t|j t��r|d|j �d�z }n�t|j ttf��r-t|j ��dkr|d|j d�d�z }nA|d�d�|j dd�D����d|j d�d�zz }|j�>|dz }|d�d�|j���D����z }|dz }|dz }|dz }|dz }|dz }|dz }|j�D|dz }|d�d�|j���D����z }|dz }n|d z }|j�!|d!z }|t'|j��z }|dz }|d"z }|d#t(�d�z }|jdkr!t+��rddl}|d$|j�d�z }n+|jd%kr t/��rddl}|d&|j�d�z }t3��rddl}|d'|j�d�z }t7��rddl}|d(|j�d�z }|S))N�F)r�rz--- r�z # z z'This model was trained from scratch on z'This model is a fine-tuned version of [z](https://huggingface.co/z) on zan unknown dataset.�the z dataset.r z, c��g|]}d|����S)r rq)r��dss rJr�z1TrainingSummary.to_model_card.<locals>.<listcomp>�s��G�G�G�r�{�b�{�{�G�G�GrV�����z and the z datasets.z: It achieves the following results on the evaluation set: r�c�>�g|]\}}d|�dt|������S�z- z: �� _maybe_round�r�r�rHs rJr�z1TrainingSummary.to_model_card.<locals>.<listcomp>�s6��$u�$u�$u�K�D�RW�%G�$�%G�%G�,�u�2E�2E�%G�%G�$u�$u�$urVz/ ## Model description More information needed z9 ## Intended uses & limitations More information needed z: ## Training and evaluation data More information needed z ## Training procedure z ### Training hyperparameters z: The following hyperparameters were used during training: c�$�g|] \}}d|�d|����Srrqrs rJr�z1TrainingSummary.to_model_card.<locals>.<listcomp>s-��$j�$j�$j�k�d�E�%9�$�%9�%9�%�%9�%9�$j�$j�$jrVz More information needed z ### Training results z ### Framework versions z- Transformers z - Pytorch �kerasz - TensorFlow z - Datasets z - Tokenizers )�yaml�dumpr r�r��AUTOGENERATED_TRAINER_COMMENT�AUTOGENERATED_KERAS_COMMENTr�r�r�r�r�r�r�rPr�r@r�r��make_markdown_tabler r"�torchr � tensorflowrr�r!� tokenizers)rEr]r�r�tfr�rs rJ� to_model_cardzTrainingSummary.to_model_card�s���� ��9�T�1�1�3�3�u�E�E�E�� �x�=�=�1� � �0��0�0�0�J� �;�)� #� #� �7� 7�J�J� �5� 5�J��2�T�_�2�2�2�2� � � � &� �C� C�J�J� �^��(�^�^�CG�CV�^�^�^� �J� �<� �J�t�|�T�$B�$B� �s�4�<�GX�GX�\]�G]�G]� �/� /�J�J��$�,��,�,� ��<�T�\�<�<�<�<� � ��D�L�5�$�-�8�8� �S���=N�=N�RS�=S�=S��?�T�\�!�_�?�?�?�?� � ���I�I�G�G�T�\�#�2�#�5F�G�G�G�H�H�Ks�W[�Wc�df�Wg�Ks�Ks�Ks�s�� � � � (� �X� X�J� �$�)�)�$u�$u�[_�[l�[r�[r�[t�[t�$u�$u�$u�v�v� v�J��d�� ��K�K� ��U�U� ��V�V� ��1�1� ��8�8� � � � +� �X� X�J� �$�)�)�$j�$j�T�Ma�Mg�Mg�Mi�Mi�$j�$j�$j�k�k� k�J� �$� �J�J� �7� 7�J� �?� &� �6� 6�J� �-�d�o�>�>� >�J� �$� �J��4�4� ��7� �7�7�7�7� � �;�)� #� #�(:�(<�(<� #� �L�L�L� �<�u�'8�<�<�<� <�J�J� �[�G� #� #��(9�(9� #� #� #� #� #� �<�"�.�<�<�<� <�J� � "� "� A� �O�O�O� �@��(<�@�@�@� @�J� "� $� $� E� � � � � �D�*�*@�D�D�D� D�J��rVc ��|j�|jn|j} t| ��r?|�| �| �9| j} | dvr.| �| jt | j��d�g} |�| g}| �| jg} | �|�|} |�Yt|jj d��r?tj � |jj j ��s|jj j }|�C|jjj}t ���D]\}}|t%|��vr|}�|�t'|jj��j}t/|��dkr|}|�dg}n9t1|t ��r |dkr|dg}nd|vr|�d��t5|jj��\}}}t;|��}|||||||| || | |||�� � S)N��csvrd�pandas�parquetr})�config�split� _name_or_pathr�generated_from_trainer) r�r�r�r�r�r�r�r�r�r�r�r�r�)� eval_dataset� train_datasetr�� builder_name� config_namer�r'rf�modelr&rMrNrOr(� __class__r�� TASK_MAPPINGr@r�rr�� output_dirr�r�r�rg�parse_log_history�state� log_history�$extract_hyperparameters_from_trainer)rhr�r�r�r�r�r�r�r�r�r�r�� one_dataset� default_tag�model_class_namer�r�r�r�r�r�s rJ� from_trainerzTrainingSummary.from_trainer&s/�� /6�.B�.N�g�*�*�T[�Ti� � �� %� %� =�<�+?�<�CW�[k�[s�%�2�K��"N�N�N�#�+�3>�3J�UX�Yd�Yj�Uk�Uk�(l�(l�'m�$��'�$/�=�L��'�$/�$;�#<�L� �?�|�7�"�G� � "��� �,�o�>�>� #��G�M�M�'�-�"6�"D�E�E� #�%�]�1�?�N� �=�&�}�6�?� �!-�!3�!3�!5�!5� !� !� ��g�#�':�7�'C�'C�C�C� �E�� � ��g�l�5�6�6�;�J� �z�?�?�a� � �'�J� �<�,�-�D�D� ��c� "� "� 2�t�/G�'G�'G��2�3�D�D� %�T� 1� 1� �K�K�0� 1� 1� 1�&7�� �8Q�&R�&R�#��:�|�>�w�G�G���s����!�)���%�%�-�%�!�+� � � � rVc ��| �-t| ��r| �| �| j} | dvr| �| g} | �| jg} | �| �| } |�Jt|jd��r5t j�|jj��s |jj}|�>|j j } t� ��D]\}}| t|��vr|}�|�dg}n9t|t��r |dkr|dg}nd|vr|�d��|�t#|��\}}}ng}i}t%|��}|||||||| | | |||d�� � S)Nr"r(�generated_from_keras_callbackr) r�r�r�r�r�r�r�r�r�r�r�r�r�)r�r,r-rfr&rMrNrOr(r/r�r0r@r�r�r�rg�parse_keras_history�"extract_hyperparameters_from_keras)rhr.r�� keras_historyr�r�r�r�r�r�r�r�r7r8r�r�r�r�r�r�s rJ� from_keraszTrainingSummary.from_kerasts��� � ��W�%�%� =�<�+?�<�CW�%�2� ��&R�R�R�#�+�(3�}� �#�+�(/�(;�'<� � �?�|�7�"�G� � "��� �o�6�6� #��G�M�M�%�,�"<�=�=� #�#�\�7�N� �=�$��7� �!-�!3�!3�!5�!5� !� !� ��g�#�':�7�'C�'C�C�C� �E�� �<�3�4�D�D� ��c� "� "� 9�t�/N�'N�'N��9�:�D�D� ,�D� 8� 8� �K�K�7� 8� 8� 8� � $�*=�m�*L�*L� '�A�z�<�<��J��L�<�U�C�C���s����!�)��%��%�%�!�+�� � � � rV) NNNNNNNNNN) NNNNNNNNN)r�r�r�r��__annotations__r�rrr�r�r�r�r�r�r�r�r�r�rr��floatr�r�r�r�rr r r�r9r?rqrVrJr�r�fsb��������O�O�O�04�H�h�u�S�$�s�)�^�,�-�4�4�4�!�G�X�c�]�!�!�!�,0�D�(�5��d�3�i��(� )�0�0�0�$(�N�H�S�M�(�(�(�-1�E�8�E�#�t�C�y�.�)� *�1�1�1�/3�G�X�e�C��c��N�+� ,�3�3�3�48�L�(�5��d�3�i��0�1�8�8�8�48�L�(�5��d�3�i��0�1�8�8�8�15��h�t�C��H�~�.�5�5�5�/3�L�(�4��U� �+�,�3�3�3�&*�J���c��#�*�*�*�04�O�X�d�3��8�n�-�4�4�4�%�F�H�S�M�%�%�%���� =�=�=�~��� N�N�N�`��� ��������K �K �K ��[�K �Z� ��� ������H �H �H ��[�H �H �H rVr�c�~�� �t�d��r,t�d��sdgifS�j�jd<�j�n�fd��dD���g}tt �d����D]�� � fd�����D��}i}|���D]l\}}|�d��rd|d d�z}n |dkrd |z}|�d ��}d �d �|D����}|||<�m|� |����|d}�||fS)z� Parse the `logs` of either a `keras.History` object returned by `model.fit()` or an accumulated logs `dict` passed to the `PushToHubCallback`. Returns lines and logs compatible with those returned by `parse_log_history`. �history�epochNc�0���i|]���fd��D����S)c� ��g|] }|��� Srqrq)r�� single_dict�log_keys �rJr�z2parse_keras_history.<locals>.<dictcomp>.<listcomp>�s���G�G�G�;�+�g�.�G�G�GrVrq)r�rH�logss @�rJr�z'parse_keras_history.<locals>.<dictcomp>�s1����_�_�_�G��G�G�G�G�$�G�G�G�_�_�_rVrc�(��i|]\}}||���Srqrq)r�rH�log_value_list�is �rJr�z'parse_keras_history.<locals>.<dictcomp>�s%���]�]�]�5L�W�n�g�~�a�0�]�]�]rV�val_� validation_��train_r�r�c�6�g|]}|�����Srq�� capitalize�r��parts rJr�z'parse_keras_history.<locals>.<listcomp>�s"��B�B�B�4�T�_�_�.�.�B�B�BrVr) rfrDrC�ranger�r@r�r'rPrg) rI�lines� epoch_dictr��kr��splitsr�r�rLs ` @rJr<r<�s����� �t�Y��� `��t�W�%�%� ���R�<� � $� �� �W���|���`�_�_�_�W[�\]�W^�_�_�_�� �E� �3�t�G�}�%�%� &� &� � ��]�]�]�]�PT�PZ�PZ�P\�P\�]�]�]� ����$�$�&�&� � �D�A�q��|�|�F�#�#� !�!�A�a�b�b�E�)����g����q�L���W�W�S�\�\�F��8�8�B�B�6�B�B�B�C�C�D��F�4�L�L� � � �V�������9�L� �� � $�$rVc��d}|t|��kr,d||vr"|dz }|t|��kr d||v�"|t|��kr=|dz}|dkrd||vr|dz}|dkr d||v�|dkr dd||fSdS||}g}d}t|��D�]\}d||vr||d}d||v�r6||���}|�d d��}|�d d��}|�d d��} |�d d��}|�d d��}|�dd��}|�dd��}||| d�} |���D]R\} } | dkr| | d<�| �d��} d�d�| dd�D����}| | |<�S|�| ����^t|��dz }|dkrd||vr|dz}|dkr d||v�|dkr�i}||���D]_\}}|�d��r |dd�}|dvr7d�d�|�d��D����}|||<�`|||fS||dfS)zd Parse the `log_history` of a Trainer to get the intermediate and final evaluation results. r� train_runtimer � eval_lossN)NNNzNo log�loss� total_flosrD�step� eval_runtime�eval_samples_per_second�eval_steps_per_second�eval_jit_compilation_time)z Training Loss�Epoch�StepzValidation Lossr�r�c�6�g|]}|�����SrqrRrTs rJr�z%parse_log_history.<locals>.<listcomp> s"��$N�$N�$N�4�T�_�_�%6�%6�$N�$N�$NrV�eval_�)�runtime�samples_per_second�steps_per_secondrDr`c�6�g|]}|�����SrqrRrTs rJr�z%parse_log_history.<locals>.<listcomp>s"��+Y�+Y�+Y�$�D�O�O�,=�,=�+Y�+Y�+YrV) r�rVr�r?r@r'rPrgr�)r4�idx� train_logrW� training_lossrLr6r�rDr`r�rYr�rZr�r�rGrH�camel_cased_keys rJr2r2�s^�� �C� ��K� � � � �_�K��<L�%L�%L� �q��� ��K� � � � �_�K��<L�%L�%L� �c�+����� �q����Q�h�h�;�k�#�.>�>�>� �1�H�C��Q�h�h�;�k�#�.>�>�>� �!�8�8���{�3�/�/� /�#�#��C� �I� �E��M� �3�Z�Z�!�!�� �[��^� #� #�'��N�6�2�M� �+�a�.� (� (�!�!�n�)�)�+�+�G�� � �L�$�/�/�A��K�K���.�.�E��;�;�v�t�,�,�D�� � �N�D�1�1�A�� � �5�t�<�<�A�� � �3�T�:�:�A�� � �7��>�>�A�'4�u�d�S�S�F�� � ��� %� %���1�� �#�#�01�F�,�-�-��W�W�S�\�\�F��8�8�$N�$N�6�!�"�"�:�$N�$N�$N�O�O�D�#$�F�4�L�L� �L�L�� � � �� �k� � �Q� �C� ��(�(�{�+�c�*:�:�:� �q��� ��(�(�{�+�c�*:�:�:� �Q�w�w�� �%�c�*�0�0�2�2� 6� 6�J�C���~�~�g�&�&� ��!�"�"�g���`�`�`�"%�(�(�+Y�+Y�#�)�)�TW�.�.�+Y�+Y�+Y�"Z�"Z��05� �_�-���%��-�-��%��%�%rVc���ddlm}i}t|d��r$|j�|j���|d<nd|d<|j���j|d<|S)Nr )r� optimizer�training_precision)�modeling_tf_utilsrrfrs� get_config�mixed_precision� global_policyr�)r.rr�s rJr=r=!sz��(�(�(�(�(�(��O��u�k�"�"�,�u��'B�',��'A�'A�'C�'C�� �$�$�'+�� �$�,1�,A�,O�,O�,Q�,Q�,V�O�(�)� �rVrOc�2�t|t��rttt|���d����dkrAtt|���d��d��|kr|d|�d��St|��S)N�.r �f)r�rAr�r�r')r��decimalss rJrr.s����!�U���#��C��F�F�L�L��$5�$5� 6� 6�� :� :�s�3�q�6�6�<�<�PS�CT�CT�UV�CW�?X�?X�[c�?c�?c��"�h�"�"�"�"�"� �q�6�6�MrVc�f�d�t||��D��}d�|��dzS)Nc�P�g|]#\}}d|��d|t|��z dzzz��$S)z| r�r )r�)r�r�r�s rJr�z'_regular_table_line.<locals>.<listcomp>5s:��_�_�_�t�q�!��a���C�1�s�1�v�v�:��>�$:�:�_�_�_rVr �| )r�rP)r�� col_widths�values_with_spaces rJ�_regular_table_liner�4s9��_�_�s�6�S]�G^�G^�_�_�_�� �7�7�$� %� %�� -�-rVc�J�d�|D��}d�|��dzS)Nc�$�g|] }dd|zzdz��S)z|:�-�:rq)r�r�s rJr�z&_second_table_line.<locals>.<listcomp>:s%�� 7� 7� 7�q�d�S�1�W�n�s�"� 7� 7� 7rVr r)rP)r�r�s rJ�_second_table_liner�9s*�� 7� 7�J� 7� 7� 7�F� �7�7�6�?�?�U� "�"rVc ���|�t|��dkrdSd�|d���D��}|D]a}|���D]J\}}||tt|����krtt|����||<�K�bt t |d�����t |�������}|tt |�������z }|D]P}|t d�|���D��t |�������z }�Q|S)zC Create a nice Markdown table from the results in `lines`. Nrr c�H�i|]}|tt|������ Srq)r�r�)r�rGs rJr�z'make_markdown_table.<locals>.<dictcomp>Ds&��@�@�@��#�s�3�s�8�8�}�}�@�@�@rVc�,�g|]}t|����Srqrr�s rJr�z'make_markdown_table.<locals>.<listcomp>Ms��%M�%M�%M�!�l�1�o�o�%M�%M�%MrV)r�r�r@rr�r�r�r�)rWr��linerGrH�tables rJrr>s\�� �}��E� � �a����r�@�@��a�� � ���@�@�@�J��;�;���*�*�,�,� ;� ;�J�C���#���\�%�%8�%8�!9�!9�9�9�"%�l�5�&9�&9�":�":� �3��� ;� ��U�1�X�]�]�_�_� 5� 5�t�J�<M�<M�<O�<O�7P�7P� Q� Q�E� � ��Z�%6�%6�%8�%8� 9� 9� :� :�:�E��j�j�� �$�%M�%M�t�{�{�}�}�%M�%M�%M�t�T^�Te�Te�Tg�Tg�Oh�Oh�i�i�i��� �LrV)� learning_rate�train_batch_size�eval_batch_size�seedc ����fd�tD��}�jjtjtjfvr0�jjtjkrdn�jjj|d<�jjdkr�jj|d<�jj dkr�jj |d<�jj �jjz�jj z}||dkr||d<�jj �jjz}||d kr||d <�jj rz�jj }�jj r �jj nd }d |���vr3d |�d�jj�d�jj�d�jj�d|�� |d<n d |�d|��|d<�jjj|d<�jjdkr�jj|d<�jjdkr�jj|d<�jjdkr�jj|d<n�jj|d<�jjr�jrd�jj��|d<nd|d<�jjdkr�jj|d<|S)Nc�<��i|]}|t�j|����Srq)�getattrr�)r�rYr�s �rJr�z8extract_hyperparameters_from_trainer.<locals>.<dictcomp>Zs'���P�P�P�q�q�'�'�,��2�2�P�P�PrVz multi-GPU�distributed_typer � num_devices�gradient_accumulation_stepsr��total_train_batch_sizer��total_eval_batch_sizez!No additional optimizer arguments�adamzUse z with betas=(�,z) and epsilon=z and optimizer_args=rsz and the args are: �lr_scheduler_typeg�lr_scheduler_warmup_ratio�lr_scheduler_warmup_stepsr�training_steps� num_epochszApex, opt level �mixed_precision_trainingz Native AMP�label_smoothing_factor)�_TRAINING_ARGS_KEYSr�� parallel_moder� NOT_PARALLEL�NOT_DISTRIBUTED� DISTRIBUTEDrH� world_sizer�r�r��optim� optim_argsr�� adam_beta1� adam_beta2� adam_epsilonr�� warmup_ratio� warmup_steps� max_steps�num_train_epochs�fp16�use_apex�fp16_opt_levelr�)r�r�r�r��optimizer_name�optimizer_argss` rJr5r5Ys����P�P�P�P�<O�P�P�P�O��|�!�,�*C�\�Ea�)b�b�b�"�<�5��9Q�Q�Q�K�K�W^�Wc�Wq�Ww� �*�+��|���"�"�)0��)@�� �&��|�/�!�3�3�9@��9a��5�6� � �%�� �(?�?�'�,�Bj�j����1C�!D�D�D�4J��0�1�#�L�8�7�<�;R�R����0A� B�B�B�3H��/�0��|�� g� ��+��4;�L�4K�t���0�0�Qt�� �^�)�)�+�+� +� +�\�~�\�\�G�L�4K�\�\�g�l�Ne�\�\�#�L�5�\�\�KY�\�\� �K� (� (� ,g�.�+f�+f�Vd�+f�+f�O�K� (�+2�<�+I�+O�O�'�(��|� �C�'�'�7>�|�7P��3�4��|� �C�'�'�7>�|�7P��3�4��|���#�#�,3�L�,B��(�)�)�(/� �(E�� �%��|��G� � � G�:j�W�\�Mh�:j�:j�O�6� 7� 7�:F�O�6� 7��|�*�c�1�1�4;�L�4W��0�1� �rV)rO)Ir�r�rdrMr<� dataclassesr�pathlibr�typingrrrr�r�huggingface_hubr�huggingface_hub.utilsr r r �models.auto.modeling_autor r rrrrrrrrrrrrr� training_argsr�utilsrrrrr r!r"r#r0� get_loggerr�rCr1rrr�r�r�r�r�r�r�r�r�r<r2r=rr�r�rr�r5rqrVrJ�<module>r�s���.�-� � � � � � � � � � � � �����!�!�!�!�!�!�������'�'�'�'�'�'�'�'�'�'����� � � � �&�&�&�&�&�&�3�3�3�3�3�3�����������������������������������������"(�'�'�'�'�'� � � � � � � � � � � � � � � � � � � � �9�H�D�2�@�D�H�J� P�H�H�$o�'B�$o�Fn�$o�&\�D��� �" �� �H� %� %��j0�j0�j0�j0�j0�j0�j0�j0�Z!�� �� ��+���2���.���(� � �*� � �.� ��_��� :���0���1���D���2���=��� :��#�$B�� �2�!��( � � � ���� � � � � � ����;�;�;���� �V �V �V �V �V �V �V � ��V �r %� %� %�F;&�;&�;&�| � � ����� .�.�.� #�#�#� ���&����4�4�4�4�4rV
Memory