






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





				"""simple docstring"""







				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

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

														__UpperCamelCase      :					str       		=TFAutoModel.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					List[Any]       		=AutoModel.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )


				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

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

														__UpperCamelCase      :					List[str]       		=TFAutoModelForPreTraining.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Optional[Any]       		=AutoModelForPreTraining.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )


				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

									for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														__UpperCamelCase      :					Tuple       		=AutoConfig.from_pretrained(lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					str       		=TFAutoModelForCausalLM.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														__UpperCamelCase		,				__UpperCamelCase      :					Tuple       		=TFAutoModelForCausalLM.from_pretrained(
														    lowerCamelCase__							,  output_loading_info=lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Optional[int]       		=AutoModelForCausalLM.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														__UpperCamelCase		,				__UpperCamelCase      :					Union[str, Any]       		=AutoModelForCausalLM.from_pretrained(
														    lowerCamelCase__							,  output_loading_info=lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )


				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

									for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														__UpperCamelCase      :					int       		=AutoConfig.from_pretrained(lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Dict       		=TFAutoModelWithLMHead.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					List[Any]       		=AutoModelWithLMHead.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )


				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

									for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														__UpperCamelCase      :					List[Any]       		=AutoConfig.from_pretrained(lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					List[str]       		=TFAutoModelForMaskedLM.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														__UpperCamelCase		,				__UpperCamelCase      :					Tuple       		=TFAutoModelForMaskedLM.from_pretrained(
														    lowerCamelCase__							,  output_loading_info=lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					List[str]       		=AutoModelForMaskedLM.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														__UpperCamelCase		,				__UpperCamelCase      :					Optional[Any]       		=AutoModelForMaskedLM.from_pretrained(
														    lowerCamelCase__							,  output_loading_info=lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )


				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

									for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														__UpperCamelCase      :					Any       		=AutoConfig.from_pretrained(lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					List[Any]       		=TFAutoModelForSeqaSeqLM.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														__UpperCamelCase		,				__UpperCamelCase      :					List[str]       		=TFAutoModelForSeqaSeqLM.from_pretrained(
														    lowerCamelCase__							,  output_loading_info=lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Dict       		=AutoModelForSeqaSeqLM.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														__UpperCamelCase		,				__UpperCamelCase      :					List[Any]       		=AutoModelForSeqaSeqLM.from_pretrained(
														    lowerCamelCase__							,  output_loading_info=lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )


				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

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

														__UpperCamelCase      :					Union[str, Any]       		=TFAutoModelForSequenceClassification.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					str       		=AutoModelForSequenceClassification.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )


				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

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

														__UpperCamelCase      :					Tuple       		=TFAutoModelForQuestionAnswering.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Optional[Any]       		=AutoModelForQuestionAnswering.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )
														self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					int       		=TFAutoModelWithLMHead.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
									self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )
									self.assertEqual(model.num_parameters()							,  14410    )
									self.assertEqual(model.num_parameters(only_trainable=lowerCamelCase__    )							,  14410    )

									__UpperCamelCase      :					str       		=AutoModelWithLMHead.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
									self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )
									self.assertEqual(model.num_parameters()							,  14410    )
									self.assertEqual(model.num_parameters(only_trainable=lowerCamelCase__    )							,  14410    )







				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Union[str, Any]       		=TFAutoModelWithLMHead.from_pretrained(lowerCamelCase__							,  from_pt=lowerCamelCase__    )
									self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )
									self.assertEqual(model.num_parameters()							,  14410    )
									self.assertEqual(model.num_parameters(only_trainable=lowerCamelCase__    )							,  14410    )

									__UpperCamelCase      :					int       		=AutoModelWithLMHead.from_pretrained(lowerCamelCase__							,  from_tf=lowerCamelCase__    )
									self.assertIsInstance(lowerCamelCase__							,  lowerCamelCase__    )
									self.assertEqual(model.num_parameters()							,  14410    )
									self.assertEqual(model.num_parameters(only_trainable=lowerCamelCase__    )							,  14410    )









def      lowercase__      (     __snake_case    :							Dict  ):


					'''simple docstring'''


					if not head:
										return True
					# split the list to two parts
					UpperCAmelCase_       ,  UpperCAmelCase_    :      Any            =						head.next, head
					while fast and fast.next:
										UpperCAmelCase_    :      str            =						fast.next.next
										UpperCAmelCase_    :      Union[str, Any]            =						slow.next
					UpperCAmelCase_    :      int            =						slow.next
					UpperCAmelCase_    :      List[Any]            =						None  # Don't forget here! But forget still works!
					# reverse the second part
					UpperCAmelCase_    :      Tuple            =						None
					while second:
										UpperCAmelCase_    :      int            =						second.next
										UpperCAmelCase_    :      Any            =						node
										UpperCAmelCase_    :      Optional[Any]            =						second
										UpperCAmelCase_    :      Tuple            =						nxt
					# compare two parts
					# second part has the same or one less node
					while node:
										if node.val != head.val:
															return False
										UpperCAmelCase_    :      Optional[Any]            =						node.next
										UpperCAmelCase_    :      Dict            =						head.next
					return True




def      lowercase__      (     __snake_case    :							Union[str, Any]  ):


					'''simple docstring'''


					if not head or not head.next:
										return True

					# 1. Get the midpoint (slow)
					UpperCAmelCase_    :      Any            =						head
					while fast and fast.next:
										UpperCAmelCase_       ,  UpperCAmelCase_    :      Tuple            =						fast.next.next, slow.next

					# 2. Push the second half into the stack
					UpperCAmelCase_    :      List[str]            =						[slow.val]
					while slow.next:
										UpperCAmelCase_    :      List[str]            =						slow.next
										stack.append(slow.val  )

					# 3. Comparison
					while stack:
										if stack.pop() != cur.val:
															return False
										UpperCAmelCase_    :      int            =						cur.next

					return True






def      lowercase__      (     __snake_case    :							Dict  ):


					'''simple docstring'''


					if not head or not head.next:
										return True
					UpperCAmelCase_    :      Tuple            =						{}
					UpperCAmelCase_    :      int            =						0
					while head:
										if head.val in d:
															d[head.val].append(__snake_case  )
										else:
															UpperCAmelCase_    :      List[Any]            =						[pos]
										UpperCAmelCase_    :      Any            =						head.next
										pos += 1
					UpperCAmelCase_    :      Dict            =						pos - 1
					UpperCAmelCase_    :      Optional[int]            =						0
					for v in d.values():
										if len(__snake_case  ) % 2 != 0:
															middle += 1
										else:
															UpperCAmelCase_    :      int            =						0
															for i in range(0     ,       len(__snake_case  )  ):
																				if v[i] + v[len(__snake_case  ) - 1 - step] != checksum:
																									return False
																				step += 1
										if middle > 1:
															return False
					return True






