



'''simple docstring'''




from __future__ import annotations

import copy
import tempfile
import unittest

from transformers import CONFIG_MAPPING, AutoConfig, BertConfig, GPTaConfig, TaConfig, TapasConfig, is_tf_available
from transformers.testing_utils import (
    DUMMY_UNKNOWN_IDENTIFIER,
    SMALL_MODEL_IDENTIFIER,
    RequestCounter,
    require_tensorflow_probability,
    require_tf,
    slow,
)

from ..bert.test_modeling_bert import BertModelTester


if is_tf_available():
						from transformers import (
						    TFAutoModel,
						    TFAutoModelForCausalLM,
						    TFAutoModelForMaskedLM,
						    TFAutoModelForPreTraining,
						    TFAutoModelForQuestionAnswering,
						    TFAutoModelForSeqaSeqLM,
						    TFAutoModelForSequenceClassification,
						    TFAutoModelForTableQuestionAnswering,
						    TFAutoModelForTokenClassification,
						    TFAutoModelWithLMHead,
						    TFBertForMaskedLM,
						    TFBertForPreTraining,
						    TFBertForQuestionAnswering,
						    TFBertForSequenceClassification,
						    TFBertModel,
						    TFFunnelBaseModel,
						    TFFunnelModel,
						    TFGPTaLMHeadModel,
						    TFRobertaForMaskedLM,
						    TFTaForConditionalGeneration,
						    TFTapasForQuestionAnswering,
						)
						from transformers.models.auto.modeling_tf_auto import (
						    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
						    TF_MODEL_FOR_MASKED_LM_MAPPING,
						    TF_MODEL_FOR_PRETRAINING_MAPPING,
						    TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
						    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
						    TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
						    TF_MODEL_MAPPING,
						)
						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
						from transformers.models.tapas.modeling_tf_tapas import TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST






class 						_UpperCamelCase  (							__lowercase    ):


			'''simple docstring'''

			_A      :		Optional[int]			    =		'''new-model'''


if is_tf_available():






						class 						_UpperCamelCase  (							__lowercase    ):


									'''simple docstring'''

									_A      :		Dict			    =		NewModelConfig






