
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 __snake_case		(				unittest.TestCase					):
    @slow
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







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

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

                  lowercase							:					List[str]	     =				AutoModel.from_pretrained(snake_case		,from_tf=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)
    @slow
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           for model_name in ["bert-base-uncased"]:
                  lowercase							:					Optional[Any]	     =				AutoConfig.from_pretrained(snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					Optional[int]	     =				TFAutoModelForPreTraining.from_pretrained(snake_case		,from_pt=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					Union[str, Any]	     =				AutoModelForPreTraining.from_pretrained(snake_case		,from_tf=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)
    @slow
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                  lowercase							:					List[str]	     =				AutoConfig.from_pretrained(snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					List[str]	     =				TFAutoModelForCausalLM.from_pretrained(snake_case		,from_pt=snake_case				)
                  lowercase     ,      lowercase							:					int	     =				TFAutoModelForCausalLM.from_pretrained(
                      snake_case		,output_loading_info=snake_case		,from_pt=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					Any	     =				AutoModelForCausalLM.from_pretrained(snake_case		,from_tf=snake_case				)
                  lowercase     ,      lowercase							:					int	     =				AutoModelForCausalLM.from_pretrained(
                      snake_case		,output_loading_info=snake_case		,from_tf=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)
    @slow
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                  lowercase							:					str	     =				AutoConfig.from_pretrained(snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					int	     =				TFAutoModelWithLMHead.from_pretrained(snake_case		,from_pt=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					Tuple	     =				AutoModelWithLMHead.from_pretrained(snake_case		,from_tf=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)
    @slow
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                  lowercase							:					Optional[Any]	     =				AutoConfig.from_pretrained(snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					int	     =				TFAutoModelForMaskedLM.from_pretrained(snake_case		,from_pt=snake_case				)
                  lowercase     ,      lowercase							:					Optional[Any]	     =				TFAutoModelForMaskedLM.from_pretrained(
                      snake_case		,output_loading_info=snake_case		,from_pt=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					Any	     =				AutoModelForMaskedLM.from_pretrained(snake_case		,from_tf=snake_case				)
                  lowercase     ,      lowercase							:					Optional[Any]	     =				AutoModelForMaskedLM.from_pretrained(
                      snake_case		,output_loading_info=snake_case		,from_tf=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)
    @slow
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                  lowercase							:					str	     =				AutoConfig.from_pretrained(snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					str	     =				TFAutoModelForSeqaSeqLM.from_pretrained(snake_case		,from_pt=snake_case				)
                  lowercase     ,      lowercase							:					List[str]	     =				TFAutoModelForSeqaSeqLM.from_pretrained(
                      snake_case		,output_loading_info=snake_case		,from_pt=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					Tuple	     =				AutoModelForSeqaSeqLM.from_pretrained(snake_case		,from_tf=snake_case				)
                  lowercase     ,      lowercase							:					List[Any]	     =				AutoModelForSeqaSeqLM.from_pretrained(
                      snake_case		,output_loading_info=snake_case		,from_tf=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)
    @slow
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







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

                  lowercase							:					str	     =				TFAutoModelForSequenceClassification.from_pretrained(snake_case		,from_pt=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					Tuple	     =				AutoModelForSequenceClassification.from_pretrained(snake_case		,from_tf=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)
    @slow
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           for model_name in ["bert-base-uncased"]:
                  lowercase							:					List[str]	     =				AutoConfig.from_pretrained(snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					List[Any]	     =				TFAutoModelForQuestionAnswering.from_pretrained(snake_case		,from_pt=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)

                  lowercase							:					List[str]	     =				AutoModelForQuestionAnswering.from_pretrained(snake_case		,from_tf=snake_case				)
                  self.assertIsNotNone(snake_case				)
                  self.assertIsInstance(snake_case		,snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					Tuple	     =				TFAutoModelWithLMHead.from_pretrained(snake_case		,from_pt=snake_case				)
           self.assertIsInstance(snake_case		,snake_case				)
           self.assertEqual(model.num_parameters()		,14410				)
           self.assertEqual(model.num_parameters(only_trainable=snake_case				)		,14410				)

           lowercase							:					Optional[Any]	     =				AutoModelWithLMHead.from_pretrained(snake_case		,from_tf=snake_case				)
           self.assertIsInstance(snake_case		,snake_case				)
           self.assertEqual(model.num_parameters()		,14410				)
           self.assertEqual(model.num_parameters(only_trainable=snake_case				)		,14410				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					str	     =				TFAutoModelWithLMHead.from_pretrained(snake_case		,from_pt=snake_case				)
           self.assertIsInstance(snake_case		,snake_case				)
           self.assertEqual(model.num_parameters()		,14410				)
           self.assertEqual(model.num_parameters(only_trainable=snake_case				)		,14410				)

           lowercase							:					Optional[int]	     =				AutoModelWithLMHead.from_pretrained(snake_case		,from_tf=snake_case				)
           self.assertIsInstance(snake_case		,snake_case				)
           self.assertEqual(model.num_parameters()		,14410				)
           self.assertEqual(model.num_parameters(only_trainable=snake_case				)		,14410				)


class __snake_case		:
    def __init__(  self		,snake_case		,snake_case=None		,snake_case=None				):



           '''simple docstring'''







           lowercase							:					Tuple	     =				data
           lowercase							:					List[Any]	     =				previous
           lowercase							:					List[str]	     =				next_node
    def __str__(  self				):



           '''simple docstring'''







           return f"{self.data}"
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           return self.data
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           return self.next
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           return self.previous






class __snake_case		:
    def __init__(  self		,snake_case				):



           '''simple docstring'''







           lowercase							:					Optional[int]	     =				head
    def __iter__(  self				):



           '''simple docstring'''







           return self
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           if not self.current:
                  raise StopIteration
           else:
                  lowercase							:					Union[str, Any]	     =				self.current.get_data()
                  lowercase							:					Optional[Any]	     =				self.current.get_next()
                  return value






class __snake_case		:
    def __init__(  self				):



           '''simple docstring'''







           lowercase							:					str	     =				None  # First node in list
           lowercase							:					str	     =				None  # Last node in list
    def __str__(  self				):



           '''simple docstring'''







           lowercase							:					int	     =				self.head
           lowercase							:					str	     =				[]
           while current is not None:
                  nodes.append(current.get_data()				)
                  lowercase							:					Dict	     =				current.get_next()
           return " ".join(str(snake_case				) for node in nodes				)
    def __contains__(  self		,snake_case				):



           '''simple docstring'''







           lowercase							:					Dict	     =				self.head
           while current:
                  if current.get_data() == value:
                         return True
                  lowercase							:					Any	     =				current.get_next()
           return False
    def __iter__(  self				):



           '''simple docstring'''







           return LinkedListIterator(self.head				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           if self.head:
                  return self.head.get_data()
           return None
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           if self.tail:
                  return self.tail.get_data()
           return None
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case				):



           '''simple docstring'''







           if self.head is None:
                  lowercase							:					Any	     =				node
                  lowercase							:					Dict	     =				node
           else:
                  self.insert_before_node(self.head		,snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case				):



           '''simple docstring'''







           if self.head is None:
                  self.set_head(snake_case				)
           else:
                  self.insert_after_node(self.tail		,snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case				):



           '''simple docstring'''







           lowercase							:					Dict	     =				Node(snake_case				)
           if self.head is None:
                  self.set_head(snake_case				)
           else:
                  self.set_tail(snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case				):



           '''simple docstring'''







           lowercase							:					Optional[int]	     =				node
           lowercase							:					Optional[int]	     =				node.previous

           if node.get_previous() is None:
                  lowercase							:					Optional[int]	     =				node_to_insert
           else:
                  lowercase							:					Optional[int]	     =				node_to_insert

           lowercase							:					List[Any]	     =				node_to_insert
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case				):



           '''simple docstring'''







           lowercase							:					Dict	     =				node
           lowercase							:					List[str]	     =				node.next

           if node.get_next() is None:
                  lowercase							:					Union[str, Any]	     =				node_to_insert
           else:
                  lowercase							:					List[str]	     =				node_to_insert

           lowercase							:					Dict	     =				node_to_insert
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case				):



           '''simple docstring'''







           lowercase							:					List[Any]	     =				1
           lowercase							:					List[str]	     =				Node(snake_case				)
           lowercase							:					Any	     =				self.head
           while node:
                  if current_position == position:
                         self.insert_before_node(snake_case		,snake_case				)
                         return
                  current_position += 1
                  lowercase							:					List[Any]	     =				node.next
           self.insert_after_node(self.tail		,snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case				):



           '''simple docstring'''







           lowercase							:					Optional[int]	     =				self.head
           while node:
                  if node.get_data() == item:
                         return node
                  lowercase							:					Any	     =				node.get_next()
           raise Exception("""Node not found"""				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case				):



           '''simple docstring'''







           if (node := self.get_node(snake_case				)) is not None:
                  if node == self.head:
                         lowercase							:					Optional[Any]	     =				self.head.get_next()

                  if node == self.tail:
                         lowercase							:					List[str]	     =				self.tail.get_previous()

                  self.remove_node_pointers(snake_case				)
    @staticmethod
    def 				_SCREAMING_SNAKE_CASE	(  snake_case				):



           '''simple docstring'''







           if node.get_next():
                  lowercase							:					Optional[int]	     =				node.previous

           if node.get_previous():
                  lowercase							:					Union[str, Any]	     =				node.next

           lowercase							:					Union[str, Any]	     =				None
           lowercase							:					Optional[Any]	     =				None
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           return self.head is None







def 						_snake_case(  )			->   None:
       pass


if __name__ == "__main__":
  import doctest

  doctest.testmod()
