
'''simple docstring'''







from __future__ import annotations

import unittest

from transformers import is_tf_available, is_torch_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, SMALL_MODEL_IDENTIFIER, is_pt_tf_cross_test, slow


if is_tf_available():
							from transformers import (
							    AutoConfig,
							    BertConfig,
							    GPTaConfig,
							    TaConfig,
							    TFAutoModel,
							    TFAutoModelForCausalLM,
							    TFAutoModelForMaskedLM,
							    TFAutoModelForPreTraining,
							    TFAutoModelForQuestionAnswering,
							    TFAutoModelForSeqaSeqLM,
							    TFAutoModelForSequenceClassification,
							    TFAutoModelWithLMHead,
							    TFBertForMaskedLM,
							    TFBertForPreTraining,
							    TFBertForQuestionAnswering,
							    TFBertForSequenceClassification,
							    TFBertModel,
							    TFGPTaLMHeadModel,
							    TFRobertaForMaskedLM,
							    TFTaForConditionalGeneration,
							)
							from transformers.models.bert.modeling_tf_bert import TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST
							from transformers.models.gpta.modeling_tf_gpta import TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST
							from transformers.models.ta.modeling_tf_ta import TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST

if is_torch_available():
							from transformers import (
							    AutoModel,
							    AutoModelForCausalLM,
							    AutoModelForMaskedLM,
							    AutoModelForPreTraining,
							    AutoModelForQuestionAnswering,
							    AutoModelForSeqaSeqLM,
							    AutoModelForSequenceClassification,
							    AutoModelWithLMHead,
							    BertForMaskedLM,
							    BertForPreTraining,
							    BertForQuestionAnswering,
							    BertForSequenceClassification,
							    BertModel,
							    GPTaLMHeadModel,
							    RobertaForMaskedLM,
							    TaForConditionalGeneration,
							)