@require_tf
class 						_UpperCamelCase  (							unittest.TestCase    ):


			'''simple docstring'''

			@slow
			def UpperCamelCase__					(							self     : int						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		List[Any]           =		"bert-base-cased"
					__SCREAMING_SNAKE_CASE       :		Any           =		AutoConfig.from_pretrained(lowerCAmelCase__						)
					self.assertIsNotNone(lowerCAmelCase__						)
					self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

					__SCREAMING_SNAKE_CASE       :		Any           =		TFAutoModel.from_pretrained(lowerCAmelCase__						)
					self.assertIsNotNone(lowerCAmelCase__						)
					self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

			@slow
			def UpperCamelCase__					(							self     : str						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		List[Any]           =		"bert-base-cased"
					__SCREAMING_SNAKE_CASE       :		List[str]           =		AutoConfig.from_pretrained(lowerCAmelCase__						)
					self.assertIsNotNone(lowerCAmelCase__						)
					self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		TFAutoModelForPreTraining.from_pretrained(lowerCAmelCase__						)
					self.assertIsNotNone(lowerCAmelCase__						)
					self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

			@slow
			def UpperCamelCase__					(							self     : int						):





					"""simple docstring"""






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

							__SCREAMING_SNAKE_CASE       :		Any           =		TFAutoModelForCausalLM.from_pretrained(lowerCAmelCase__						)
							__SCREAMING_SNAKE_CASE       :		Dict           =		TFAutoModelForCausalLM.from_pretrained(lowerCAmelCase__							,     output_loading_info=lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

			@slow
			def UpperCamelCase__					(							self     : Any						):





					"""simple docstring"""






					for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__SCREAMING_SNAKE_CASE       :		Optional[int]           =		AutoConfig.from_pretrained(lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

							__SCREAMING_SNAKE_CASE       :		List[str]           =		TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

			@slow
			def UpperCamelCase__					(							self     : str						):





					"""simple docstring"""






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

							__SCREAMING_SNAKE_CASE       :		List[str]           =		TFAutoModelForMaskedLM.from_pretrained(lowerCAmelCase__						)
							__SCREAMING_SNAKE_CASE       :		Dict           =		TFAutoModelForMaskedLM.from_pretrained(lowerCAmelCase__							,     output_loading_info=lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

			@slow
			def UpperCamelCase__					(							self     : Any						):





					"""simple docstring"""






					for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		AutoConfig.from_pretrained(lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

							__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		TFAutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase__						)
							__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		TFAutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase__							,     output_loading_info=lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

			@slow
			def UpperCamelCase__					(							self     : Dict						):





					"""simple docstring"""






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

							__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		TFAutoModelForSequenceClassification.from_pretrained(lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

			@slow
			def UpperCamelCase__					(							self     : str						):





					"""simple docstring"""






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

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

			@slow
			@require_tensorflow_probability
			def UpperCamelCase__					(							self     : Optional[Any]						):





					"""simple docstring"""






					for model_name in TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST[5:6]:
							__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		AutoConfig.from_pretrained(lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

							__SCREAMING_SNAKE_CASE       :		Optional[int]           =		TFAutoModelForTableQuestionAnswering.from_pretrained(lowerCAmelCase__						)
							__SCREAMING_SNAKE_CASE       :		List[str]           =		TFAutoModelForTableQuestionAnswering.from_pretrained(
							    lowerCAmelCase__							,     output_loading_info=lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

			def UpperCamelCase__					(							self     : int						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__						)
					self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)
					self.assertEqual(model.num_parameters()							,     1_4_4_1_0						)
					self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__						)							,     1_4_4_1_0						)

			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__						)
					self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)
					self.assertEqual(model.num_parameters()							,     1_4_4_1_0						)
					self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__						)							,     1_4_4_1_0						)

			def UpperCamelCase__					(							self     : Dict						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		str           =		TFAutoModel.from_pretrained("""sgugger/funnel-random-tiny"""						)
					self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

					__SCREAMING_SNAKE_CASE       :		Dict           =		copy.deepcopy(model.config						)
					__SCREAMING_SNAKE_CASE       :		Dict           =		["FunnelBaseModel"]
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		TFAutoModel.from_config(lowerCAmelCase__						)
					self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

					with tempfile.TemporaryDirectory() as tmp_dir:
							model.save_pretrained(lowerCAmelCase__						)
							__SCREAMING_SNAKE_CASE       :		List[Any]           =		TFAutoModel.from_pretrained(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

			def UpperCamelCase__					(							self     : List[str]						):





					"""simple docstring"""






					try:
							AutoConfig.register("""new-model"""							,     lowerCAmelCase__						)

							__SCREAMING_SNAKE_CASE       :		List[str]           =		[
							    TFAutoModel,
							    TFAutoModelForCausalLM,
							    TFAutoModelForMaskedLM,
							    TFAutoModelForPreTraining,
							    TFAutoModelForQuestionAnswering,
							    TFAutoModelForSequenceClassification,
							    TFAutoModelForTokenClassification,
							]

							for auto_class in auto_classes:
									with self.subTest(auto_class.__name__						):
											# Wrong config class will raise an error
											with self.assertRaises(lowerCAmelCase__						):
													auto_class.register(lowerCAmelCase__							,     lowerCAmelCase__						)
											auto_class.register(lowerCAmelCase__							,     lowerCAmelCase__						)
											# Trying to register something existing in the Transformers library will raise an error
											with self.assertRaises(lowerCAmelCase__						):
													auto_class.register(lowerCAmelCase__							,     lowerCAmelCase__						)

											# Now that the config is registered, it can be used as any other config with the auto-API
											__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		BertModelTester(self						).get_config()
											__SCREAMING_SNAKE_CASE       :		Optional[int]           =		NewModelConfig(**tiny_config.to_dict()						)
											__SCREAMING_SNAKE_CASE       :		Optional[int]           =		auto_class.from_config(lowerCAmelCase__						)
											self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

											with tempfile.TemporaryDirectory() as tmp_dir:
													model.save_pretrained(lowerCAmelCase__						)
													__SCREAMING_SNAKE_CASE       :		Optional[int]           =		auto_class.from_pretrained(lowerCAmelCase__						)
													self.assertIsInstance(lowerCAmelCase__							,     lowerCAmelCase__						)

					finally:
							if "new-model" in CONFIG_MAPPING._extra_content:
									del CONFIG_MAPPING._extra_content["new-model"]
							for mapping in (
							    TF_MODEL_MAPPING,
							    TF_MODEL_FOR_PRETRAINING_MAPPING,
							    TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
							    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
							    TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
							    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
							    TF_MODEL_FOR_MASKED_LM_MAPPING,
							):
									if NewModelConfig in mapping._extra_content:
											del mapping._extra_content[NewModelConfig]

			def UpperCamelCase__					(							self     : Any						):





					"""simple docstring"""






					with self.assertRaisesRegex(
					    lowerCAmelCase__							,     """bert-base is not a local folder and is not a valid model identifier"""						):
							__SCREAMING_SNAKE_CASE       :		List[str]           =		TFAutoModel.from_pretrained("""bert-base"""						)

			def UpperCamelCase__					(							self     : int						):





					"""simple docstring"""






					with self.assertRaisesRegex(
					    lowerCAmelCase__							,     r"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""						):
							__SCREAMING_SNAKE_CASE       :		Tuple           =		TFAutoModel.from_pretrained(lowerCAmelCase__							,     revision="""aaaaaa"""						)

			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






					with self.assertRaisesRegex(
					    lowerCAmelCase__							,     """hf-internal-testing/config-no-model does not appear to have a file named pytorch_model.bin"""							,     ):
							__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		TFAutoModel.from_pretrained("""hf-internal-testing/config-no-model"""						)

			def UpperCamelCase__					(							self     : Dict						):





					"""simple docstring"""






					with self.assertRaisesRegex(lowerCAmelCase__							,     """Use `from_pt=True` to load this model"""						):
							__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		TFAutoModel.from_pretrained("""hf-internal-testing/tiny-bert-pt-only"""						)



			def UpperCamelCase__					(							self     : int						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		str           =		TFAutoModel.from_pretrained("""hf-internal-testing/tiny-random-bert"""						)
					with RequestCounter() as counter:
							__SCREAMING_SNAKE_CASE       :		int           =		TFAutoModel.from_pretrained("""hf-internal-testing/tiny-random-bert"""						)
							self.assertEqual(counter.get_request_count							,     0						)
							self.assertEqual(counter.head_request_count							,     1						)
							self.assertEqual(counter.other_request_count							,     0						)

					# With a sharded checkpoint
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		TFAutoModel.from_pretrained("""ArthurZ/tiny-random-bert-sharded"""						)
					with RequestCounter() as counter:
							__SCREAMING_SNAKE_CASE       :		int           =		TFAutoModel.from_pretrained("""ArthurZ/tiny-random-bert-sharded"""						)
							self.assertEqual(counter.get_request_count							,     0						)
							self.assertEqual(counter.head_request_count							,     1						)
							self.assertEqual(counter.other_request_count							,     0						)

from __future__ import annotations

import math

lowercase  :					Any													=       '2020.9.26'
lowercase  :					Union[str, Any]													=       'xcodz-dot, cclaus, dhruvmanila'




def 	_SCREAMING_SNAKE_CASE					(		_lowerCamelCase :			float						,  _lowerCamelCase :			float						,  _lowerCamelCase :			float						,  _lowerCamelCase :			float						,  _lowerCamelCase :			float)					->    tuple[float, float]:






							'''simple docstring'''





							if not all(isinstance(_lowerCamelCase						,  (float, int)) for val in locals().values()):
														__UpperCamelCase	:   str			   =					F'Input values must either be float or int: {list(locals().values())}'
														raise TypeError(_lowerCamelCase)
							__UpperCamelCase	:   List[str]			   =					((x * distance) / (z + distance)) * scale
							__UpperCamelCase	:   List[Any]			   =					((y * distance) / (z + distance)) * scale
							return projected_x, projected_y




def 	_SCREAMING_SNAKE_CASE					(		_lowerCamelCase :			float						,  _lowerCamelCase :			float						,  _lowerCamelCase :			float						,  _lowerCamelCase :			str						,  _lowerCamelCase :			float)					->    tuple[float, float, float]:






							'''simple docstring'''





							if not isinstance(_lowerCamelCase						,  _lowerCamelCase):
														raise TypeError("Axis must be a str")
							__UpperCamelCase	:   str			   =					locals()
							del input_variables["axis"]
							if not all(isinstance(_lowerCamelCase						,  (float, int)) for val in input_variables.values()):
														__UpperCamelCase	:   Dict			   =					(
														    "Input values except axis must either be float or int: "
														    F'{list(input_variables.values())}'
														)
														raise TypeError(_lowerCamelCase)
							__UpperCamelCase	:   Optional[Any]			   =					(angle % 360) / 450 * 180 / math.pi
							if axis == "z":
														__UpperCamelCase	:   Tuple			   =					x * math.cos(_lowerCamelCase) - y * math.sin(_lowerCamelCase)
														__UpperCamelCase	:   Union[str, Any]			   =					y * math.cos(_lowerCamelCase) + x * math.sin(_lowerCamelCase)
														__UpperCamelCase	:   Any			   =					z
							elif axis == "x":
														__UpperCamelCase	:   Dict			   =					y * math.cos(_lowerCamelCase) - z * math.sin(_lowerCamelCase)
														__UpperCamelCase	:   Any			   =					z * math.cos(_lowerCamelCase) + y * math.sin(_lowerCamelCase)
														__UpperCamelCase	:   List[str]			   =					x
							elif axis == "y":
														__UpperCamelCase	:   Any			   =					x * math.cos(_lowerCamelCase) - z * math.sin(_lowerCamelCase)
														__UpperCamelCase	:   Any			   =					z * math.cos(_lowerCamelCase) + x * math.sin(_lowerCamelCase)
														__UpperCamelCase	:   Dict			   =					y
							else:
														raise ValueError("not a valid axis, choose one of 'x', 'y', 'z'")

							return new_x, new_y, new_z


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		print(f"{convert_to_ad(1.0, 2.0, 3.0, 1_0.0, 1_0.0) = }")
		print(f"{rotate(1.0, 2.0, 3.0, 'y', 9_0.0) = }")