


import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
						import jax

						from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
						from transformers.models.bert.modeling_flax_bert import FlaxBertModel
						from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel
@require_flax
class        _lowercase      (			unittest.TestCase       ):






				'''simple docstring'''



				@slow
				def 		__magic_name__(       self			:str	)		->			int:
										for model_name in ["bert-base-cased", "bert-large-uncased"]:
																with self.subTest(lowerCAmelCase__	):
																						__SCREAMING_SNAKE_CASE						:     Dict					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																						self.assertIsNotNone(lowerCAmelCase__	)
																						self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																						__SCREAMING_SNAKE_CASE						:     int					=		FlaxAutoModel.from_pretrained(lowerCAmelCase__	)
																						self.assertIsNotNone(lowerCAmelCase__	)
																						self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)


				@slow
				def 		__magic_name__(       self			:Dict	)		->			Dict:
										for model_name in ["roberta-base", "roberta-large"]:
																with self.subTest(lowerCAmelCase__	):
																						__SCREAMING_SNAKE_CASE						:     List[Any]					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																						self.assertIsNotNone(lowerCAmelCase__	)
																						self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																						__SCREAMING_SNAKE_CASE						:     Optional[int]					=		FlaxAutoModel.from_pretrained(lowerCAmelCase__	)
																						self.assertIsNotNone(lowerCAmelCase__	)
																						self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)


				@slow
				def 		__magic_name__(       self			:Optional[int]	)		->			List[Any]:
										for model_name in ["bert-base-cased", "bert-large-uncased"]:
																__SCREAMING_SNAKE_CASE						:     Optional[int]					=		AutoTokenizer.from_pretrained(lowerCAmelCase__	)
																__SCREAMING_SNAKE_CASE						:     Optional[int]					=		FlaxBertModel.from_pretrained(lowerCAmelCase__	)
																__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		tokenizer('''Do you support jax jitted function?'''			,			return_tensors=TensorType.JAX	)

																@jax.jit
																def eval(**lowerCAmelCase__			:List[Any]	):
																						return model(**lowerCAmelCase__	)

																eval(**lowerCAmelCase__	).block_until_ready()


				@slow
				def 		__magic_name__(       self			:List[str]	)		->			Optional[int]:
										for model_name in ["roberta-base", "roberta-large"]:
																__SCREAMING_SNAKE_CASE						:     str					=		AutoTokenizer.from_pretrained(lowerCAmelCase__	)
																__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		FlaxRobertaModel.from_pretrained(lowerCAmelCase__	)
																__SCREAMING_SNAKE_CASE						:     Optional[int]					=		tokenizer('''Do you support jax jitted function?'''			,			return_tensors=TensorType.JAX	)

																@jax.jit
																def eval(**lowerCAmelCase__			:List[Any]	):
																						return model(**lowerCAmelCase__	)

																eval(**lowerCAmelCase__	).block_until_ready()


				def 		__magic_name__(       self			:Dict	)		->			Union[str, Any]:
										with self.assertRaisesRegex(
										    lowerCAmelCase__			,			'''bert-base is not a local folder and is not a valid model identifier'''	):
																__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		FlaxAutoModel.from_pretrained('''bert-base'''	)


				def 		__magic_name__(       self			:int	)		->			Optional[int]:
										with self.assertRaisesRegex(
										    lowerCAmelCase__			,			r'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''	):
																__SCREAMING_SNAKE_CASE						:     Optional[int]					=		FlaxAutoModel.from_pretrained(lowerCAmelCase__			,			revision='''aaaaaa'''	)


				def 		__magic_name__(       self			:str	)		->			Tuple:
										with self.assertRaisesRegex(
										    lowerCAmelCase__			,			'''hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack'''			,			):
																__SCREAMING_SNAKE_CASE						:     str					=		FlaxAutoModel.from_pretrained('''hf-internal-testing/config-no-model'''	)



				def 		__magic_name__(       self			:Dict	)		->			int:
										with self.assertRaisesRegex(lowerCAmelCase__			,			'''Use `from_pt=True` to load this model'''	):
																__SCREAMING_SNAKE_CASE						:     Dict					=		FlaxAutoModel.from_pretrained('''hf-internal-testing/tiny-bert-pt-only'''	)







import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)


class   A			(unittest.TestCase    ):
			'''simple docstring'''




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







					"""simple docstring"""






					A__        =   ["""a""", """b""", """c"""]

					# Defaults to last layer if both are None
					A__      ,			A__        =   get_aligned_output_features_output_indices(__lowerCAmelCase							,	__lowerCAmelCase							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[2]   )

					# Out indices set to match out features
					A__      ,			A__        =   get_aligned_output_features_output_indices(["""a""", """c"""]							,	__lowerCAmelCase							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""a""", """c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[0, 2]   )

					# Out features set to match out indices
					A__      ,			A__        =   get_aligned_output_features_output_indices(__lowerCAmelCase							,	[0, 2]							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""a""", """c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[0, 2]   )

					# Out features selected from negative indices
					A__      ,			A__        =   get_aligned_output_features_output_indices(__lowerCAmelCase							,	[-3, -1]							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""a""", """c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[-3, -1]   )






			def    a_       (			self   :    Optional[Any]   )	->	Optional[Any]:







					"""simple docstring"""






					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0, 1)							,	__lowerCAmelCase   )

					# Out features must be a list
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(("""a""", """b""")							,	(0, 1)							,	["""a""", """b"""]   )

					# Out features must be a subset of stage names
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0, 1)							,	["""a"""]   )

					# Out indices must be a list or tuple
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(__lowerCAmelCase							,	0							,	["""a""", """b"""]   )

					# Out indices must be a subset of stage names
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(__lowerCAmelCase							,	(0, 1)							,	["""a"""]   )

					# Out features and out indices must be the same length
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0,)							,	["""a""", """b""", """c"""]   )

					# Out features should match out indices
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0, 2)							,	["""a""", """b""", """c"""]   )

					# Out features and out indices should be in order
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""b""", """a"""]							,	(0, 1)							,	["""a""", """b"""]   )

					# Check passes with valid inputs
					verify_out_features_out_indices(["""a""", """b""", """d"""]							,	(0, 1, -1)							,	["""a""", """b""", """c""", """d"""]   )







			def    a_       (			self   :    Union[str, Any]   )	->	List[str]:







					"""simple docstring"""






					A__        =   BackboneMixin()

					A__        =   ["""a""", """b""", """c"""]
					A__        =   ["""a""", """c"""]
					A__        =   [0, 2]

					# Check that the output features and indices are set correctly
					self.assertEqual(backbone.out_features							,	["""a""", """c"""]   )
					self.assertEqual(backbone.out_indices							,	[0, 2]   )

					# Check out features and indices are updated correctly
					A__        =   ["""a""", """b"""]
					self.assertEqual(backbone.out_features							,	["""a""", """b"""]   )
					self.assertEqual(backbone.out_indices							,	[0, 1]   )

					A__        =   [-3, -1]
					self.assertEqual(backbone.out_features							,	["""a""", """c"""]   )
					self.assertEqual(backbone.out_indices							,	[-3, -1]   )



