
'''simple docstring'''
import unittest

import numpy as np
import timeout_decorator  # noqa

from transformers import OPTConfig, is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, slow

from ...generation.test_flax_utils import FlaxGenerationTesterMixin
from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor


if is_flax_available():
						import os

						# The slow tests are often failing with OOM error on GPU
						# This makes JAX allocate exactly what is needed on demand, and deallocate memory that is no longer needed
						# but will be slower as stated here https://jax.readthedocs.io/en/latest/gpu_memory_allocation.html
						lowercase__		    =	"platform"

						import jax
						import jax.numpy as jnp

						from transformers import FlaxOPTForCausalLM, FlaxOPTModel, GPTaTokenizer




def 					_UpperCamelCase		(    SCREAMING_SNAKE_CASE__      ,    SCREAMING_SNAKE_CASE__      ,    SCREAMING_SNAKE_CASE__=None      ,    SCREAMING_SNAKE_CASE__=None       )   ->				Union[str, Any]:


		'''simple docstring'''


		if attention_mask is None:
				snake_case   :    Union[str, Any]			       =		np.where(input_ids != config.pad_token_id      ,    1      ,    0       )
		return {
		    "input_ids": input_ids,
		    "attention_mask": attention_mask,
		}






@require_flax
class      snake_case__    :







		"""simple docstring"""

		def __init__(	self							:       Optional[Any]   ,     UpperCamelCase__							:       Dict   ,     UpperCamelCase__							:       List[Any]=13   ,     UpperCamelCase__							:       Any=7   ,     UpperCamelCase__							:       Optional[int]=True   ,     UpperCamelCase__							:       Optional[Any]=False   ,     UpperCamelCase__							:       str=99   ,     UpperCamelCase__							:       int=16   ,     UpperCamelCase__							:       Dict=2   ,     UpperCamelCase__							:       Tuple=4   ,     UpperCamelCase__							:       Dict=4   ,     UpperCamelCase__							:       Optional[int]="gelu"   ,     UpperCamelCase__							:       str=0.1   ,     UpperCamelCase__							:       Tuple=0.1   ,     UpperCamelCase__							:       List[Any]=20   ,     UpperCamelCase__							:       Tuple=2   ,     UpperCamelCase__							:       Tuple=1   ,     UpperCamelCase__							:       Optional[Any]=0   ,     UpperCamelCase__							:       Any=16   ,     UpperCamelCase__							:       Tuple=16   ,     UpperCamelCase__							:       str=0.02   ,     )		->       List[Any]:






				"""simple docstring"""







				snake_case   :    Dict			       =		parent
				snake_case   :    Tuple			       =		batch_size
				snake_case   :    List[Any]			       =		seq_length
				snake_case   :    Any			       =		is_training
				snake_case   :    List[str]			       =		use_labels
				snake_case   :    str			       =		vocab_size
				snake_case   :    int			       =		hidden_size
				snake_case   :    int			       =		num_hidden_layers
				snake_case   :    List[str]			       =		num_attention_heads
				snake_case   :    List[Any]			       =		intermediate_size
				snake_case   :    Tuple			       =		hidden_act
				snake_case   :    Optional[Any]			       =		hidden_dropout_prob
				snake_case   :    Union[str, Any]			       =		attention_probs_dropout_prob
				snake_case   :    Optional[Any]			       =		max_position_embeddings
				snake_case   :    Tuple			       =		eos_token_id
				snake_case   :    int			       =		pad_token_id
				snake_case   :    List[str]			       =		bos_token_id
				snake_case   :    Tuple			       =		embed_dim
				snake_case   :    Tuple			       =		word_embed_proj_dim
				snake_case   :    int			       =		initializer_range
				snake_case   :    str			       =		False



		def 	lowerCAmelCase							(	self							:       int	)		->       Optional[int]:






				"""simple docstring"""







				snake_case   :    List[Any]			       =		np.clip(ids_tensor([self.batch_size, self.seq_length - 1]   ,     self.vocab_size	)   ,     3   ,     self.vocab_size	)
				snake_case   :    Optional[int]			       =		np.concatenate((input_ids, 2 * np.ones((self.batch_size, 1)   ,     dtype=np.intaa	))   ,     -1	)

				snake_case   :    Union[str, Any]			       =		OPTConfig(
				    vocab_size=self.vocab_size   ,     hidden_size=self.hidden_size   ,     num_hidden_layers=self.num_hidden_layers   ,     num_attention_heads=self.num_attention_heads   ,     ffn_dim=self.intermediate_size   ,     dropout=self.hidden_dropout_prob   ,     attention_dropout=self.attention_probs_dropout_prob   ,     max_position_embeddings=self.max_position_embeddings   ,     eos_token_id=self.eos_token_id   ,     bos_token_id=self.bos_token_id   ,     pad_token_id=self.pad_token_id   ,     embed_dim=self.embed_dim   ,     is_encoder_decoder=UpperCamelCase__   ,     word_embed_proj_dim=self.word_embed_proj_dim   ,     initializer_range=self.initializer_range   ,     use_cache=UpperCamelCase__   ,     )
				snake_case   :    str			       =		prepare_opt_inputs_dict(UpperCamelCase__   ,     UpperCamelCase__	)
				return config, inputs_dict



		def 	lowerCAmelCase							(	self							:       Any	)		->       Dict:






				"""simple docstring"""







				snake_case       ,snake_case   :    Union[str, Any]			       =		self.prepare_config_and_inputs()
				return config, inputs_dict



		def 	lowerCAmelCase							(	self							:       Tuple   ,     UpperCamelCase__							:       Dict   ,     UpperCamelCase__							:       Any   ,     UpperCamelCase__							:       Optional[Any]	)		->       Any:






				"""simple docstring"""







				snake_case   :    Optional[int]			       =		20
				snake_case   :    int			       =		model_class_name(UpperCamelCase__	)

				snake_case   :    int			       =		inputs_dict['''input_ids''']
				snake_case   :    Union[str, Any]			       =		inputs_dict['''attention_mask''']

				snake_case   :    Tuple			       =		model.init_cache(input_ids.shape[0]   ,     UpperCamelCase__	)
				snake_case   :    Tuple			       =		jnp.ones((input_ids.shape[0], max_length)   ,     dtype='''i4'''	)

				snake_case   :    Dict			       =		jnp.broadcast_to(
				    jnp.arange(input_ids.shape[-1] - 1	)[None, :]   ,     (input_ids.shape[0], input_ids.shape[-1] - 1)   ,     )
				snake_case   :    Dict			       =		model(
				    input_ids[:, :-1]   ,     attention_mask=UpperCamelCase__   ,     past_key_values=UpperCamelCase__   ,     position_ids=UpperCamelCase__   ,     )

				snake_case   :    str			       =		jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]   ,     dtype='''i4'''	)
				snake_case   :    Optional[Any]			       =		model(
				    input_ids[:, -1:]   ,     attention_mask=UpperCamelCase__   ,     past_key_values=outputs_cache.past_key_values   ,     position_ids=UpperCamelCase__   ,     )

				snake_case   :    List[Any]			       =		model(UpperCamelCase__	)

				snake_case   :    Union[str, Any]			       =		np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])	)	)
				self.parent.assertTrue(diff < 1e-3   ,     msg=f'Max diff is {diff}'	)



		def 	lowerCAmelCase							(	self							:       Union[str, Any]   ,     UpperCamelCase__							:       int   ,     UpperCamelCase__							:       Dict   ,     UpperCamelCase__							:       Union[str, Any]	)		->       str:






				"""simple docstring"""







				snake_case   :    Optional[Any]			       =		20
				snake_case   :    List[Any]			       =		model_class_name(UpperCamelCase__	)

				snake_case       ,snake_case   :    Any			       =		(
				    inputs_dict['''input_ids'''],
				    inputs_dict['''attention_mask'''],
				)

				snake_case   :    str			       =		jnp.concatenate(
				    [
				        attention_mask,
				        jnp.zeros((attention_mask.shape[0], max_length - attention_mask.shape[1])	),
				    ]   ,     axis=-1   ,     )

				snake_case   :    List[str]			       =		model.init_cache(input_ids.shape[0]   ,     UpperCamelCase__	)
				snake_case   :    str			       =		jnp.broadcast_to(
				    jnp.arange(input_ids.shape[-1] - 1	)[None, :]   ,     (input_ids.shape[0], input_ids.shape[-1] - 1)   ,     )

				snake_case   :    Dict			       =		model(
				    input_ids[:, :-1]   ,     attention_mask=UpperCamelCase__   ,     past_key_values=UpperCamelCase__   ,     position_ids=UpperCamelCase__   ,     )
				snake_case   :    List[Any]			       =		jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]   ,     dtype='''i4'''	)
				snake_case   :    str			       =		model(
				    input_ids[:, -1:]   ,     past_key_values=outputs_cache.past_key_values   ,     attention_mask=UpperCamelCase__   ,     position_ids=UpperCamelCase__   ,     )

				snake_case   :    Optional[Any]			       =		model(UpperCamelCase__   ,     attention_mask=UpperCamelCase__	)

				snake_case   :    Dict			       =		np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])	)	)
				self.parent.assertTrue(diff < 1e-3   ,     msg=f'Max diff is {diff}'	)







