



import unittest

from transformers import 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
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import (
				    RemBertConfig,
				    RemBertForCausalLM,
				    RemBertForMaskedLM,
				    RemBertForMultipleChoice,
				    RemBertForQuestionAnswering,
				    RemBertForSequenceClassification,
				    RemBertForTokenClassification,
				    RemBertModel,
				)
				from transformers.models.rembert.modeling_rembert import REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST

class 						UpperCAmelCase__     :




			'''simple docstring'''






			def __init__(  self				:					List[str]			,			a_				:					str			,			a_				:					Optional[Any]=13			,			a_				:					Any=7			,			a_				:					Optional[Any]=True			,			a_				:					List[Any]=True			,			a_				:					List[str]=True			,			a_				:					Any=True			,			a_				:					List[Any]=99			,			a_				:					Optional[Any]=32			,			a_				:					List[str]=18			,			a_				:					List[Any]=43			,			a_				:					Any=5			,			a_				:					Optional[Any]=4			,			a_				:					Union[str, Any]=37			,			a_				:					List[str]="gelu"			,			a_				:					Union[str, Any]=0.1			,			a_				:					Optional[Any]=0.1			,			a_				:					Tuple=5_12			,			a_				:					Union[str, Any]=16			,			a_				:					str=2			,			a_				:					List[str]=0.0_2			,			a_				:					Tuple=3			,			a_				:					int=4			,			a_				:					Dict=None			,			):
					'''simple docstring'''





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




			def 					snake_case__	(  self				:					List[Any]					):
					'''simple docstring'''





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

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

					__UpperCAmelCase       :	Union[str, Any]						=      None
					if self.use_token_type_ids:
							__UpperCAmelCase       :	Optional[Any]						=      ids_tensor([self.batch_size, self.seq_length]			,			self.type_vocab_size					)

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

					__UpperCAmelCase       :	List[str]						=      RemBertConfig(
					    vocab_size=self.vocab_size			,			hidden_size=self.hidden_size			,			input_embedding_size=self.input_embedding_size			,			output_embedding_size=self.output_embedding_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			,			)

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




			def 					snake_case__	(  self				:					Optional[int]					):
					'''simple docstring'''





					(
					    (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   
					)       :	int						=      self.prepare_config_and_inputs()

					__UpperCAmelCase       :	Optional[Any]						=      True
					__UpperCAmelCase       :	Dict						=      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]					)
					__UpperCAmelCase       :	Dict						=      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				:					List[Any]			,			a_				:					Union[str, Any]			,			a_				:					Optional[int]			,			a_				:					Union[str, Any]			,			a_				:					List[Any]			,			a_				:					Dict			,			a_				:					str			,			a_				:					Union[str, Any]					):
					'''simple docstring'''





					__UpperCAmelCase       :	Dict						=      RemBertModel(config=a_					)
					model.to(a_					)
					model.eval()
					__UpperCAmelCase       :	Optional[int]						=      model(a_			,			attention_mask=a_			,			token_type_ids=a_					)
					__UpperCAmelCase       :	Tuple						=      model(a_			,			token_type_ids=a_					)
					__UpperCAmelCase       :	Dict						=      model(a_					)
					self.parent.assertEqual(result.last_hidden_state.shape			,			(self.batch_size, self.seq_length, self.hidden_size)					)




			def 					snake_case__	(  self				:					Tuple			,			a_				:					List[Any]			,			a_				:					Optional[int]			,			a_				:					int			,			a_				:					Optional[int]			,			a_				:					str			,			a_				:					List[str]			,			a_				:					Any			,			a_				:					Optional[Any]			,			a_				:					List[str]			,			):
					'''simple docstring'''





					__UpperCAmelCase       :	str						=      True
					__UpperCAmelCase       :	Any						=      RemBertModel(a_					)
					model.to(a_					)
					model.eval()
					__UpperCAmelCase       :	List[str]						=      model(
					    a_			,			attention_mask=a_			,			token_type_ids=a_			,			encoder_hidden_states=a_			,			encoder_attention_mask=a_			,			)
					__UpperCAmelCase       :	Optional[Any]						=      model(
					    a_			,			attention_mask=a_			,			token_type_ids=a_			,			encoder_hidden_states=a_			,			)
					__UpperCAmelCase       :	Tuple						=      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				:					List[Any]			,			a_				:					Any			,			a_				:					Tuple			,			a_				:					Optional[int]			,			a_				:					List[Any]			,			a_				:					Dict			,			a_				:					Optional[Any]			,			a_				:					Union[str, Any]			,			a_				:					Dict			,			a_				:					List[str]			,			):
					'''simple docstring'''





					__UpperCAmelCase       :	Union[str, Any]						=      RemBertForCausalLM(config=a_					)
					model.to(a_					)
					model.eval()
					__UpperCAmelCase       :	str						=      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				:					Any			,			a_				:					Union[str, Any]			,			a_				:					Union[str, Any]			,			a_				:					Tuple			,			a_				:					List[Any]			,			a_				:					Union[str, Any]			,			a_				:					Any			,			a_				:					str					):
					'''simple docstring'''





					__UpperCAmelCase       :	Optional[Any]						=      RemBertForMaskedLM(config=a_					)
					model.to(a_					)
					model.eval()
					__UpperCAmelCase       :	List[str]						=      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				:					Tuple			,			a_				:					Optional[Any]			,			a_				:					int			,			a_				:					List[str]			,			a_				:					str			,			a_				:					List[str]			,			a_				:					Optional[int]			,			a_				:					int			,			a_				:					Dict			,			a_				:					Optional[int]			,			):
					'''simple docstring'''





					__UpperCAmelCase       :	List[str]						=      True
					__UpperCAmelCase       :	Any						=      True
					__UpperCAmelCase       :	List[str]						=      RemBertForCausalLM(config=a_					)
					model.to(a_					)
					model.eval()

					# first forward pass
					__UpperCAmelCase       :	Optional[Any]						=      model(
					    a_			,			attention_mask=a_			,			encoder_hidden_states=a_			,			encoder_attention_mask=a_			,			use_cache=a_			,			)
					__UpperCAmelCase       :	str						=      outputs.past_key_values

					# create hypothetical multiple next token and extent to next_input_ids
					__UpperCAmelCase       :	int						=      ids_tensor((self.batch_size, 3)			,			config.vocab_size					)
					__UpperCAmelCase       :	Dict						=      ids_tensor((self.batch_size, 3)			,			vocab_size=2					)

					# append to next input_ids and
					__UpperCAmelCase       :	List[str]						=      torch.cat([input_ids, next_tokens]			,			dim=-1					)
					__UpperCAmelCase       :	int						=      torch.cat([input_mask, next_mask]			,			dim=-1					)

					__UpperCAmelCase       :	str						=      model(
					    a_			,			attention_mask=a_			,			encoder_hidden_states=a_			,			encoder_attention_mask=a_			,			output_hidden_states=a_			,			)['''hidden_states'''][0]
					__UpperCAmelCase       :	Tuple						=      model(
					    a_			,			attention_mask=a_			,			encoder_hidden_states=a_			,			encoder_attention_mask=a_			,			past_key_values=a_			,			output_hidden_states=a_			,			)['''hidden_states'''][0]

					# select random slice
					__UpperCAmelCase       :	Union[str, Any]						=      ids_tensor((1,)			,			output_from_past.shape[-1]					).item()
					__UpperCAmelCase       :	List[str]						=      output_from_no_past[:, -3:, random_slice_idx].detach()
					__UpperCAmelCase       :	str						=      output_from_past[:, :, random_slice_idx].detach()

					self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]					)

					# test that outputs are equal for slice
					self.parent.assertTrue(torch.allclose(a_			,			a_			,			atol=1e-3					)					)




			def 					snake_case__	(  self				:					Optional[int]			,			a_				:					List[str]			,			a_				:					Optional[Any]			,			a_				:					str			,			a_				:					Tuple			,			a_				:					Any			,			a_				:					Optional[int]			,			a_				:					Optional[Any]					):
					'''simple docstring'''





					__UpperCAmelCase       :	str						=      RemBertForQuestionAnswering(config=a_					)
					model.to(a_					)
					model.eval()
					__UpperCAmelCase       :	str						=      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				:					Any			,			a_				:					Union[str, Any]			,			a_				:					str			,			a_				:					Optional[int]			,			a_				:					Any			,			a_				:					Any			,			a_				:					List[Any]			,			a_				:					Optional[int]					):
					'''simple docstring'''





					__UpperCAmelCase       :	Optional[int]						=      self.num_labels
					__UpperCAmelCase       :	List[Any]						=      RemBertForSequenceClassification(a_					)
					model.to(a_					)
					model.eval()
					__UpperCAmelCase       :	Tuple						=      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				:					Union[str, Any]			,			a_				:					Union[str, Any]			,			a_				:					Any			,			a_				:					List[str]			,			a_				:					str			,			a_				:					List[str]			,			a_				:					Any			,			a_				:					List[str]					):
					'''simple docstring'''





					__UpperCAmelCase       :	Optional[Any]						=      self.num_labels
					__UpperCAmelCase       :	str						=      RemBertForTokenClassification(config=a_					)
					model.to(a_					)
					model.eval()
					__UpperCAmelCase       :	Tuple						=      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				:					Tuple			,			a_				:					List[str]			,			a_				:					List[str]			,			a_				:					Union[str, Any]			,			a_				:					List[str]			,			a_				:					Optional[int]			,			a_				:					int			,			a_				:					str					):
					'''simple docstring'''





					__UpperCAmelCase       :	Tuple						=      self.num_choices
					__UpperCAmelCase       :	List[Any]						=      RemBertForMultipleChoice(config=a_					)
					model.to(a_					)
					model.eval()
					__UpperCAmelCase       :	Any						=      input_ids.unsqueeze(1					).expand(-1			,			self.num_choices			,			-1					).contiguous()
					__UpperCAmelCase       :	str						=      token_type_ids.unsqueeze(1					).expand(-1			,			self.num_choices			,			-1					).contiguous()
					__UpperCAmelCase       :	List[Any]						=      input_mask.unsqueeze(1					).expand(-1			,			self.num_choices			,			-1					).contiguous()
					__UpperCAmelCase       :	int						=      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				:					Any					):
					'''simple docstring'''





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

