

import unittest

from transformers import ElectraConfig, is_torch_available
from transformers.models.auto import get_values
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
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     MODEL_FOR_PRETRAINING_MAPPING,
     ElectraForCausalLM,
     ElectraForMaskedLM,
     ElectraForMultipleChoice,
     ElectraForPreTraining,
     ElectraForQuestionAnswering,
     ElectraForSequenceClassification,
     ElectraForTokenClassification,
     ElectraModel,
 )
 from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST




class  snake_case__						:






     """simple docstring"""


     def __init__(	self  :  Union[str, Any],			_snake_case  :  int,			_snake_case  :  Dict=1_3,			_snake_case  :  Union[str, Any]=7,			_snake_case  :  int=True,			_snake_case  :  Union[str, Any]=True,			_snake_case  :  Optional[int]=True,			_snake_case  :  Optional[int]=True,			_snake_case  :  List[Any]=9_9,			_snake_case  :  Optional[int]=3_2,			_snake_case  :  Tuple=5,			_snake_case  :  str=4,			_snake_case  :  str=3_7,			_snake_case  :  Dict="gelu",			_snake_case  :  int=0.1,			_snake_case  :  Tuple=0.1,			_snake_case  :  str=5_1_2,			_snake_case  :  Union[str, Any]=1_6,			_snake_case  :  Any=2,			_snake_case  :  Dict=0.0_2,			_snake_case  :  Optional[int]=3,			_snake_case  :  Dict=4,			_snake_case  :  List[str]=None,			)       ->List[str]:
            snake_case__							:     Dict            =     parent
            snake_case__							:     List[str]            =     batch_size
            snake_case__							:     Dict            =     seq_length
            snake_case__							:     List[str]            =     is_training
            snake_case__							:     List[Any]            =     use_input_mask
            snake_case__							:     Optional[Any]            =     use_token_type_ids
            snake_case__							:     Optional[int]            =     use_labels
            snake_case__							:     List[str]            =     vocab_size
            snake_case__							:     Any            =     hidden_size
            snake_case__							:     List[Any]            =     num_hidden_layers
            snake_case__							:     Any            =     num_attention_heads
            snake_case__							:     Dict            =     intermediate_size
            snake_case__							:     Optional[Any]            =     hidden_act
            snake_case__							:     Optional[int]            =     hidden_dropout_prob
            snake_case__							:     List[Any]            =     attention_probs_dropout_prob
            snake_case__							:     Optional[Any]            =     max_position_embeddings
            snake_case__							:     Optional[Any]            =     type_vocab_size
            snake_case__							:     List[Any]            =     type_sequence_label_size
            snake_case__							:     Tuple            =     initializer_range
            snake_case__							:     List[str]            =     num_labels
            snake_case__							:     Optional[Any]            =     num_choices
            snake_case__							:     List[str]            =     scope






     def        lowercase_       (	self  :  str )       ->str:
            snake_case__							:     List[str]            =     ids_tensor([self.batch_size, self.seq_length],			self.vocab_size )

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

            snake_case__							:     List[Any]            =     None
            if self.use_token_type_ids:
                   snake_case__							:     Optional[Any]            =     ids_tensor([self.batch_size, self.seq_length],			self.type_vocab_size )

            snake_case__							:     str            =     None
            snake_case__							:     Optional[int]            =     None
            snake_case__							:     Tuple            =     None
            if self.use_labels:
                   snake_case__							:     Optional[int]            =     ids_tensor([self.batch_size],			self.type_sequence_label_size )
                   snake_case__							:     List[Any]            =     ids_tensor([self.batch_size, self.seq_length],			self.num_labels )
                   snake_case__							:     str            =     ids_tensor([self.batch_size],			self.num_choices )
                   snake_case__							:     Tuple            =     ids_tensor([self.batch_size, self.seq_length],			1 )

            snake_case__							:     Any            =     self.get_config()

            return (
                config,
                input_ids,
                token_type_ids,
                input_mask,
                sequence_labels,
                token_labels,
                choice_labels,
                fake_token_labels,
            )






     def        lowercase_       (	self  :  str )       ->int:
            return ElectraConfig(
                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=snake_case_,			initializer_range=self.initializer_range,			)






     def        lowercase_       (	self  :  List[Any] )       ->str:
            (
                snake_case__   
            )							:     int            =     self.prepare_config_and_inputs()

            snake_case__							:     str            =     True
            snake_case__							:     List[str]            =     floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
            snake_case__							:     Optional[Any]            =     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        lowercase_       (	self  :  Tuple,			_snake_case  :  Any,			_snake_case  :  List[str],			_snake_case  :  Union[str, Any],			_snake_case  :  Any,			_snake_case  :  Tuple,			_snake_case  :  str,			_snake_case  :  List[Any],			_snake_case  :  Optional[int],			)       ->Any:
            snake_case__							:     List[Any]            =     ElectraModel(config=snake_case_ )
            model.to(snake_case_ )
            model.eval()
            snake_case__							:     List[Any]            =     model(snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_ )
            snake_case__							:     Optional[int]            =     model(snake_case_,			token_type_ids=snake_case_ )
            snake_case__							:     List[str]            =     model(snake_case_ )
            self.parent.assertEqual(result.last_hidden_state.shape,			(self.batch_size, self.seq_length, self.hidden_size) )






     def        lowercase_       (	self  :  Optional[int],			_snake_case  :  List[str],			_snake_case  :  Dict,			_snake_case  :  Union[str, Any],			_snake_case  :  str,			_snake_case  :  Any,			_snake_case  :  str,			_snake_case  :  Tuple,			_snake_case  :  Dict,			_snake_case  :  Any,			)       ->List[Any]:
            snake_case__							:     Optional[int]            =     True
            snake_case__							:     List[str]            =     ElectraModel(snake_case_ )
            model.to(snake_case_ )
            model.eval()
            snake_case__							:     Tuple            =     model(
                snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_,			encoder_hidden_states=snake_case_,			encoder_attention_mask=snake_case_,			)
            snake_case__							:     Dict            =     model(
                snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_,			encoder_hidden_states=snake_case_,			)
            snake_case__							:     Any            =     model(snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_ )
            self.parent.assertEqual(result.last_hidden_state.shape,			(self.batch_size, self.seq_length, self.hidden_size) )






     def        lowercase_       (	self  :  Union[str, Any],			_snake_case  :  Optional[int],			_snake_case  :  List[str],			_snake_case  :  Optional[int],			_snake_case  :  Union[str, Any],			_snake_case  :  str,			_snake_case  :  List[Any],			_snake_case  :  Any,			_snake_case  :  Union[str, Any],			)       ->int:
            snake_case__							:     Tuple            =     ElectraForMaskedLM(config=snake_case_ )
            model.to(snake_case_ )
            model.eval()
            snake_case__							:     Optional[int]            =     model(snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_,			labels=snake_case_ )
            self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.seq_length, self.vocab_size) )






     def        lowercase_       (	self  :  Optional[Any],			_snake_case  :  Union[str, Any],			_snake_case  :  Tuple,			_snake_case  :  List[str],			_snake_case  :  int,			_snake_case  :  Union[str, Any],			_snake_case  :  str,			_snake_case  :  Optional[int],			_snake_case  :  Dict,			_snake_case  :  str,			)       ->str:
            snake_case__							:     Union[str, Any]            =     ElectraForCausalLM(config=snake_case_ )
            model.to(snake_case_ )
            model.eval()
            snake_case__							:     Any            =     model(snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_,			labels=snake_case_ )
            self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.seq_length, self.vocab_size) )






     def        lowercase_       (	self  :  Optional[Any],			_snake_case  :  Optional[int],			_snake_case  :  Any,			_snake_case  :  Union[str, Any],			_snake_case  :  int,			_snake_case  :  int,			_snake_case  :  Any,			_snake_case  :  Optional[int],			_snake_case  :  Optional[Any],			)       ->Any:
            snake_case__							:     Dict            =     self.num_labels
            snake_case__							:     int            =     ElectraForTokenClassification(config=snake_case_ )
            model.to(snake_case_ )
            model.eval()
            snake_case__							:     Optional[Any]            =     model(snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_,			labels=snake_case_ )
            self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.seq_length, self.num_labels) )






     def        lowercase_       (	self  :  Tuple,			_snake_case  :  Tuple,			_snake_case  :  str,			_snake_case  :  Any,			_snake_case  :  Optional[Any],			_snake_case  :  Union[str, Any],			_snake_case  :  Optional[Any],			_snake_case  :  Union[str, Any],			_snake_case  :  Any,			)       ->List[str]:
            snake_case__							:     Tuple            =     self.num_labels
            snake_case__							:     Optional[int]            =     ElectraForPreTraining(config=snake_case_ )
            model.to(snake_case_ )
            model.eval()
            snake_case__							:     str            =     model(snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_,			labels=snake_case_ )
            self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.seq_length) )






     def        lowercase_       (	self  :  Union[str, Any],			_snake_case  :  str,			_snake_case  :  List[Any],			_snake_case  :  Optional[int],			_snake_case  :  str,			_snake_case  :  Optional[int],			_snake_case  :  Any,			_snake_case  :  str,			_snake_case  :  List[str],			)       ->List[str]:
            snake_case__							:     List[str]            =     self.num_labels
            snake_case__							:     Union[str, Any]            =     ElectraForSequenceClassification(snake_case_ )
            model.to(snake_case_ )
            model.eval()
            snake_case__							:     Dict            =     model(snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_,			labels=snake_case_ )
            self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.num_labels) )






     def        lowercase_       (	self  :  Any,			_snake_case  :  Dict,			_snake_case  :  List[str],			_snake_case  :  Union[str, Any],			_snake_case  :  str,			_snake_case  :  Tuple,			_snake_case  :  str,			_snake_case  :  str,			_snake_case  :  Optional[int],			)       ->Optional[int]:
            snake_case__							:     List[str]            =     ElectraForQuestionAnswering(config=snake_case_ )
            model.to(snake_case_ )
            model.eval()
            snake_case__							:     Any            =     model(
                snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_,			start_positions=snake_case_,			end_positions=snake_case_,			)
            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        lowercase_       (	self  :  Union[str, Any],			_snake_case  :  Tuple,			_snake_case  :  Union[str, Any],			_snake_case  :  Any,			_snake_case  :  int,			_snake_case  :  int,			_snake_case  :  Tuple,			_snake_case  :  str,			_snake_case  :  Tuple,			)       ->Optional[Any]:
            snake_case__							:     Optional[Any]            =     self.num_choices
            snake_case__							:     List[Any]            =     ElectraForMultipleChoice(config=snake_case_ )
            model.to(snake_case_ )
            model.eval()
            snake_case__							:     Optional[int]            =     input_ids.unsqueeze(1 ).expand(-1,			self.num_choices,			-1 ).contiguous()
            snake_case__							:     Any            =     token_type_ids.unsqueeze(1 ).expand(-1,			self.num_choices,			-1 ).contiguous()
            snake_case__							:     Optional[Any]            =     input_mask.unsqueeze(1 ).expand(-1,			self.num_choices,			-1 ).contiguous()
            snake_case__							:     Dict            =     model(
                snake_case_,			attention_mask=snake_case_,			token_type_ids=snake_case_,			labels=snake_case_,			)
            self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.num_choices) )






     def        lowercase_       (	self  :  Optional[Any] )       ->Dict:
            snake_case__							:     str            =     self.prepare_config_and_inputs()
            (
                snake_case__   
            )							:     Dict            =     config_and_inputs
            snake_case__							:     Dict            =     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
            return config, inputs_dict