@require_flax
class      snake_case__    (	__SCREAMING_SNAKE_CASE  , unittest.TestCase  , __SCREAMING_SNAKE_CASE ):







		"""simple docstring"""

		lowerCamelCase							=		(FlaxOPTModel, FlaxOPTForCausalLM) if is_flax_available() else ()
		lowerCamelCase							=		() if is_flax_available() else ()



		def 	lowerCAmelCase							(	self							:       Union[str, Any]	)		->       Optional[Any]:






				"""simple docstring"""







				snake_case   :    Union[str, Any]			       =		FlaxOPTModelTester(self	)



		def 	lowerCAmelCase							(	self							:       List[Any]	)		->       List[Any]:






				"""simple docstring"""







				snake_case       ,snake_case   :    Tuple			       =		self.model_tester.prepare_config_and_inputs()
				for model_class in self.all_model_classes:
						self.model_tester.check_use_cache_forward(UpperCamelCase__   ,     UpperCamelCase__   ,     UpperCamelCase__	)



		def 	lowerCAmelCase							(	self							:       Optional[Any]	)		->       str:






				"""simple docstring"""







				snake_case       ,snake_case   :    str			       =		self.model_tester.prepare_config_and_inputs()
				for model_class in self.all_model_classes:
						self.model_tester.check_use_cache_forward_with_attn_mask(UpperCamelCase__   ,     UpperCamelCase__   ,     UpperCamelCase__	)



		@slow
		def 	lowerCAmelCase							(	self							:       Any	)		->       Optional[Any]:






				"""simple docstring"""







				for model_class_name in self.all_model_classes:
						snake_case   :    Optional[int]			       =		model_class_name.from_pretrained('''facebook/opt-125m'''	)
						snake_case   :    List[str]			       =		np.ones((1, 1)	) * model.config.eos_token_id
						snake_case   :    int			       =		model(UpperCamelCase__	)
						self.assertIsNotNone(UpperCamelCase__	)







