



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







					@slow
					def  _lowercase			(       self      :     int):
											for model_name in ["bert-base-cased", "bert-large-uncased"]:
																	with self.subTest(_A):
																							A__	:							int						    = AutoConfig.from_pretrained(_A)
																							self.assertIsNotNone(_A)
																							self.assertIsInstance(_A			,		_A)

																							A__	:							List[Any]						    = FlaxAutoModel.from_pretrained(_A)
																							self.assertIsNotNone(_A)
																							self.assertIsInstance(_A			,		_A)







					@slow
					def  _lowercase			(       self      :     Dict):
											for model_name in ["roberta-base", "roberta-large"]:
																	with self.subTest(_A):
																							A__	:							Optional[int]						    = AutoConfig.from_pretrained(_A)
																							self.assertIsNotNone(_A)
																							self.assertIsInstance(_A			,		_A)

																							A__	:							Tuple						    = FlaxAutoModel.from_pretrained(_A)
																							self.assertIsNotNone(_A)
																							self.assertIsInstance(_A			,		_A)







					@slow
					def  _lowercase			(       self      :     str):
											for model_name in ["bert-base-cased", "bert-large-uncased"]:
																	A__	:							List[Any]						    = AutoTokenizer.from_pretrained(_A)
																	A__	:							Optional[Any]						    = FlaxBertModel.from_pretrained(_A)
																	A__	:							List[str]						    = tokenizer("Do you support jax jitted function?"			,		return_tensors=TensorType.JAX)

																	@jax.jit
																	def eval(**_A      :     int):
																							return model(**_A)

																	eval(**_A).block_until_ready()







					@slow
					def  _lowercase			(       self      :     int):
											for model_name in ["roberta-base", "roberta-large"]:
																	A__	:							Dict						    = AutoTokenizer.from_pretrained(_A)
																	A__	:							int						    = FlaxRobertaModel.from_pretrained(_A)
																	A__	:							Union[str, Any]						    = tokenizer("Do you support jax jitted function?"			,		return_tensors=TensorType.JAX)

																	@jax.jit
																	def eval(**_A      :     List[str]):
																							return model(**_A)

																	eval(**_A).block_until_ready()







					def  _lowercase			(       self      :     List[str]):
											with self.assertRaisesRegex(
											    _A			,		"bert-base is not a local folder and is not a valid model identifier"):
																	A__	:							List[str]						    = FlaxAutoModel.from_pretrained("bert-base")







					def  _lowercase			(       self      :     Optional[int]):
											with self.assertRaisesRegex(
											    _A			,		r"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"):
																	A__	:							Optional[int]						    = FlaxAutoModel.from_pretrained(_A			,		revision="aaaaaa")







					def  _lowercase			(       self      :     Optional[int]):
											with self.assertRaisesRegex(
											    _A			,		"hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack"			,		):
																	A__	:							Dict						    = FlaxAutoModel.from_pretrained("hf-internal-testing/config-no-model")







					def  _lowercase			(       self      :     int):
											with self.assertRaisesRegex(_A			,		"Use `from_pt=True` to load this model"):
																	A__	:							Optional[int]						    = FlaxAutoModel.from_pretrained("hf-internal-testing/tiny-bert-pt-only")




import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
		import ctypes
		import msvcrt  # noqa




		class 							lowerCAmelCase__  (	ctypes.Structure						):
							# _fields is a specific attr expected by ctypes
							__A     :    Optional[Any]           =						[('size', ctypes.c_int), ('visible', ctypes.c_byte)]
def 	snake_case__       (					)		->		List[Any]:







						"""simple docstring"""

						if os.name == "nt":
												A__	:							Optional[Any]						    = CursorInfo()
												A__	:							Tuple						    = ctypes.windll.kernelaa.GetStdHandle(-1_1       )
												ctypes.windll.kernelaa.GetConsoleCursorInfo(__lowercase							,     ctypes.byref(__lowercase       )       )
												A__	:							Any						    = False
												ctypes.windll.kernelaa.SetConsoleCursorInfo(__lowercase							,     ctypes.byref(__lowercase       )       )
						elif os.name == "posix":
												sys.stdout.write("\033[?25l"       )
												sys.stdout.flush()
def 	snake_case__       (					)		->		Dict:







						"""simple docstring"""

						if os.name == "nt":
												A__	:							List[str]						    = CursorInfo()
												A__	:							Optional[int]						    = ctypes.windll.kernelaa.GetStdHandle(-1_1       )
												ctypes.windll.kernelaa.GetConsoleCursorInfo(__lowercase							,     ctypes.byref(__lowercase       )       )
												A__	:							int						    = True
												ctypes.windll.kernelaa.SetConsoleCursorInfo(__lowercase							,     ctypes.byref(__lowercase       )       )
						elif os.name == "posix":
												sys.stdout.write("\033[?25h"       )
												sys.stdout.flush()




@contextmanager
def 	snake_case__       (					)		->		Optional[int]:







						"""simple docstring"""

						try:
												hide_cursor()
												yield
						finally:
												show_cursor()