@require_torch
class  snake_case__						(	_a    ,					_a    ,					unittest.TestCase					):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE            =     (
         (
             ElectraModel,
             ElectraForPreTraining,
             ElectraForMaskedLM,
             ElectraForCausalLM,
             ElectraForMultipleChoice,
             ElectraForTokenClassification,
             ElectraForSequenceClassification,
             ElectraForQuestionAnswering,
         )
         if is_torch_available()
         else ()
     )
     _SCREAMING_SNAKE_CASE            =     (
         {
             """feature-extraction""": ElectraModel,
             """fill-mask""": ElectraForMaskedLM,
             """question-answering""": ElectraForQuestionAnswering,
             """text-classification""": ElectraForSequenceClassification,
             """text-generation""": ElectraForCausalLM,
             """token-classification""": ElectraForTokenClassification,
             """zero-shot""": ElectraForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     _SCREAMING_SNAKE_CASE            =     True






     def        lowercase_       (	self  :  Optional[Any],			_snake_case  :  Any,			_snake_case  :  str,			_snake_case  :  Optional[Any]=False )       ->Tuple:
            snake_case__							:     Tuple            =     super()._prepare_for_class(snake_case_,			snake_case_,			return_labels=snake_case_ )

            if return_labels:
                   if model_class in get_values(snake_case_ ):
                          snake_case__							:     List[Any]            =     torch.zeros(
                              (self.model_tester.batch_size, self.model_tester.seq_length),			dtype=torch.long,			device=snake_case_ )
            return inputs_dict






     def        lowercase_       (	self  :  List[Any] )       ->Optional[Any]:
            snake_case__							:     Tuple            =     ElectraModelTester(self )
            snake_case__							:     List[str]            =     ConfigTester(self,			config_class=snake_case_,			hidden_size=3_7 )






     def        lowercase_       (	self  :  Tuple )       ->Dict:
            self.config_tester.run_common_tests()






     def        lowercase_       (	self  :  Union[str, Any] )       ->Union[str, Any]:
            snake_case__							:     Dict            =     self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_electra_model(*snake_case_ )






     def        lowercase_       (	self  :  List[Any] )       ->List[str]:
            snake_case__							:     List[Any]            =     self.model_tester.prepare_config_and_inputs_for_decoder()
            self.model_tester.create_and_check_electra_model_as_decoder(*snake_case_ )






     def        lowercase_       (	self  :  Dict )       ->Tuple:
            snake_case__							:     Dict            =     self.model_tester.prepare_config_and_inputs()
            for type in ["absolute", "relative_key", "relative_key_query"]:
                   snake_case__							:     str            =     type
                   self.model_tester.create_and_check_electra_model(*snake_case_ )






     def        lowercase_       (	self  :  Tuple )       ->str:
            snake_case__							:     Union[str, Any]            =     self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_electra_for_masked_lm(*snake_case_ )






     def        lowercase_       (	self  :  str )       ->List[str]:
            snake_case__							:     Dict            =     self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_electra_for_token_classification(*snake_case_ )






     def        lowercase_       (	self  :  List[str] )       ->Any:
            snake_case__							:     List[str]            =     self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_electra_for_pretraining(*snake_case_ )






     def        lowercase_       (	self  :  List[str] )       ->int:
            snake_case__							:     int            =     self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_electra_for_sequence_classification(*snake_case_ )






     def        lowercase_       (	self  :  List[Any] )       ->Any:
            snake_case__							:     Optional[Any]            =     self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_electra_for_question_answering(*snake_case_ )






     def        lowercase_       (	self  :  Optional[int] )       ->Tuple:
            snake_case__							:     List[Any]            =     self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_electra_for_multiple_choice(*snake_case_ )






     @slow
     def        lowercase_       (	self  :  Dict )       ->str:
            for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   snake_case__							:     str            =     ElectraModel.from_pretrained(snake_case_ )
                   self.assertIsNotNone(snake_case_ )






     def        lowercase_       (	self  :  str )       ->List[str]:
            snake_case__							:     Any            =     self.model_tester.prepare_config_and_inputs_for_decoder()
            self.model_tester.create_and_check_electra_for_causal_lm(*snake_case_ )




@require_torch
class  snake_case__						(	unittest.TestCase					):






     """simple docstring"""


     @slow
     def        lowercase_       (	self  :  Dict )       ->int:
            snake_case__							:     List[Any]            =     ElectraModel.from_pretrained('google/electra-small-discriminator' )
            snake_case__							:     Union[str, Any]            =     torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]] )
            snake_case__							:     Dict            =     torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
            snake_case__							:     Optional[Any]            =     model(snake_case_,			attention_mask=snake_case_ )[0]
            snake_case__							:     List[str]            =     torch.Size((1, 1_1, 2_5_6) )
            self.assertEqual(output.shape,			snake_case_ )
            snake_case__							:     Optional[int]            =     torch.tensor(
                [[[0.4_4_7_1, 0.6_8_2_1, -0.3_2_6_5], [0.4_6_2_7, 0.5_2_5_5, -0.3_6_6_8], [0.4_5_3_2, 0.3_3_1_3, -0.4_3_4_4]]] )

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