@require_sentencepiece
@require_flax
class      snake_case__    (	unittest.TestCase ):







		"""simple docstring"""

		@slow
		def 	lowerCAmelCase							(	self							:       Union[str, Any]	)		->       int:






				"""simple docstring"""







				snake_case   :    str			       =		FlaxOPTModel.from_pretrained('''facebook/opt-350m'''	)
				snake_case   :    List[str]			       =		jnp.array([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]	)
				snake_case   :    List[Any]			       =		model(input_ids=UpperCamelCase__	).last_hidden_state
				snake_case   :    Dict			       =		(1, 11, 512)
				self.assertEqual(output.shape   ,     UpperCamelCase__	)
				snake_case   :    Dict			       =		jnp.array(
				    [[-0.2_867, -1.9_256, -0.3_062], [-1.2_711, -0.1_337, -0.1_897], [0.4_109, 0.1_187, -1.3_142]]	)
				self.assertTrue(jnp.allclose(output[:, :3, :3]   ,     UpperCamelCase__   ,     atol=4e-2	)	)







@require_flax
@slow
class      snake_case__    (	unittest.TestCase ):







		"""simple docstring"""

		def 	lowerCAmelCase							(	self							:       Union[str, Any]	)		->       Union[str, Any]:






				"""simple docstring"""







				super().setUp()
				snake_case   :    str			       =		'''facebook/opt-350m'''



		def 	lowerCAmelCase							(	self							:       Tuple	)		->       Dict:






				"""simple docstring"""







				snake_case   :    Optional[Any]			       =		FlaxOPTForCausalLM.from_pretrained(self.path_model	)
				snake_case   :    Any			       =		GPTaTokenizer.from_pretrained(self.path_model	)

				snake_case   :    List[str]			       =		[
				    '''Today is a beautiful day and I want to''',
				    '''In the city of''',
				    '''Paris is the capital of France and''',
				    '''Computers and mobile phones have taken''',
				]
				# verify that prompt without BOS token is identical to Metaseq -> add_special_tokens=False
				snake_case   :    List[Any]			       =		tokenizer(UpperCamelCase__   ,     return_tensors='''jax'''   ,     padding=UpperCamelCase__   ,     add_special_tokens=UpperCamelCase__	)
				snake_case   :    Dict			       =		model(inputs.input_ids   ,     attention_mask=inputs.attention_mask	)[0].mean(axis=-1	)
				snake_case   :    str			       =		jnp.array(
				    [
				        [1.3_851, -13.8_923, -10.5_229, -10.7_533, -0.2_309, -10.2_384, -0.5_365, -9.0_947, -5.1_670],
				        [-4.7_073, -10.6_276, -3.9_415, -21.5_242, -0.2_822, -0.2_822, -0.2_822, -0.2_822, -0.2_822],
				        [0.6_247, -3.4_229, -8.9_179, -1.4_297, -14.1_650, 1.4_146, -9.0_218, -0.2_703, -0.2_703],
				        [6.4_783, -1.9_913, -10.7_926, -2.3_336, 1.5_092, -0.9_974, -6.8_213, 1.3_477, 1.3_477],
				    ]	)
				self.assertTrue(jnp.allclose(UpperCamelCase__   ,     UpperCamelCase__   ,     atol=4e-2	)	)

				snake_case   :    Optional[Any]			       =		jax.jit(UpperCamelCase__	)
				snake_case   :    Dict			       =		model(inputs.input_ids   ,     attention_mask=inputs.attention_mask	)[0].mean(axis=-1	)
				self.assertTrue(jnp.allclose(UpperCamelCase__   ,     UpperCamelCase__   ,     atol=4e-2	)	)







