





'''simple docstring'''


import unittest

from transformers import MraConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_torch_available():
    import torch

    from transformers import (
        MraForMaskedLM,
        MraForMultipleChoice,
        MraForQuestionAnswering,
        MraForSequenceClassification,
        MraForTokenClassification,
        MraModel,
    )
    from transformers.models.mra.modeling_mra import MRA_PRETRAINED_MODEL_ARCHIVE_LIST






class     lowerCAmelCase__ :

       '''simple docstring'''

       def __init__( self					:				str       ,     a__					:				str       ,     a__					:				Optional[Any]=2       ,     a__					:				Dict=8       ,     a__					:				Optional[Any]=True       ,     a__					:				List[Any]=True       ,     a__					:				Optional[Any]=True       ,     a__					:				Optional[Any]=True       ,     a__					:				Optional[Any]=99       ,     a__					:				Dict=16       ,     a__					:				Optional[int]=5       ,     a__					:				str=2       ,     a__					:				List[Any]=36       ,     a__					:				Optional[Any]="gelu"       ,     a__					:				List[str]=0.0       ,     a__					:				Union[str, Any]=0.0       ,     a__					:				int=512       ,     a__					:				str=16       ,     a__					:				str=2       ,     a__					:				Any=0.02       ,     a__					:				Tuple=3       ,     a__					:				Any=4       ,     a__					:				int=None       ,     ):
              UpperCAmelCase  =						parent
              UpperCAmelCase  =						batch_size
              UpperCAmelCase  =						seq_length
              UpperCAmelCase  =						is_training
              UpperCAmelCase  =						use_input_mask
              UpperCAmelCase  =						use_token_type_ids
              UpperCAmelCase  =						use_labels
              UpperCAmelCase  =						vocab_size
              UpperCAmelCase  =						hidden_size
              UpperCAmelCase  =						num_hidden_layers
              UpperCAmelCase  =						num_attention_heads
              UpperCAmelCase  =						intermediate_size
              UpperCAmelCase  =						hidden_act
              UpperCAmelCase  =						hidden_dropout_prob
              UpperCAmelCase  =						attention_probs_dropout_prob
              UpperCAmelCase  =						max_position_embeddings
              UpperCAmelCase  =						type_vocab_size
              UpperCAmelCase  =						type_sequence_label_size
              UpperCAmelCase  =						initializer_range
              UpperCAmelCase  =						num_labels
              UpperCAmelCase  =						num_choices
              UpperCAmelCase  =						scope

       def 			__snake_case      ( self					:				Optional[int]						):
              UpperCAmelCase  =						ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size						)

              UpperCAmelCase  =						None
              if self.use_input_mask:
                     UpperCAmelCase  =						random_attention_mask([self.batch_size, self.seq_length]						)

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

              UpperCAmelCase  =						None
              UpperCAmelCase  =						None
              UpperCAmelCase  =						None
              if self.use_labels:
                     UpperCAmelCase  =						ids_tensor([self.batch_size]       ,     self.type_sequence_label_size						)
                     UpperCAmelCase  =						ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels						)
                     UpperCAmelCase  =						ids_tensor([self.batch_size]       ,     self.num_choices						)

              UpperCAmelCase  =						self.get_config()

              return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

       def 			__snake_case      ( self					:				Any						):
              return MraConfig(
                  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=a__       ,     initializer_range=self.initializer_range       ,     )

       def 			__snake_case      ( self					:				Tuple						):
              UpperCAmelCase  =						self.get_config()
              UpperCAmelCase  =						300
              return config

       def 			__snake_case      ( self					:				Optional[Any]						):
              (
                  (
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					
              )  =						self.prepare_config_and_inputs()

              UpperCAmelCase  =						True
              UpperCAmelCase  =						floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
              UpperCAmelCase  =						ids_tensor([self.batch_size, self.seq_length]       ,     vocab_size=2						)

              return (
                  config,
                  input_ids,
                  token_type_ids,
                  input_mask,
                  sequence_labels,
                  token_labels,
                  choice_labels,
                  encoder_hidden_states,
                  encoder_attention_mask,
              )

       def 			__snake_case      ( self					:				Tuple       ,     a__					:				str       ,     a__					:				Tuple       ,     a__					:				Dict       ,     a__					:				Any       ,     a__					:				Any       ,     a__					:				Tuple       ,     a__					:				Tuple						):
              UpperCAmelCase  =						MraModel(config=a__						)
              model.to(a__						)
              model.eval()
              UpperCAmelCase  =						model(a__       ,     attention_mask=a__       ,     token_type_ids=a__						)
              UpperCAmelCase  =						model(a__       ,     token_type_ids=a__						)
              UpperCAmelCase  =						model(a__						)
              self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.seq_length, self.hidden_size)						)

       def 			__snake_case      ( self					:				Optional[Any]       ,     a__					:				int       ,     a__					:				str       ,     a__					:				Optional[Any]       ,     a__					:				Optional[Any]       ,     a__					:				Optional[Any]       ,     a__					:				List[str]       ,     a__					:				Optional[int]       ,     a__					:				Union[str, Any]       ,     a__					:				str       ,     ):
              UpperCAmelCase  =						True
              UpperCAmelCase  =						MraModel(a__						)
              model.to(a__						)
              model.eval()
              UpperCAmelCase  =						model(
                  a__       ,     attention_mask=a__       ,     token_type_ids=a__       ,     encoder_hidden_states=a__       ,     encoder_attention_mask=a__       ,     )
              UpperCAmelCase  =						model(
                  a__       ,     attention_mask=a__       ,     token_type_ids=a__       ,     encoder_hidden_states=a__       ,     )
              UpperCAmelCase  =						model(a__       ,     attention_mask=a__       ,     token_type_ids=a__						)
              self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.seq_length, self.hidden_size)						)

       def 			__snake_case      ( self					:				Dict       ,     a__					:				List[str]       ,     a__					:				Tuple       ,     a__					:				List[str]       ,     a__					:				Union[str, Any]       ,     a__					:				Any       ,     a__					:				int       ,     a__					:				List[Any]						):
              UpperCAmelCase  =						MraForMaskedLM(config=a__						)
              model.to(a__						)
              model.eval()
              UpperCAmelCase  =						model(a__       ,     attention_mask=a__       ,     token_type_ids=a__       ,     labels=a__						)
              self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.vocab_size)						)

       def 			__snake_case      ( self					:				List[str]       ,     a__					:				str       ,     a__					:				int       ,     a__					:				List[str]       ,     a__					:				Optional[int]       ,     a__					:				Optional[Any]       ,     a__					:				List[Any]       ,     a__					:				List[str]						):
              UpperCAmelCase  =						MraForQuestionAnswering(config=a__						)
              model.to(a__						)
              model.eval()
              UpperCAmelCase  =						model(
                  a__       ,     attention_mask=a__       ,     token_type_ids=a__       ,     start_positions=a__       ,     end_positions=a__       ,     )
              self.parent.assertEqual(result.start_logits.shape       ,     (self.batch_size, self.seq_length)						)
              self.parent.assertEqual(result.end_logits.shape       ,     (self.batch_size, self.seq_length)						)

       def 			__snake_case      ( self					:				Dict       ,     a__					:				Dict       ,     a__					:				int       ,     a__					:				Optional[int]       ,     a__					:				Dict       ,     a__					:				List[Any]       ,     a__					:				Any       ,     a__					:				Any						):
              UpperCAmelCase  =						self.num_labels
              UpperCAmelCase  =						MraForSequenceClassification(a__						)
              model.to(a__						)
              model.eval()
              UpperCAmelCase  =						model(a__       ,     attention_mask=a__       ,     token_type_ids=a__       ,     labels=a__						)
              self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_labels)						)

       def 			__snake_case      ( self					:				Optional[Any]       ,     a__					:				List[Any]       ,     a__					:				Union[str, Any]       ,     a__					:				Dict       ,     a__					:				Optional[Any]       ,     a__					:				Optional[Any]       ,     a__					:				List[str]       ,     a__					:				Union[str, Any]						):
              UpperCAmelCase  =						self.num_labels
              UpperCAmelCase  =						MraForTokenClassification(config=a__						)
              model.to(a__						)
              model.eval()
              UpperCAmelCase  =						model(a__       ,     attention_mask=a__       ,     token_type_ids=a__       ,     labels=a__						)
              self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.num_labels)						)

       def 			__snake_case      ( self					:				Optional[int]       ,     a__					:				Any       ,     a__					:				int       ,     a__					:				Any       ,     a__					:				int       ,     a__					:				str       ,     a__					:				Any       ,     a__					:				Any						):
              UpperCAmelCase  =						self.num_choices
              UpperCAmelCase  =						MraForMultipleChoice(config=a__						)
              model.to(a__						)
              model.eval()
              UpperCAmelCase  =						input_ids.unsqueeze(1						).expand(-1       ,     self.num_choices       ,     -1						).contiguous()
              UpperCAmelCase  =						token_type_ids.unsqueeze(1						).expand(-1       ,     self.num_choices       ,     -1						).contiguous()
              UpperCAmelCase  =						input_mask.unsqueeze(1						).expand(-1       ,     self.num_choices       ,     -1						).contiguous()
              UpperCAmelCase  =						model(
                  a__       ,     attention_mask=a__       ,     token_type_ids=a__       ,     labels=a__       ,     )
              self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_choices)						)



       def 			__snake_case      ( self					:				Union[str, Any]						):
              UpperCAmelCase  =						self.prepare_config_and_inputs()
              (
                  (
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					(
                  UpperCAmelCase
              ),					
              )  =						config_and_inputs
              UpperCAmelCase  =						{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
              return config, inputs_dict






@require_torch
class     lowerCAmelCase__ (				UpperCAmelCase_      , unittest.TestCase    ):

       '''simple docstring'''
       _lowerCamelCase								=(
           (
               MraModel,
               MraForMaskedLM,
               MraForMultipleChoice,
               MraForQuestionAnswering,
               MraForSequenceClassification,
               MraForTokenClassification,
           )
           if is_torch_available()
           else ()
       )
       _lowerCamelCase								=False
       _lowerCamelCase								=False
       _lowerCamelCase								=False
       _lowerCamelCase								=False

       _lowerCamelCase								=()

       def 			__snake_case      ( self					:				Union[str, Any]						):
              UpperCAmelCase  =						MraModelTester(self						)
              UpperCAmelCase  =						ConfigTester(self       ,     config_class=a__       ,     hidden_size=37						)

       def 			__snake_case      ( self					:				Dict						):
              self.config_tester.run_common_tests()

       def 			__snake_case      ( self					:				Optional[int]						):
              UpperCAmelCase  =						self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_model(*a__						)

       def 			__snake_case      ( self					:				Union[str, Any]						):
              UpperCAmelCase  =						self.model_tester.prepare_config_and_inputs()
              for type in ["absolute", "relative_key", "relative_key_query"]:
                     UpperCAmelCase  =						type
                     self.model_tester.create_and_check_model(*a__						)

       def 			__snake_case      ( self					:				int						):
              UpperCAmelCase  =						self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_masked_lm(*a__						)

       def 			__snake_case      ( self					:				Optional[Any]						):
              UpperCAmelCase  =						self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_multiple_choice(*a__						)

       def 			__snake_case      ( self					:				int						):
              UpperCAmelCase  =						self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_question_answering(*a__						)

       def 			__snake_case      ( self					:				List[str]						):
              UpperCAmelCase  =						self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_sequence_classification(*a__						)

       def 			__snake_case      ( self					:				Union[str, Any]						):
              UpperCAmelCase  =						self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_token_classification(*a__						)

       @slow
       def 			__snake_case      ( self					:				str						):
              for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                     UpperCAmelCase  =						MraModel.from_pretrained(a__						)
                     self.assertIsNotNone(a__						)



       @unittest.skip(reason='''MRA does not output attentions'''						)
       def 			__snake_case      ( self					:				int						):
              return






@require_torch
class     lowerCAmelCase__ (				unittest.TestCase    ):

       '''simple docstring'''

       @slow
       def 			__snake_case      ( self					:				str						):
              UpperCAmelCase  =						MraModel.from_pretrained('''uw-madison/mra-base-512-4'''						)
              UpperCAmelCase  =						torch.arange(256						).unsqueeze(0						)

              with torch.no_grad():
                     UpperCAmelCase  =						model(a__						)[0]

              UpperCAmelCase  =						torch.Size((1, 256, 768)						)
              self.assertEqual(output.shape       ,     a__						)

              UpperCAmelCase  =						torch.tensor(
                  [[[-0.0_140, 0.0_830, -0.0_381], [0.1_546, 0.1_402, 0.0_220], [0.1_162, 0.0_851, 0.0_165]]]						)

              self.assertTrue(torch.allclose(output[:, :3, :3]       ,     a__       ,     atol=1e-4						)						)

       @slow
       def 			__snake_case      ( self					:				Tuple						):
              UpperCAmelCase  =						MraForMaskedLM.from_pretrained('''uw-madison/mra-base-512-4'''						)
              UpperCAmelCase  =						torch.arange(256						).unsqueeze(0						)

              with torch.no_grad():
                     UpperCAmelCase  =						model(a__						)[0]

              UpperCAmelCase  =						50265

              UpperCAmelCase  =						torch.Size((1, 256, vocab_size)						)
              self.assertEqual(output.shape       ,     a__						)

              UpperCAmelCase  =						torch.tensor(
                  [[[9.2_595, -3.6_038, 11.8_819], [9.3_869, -3.2_693, 11.0_956], [11.8_524, -3.4_938, 13.1_210]]]						)

              self.assertTrue(torch.allclose(output[:, :3, :3]       ,     a__       ,     atol=1e-4						)						)



       @slow
       def 			__snake_case      ( self					:				Any						):
              UpperCAmelCase  =						MraForMaskedLM.from_pretrained('''uw-madison/mra-base-4096-8-d3'''						)
              UpperCAmelCase  =						torch.arange(4096						).unsqueeze(0						)

              with torch.no_grad():
                     UpperCAmelCase  =						model(a__						)[0]

              UpperCAmelCase  =						50265

              UpperCAmelCase  =						torch.Size((1, 4096, vocab_size)						)
              self.assertEqual(output.shape       ,     a__						)

              UpperCAmelCase  =						torch.tensor(
                  [[[5.4_789, -2.3_564, 7.5_064], [7.9_067, -1.3_369, 9.9_668], [9.0_712, -1.8_106, 7.0_380]]]						)

              self.assertTrue(torch.allclose(output[:, :3, :3]       ,     a__       ,     atol=1e-4						)						)




from typing import List

import datasets
from datasets.tasks import AudioClassification

from ..folder_based_builder import folder_based_builder


_A  =	datasets.utils.logging.get_logger(__name__)





class       _lowerCAmelCase   (      folder_based_builder.FolderBasedBuilderConfig			):
				_lowercase     						=None
				_lowercase     						=None





class       _lowerCAmelCase   (      folder_based_builder.FolderBasedBuilder			):
				_lowercase     						=datasets.Audio()
				_lowercase     						='''audio'''
				_lowercase     						=AudioFolderConfig
				_lowercase     						=42  # definition at the bottom of the script
				_lowercase     						=AudioClassification(audio_column='''audio'''   , label_column='''label'''			)


_A  =	[
    ".aiff",
    ".au",
    ".avr",
    ".caf",
    ".flac",
    ".htk",
    ".svx",
    ".mat4",
    ".mat5",
    ".mpc2k",
    ".ogg",
    ".paf",
    ".pvf",
    ".raw",
    ".rf64",
    ".sd2",
    ".sds",
    ".ircam",
    ".voc",
    ".w64",
    ".wav",
    ".nist",
    ".wavex",
    ".wve",
    ".xi",
    ".mp3",
    ".opus",
]
_A  =	AUDIO_EXTENSIONS