@require_torch
class 						UpperCAmelCase__     (     __UpperCamelCase		,__UpperCamelCase		,unittest.TestCase  ):




			'''simple docstring'''






			UpperCamelCase     		=			(
			    (
			        RemBertModel,
			        RemBertForMaskedLM,
			        RemBertForCausalLM,
			        RemBertForMultipleChoice,
			        RemBertForQuestionAnswering,
			        RemBertForSequenceClassification,
			        RemBertForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			UpperCamelCase     		=			(RemBertForCausalLM,) if is_torch_available() else ()
			UpperCamelCase     		=			(
			    {
			        """feature-extraction""": RemBertModel,
			        """fill-mask""": RemBertForMaskedLM,
			        """question-answering""": RemBertForQuestionAnswering,
			        """text-classification""": RemBertForSequenceClassification,
			        """text-generation""": RemBertForCausalLM,
			        """token-classification""": RemBertForTokenClassification,
			        """zero-shot""": RemBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)




			def 					snake_case__	(  self				:					List[str]					):
					'''simple docstring'''





					__UpperCAmelCase       :	Dict						=      RemBertModelTester(self					)
					__UpperCAmelCase       :	Dict						=      ConfigTester(self			,			config_class=a_			,			hidden_size=37					)




			def 					snake_case__	(  self				:					str					):
					'''simple docstring'''





					self.config_tester.run_common_tests()




			def 					snake_case__	(  self				:					Any					):
					'''simple docstring'''





					__UpperCAmelCase       :	Optional[Any]						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*a_					)




			def 					snake_case__	(  self				:					Any					):
					'''simple docstring'''





					__UpperCAmelCase       :	Optional[Any]						=      self.model_tester.prepare_config_and_inputs()
					for type in ["absolute", "relative_key", "relative_key_query"]:
							__UpperCAmelCase       :	List[Any]						=      type
							self.model_tester.create_and_check_model(*a_					)




			def 					snake_case__	(  self				:					int					):
					'''simple docstring'''





					__UpperCAmelCase       :	Optional[Any]						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*a_					)




			def 					snake_case__	(  self				:					Optional[int]					):
					'''simple docstring'''





					__UpperCAmelCase       :	List[str]						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_multiple_choice(*a_					)




			def 					snake_case__	(  self				:					Optional[int]					):
					'''simple docstring'''





					__UpperCAmelCase       :	int						=      self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_decoder_model_past_large_inputs(*a_					)




			def 					snake_case__	(  self				:					List[Any]					):
					'''simple docstring'''





					__UpperCAmelCase       :	str						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*a_					)




			def 					snake_case__	(  self				:					Dict					):
					'''simple docstring'''





					__UpperCAmelCase       :	List[Any]						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*a_					)




			def 					snake_case__	(  self				:					str					):
					'''simple docstring'''





					__UpperCAmelCase       :	Any						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*a_					)




			def 					snake_case__	(  self				:					Optional[int]					):
					'''simple docstring'''





					__UpperCAmelCase       :	List[str]						=      self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_model_as_decoder(*a_					)




			def 					snake_case__	(  self				:					Dict					):
					'''simple docstring'''





					(
					    (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   (
					    __UpperCAmelCase
					)				,   
					)       :	Optional[Any]						=      self.model_tester.prepare_config_and_inputs_for_decoder()

					__UpperCAmelCase       :	int						=      None

					self.model_tester.create_and_check_model_as_decoder(
					    a_			,			a_			,			a_			,			a_			,			a_			,			a_			,			a_			,			a_			,			a_			,			)




			@slow
			def 					snake_case__	(  self				:					Optional[int]					):
					'''simple docstring'''





					for model_name in REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__UpperCAmelCase       :	Union[str, Any]						=      RemBertModel.from_pretrained(a_					)
							self.assertIsNotNone(a_					)

@require_torch
class 						UpperCAmelCase__     (     unittest.TestCase  ):




			'''simple docstring'''






			@slow
			def 					snake_case__	(  self				:					Dict					):
					'''simple docstring'''





					__UpperCAmelCase       :	List[str]						=      RemBertModel.from_pretrained('''google/rembert'''					)
					__UpperCAmelCase       :	List[Any]						=      torch.tensor([[3_12, 5_64_98, 3_13, 21_25, 3_13]]					)
					__UpperCAmelCase       :	List[str]						=      torch.tensor([[0, 0, 0, 1, 1]]					)
					with torch.no_grad():
							__UpperCAmelCase       :	List[Any]						=      model(a_			,			token_type_ids=a_			,			output_hidden_states=a_					)

					__UpperCAmelCase       :	List[str]						=      11_52

					__UpperCAmelCase       :	Union[str, Any]						=      torch.Size((1, 5, hidden_size)					)
					self.assertEqual(output['''last_hidden_state'''].shape			,			a_					)

					__UpperCAmelCase       :	List[Any]						=      torch.tensor(
					    [
					        [
					            [0.0_7_5_4, -0.2_0_2_2, 0.1_9_0_4],
					            [-0.3_3_5_4, -0.3_6_9_2, -0.4_7_9_1],
					            [-0.2_3_1_4, -0.6_7_2_9, -0.0_7_4_9],
					            [-0.0_3_9_6, -0.3_1_0_5, -0.4_2_3_4],
					            [-0.1_5_7_1, -0.0_5_2_5, 0.5_3_5_3],
					        ]
					    ]					)

					# Running on the original tf implementation gives slightly different results here.
					# Not clear why this variations is present
					# TODO: Find reason for discrepancy
					# expected_original_implementation = [[
					#     [0.07630594074726105, -0.20146065950393677, 0.19107051193714142],
					#     [-0.3405614495277405, -0.36971670389175415, -0.4808273911476135],
					#     [-0.22587086260318756, -0.6656315922737122, -0.07844287157058716],
					#     [-0.04145475849509239, -0.3077218234539032, -0.42316967248916626],
					#     [-0.15887849032878876, -0.054529931396245956, 0.5356100797653198]
					# ]]

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










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


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

@require_torch
class 						UpperCAmelCase__     (     unittest.TestCase  ):




			'''simple docstring'''






			def 					snake_case__	(  self				:					List[str]					):
					'''simple docstring'''





					__UpperCAmelCase       :	str						=      tempfile.mkdtemp()

					__UpperCAmelCase       :	Optional[int]						=      SpeechTaTokenizer(a_					)
					tokenizer.save_pretrained(self.tmpdirname					)

					__UpperCAmelCase       :	Union[str, Any]						=      {
					    '''feature_size''': 1,
					    '''padding_value''': 0.0,
					    '''sampling_rate''': 1_60_00,
					    '''do_normalize''': False,
					    '''num_mel_bins''': 80,
					    '''hop_length''': 16,
					    '''win_length''': 64,
					    '''win_function''': '''hann_window''',
					    '''fmin''': 80,
					    '''fmax''': 76_00,
					    '''mel_floor''': 1e-10,
					    '''reduction_factor''': 2,
					    '''return_attention_mask''': True,
					}

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




			def 					snake_case__	(  self				:					Any			,			**a_				:					Tuple					):
					'''simple docstring'''





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




			def 					snake_case__	(  self				:					Dict			,			**a_				:					str					):
					'''simple docstring'''





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




			def 					snake_case__	(  self				:					List[str]					):
					'''simple docstring'''





					shutil.rmtree(self.tmpdirname					)




			def 					snake_case__	(  self				:					Dict					):
					'''simple docstring'''





					__UpperCAmelCase       :	int						=      self.get_tokenizer()
					__UpperCAmelCase       :	str						=      self.get_feature_extractor()

					__UpperCAmelCase       :	List[Any]						=      SpeechTaProcessor(tokenizer=a_			,			feature_extractor=a_					)

					processor.save_pretrained(self.tmpdirname					)
					__UpperCAmelCase       :	List[str]						=      SpeechTaProcessor.from_pretrained(self.tmpdirname					)

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

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




			def 					snake_case__	(  self				:					int					):
					'''simple docstring'''





					__UpperCAmelCase       :	Optional[int]						=      SpeechTaProcessor(tokenizer=self.get_tokenizer()			,			feature_extractor=self.get_feature_extractor()					)
					processor.save_pretrained(self.tmpdirname					)

					__UpperCAmelCase       :	Optional[Any]						=      self.get_tokenizer(bos_token='''(BOS)'''			,			eos_token='''(EOS)'''					)
					__UpperCAmelCase       :	List[Any]						=      self.get_feature_extractor(do_normalize=a_			,			padding_value=1.0					)

					__UpperCAmelCase       :	List[str]						=      SpeechTaProcessor.from_pretrained(
					    self.tmpdirname			,			bos_token='''(BOS)'''			,			eos_token='''(EOS)'''			,			do_normalize=a_			,			padding_value=1.0					)

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

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




			def 					snake_case__	(  self				:					Union[str, Any]					):
					'''simple docstring'''





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

					__UpperCAmelCase       :	List[Any]						=      SpeechTaProcessor(tokenizer=a_			,			feature_extractor=a_					)

					__UpperCAmelCase       :	List[Any]						=      floats_list((3, 10_00)					)

					__UpperCAmelCase       :	Tuple						=      feature_extractor(audio=a_			,			return_tensors='''np'''					)
					__UpperCAmelCase       :	List[str]						=      processor(audio=a_			,			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 					snake_case__	(  self				:					Optional[Any]					):
					'''simple docstring'''





					__UpperCAmelCase       :	List[Any]						=      self.get_feature_extractor()
					__UpperCAmelCase       :	Dict						=      self.get_tokenizer()

					__UpperCAmelCase       :	Optional[Any]						=      SpeechTaProcessor(tokenizer=a_			,			feature_extractor=a_					)

					__UpperCAmelCase       :	Union[str, Any]						=      floats_list((3, 10_00)					)

					__UpperCAmelCase       :	Dict						=      feature_extractor(audio_target=a_			,			return_tensors='''np'''					)
					__UpperCAmelCase       :	str						=      processor(audio_target=a_			,			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 					snake_case__	(  self				:					Union[str, Any]					):
					'''simple docstring'''





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

					__UpperCAmelCase       :	Optional[Any]						=      SpeechTaProcessor(tokenizer=a_			,			feature_extractor=a_					)

					__UpperCAmelCase       :	List[str]						=      '''This is a test string'''

					__UpperCAmelCase       :	List[Any]						=      processor(text=a_					)
					__UpperCAmelCase       :	Optional[int]						=      tokenizer(a_					)

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




			def 					snake_case__	(  self				:					List[str]					):
					'''simple docstring'''





					__UpperCAmelCase       :	Optional[Any]						=      self.get_feature_extractor()
					__UpperCAmelCase       :	Optional[Any]						=      self.get_tokenizer()

					__UpperCAmelCase       :	List[Any]						=      SpeechTaProcessor(tokenizer=a_			,			feature_extractor=a_					)

					__UpperCAmelCase       :	List[str]						=      '''This is a test string'''

					__UpperCAmelCase       :	Optional[Any]						=      processor(text_target=a_					)
					__UpperCAmelCase       :	Optional[int]						=      tokenizer(a_					)

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




			def 					snake_case__	(  self				:					List[str]					):
					'''simple docstring'''





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

					__UpperCAmelCase       :	int						=      SpeechTaProcessor(tokenizer=a_			,			feature_extractor=a_					)

					__UpperCAmelCase       :	Optional[Any]						=      [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

					__UpperCAmelCase       :	Optional[Any]						=      processor.batch_decode(a_					)
					__UpperCAmelCase       :	Any						=      tokenizer.batch_decode(a_					)

					self.assertListEqual(a_			,			a_					)




			def 					snake_case__	(  self				:					str					):
					'''simple docstring'''





					__UpperCAmelCase       :	str						=      self.get_feature_extractor()
					__UpperCAmelCase       :	str						=      self.get_tokenizer()

					__UpperCAmelCase       :	Optional[Any]						=      SpeechTaProcessor(tokenizer=a_			,			feature_extractor=a_					)

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