@require_flax
@slow
class      snake_case__    (	unittest.TestCase ):







		"""simple docstring"""

		@property
		def 	lowerCAmelCase							(	self							:       int	)		->       int:






				"""simple docstring"""







				return [
				    "Today is a beautiful day and I want",
				    "In the city of",
				    "Paris is the capital of France and",
				    "Computers and mobile phones have taken",
				]



		def 	lowerCAmelCase							(	self							:       Any	)		->       Optional[int]:






				"""simple docstring"""







				snake_case   :    Any			       =		'''facebook/opt-125m'''

				snake_case   :    Dict			       =		[
				    '''Today is a beautiful day and I want to''',
				    '''In the city of New York, the city''',
				    '''Paris is the capital of France and the capital''',
				    '''Computers and mobile phones have taken over the''',
				]

				snake_case   :    Optional[Any]			       =		[]

				snake_case   :    Optional[Any]			       =		FlaxOPTForCausalLM.from_pretrained(UpperCamelCase__	)
				snake_case   :    List[Any]			       =		GPTaTokenizer.from_pretrained(UpperCamelCase__	)

				for prompt in self.prompts:
						snake_case   :    Optional[Any]			       =		tokenizer(UpperCamelCase__   ,     return_tensors='''jax'''	).input_ids

						snake_case   :    List[Any]			       =		model.generate(UpperCamelCase__   ,     max_length=10	)
						snake_case   :    Union[str, Any]			       =		generated_ids[0]

						snake_case   :    Any			       =		tokenizer.batch_decode(UpperCamelCase__   ,     skip_special_tokens=UpperCamelCase__	)
						predicted_outputs += generated_string

				self.assertListEqual(UpperCamelCase__   ,     UpperCamelCase__	)



		def 	lowerCAmelCase							(	self							:       Union[str, Any]	)		->       Tuple:






				"""simple docstring"""







				snake_case   :    str			       =		'''facebook/opt-350m'''

				snake_case   :    Union[str, Any]			       =		[
				    '''Today is a beautiful day and I want to''',
				    '''In the city of San Francisco, the city''',
				    '''Paris is the capital of France and the capital''',
				    '''Computers and mobile phones have taken over the''',
				]

				snake_case   :    str			       =		[]
				snake_case   :    Union[str, Any]			       =		FlaxOPTForCausalLM.from_pretrained(UpperCamelCase__	)
				snake_case   :    Union[str, Any]			       =		GPTaTokenizer.from_pretrained(UpperCamelCase__	)

				for prompt in self.prompts:
						snake_case   :    Any			       =		tokenizer(UpperCamelCase__   ,     return_tensors='''jax'''	).input_ids

						snake_case   :    Dict			       =		model.generate(UpperCamelCase__   ,     max_length=10	)
						snake_case   :    str			       =		generated_ids[0]

						snake_case   :    Optional[int]			       =		tokenizer.batch_decode(UpperCamelCase__   ,     skip_special_tokens=UpperCamelCase__	)
						predicted_outputs += generated_string

				self.assertListEqual(UpperCamelCase__   ,     UpperCamelCase__	)



		def 	lowerCAmelCase							(	self							:       int	)		->       Tuple:






				"""simple docstring"""







				snake_case   :    List[str]			       =		'''facebook/opt-125m'''
				snake_case   :    Optional[int]			       =		[
				    '''Today is a beautiful day and I want to thank''',
				    '''In the city of Rome Canaver Canaver Canaver Canaver''',
				]
				snake_case   :    str			       =		FlaxOPTForCausalLM.from_pretrained(UpperCamelCase__	)
				snake_case   :    Any			       =		GPTaTokenizer.from_pretrained(UpperCamelCase__	)
				snake_case   :    Any			       =		tokenizer(
				    [
				        '''Today is a beautiful day and I want to''',
				        '''In the city of''',
				    ]   ,     return_tensors='''jax'''   ,     padding=UpperCamelCase__   ,     )

				snake_case   :    Tuple			       =		jax.jit(model.generate	)

				snake_case   :    Tuple			       =		jit_generate(inputs['''input_ids''']   ,     attention_mask=inputs['''attention_mask''']	).sequences

				snake_case   :    List[str]			       =		tokenizer.batch_decode(UpperCamelCase__   ,     skip_special_tokens=UpperCamelCase__	)

				self.assertIsNotNone(UpperCamelCase__   ,     UpperCamelCase__	)



		def 	lowerCAmelCase							(	self							:       Optional[int]	)		->       List[Any]:






				"""simple docstring"""







				snake_case   :    List[Any]			       =		'''facebook/opt-350m'''

				snake_case   :    Union[str, Any]			       =		GPTaTokenizer.from_pretrained(UpperCamelCase__	)
				snake_case   :    str			       =		FlaxOPTForCausalLM.from_pretrained(UpperCamelCase__	)

				snake_case   :    List[Any]			       =		'''left'''

				# use different length sentences to test batching
				snake_case   :    Any			       =		[
				    '''Hello, my dog is a little''',
				    '''Today, I''',
				]

				snake_case   :    Union[str, Any]			       =		tokenizer(UpperCamelCase__   ,     return_tensors='''jax'''   ,     padding=UpperCamelCase__	)
				snake_case   :    Union[str, Any]			       =		inputs['''input_ids''']

				snake_case   :    Dict			       =		model.generate(input_ids=UpperCamelCase__   ,     attention_mask=inputs['''attention_mask''']   ,     trace=UpperCamelCase__	)

				snake_case   :    List[str]			       =		tokenizer(sentences[0]   ,     return_tensors='''jax'''	).input_ids
				snake_case   :    List[str]			       =		model.generate(input_ids=UpperCamelCase__	)

				snake_case   :    Dict			       =		inputs_non_padded.shape[-1] - inputs['''attention_mask'''][-1].sum()
				snake_case   :    Optional[int]			       =		tokenizer(sentences[1]   ,     return_tensors='''jax'''	).input_ids
				snake_case   :    Any			       =		model.generate(input_ids=UpperCamelCase__   ,     max_length=model.config.max_length - num_paddings	)

				snake_case   :    Any			       =		tokenizer.batch_decode(outputs[0]   ,     skip_special_tokens=UpperCamelCase__	)
				snake_case   :    int			       =		tokenizer.decode(output_non_padded[0][0]   ,     skip_special_tokens=UpperCamelCase__	)
				snake_case   :    List[Any]			       =		tokenizer.decode(output_padded[0][0]   ,     skip_special_tokens=UpperCamelCase__	)

				snake_case   :    Optional[Any]			       =		[
				    '''Hello, my dog is a little bit of a dork.\nI\'m a little bit''',
				    '''Today, I was in the middle of a conversation with a friend about the''',
				]
				self.assertListEqual(UpperCamelCase__   ,     UpperCamelCase__	)
				self.assertListEqual(UpperCamelCase__   ,     [non_padded_sentence, padded_sentence]	)




