



"""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 				lowercase__       (   unittest.TestCase				):







       '''simple docstring'''


       @slow
       def 					lowercase__    (							self      :  Optional[Any]   )			->						Union[str, Any]:


             '''simple docstring'''




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

                   UpperCAmelCase_      			=							TFAutoModel.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							AutoModel.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )



       @slow
       def 					lowercase__    (							self      :  Union[str, Any]   )			->						List[str]:


             '''simple docstring'''




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

                   UpperCAmelCase_      			=							TFAutoModelForPreTraining.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							AutoModelForPreTraining.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )



       @slow
       def 					lowercase__    (							self      :  Optional[int]   )			->						int:


             '''simple docstring'''




             for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_      			=							AutoConfig.from_pretrained(_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							TFAutoModelForCausalLM.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   UpperCAmelCase_			,   UpperCAmelCase_      			=							TFAutoModelForCausalLM.from_pretrained(
                       _UpperCAmelCase		,    output_loading_info=_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							AutoModelForCausalLM.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   UpperCAmelCase_			,   UpperCAmelCase_      			=							AutoModelForCausalLM.from_pretrained(
                       _UpperCAmelCase		,    output_loading_info=_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )



       @slow
       def 					lowercase__    (							self      :  List[str]   )			->						List[Any]:


             '''simple docstring'''




             for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_      			=							AutoConfig.from_pretrained(_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							TFAutoModelWithLMHead.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							AutoModelWithLMHead.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )



       @slow
       def 					lowercase__    (							self      :  int   )			->						Optional[Any]:


             '''simple docstring'''




             for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_      			=							AutoConfig.from_pretrained(_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							TFAutoModelForMaskedLM.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   UpperCAmelCase_			,   UpperCAmelCase_      			=							TFAutoModelForMaskedLM.from_pretrained(
                       _UpperCAmelCase		,    output_loading_info=_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							AutoModelForMaskedLM.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   UpperCAmelCase_			,   UpperCAmelCase_      			=							AutoModelForMaskedLM.from_pretrained(
                       _UpperCAmelCase		,    output_loading_info=_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )



       @slow
       def 					lowercase__    (							self      :  Tuple   )			->						Optional[int]:


             '''simple docstring'''




             for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_      			=							AutoConfig.from_pretrained(_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							TFAutoModelForSeqaSeqLM.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   UpperCAmelCase_			,   UpperCAmelCase_      			=							TFAutoModelForSeqaSeqLM.from_pretrained(
                       _UpperCAmelCase		,    output_loading_info=_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							AutoModelForSeqaSeqLM.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   UpperCAmelCase_			,   UpperCAmelCase_      			=							AutoModelForSeqaSeqLM.from_pretrained(
                       _UpperCAmelCase		,    output_loading_info=_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )



       @slow
       def 					lowercase__    (							self      :  int   )			->						List[str]:


             '''simple docstring'''




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

                   UpperCAmelCase_      			=							TFAutoModelForSequenceClassification.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							AutoModelForSequenceClassification.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )



       @slow
       def 					lowercase__    (							self      :  Optional[Any]   )			->						List[Any]:


             '''simple docstring'''




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

                   UpperCAmelCase_      			=							TFAutoModelForQuestionAnswering.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )

                   UpperCAmelCase_      			=							AutoModelForQuestionAnswering.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
                   self.assertIsNotNone(_UpperCAmelCase   )
                   self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )



       def 					lowercase__    (							self      :  Tuple   )			->						List[Any]:


             '''simple docstring'''




             UpperCAmelCase_      			=							TFAutoModelWithLMHead.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
             self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )
             self.assertEqual(model.num_parameters()		,    14410   )
             self.assertEqual(model.num_parameters(only_trainable=_UpperCAmelCase   )		,    14410   )

             UpperCAmelCase_      			=							AutoModelWithLMHead.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
             self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )
             self.assertEqual(model.num_parameters()		,    14410   )
             self.assertEqual(model.num_parameters(only_trainable=_UpperCAmelCase   )		,    14410   )







       def 					lowercase__    (							self      :  Union[str, Any]   )			->						Optional[Any]:


             '''simple docstring'''




             UpperCAmelCase_      			=							TFAutoModelWithLMHead.from_pretrained(_UpperCAmelCase		,    from_pt=_UpperCAmelCase   )
             self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )
             self.assertEqual(model.num_parameters()		,    14410   )
             self.assertEqual(model.num_parameters(only_trainable=_UpperCAmelCase   )		,    14410   )

             UpperCAmelCase_      			=							AutoModelWithLMHead.from_pretrained(_UpperCAmelCase		,    from_tf=_UpperCAmelCase   )
             self.assertIsInstance(_UpperCAmelCase		,    _UpperCAmelCase   )
             self.assertEqual(model.num_parameters()		,    14410   )
             self.assertEqual(model.num_parameters(only_trainable=_UpperCAmelCase   )		,    14410   )









"""simple docstring"""





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase       	=						logging.get_logger(__name__)

lowerCamelCase       	=						{
    """roberta-base""": """https://huggingface.co/roberta-base/resolve/main/config.json""",
    """roberta-large""": """https://huggingface.co/roberta-large/resolve/main/config.json""",
    """roberta-large-mnli""": """https://huggingface.co/roberta-large-mnli/resolve/main/config.json""",
    """distilroberta-base""": """https://huggingface.co/distilroberta-base/resolve/main/config.json""",
    """roberta-base-openai-detector""": """https://huggingface.co/roberta-base-openai-detector/resolve/main/config.json""",
    """roberta-large-openai-detector""": """https://huggingface.co/roberta-large-openai-detector/resolve/main/config.json""",
}
class 				lowercase__       (   SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					'''roberta'''



       def __init__(							self      :  int		,    _UpperCAmelCase      :  List[Any]=50265		,    _UpperCAmelCase      :  str=768		,    _UpperCAmelCase      :  List[str]=12		,    _UpperCAmelCase      :  int=12		,    _UpperCAmelCase      :  Tuple=3072		,    _UpperCAmelCase      :  Dict="gelu"		,    _UpperCAmelCase      :  int=0.1		,    _UpperCAmelCase      :  Optional[int]=0.1		,    _UpperCAmelCase      :  Optional[int]=512		,    _UpperCAmelCase      :  Optional[Any]=2		,    _UpperCAmelCase      :  Optional[int]=0.02		,    _UpperCAmelCase      :  Optional[Any]=1e-12		,    _UpperCAmelCase      :  Dict=1		,    _UpperCAmelCase      :  str=0		,    _UpperCAmelCase      :  int=2		,    _UpperCAmelCase      :  Tuple="absolute"		,    _UpperCAmelCase      :  Any=True		,    _UpperCAmelCase      :  int=None		,    **_UpperCAmelCase      :  List[str]		,    )			->						Any:


             '''simple docstring'''




             super().__init__(pad_token_id=_UpperCAmelCase		,    bos_token_id=_UpperCAmelCase		,    eos_token_id=_UpperCAmelCase		,    **_UpperCAmelCase   )

             UpperCAmelCase_      			=							vocab_size
             UpperCAmelCase_      			=							hidden_size
             UpperCAmelCase_      			=							num_hidden_layers
             UpperCAmelCase_      			=							num_attention_heads
             UpperCAmelCase_      			=							hidden_act
             UpperCAmelCase_      			=							intermediate_size
             UpperCAmelCase_      			=							hidden_dropout_prob
             UpperCAmelCase_      			=							attention_probs_dropout_prob
             UpperCAmelCase_      			=							max_position_embeddings
             UpperCAmelCase_      			=							type_vocab_size
             UpperCAmelCase_      			=							initializer_range
             UpperCAmelCase_      			=							layer_norm_eps
             UpperCAmelCase_      			=							position_embedding_type
             UpperCAmelCase_      			=							use_cache
             UpperCAmelCase_      			=							classifier_dropout



class 				lowercase__       (   SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       @property
       def 					lowercase__    (							self      :  List[Any]   )			->						Mapping[str, Mapping[int, str]]:


             '''simple docstring'''




             if self.task == "multiple-choice":
                   UpperCAmelCase_      			=							{0: "batch", 1: "choice", 2: "sequence"}
             else:
                   UpperCAmelCase_      			=							{0: "batch", 1: "sequence"}
             return OrderedDict(
                 [
                     ("input_ids", dynamic_axis),
                     ("attention_mask", dynamic_axis),
                 ]   )




