





'''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						)						)









'''simple docstring'''






import itertools
import random
import unittest

import numpy as np

from transformers import WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST, WavaVecaConfig, WavaVecaFeatureExtractor
from transformers.testing_utils import require_torch, slow

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


lowerCAmelCase									=   random.Random()






def   __A    (				a_    :	Union[str, Any]   ,a_    :	Tuple=1.0   ,a_    :	Optional[int]=None   ,a_    :	Union[str, Any]=None						):
		if rng is None:
				lowerCAmelCase  :     str       						= global_rng

		lowerCAmelCase  :     Any       						= []
		for batch_idx in range(shape[0]						):
				values.append([]						)
				for _ in range(shape[1]						):
						values[-1].append(rng.random() * scale						)

		return values
class 		lowerCamelCase	(   unittest.TestCase							):



	def __init__( self		,   a_		,   a_=7		,   a_=400		,   a_=2_000		,   a_=1		,   a_=0.0		,   a_=16_000		,   a_=True		,   a_=True		,   ):
			lowerCAmelCase  :     Dict       						= parent
			lowerCAmelCase  :     Optional[int]       						= batch_size
			lowerCAmelCase  :     Dict       						= min_seq_length
			lowerCAmelCase  :     Dict       						= max_seq_length
			lowerCAmelCase  :     Optional[Any]       						= (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
			lowerCAmelCase  :     Union[str, Any]       						= feature_size
			lowerCAmelCase  :     Tuple       						= padding_value
			lowerCAmelCase  :     Dict       						= sampling_rate
			lowerCAmelCase  :     int       						= return_attention_mask
			lowerCAmelCase  :     Optional[Any]       						= do_normalize



	def 	_lowerCamelCase     ( self						):
			return {
			    "feature_size": self.feature_size,
			    "padding_value": self.padding_value,
			    "sampling_rate": self.sampling_rate,
			    "return_attention_mask": self.return_attention_mask,
			    "do_normalize": self.do_normalize,
			}





	def 	_lowerCamelCase     ( self		,   a_=False		,   a_=False						):
			def _flatten(a_						):
					return list(itertools.chain(*a_						)						)

			if equal_length:
					lowerCAmelCase  :     List[Any]       						= floats_list((self.batch_size, self.max_seq_length)						)
			else:
					# make sure that inputs increase in size
					lowerCAmelCase  :     Any       						= [
					    _flatten(floats_list((x, self.feature_size)						)						)
					    for x in range(self.min_seq_length		,   self.max_seq_length		,   self.seq_length_diff						)
					]

			if numpify:
					lowerCAmelCase  :     List[str]       						= [np.asarray(a_						) for x in speech_inputs]

			return speech_inputs






class 		lowerCamelCase	(   _A   , unittest.TestCase							):
	snake_case_   = WavaVecaFeatureExtractor



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     Tuple       						= WavaVecaFeatureExtractionTester(self						)



	def 	_lowerCamelCase     ( self		,   a_						):
			self.assertTrue(np.all(np.mean(a_		,   axis=0						) < 1e-3						)						)
			self.assertTrue(np.all(np.abs(np.var(a_		,   axis=0						) - 1						) < 1e-3						)						)



	def 	_lowerCamelCase     ( self						):
			# Tests that all call wrap to encode_plus and batch_encode_plus
			lowerCAmelCase  :     int       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			# create three inputs of length 800, 1000, and 1200
			lowerCAmelCase  :     str       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]
			lowerCAmelCase  :     Dict       						= [np.asarray(a_						) for speech_input in speech_inputs]

			# Test not batched input
			lowerCAmelCase  :     Optional[int]       						= feat_extract(speech_inputs[0]		,   return_tensors="np"						).input_values
			lowerCAmelCase  :     Any       						= feat_extract(np_speech_inputs[0]		,   return_tensors="np"						).input_values
			self.assertTrue(np.allclose(a_		,   a_		,   atol=1e-3						)						)

			# Test batched
			lowerCAmelCase  :     Any       						= feat_extract(a_		,   return_tensors="np"						).input_values
			lowerCAmelCase  :     int       						= feat_extract(a_		,   return_tensors="np"						).input_values
			for enc_seq_a, enc_seq_a in zip(a_		,   a_						):
					self.assertTrue(np.allclose(a_		,   a_		,   atol=1e-3						)						)

			# Test 2-D numpy arrays are batched.
			lowerCAmelCase  :     Dict       						= [floats_list((1, x)						)[0] for x in (800, 800, 800)]
			lowerCAmelCase  :     Tuple       						= np.asarray(a_						)
			lowerCAmelCase  :     int       						= feat_extract(a_		,   return_tensors="np"						).input_values
			lowerCAmelCase  :     Union[str, Any]       						= feat_extract(a_		,   return_tensors="np"						).input_values
			for enc_seq_a, enc_seq_a in zip(a_		,   a_						):
					self.assertTrue(np.allclose(a_		,   a_		,   atol=1e-3						)						)



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     int       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     Any       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]

			lowerCAmelCase  :     Union[str, Any]       						= ["longest", "max_length", "do_not_pad"]
			lowerCAmelCase  :     Optional[int]       						= [None, 1_600, None]
			for max_length, padding in zip(a_		,   a_						):
					lowerCAmelCase  :     List[Any]       						= feat_extract(a_		,   padding=a_		,   max_length=a_		,   return_tensors="np"						)
					lowerCAmelCase  :     Any       						= processed.input_values

					self._check_zero_mean_unit_variance(input_values[0][:800]						)
					self.assertTrue(input_values[0][800:].sum() < 1e-6						)
					self._check_zero_mean_unit_variance(input_values[1][:1_000]						)
					self.assertTrue(input_values[0][1_000:].sum() < 1e-6						)
					self._check_zero_mean_unit_variance(input_values[2][:1_200]						)



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     List[Any]       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     Optional[int]       						= range(800		,   1_400		,   200						)
			lowerCAmelCase  :     Tuple       						= [floats_list((1, x)						)[0] for x in lengths]

			lowerCAmelCase  :     str       						= ["longest", "max_length", "do_not_pad"]
			lowerCAmelCase  :     Any       						= [None, 1_600, None]

			for max_length, padding in zip(a_		,   a_						):
					lowerCAmelCase  :     Dict       						= feat_extract(a_		,   max_length=a_		,   padding=a_						)
					lowerCAmelCase  :     int       						= processed.input_values

					self._check_zero_mean_unit_variance(input_values[0][:800]						)
					self._check_zero_mean_unit_variance(input_values[1][:1_000]						)
					self._check_zero_mean_unit_variance(input_values[2][:1_200]						)



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     List[Any]       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     Tuple       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]
			lowerCAmelCase  :     Dict       						= feat_extract(
			    a_		,   truncation=a_		,   max_length=1_000		,   padding="max_length"		,   return_tensors="np"						)
			lowerCAmelCase  :     Union[str, Any]       						= processed.input_values

			self._check_zero_mean_unit_variance(input_values[0, :800]						)
			self._check_zero_mean_unit_variance(input_values[1]						)
			self._check_zero_mean_unit_variance(input_values[2]						)



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     Optional[int]       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     Tuple       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]
			lowerCAmelCase  :     Union[str, Any]       						= feat_extract(
			    a_		,   truncation=a_		,   max_length=1_000		,   padding="longest"		,   return_tensors="np"						)
			lowerCAmelCase  :     Dict       						= processed.input_values

			self._check_zero_mean_unit_variance(input_values[0, :800]						)
			self._check_zero_mean_unit_variance(input_values[1, :1_000]						)
			self._check_zero_mean_unit_variance(input_values[2]						)

			# make sure that if max_length < longest -> then pad to max_length
			self.assertTrue(input_values.shape == (3, 1_000)						)

			lowerCAmelCase  :     List[str]       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]
			lowerCAmelCase  :     Union[str, Any]       						= feat_extract(
			    a_		,   truncation=a_		,   max_length=2_000		,   padding="longest"		,   return_tensors="np"						)
			lowerCAmelCase  :     Optional[Any]       						= processed.input_values

			self._check_zero_mean_unit_variance(input_values[0, :800]						)
			self._check_zero_mean_unit_variance(input_values[1, :1_000]						)
			self._check_zero_mean_unit_variance(input_values[2]						)

			# make sure that if max_length > longest -> then pad to longest
			self.assertTrue(input_values.shape == (3, 1_200)						)



	@require_torch
	def 	_lowerCamelCase     ( self						):
			import torch

			lowerCAmelCase  :     Optional[int]       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     List[Any]       						= np.random.rand(100						).astype(np.floataa						)
			lowerCAmelCase  :     List[Any]       						= np_speech_inputs.tolist()

			for inputs in [py_speech_inputs, np_speech_inputs]:
					lowerCAmelCase  :     Union[str, Any]       						= feature_extractor.pad([{"input_values": inputs}]		,   return_tensors="np"						)
					self.assertTrue(np_processed.input_values.dtype == np.floataa						)
					lowerCAmelCase  :     Tuple       						= feature_extractor.pad([{"input_values": inputs}]		,   return_tensors="pt"						)
					self.assertTrue(pt_processed.input_values.dtype == torch.floataa						)





	@slow
	@require_torch
	def 	_lowerCamelCase     ( self						):
			# this test makes sure that models that are using
			# group norm don't have their feature extractor return the
			# attention_mask
			for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
					lowerCAmelCase  :     Any       						= WavaVecaConfig.from_pretrained(a_						)
					lowerCAmelCase  :     List[str]       						= WavaVecaFeatureExtractor.from_pretrained(a_						)

					# only "layer" feature extraction norm should make use of
					# attention_mask
					self.assertEqual(feat_extract.return_attention_mask		,   config.feat_extract_norm == "layer"						)