'''simple docstring'''
import json
import os
import shutil
import tempfile
import unittest

from transformers import is_speech_available, is_torch_available
from transformers.models.speechta import SpeechTaTokenizer
from transformers.testing_utils import get_tests_dir, require_torch
from transformers.utils import FEATURE_EXTRACTOR_NAME


if is_speech_available() and is_torch_available():
						from transformers import SpeechTaFeatureExtractor, SpeechTaProcessor

						from .test_feature_extraction_speechta import floats_list


lowercase__		    =	get_tests_dir("fixtures/test_sentencepiece_bpe_char.model")






@require_torch
class      snake_case__    (	unittest.TestCase ):







		"""simple docstring"""

		def 	lowerCAmelCase							(	self							:       Optional[Any]	)		->       Optional[int]:






				"""simple docstring"""







				snake_case   :    List[str]			       =		tempfile.mkdtemp()

				snake_case   :    Optional[int]			       =		SpeechTaTokenizer(UpperCamelCase__	)
				tokenizer.save_pretrained(self.tmpdirname	)

				snake_case   :    Any			       =		{
				    '''feature_size''': 1,
				    '''padding_value''': 0.0,
				    '''sampling_rate''': 1_6000,
				    '''do_normalize''': False,
				    '''num_mel_bins''': 80,
				    '''hop_length''': 16,
				    '''win_length''': 64,
				    '''win_function''': '''hann_window''',
				    '''fmin''': 80,
				    '''fmax''': 7600,
				    '''mel_floor''': 1e-1_0,
				    '''reduction_factor''': 2,
				    '''return_attention_mask''': True,
				}

				snake_case   :    Tuple			       =		os.path.join(self.tmpdirname   ,     UpperCamelCase__	)
				with open(self.feature_extraction_file   ,     '''w'''   ,     encoding='''utf-8'''	) as fp:
						fp.write(json.dumps(UpperCamelCase__	) + '''\n'''	)



		def 	lowerCAmelCase							(	self							:       Dict   ,     **UpperCamelCase__							:       Any	)		->       str:






				"""simple docstring"""







				return SpeechTaTokenizer.from_pretrained(self.tmpdirname   ,     **UpperCamelCase__	)



		def 	lowerCAmelCase							(	self							:       Union[str, Any]   ,     **UpperCamelCase__							:       int	)		->       Optional[Any]:






				"""simple docstring"""







				return SpeechTaFeatureExtractor.from_pretrained(self.tmpdirname   ,     **UpperCamelCase__	)



		def 	lowerCAmelCase							(	self							:       Any	)		->       Any:






				"""simple docstring"""







				shutil.rmtree(self.tmpdirname	)



		def 	lowerCAmelCase							(	self							:       Tuple	)		->       Dict:






				"""simple docstring"""







				snake_case   :    str			       =		self.get_tokenizer()
				snake_case   :    List[str]			       =		self.get_feature_extractor()

				snake_case   :    Dict			       =		SpeechTaProcessor(tokenizer=UpperCamelCase__   ,     feature_extractor=UpperCamelCase__	)

				processor.save_pretrained(self.tmpdirname	)
				snake_case   :    Dict			       =		SpeechTaProcessor.from_pretrained(self.tmpdirname	)

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

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



		def 	lowerCAmelCase							(	self							:       str	)		->       Any:






				"""simple docstring"""







				snake_case   :    int			       =		SpeechTaProcessor(tokenizer=self.get_tokenizer()   ,     feature_extractor=self.get_feature_extractor()	)
				processor.save_pretrained(self.tmpdirname	)

				snake_case   :    int			       =		self.get_tokenizer(bos_token='''(BOS)'''   ,     eos_token='''(EOS)'''	)
				snake_case   :    str			       =		self.get_feature_extractor(do_normalize=UpperCamelCase__   ,     padding_value=1.0	)

				snake_case   :    Tuple			       =		SpeechTaProcessor.from_pretrained(
				    self.tmpdirname   ,     bos_token='''(BOS)'''   ,     eos_token='''(EOS)'''   ,     do_normalize=UpperCamelCase__   ,     padding_value=1.0	)

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

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



		def 	lowerCAmelCase							(	self							:       Optional[Any]	)		->       Dict:






				"""simple docstring"""







				snake_case   :    List[Any]			       =		self.get_feature_extractor()
				snake_case   :    List[str]			       =		self.get_tokenizer()

				snake_case   :    Union[str, Any]			       =		SpeechTaProcessor(tokenizer=UpperCamelCase__   ,     feature_extractor=UpperCamelCase__	)

				snake_case   :    Union[str, Any]			       =		floats_list((3, 1000)	)

				snake_case   :    List[str]			       =		feature_extractor(audio=UpperCamelCase__   ,     return_tensors='''np'''	)
				snake_case   :    Any			       =		processor(audio=UpperCamelCase__   ,     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 	lowerCAmelCase							(	self							:       Dict	)		->       str:






				"""simple docstring"""







				snake_case   :    str			       =		self.get_feature_extractor()
				snake_case   :    Optional[int]			       =		self.get_tokenizer()

				snake_case   :    Union[str, Any]			       =		SpeechTaProcessor(tokenizer=UpperCamelCase__   ,     feature_extractor=UpperCamelCase__	)

				snake_case   :    Dict			       =		floats_list((3, 1000)	)

				snake_case   :    str			       =		feature_extractor(audio_target=UpperCamelCase__   ,     return_tensors='''np'''	)
				snake_case   :    List[Any]			       =		processor(audio_target=UpperCamelCase__   ,     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 	lowerCAmelCase							(	self							:       List[Any]	)		->       int:






				"""simple docstring"""







				snake_case   :    Optional[int]			       =		self.get_feature_extractor()
				snake_case   :    Union[str, Any]			       =		self.get_tokenizer()

				snake_case   :    List[str]			       =		SpeechTaProcessor(tokenizer=UpperCamelCase__   ,     feature_extractor=UpperCamelCase__	)

				snake_case   :    Optional[Any]			       =		'''This is a test string'''

				snake_case   :    Dict			       =		processor(text=UpperCamelCase__	)
				snake_case   :    List[str]			       =		tokenizer(UpperCamelCase__	)

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



		def 	lowerCAmelCase							(	self							:       Optional[Any]	)		->       Dict:






				"""simple docstring"""







				snake_case   :    Optional[int]			       =		self.get_feature_extractor()
				snake_case   :    str			       =		self.get_tokenizer()

				snake_case   :    str			       =		SpeechTaProcessor(tokenizer=UpperCamelCase__   ,     feature_extractor=UpperCamelCase__	)

				snake_case   :    Dict			       =		'''This is a test string'''

				snake_case   :    Any			       =		processor(text_target=UpperCamelCase__	)
				snake_case   :    List[str]			       =		tokenizer(UpperCamelCase__	)

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



		def 	lowerCAmelCase							(	self							:       str	)		->       Optional[int]:






				"""simple docstring"""







				snake_case   :    List[str]			       =		self.get_feature_extractor()
				snake_case   :    str			       =		self.get_tokenizer()

				snake_case   :    Optional[Any]			       =		SpeechTaProcessor(tokenizer=UpperCamelCase__   ,     feature_extractor=UpperCamelCase__	)

				snake_case   :    Optional[int]			       =		[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

				snake_case   :    List[str]			       =		processor.batch_decode(UpperCamelCase__	)
				snake_case   :    List[str]			       =		tokenizer.batch_decode(UpperCamelCase__	)

				self.assertListEqual(UpperCamelCase__   ,     UpperCamelCase__	)



		def 	lowerCAmelCase							(	self							:       Optional[Any]	)		->       Union[str, Any]:






				"""simple docstring"""







				snake_case   :    List[Any]			       =		self.get_feature_extractor()
				snake_case   :    Tuple			       =		self.get_tokenizer()

				snake_case   :    List[Any]			       =		SpeechTaProcessor(tokenizer=UpperCamelCase__   ,     feature_extractor=UpperCamelCase__	)

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


