






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

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





@dataclass(frozen=__lowercase	)
class       __a  (   __lowercase	):
 _lowerCAmelCase	:	str				=			field(default='''automatic-speech-recognition'''	,       metadata={'''include_in_asdict_even_if_is_default''': True}	)
 _lowerCAmelCase	:	ClassVar[Features]				=			Features({'''audio''': Audio()}	)
 _lowerCAmelCase	:	ClassVar[Features]				=			Features({'''transcription''': Value('''string'''	)}	)
 _lowerCAmelCase	:	str				=			"audio"
 _lowerCAmelCase	:	str				=			"transcription"







 def  __lowercase (		self :       Optional[int]							,       SCREAMING_SNAKE_CASE :       str						):


      '''simple docstring'''






      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]							,       SCREAMING_SNAKE_CASE						):
           raise ValueError(F'Column {self.audio_column} is not an Audio type.'						)
      UpperCamelCase__      :       List[Any]	    =  copy.deepcopy(self						)
      UpperCamelCase__      :       Any	    =  self.input_schema.copy()
      UpperCamelCase__      :       Union[str, Any]	    =  features[self.audio_column]
      UpperCamelCase__      :       int	    =  input_schema
      return task_template







 @property
 def  __lowercase (		self :       int						):


      '''simple docstring'''






      return {self.audio_column: "audio", self.transcription_column: "transcription"}







import unittest

from transformers import BigBirdConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
 import jax

 from transformers.models.big_bird.modeling_flax_big_bird import (
     FlaxBigBirdForCausalLM,
     FlaxBigBirdForMaskedLM,
     FlaxBigBirdForMultipleChoice,
     FlaxBigBirdForPreTraining,
     FlaxBigBirdForQuestionAnswering,
     FlaxBigBirdForSequenceClassification,
     FlaxBigBirdForTokenClassification,
     FlaxBigBirdModel,
 )





class       __a  (   unittest.TestCase	):







 def __init__(		self :       int							,       SCREAMING_SNAKE_CASE :       Optional[Any]							,       SCREAMING_SNAKE_CASE :       Dict=2							,       SCREAMING_SNAKE_CASE :       List[Any]=56							,       SCREAMING_SNAKE_CASE :       List[str]=True							,       SCREAMING_SNAKE_CASE :       str=True							,       SCREAMING_SNAKE_CASE :       Any=True							,       SCREAMING_SNAKE_CASE :       int=True							,       SCREAMING_SNAKE_CASE :       List[str]=99							,       SCREAMING_SNAKE_CASE :       str=32							,       SCREAMING_SNAKE_CASE :       Optional[int]=2							,       SCREAMING_SNAKE_CASE :       Union[str, Any]=2							,       SCREAMING_SNAKE_CASE :       Dict=7							,       SCREAMING_SNAKE_CASE :       List[Any]="gelu_new"							,       SCREAMING_SNAKE_CASE :       List[Any]=0.1							,       SCREAMING_SNAKE_CASE :       int=0.1							,       SCREAMING_SNAKE_CASE :       Any=5_12							,       SCREAMING_SNAKE_CASE :       Dict=16							,       SCREAMING_SNAKE_CASE :       Union[str, Any]=2							,       SCREAMING_SNAKE_CASE :       Any=0.0_2							,       SCREAMING_SNAKE_CASE :       Optional[Any]=4							,       SCREAMING_SNAKE_CASE :       int="block_sparse"							,       SCREAMING_SNAKE_CASE :       int=True							,       SCREAMING_SNAKE_CASE :       Optional[Any]=False							,       SCREAMING_SNAKE_CASE :       Tuple=2							,       SCREAMING_SNAKE_CASE :       Dict=3							,       ):


      '''simple docstring'''






      UpperCamelCase__      :       List[str]	    =  parent
      UpperCamelCase__      :       Union[str, Any]	    =  batch_size
      UpperCamelCase__      :       Union[str, Any]	    =  seq_length
      UpperCamelCase__      :       Dict	    =  is_training
      UpperCamelCase__      :       Optional[int]	    =  use_attention_mask
      UpperCamelCase__      :       List[str]	    =  use_token_type_ids
      UpperCamelCase__      :       Dict	    =  use_labels
      UpperCamelCase__      :       Optional[int]	    =  vocab_size
      UpperCamelCase__      :       List[Any]	    =  hidden_size
      UpperCamelCase__      :       List[str]	    =  num_hidden_layers
      UpperCamelCase__      :       List[str]	    =  num_attention_heads
      UpperCamelCase__      :       int	    =  intermediate_size
      UpperCamelCase__      :       str	    =  hidden_act
      UpperCamelCase__      :       Tuple	    =  hidden_dropout_prob
      UpperCamelCase__      :       Any	    =  attention_probs_dropout_prob
      UpperCamelCase__      :       str	    =  max_position_embeddings
      UpperCamelCase__      :       Tuple	    =  type_vocab_size
      UpperCamelCase__      :       Dict	    =  type_sequence_label_size
      UpperCamelCase__      :       Optional[Any]	    =  initializer_range
      UpperCamelCase__      :       Any	    =  num_choices

      UpperCamelCase__      :       Dict	    =  rescale_embeddings
      UpperCamelCase__      :       Union[str, Any]	    =  attention_type
      UpperCamelCase__      :       int	    =  use_bias
      UpperCamelCase__      :       List[Any]	    =  block_size
      UpperCamelCase__      :       Union[str, Any]	    =  num_random_blocks







 def  __lowercase (		self :       List[str]						):


      '''simple docstring'''






      UpperCamelCase__      :       Dict	    =  ids_tensor([self.batch_size, self.seq_length]							,       self.vocab_size						)

      UpperCamelCase__      :       Any	    =  None
      if self.use_attention_mask:
           UpperCamelCase__      :       str	    =  random_attention_mask([self.batch_size, self.seq_length]						)

      UpperCamelCase__      :       Any	    =  None
      if self.use_token_type_ids:
           UpperCamelCase__      :       int	    =  ids_tensor([self.batch_size, self.seq_length]							,       self.type_vocab_size						)

      UpperCamelCase__      :       List[Any]	    =  BigBirdConfig(
          vocab_size=self.vocab_size							,       hidden_size=self.hidden_size							,       num_hidden_layers=self.num_hidden_layers							,       num_attention_heads=self.num_attention_heads							,       intermediate_size=self.intermediate_size							,       hidden_act=self.hidden_act							,       hidden_dropout_prob=self.hidden_dropout_prob							,       attention_probs_dropout_prob=self.attention_probs_dropout_prob							,       max_position_embeddings=self.max_position_embeddings							,       type_vocab_size=self.type_vocab_size							,       is_decoder=SCREAMING_SNAKE_CASE							,       initializer_range=self.initializer_range							,       attention_type=self.attention_type							,       block_size=self.block_size							,       num_random_blocks=self.num_random_blocks							,       use_bias=self.use_bias							,       rescale_embeddings=self.rescale_embeddings							,       )

      return config, input_ids, token_type_ids, attention_mask







 def  __lowercase (		self :       Any						):


      '''simple docstring'''






      UpperCamelCase__      :       int	    =  self.prepare_config_and_inputs()
      UpperCamelCase__    ,					UpperCamelCase__    ,					UpperCamelCase__    ,					UpperCamelCase__      :       Tuple	    =  config_and_inputs
      UpperCamelCase__      :       int	    =  {
          "input_ids": input_ids,
          "token_type_ids": token_type_ids,
          "attention_mask": attention_mask,
      }
      return config, inputs_dict