@is_pt_tf_cross_test
class 			lowerCAmelCase__       (  unittest.TestCase					):






					@slow
					def      _snake_case   (       self		):


											"""simple docstring"""





											for model_name in ["bert-base-uncased"]:
																	lowercase_     :					int													=	AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Optional[Any]													=	TFAutoModel.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Union[str, Any]													=	AutoModel.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)






					@slow
					def      _snake_case   (       self		):


											"""simple docstring"""





											for model_name in ["bert-base-uncased"]:
																	lowercase_     :					List[Any]													=	AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Any													=	TFAutoModelForPreTraining.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					int													=	AutoModelForPreTraining.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)






					@slow
					def      _snake_case   (       self		):


											"""simple docstring"""





											for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowercase_     :					int													=	AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Union[str, Any]													=	TFAutoModelForCausalLM.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	lowercase_     :					Optional[int]													=	TFAutoModelForCausalLM.from_pretrained(
																	    __SCREAMING_SNAKE_CASE    ,							output_loading_info=__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Dict													=	AutoModelForCausalLM.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	lowercase_     :					Optional[int]													=	AutoModelForCausalLM.from_pretrained(
																	    __SCREAMING_SNAKE_CASE    ,							output_loading_info=__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)






					@slow
					def      _snake_case   (       self		):


											"""simple docstring"""





											for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowercase_     :					Union[str, Any]													=	AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					List[Any]													=	TFAutoModelWithLMHead.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Any													=	AutoModelWithLMHead.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)






					@slow
					def      _snake_case   (       self		):


											"""simple docstring"""





											for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowercase_     :					Union[str, Any]													=	AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					List[str]													=	TFAutoModelForMaskedLM.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	lowercase_     :					int													=	TFAutoModelForMaskedLM.from_pretrained(
																	    __SCREAMING_SNAKE_CASE    ,							output_loading_info=__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					List[Any]													=	AutoModelForMaskedLM.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	lowercase_     :					List[str]													=	AutoModelForMaskedLM.from_pretrained(
																	    __SCREAMING_SNAKE_CASE    ,							output_loading_info=__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)






					@slow
					def      _snake_case   (       self		):


											"""simple docstring"""





											for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowercase_     :					Tuple													=	AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Optional[Any]													=	TFAutoModelForSeqaSeqLM.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	lowercase_     :					Optional[int]													=	TFAutoModelForSeqaSeqLM.from_pretrained(
																	    __SCREAMING_SNAKE_CASE    ,							output_loading_info=__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Union[str, Any]													=	AutoModelForSeqaSeqLM.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	lowercase_     :					List[Any]													=	AutoModelForSeqaSeqLM.from_pretrained(
																	    __SCREAMING_SNAKE_CASE    ,							output_loading_info=__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)






					@slow
					def      _snake_case   (       self		):


											"""simple docstring"""





											for model_name in ["bert-base-uncased"]:
																	lowercase_     :					Optional[int]													=	AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					List[Any]													=	TFAutoModelForSequenceClassification.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Tuple													=	AutoModelForSequenceClassification.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)






					@slow
					def      _snake_case   (       self		):


											"""simple docstring"""





											for model_name in ["bert-base-uncased"]:
																	lowercase_     :					Tuple													=	AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					Union[str, Any]													=	TFAutoModelForQuestionAnswering.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

																	lowercase_     :					str													=	AutoModelForQuestionAnswering.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
																	self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)






					def      _snake_case   (       self		):


											"""simple docstring"""





											lowercase_     :					Dict													=	TFAutoModelWithLMHead.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
											self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)
											self.assertEqual(model.num_parameters()    ,							1_44_10		)
											self.assertEqual(model.num_parameters(only_trainable=__SCREAMING_SNAKE_CASE		)    ,							1_44_10		)

											lowercase_     :					List[Any]													=	AutoModelWithLMHead.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
											self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)
											self.assertEqual(model.num_parameters()    ,							1_44_10		)
											self.assertEqual(model.num_parameters(only_trainable=__SCREAMING_SNAKE_CASE		)    ,							1_44_10		)






					def      _snake_case   (       self		):


											"""simple docstring"""





											lowercase_     :					int													=	TFAutoModelWithLMHead.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_pt=__SCREAMING_SNAKE_CASE		)
											self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)
											self.assertEqual(model.num_parameters()    ,							1_44_10		)
											self.assertEqual(model.num_parameters(only_trainable=__SCREAMING_SNAKE_CASE		)    ,							1_44_10		)

											lowercase_     :					str													=	AutoModelWithLMHead.from_pretrained(__SCREAMING_SNAKE_CASE    ,							from_tf=__SCREAMING_SNAKE_CASE		)
											self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)
											self.assertEqual(model.num_parameters()    ,							1_44_10		)
											self.assertEqual(model.num_parameters(only_trainable=__SCREAMING_SNAKE_CASE		)    ,							1_44_10		)


'''simple docstring'''







import logging
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional, Union

from .generation.configuration_utils import GenerationConfig
from .training_args import TrainingArguments
from .utils import add_start_docstrings


_lowercase			:  Tuple   							=	logging.getLogger(__name__)






@dataclass
@add_start_docstrings(TrainingArguments.__doc__					)
class 			lowerCAmelCase__       (  lowerCamelCase_					):
					lowerCAmelCase_					       =					field(default=lowerCamelCase_   ,						metadata={'''help''': '''Whether to use SortishSampler or not.'''}					)
					lowerCAmelCase_					       =					field(
					    default=lowerCamelCase_   ,						metadata={'''help''': '''Whether to use generate to calculate generative metrics (ROUGE, BLEU).'''}					)
					lowerCAmelCase_					       =					field(
					    default=lowerCamelCase_   ,						metadata={
					        '''help''': (
					            '''The `max_length` to use on each evaluation loop when `predict_with_generate=True`. Will default '''
					            '''to the `max_length` value of the model configuration.'''
					        )
					    }   ,						)
					lowerCAmelCase_					       =					field(
					    default=lowerCamelCase_   ,						metadata={
					        '''help''': (
					            '''The `num_beams` to use on each evaluation loop when `predict_with_generate=True`. Will default '''
					            '''to the `num_beams` value of the model configuration.'''
					        )
					    }   ,						)
					lowerCAmelCase_					       =					field(
					    default=lowerCamelCase_   ,						metadata={
					        '''help''': '''Model id, file path or url pointing to a GenerationConfig json file, to use during prediction.'''
					    }   ,						)






					def      _snake_case   (       self		):


											"""simple docstring"""





											lowercase_     :					Dict													=	super().to_dict()
											for k, v in d.items():
																	if isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):
																							lowercase_     :					str													=	v.to_dict()
											return d