import shutil
import tempfile
import unittest

import pytest

from transformers import WhisperTokenizer, is_speech_available
from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio

from .test_feature_extraction_whisper import floats_list


if is_speech_available():
 from transformers import WhisperFeatureExtractor, WhisperProcessor


a_       :List[Any]				  =				50_358
a_       :int				  =				50_362




@require_torch
@require_torchaudio
@require_sentencepiece
class  snake_case__						(	unittest.TestCase					):






     """simple docstring"""


     def        lowercase_       (	self  :  Dict )       ->List[Any]:
            snake_case__							:     int            =     'openai/whisper-small.en'
            snake_case__							:     List[Any]            =     tempfile.mkdtemp()






     def        lowercase_       (	self  :  Any,			**_snake_case  :  List[str] )       ->Union[str, Any]:
            return WhisperTokenizer.from_pretrained(self.checkpoint,			**_snake_case )






     def        lowercase_       (	self  :  Union[str, Any],			**_snake_case  :  int )       ->Optional[int]:
            return WhisperFeatureExtractor.from_pretrained(self.checkpoint,			**_snake_case )






     def        lowercase_       (	self  :  Any )       ->Union[str, Any]:
            shutil.rmtree(self.tmpdirname )






     def        lowercase_       (	self  :  Dict )       ->Tuple:
            snake_case__							:     Dict            =     self.get_tokenizer()
            snake_case__							:     List[str]            =     self.get_feature_extractor()

            snake_case__							:     List[Any]            =     WhisperProcessor(tokenizer=_snake_case,			feature_extractor=_snake_case )

            processor.save_pretrained(self.tmpdirname )
            snake_case__							:     Dict            =     WhisperProcessor.from_pretrained(self.tmpdirname )

            self.assertEqual(processor.tokenizer.get_vocab(),			tokenizer.get_vocab() )
            self.assertIsInstance(processor.tokenizer,			_snake_case )

            self.assertEqual(processor.feature_extractor.to_json_string(),			feature_extractor.to_json_string() )
            self.assertIsInstance(processor.feature_extractor,			_snake_case )






     def        lowercase_       (	self  :  List[Any] )       ->str:
            snake_case__							:     str            =     WhisperProcessor(tokenizer=self.get_tokenizer(),			feature_extractor=self.get_feature_extractor() )
            processor.save_pretrained(self.tmpdirname )

            snake_case__							:     Dict            =     self.get_tokenizer(bos_token='(BOS)',			eos_token='(EOS)' )
            snake_case__							:     List[str]            =     self.get_feature_extractor(do_normalize=_snake_case,			padding_value=1.0 )

            snake_case__							:     List[Any]            =     WhisperProcessor.from_pretrained(
                self.tmpdirname,			bos_token='(BOS)',			eos_token='(EOS)',			do_normalize=_snake_case,			padding_value=1.0 )

            self.assertEqual(processor.tokenizer.get_vocab(),			tokenizer_add_kwargs.get_vocab() )
            self.assertIsInstance(processor.tokenizer,			_snake_case )

            self.assertEqual(processor.feature_extractor.to_json_string(),			feature_extractor_add_kwargs.to_json_string() )
            self.assertIsInstance(processor.feature_extractor,			_snake_case )






     def        lowercase_       (	self  :  Union[str, Any] )       ->Dict:
            snake_case__							:     Dict            =     self.get_feature_extractor()
            snake_case__							:     Dict            =     self.get_tokenizer()

            snake_case__							:     List[Any]            =     WhisperProcessor(tokenizer=_snake_case,			feature_extractor=_snake_case )

            snake_case__							:     int            =     floats_list((3, 1_0_0_0) )

            snake_case__							:     Optional[int]            =     feature_extractor(_snake_case,			return_tensors='np' )
            snake_case__							:     Optional[int]            =     processor(_snake_case,			return_tensors='np' )

            for key in input_feat_extract.keys():
                   self.assertAlmostEqual(input_feat_extract[key].sum(),			input_processor[key].sum(),			delta=1e-2 )






     def        lowercase_       (	self  :  Dict )       ->Any:
            snake_case__							:     Tuple            =     self.get_feature_extractor()
            snake_case__							:     Optional[int]            =     self.get_tokenizer()

            snake_case__							:     Optional[int]            =     WhisperProcessor(tokenizer=_snake_case,			feature_extractor=_snake_case )

            snake_case__							:     Any            =     'This is a test string'

            snake_case__							:     Dict            =     processor(text=_snake_case )

            snake_case__							:     List[str]            =     tokenizer(_snake_case )

            for key in encoded_tok.keys():
                   self.assertListEqual(encoded_tok[key],			encoded_processor[key] )






     def        lowercase_       (	self  :  Dict )       ->Dict:
            snake_case__							:     Optional[Any]            =     self.get_feature_extractor()
            snake_case__							:     Optional[int]            =     self.get_tokenizer()

            snake_case__							:     Optional[int]            =     WhisperProcessor(tokenizer=_snake_case,			feature_extractor=_snake_case )

            snake_case__							:     Union[str, Any]            =     [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

            snake_case__							:     List[str]            =     processor.batch_decode(_snake_case )
            snake_case__							:     Dict            =     tokenizer.batch_decode(_snake_case )

            self.assertListEqual(_snake_case,			_snake_case )






     def        lowercase_       (	self  :  Union[str, Any] )       ->Optional[Any]:
            snake_case__							:     str            =     self.get_feature_extractor()
            snake_case__							:     Dict            =     self.get_tokenizer()

            snake_case__							:     Any            =     WhisperProcessor(tokenizer=_snake_case,			feature_extractor=_snake_case )

            self.assertListEqual(
                processor.model_input_names,			feature_extractor.model_input_names,			msg='`processor` and `feature_extractor` model input names do not match',			)






     def        lowercase_       (	self  :  int )       ->Dict:
            snake_case__							:     Tuple            =     self.get_feature_extractor()
            snake_case__							:     Tuple            =     self.get_tokenizer()

            snake_case__							:     Optional[int]            =     WhisperProcessor(tokenizer=_snake_case,			feature_extractor=_snake_case )
            snake_case__							:     Any            =     processor.get_decoder_prompt_ids(task='transcribe',			no_timestamps=_snake_case )

            self.assertIsInstance(_snake_case,			_snake_case )
            for ids in forced_decoder_ids:
                   self.assertIsInstance(_snake_case,			(list, tuple) )

            snake_case__							:     List[str]            =     [TRANSCRIBE, NOTIMESTAMPS]
            self.assertListEqual([ids[-1] for ids in forced_decoder_ids],			_snake_case )






     def        lowercase_       (	self  :  Optional[int] )       ->int:
            snake_case__							:     List[Any]            =     WhisperProcessor(tokenizer=self.get_tokenizer(),			feature_extractor=self.get_feature_extractor() )
            snake_case__							:     Optional[Any]            =     processor.get_prompt_ids('Mr. Quilter' )
            snake_case__							:     List[Any]            =     processor.tokenizer.decode(_snake_case )

            self.assertListEqual(prompt_ids.tolist(),			[5_0_3_6_0, 1_7_7_0, 1_3, 2_2_6_4, 3_4_6, 3_5_3] )
            self.assertEqual(_snake_case,			'<|startofprev|> Mr. Quilter' )






     def        lowercase_       (	self  :  Tuple )       ->Tuple:
            snake_case__							:     int            =     WhisperProcessor(tokenizer=self.get_tokenizer(),			feature_extractor=self.get_feature_extractor() )
            snake_case__							:     List[str]            =     processor.get_prompt_ids('' )
            snake_case__							:     List[Any]            =     processor.tokenizer.decode(_snake_case )

            self.assertListEqual(prompt_ids.tolist(),			[5_0_3_6_0, 2_2_0] )
            self.assertEqual(_snake_case,			'<|startofprev|> ' )






     def        lowercase_       (	self  :  Tuple )       ->str:
            snake_case__							:     Any            =     WhisperProcessor(tokenizer=self.get_tokenizer(),			feature_extractor=self.get_feature_extractor() )

            def _test_prompt_error_raised_helper(_snake_case  :  str,			_snake_case  :  int ):
                   with pytest.raises(_snake_case ) as excinfo:
                          processor.get_prompt_ids(_snake_case )
                   snake_case__							:     Dict            =     F'''Encountered text in the prompt corresponding to disallowed special token: {special_token}.'''
                   self.assertEqual(_snake_case,			str(excinfo.value ) )

            _test_prompt_error_raised_helper('<|startofprev|> test',			'<|startofprev|>' )
            _test_prompt_error_raised_helper('test <|notimestamps|>',			'<|notimestamps|>' )
            _test_prompt_error_raised_helper('test <|zh|> test <|transcribe|>',			'<|zh|>' )