@require_flax
class       __a  (   A__	,       unittest.TestCase	):
 _lowerCAmelCase	:	Optional[Any]				=			(
     (
         FlaxBigBirdForCausalLM,
         FlaxBigBirdModel,
         FlaxBigBirdForPreTraining,
         FlaxBigBirdForMaskedLM,
         FlaxBigBirdForMultipleChoice,
         FlaxBigBirdForQuestionAnswering,
         FlaxBigBirdForSequenceClassification,
         FlaxBigBirdForTokenClassification,
     )
     if is_flax_available()
     else ()
 )

 _lowerCAmelCase	:	Dict				=			False
 _lowerCAmelCase	:	Optional[int]				=			False







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       Any	    =  FlaxBigBirdModelTester(self						)







 @slow
 # copied from `test_modeling_flax_common` because it takes much longer than other models
 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      super().test_from_pretrained_save_pretrained()







 @slow
 # copied from `test_modeling_flax_common` because it takes much longer than other models
 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      super().test_from_pretrained_with_no_automatic_init()







 @slow
 # copied from `test_modeling_flax_common` because it takes much longer than other models
 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      super().test_no_automatic_init()







 @slow
 # copied from `test_modeling_flax_common` because it takes much longer than other models
 def  __lowercase (		self :       Union[str, Any]						):


      '''simple docstring'''






      super().test_hidden_states_output()







 @slow
 def  __lowercase (		self :       str						):


      '''simple docstring'''






      for model_class_name in self.all_model_classes:
           UpperCamelCase__      :       Any	    =  model_class_name.from_pretrained("google/bigbird-roberta-base"						)
           self.assertIsNotNone(SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       Optional[int]						):


      '''simple docstring'''






      if self.test_attn_probs:
           super().test_attention_outputs()







 @slow
 # copied from `test_modeling_flax_common` because it takes much longer than other models
 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      UpperCamelCase__    ,					UpperCamelCase__      :       Tuple	    =  self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           with self.subTest(model_class.__name__						):
                UpperCamelCase__      :       Dict	    =  self._prepare_for_class(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						)
                UpperCamelCase__      :       Union[str, Any]	    =  model_class(SCREAMING_SNAKE_CASE						)

                @jax.jit
                def model_jitted(SCREAMING_SNAKE_CASE :       str							,       SCREAMING_SNAKE_CASE :       List[str]=None							,       **SCREAMING_SNAKE_CASE :       List[Any]						):
                     return model(input_ids=SCREAMING_SNAKE_CASE							,       attention_mask=SCREAMING_SNAKE_CASE							,       **SCREAMING_SNAKE_CASE						)

                with self.subTest("JIT Enabled"						):
                     UpperCamelCase__      :       Tuple	    =  model_jitted(**SCREAMING_SNAKE_CASE						).to_tuple()

                with self.subTest("JIT Disabled"						):
                     with jax.disable_jit():
                          UpperCamelCase__      :       List[Any]	    =  model_jitted(**SCREAMING_SNAKE_CASE						).to_tuple()

                self.assertEqual(len(SCREAMING_SNAKE_CASE						)							,       len(SCREAMING_SNAKE_CASE						)						)
                for jitted_output, output in zip(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						):
                     self.assertEqual(jitted_output.shape							,       output.shape						)







 def  __lowercase (		self :       int							,       SCREAMING_SNAKE_CASE :       int							,       SCREAMING_SNAKE_CASE :       int							,       SCREAMING_SNAKE_CASE :       Union[str, Any]							,       SCREAMING_SNAKE_CASE :       Any=1e-5							,       SCREAMING_SNAKE_CASE :       Tuple="outputs"							,       SCREAMING_SNAKE_CASE :       Optional[Any]=None						):


      '''simple docstring'''






      if name.startswith("outputs.attentions"						):
           return
      else:
           super().check_pt_flax_outputs(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						)