


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







						'''simple docstring'''




						@slow
						def 						lowercase_ (				self							)					->    List[str]:
										for model_name in ["bert-base-cased", "bert-large-uncased"]:
														with self.subTest(__lowercase							):
																		lowerCAmelCase_ :      Union[str, Any]    				=				AutoConfig.from_pretrained(__lowercase							)
																		self.assertIsNotNone(__lowercase							)
																		self.assertIsInstance(__lowercase   ,						__lowercase							)

																		lowerCAmelCase_ :      Any    				=				FlaxAutoModel.from_pretrained(__lowercase							)
																		self.assertIsNotNone(__lowercase							)
																		self.assertIsInstance(__lowercase   ,						__lowercase							)




						@slow
						def 						lowercase_ (				self							)					->    List[str]:
										for model_name in ["roberta-base", "roberta-large"]:
														with self.subTest(__lowercase							):
																		lowerCAmelCase_ :      Tuple    				=				AutoConfig.from_pretrained(__lowercase							)
																		self.assertIsNotNone(__lowercase							)
																		self.assertIsInstance(__lowercase   ,						__lowercase							)

																		lowerCAmelCase_ :      Union[str, Any]    				=				FlaxAutoModel.from_pretrained(__lowercase							)
																		self.assertIsNotNone(__lowercase							)
																		self.assertIsInstance(__lowercase   ,						__lowercase							)




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

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

														eval(**__lowercase							).block_until_ready()




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

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

														eval(**__lowercase							).block_until_ready()




						def 						lowercase_ (				self							)					->    Union[str, Any]:
										with self.assertRaisesRegex(
										    __lowercase   ,						'''bert-base is not a local folder and is not a valid model identifier'''							):
														lowerCAmelCase_ :      Optional[int]    				=				FlaxAutoModel.from_pretrained('''bert-base'''							)




						def 						lowercase_ (				self							)					->    List[str]:
										with self.assertRaisesRegex(
										    __lowercase   ,						R'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''							):
														lowerCAmelCase_ :      Any    				=				FlaxAutoModel.from_pretrained(__lowercase   ,						revision='''aaaaaa'''							)




						def 						lowercase_ (				self							)					->    Tuple:
										with self.assertRaisesRegex(
										    __lowercase   ,						'''hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack'''   ,						):
														lowerCAmelCase_ :      List[str]    				=				FlaxAutoModel.from_pretrained('''hf-internal-testing/config-no-model'''							)




						def 						lowercase_ (				self							)					->    Tuple:
										with self.assertRaisesRegex(__lowercase   ,						'''Use `from_pt=True` to load this model'''							):
														lowerCAmelCase_ :      Tuple    				=				FlaxAutoModel.from_pretrained('''hf-internal-testing/tiny-bert-pt-only'''							)










import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, Features, Value
from .base import TaskTemplate







@dataclass(frozen=UpperCAmelCase__							)
class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  str					=							field(default="""automatic-speech-recognition""",						metadata={"""include_in_asdict_even_if_is_default""": True}							)
						SCREAMING_SNAKE_CASE__      :  ClassVar[Features]					=							Features({"""audio""": Audio()}							)
						SCREAMING_SNAKE_CASE__      :  ClassVar[Features]					=							Features({"""transcription""": Value("""string"""							)}							)
						SCREAMING_SNAKE_CASE__      :  str					=							"audio"
						SCREAMING_SNAKE_CASE__      :  str					=							"transcription"




						def 						lowercase_ (				self   ,						__lowercase							)					->    int:
										if self.audio_column not in features:
														raise ValueError(f"""Column {self.audio_column} is not present in features."""							)
										if not isinstance(features[self.audio_column]   ,						__lowercase							):
														raise ValueError(f"""Column {self.audio_column} is not an Audio type."""							)
										lowerCAmelCase_ :      List[str]    				=				copy.deepcopy(self							)
										lowerCAmelCase_ :      Optional[Any]    				=				self.input_schema.copy()
										lowerCAmelCase_ :      Optional[Any]    				=				features[self.audio_column]
										lowerCAmelCase_ :      List[str]    				=				input_schema
										return task_template




						@property
						def 						lowercase_ (				self							)					->    Dict[str, str]:
										return {self.audio_column: "audio", self.transcription_column: "transcription"}