
import unittest

from transformers import load_tool
from transformers.utils import is_torch_available


if is_torch_available():
				import torch

from transformers.testing_utils import require_torch

from .test_tools_common import ToolTesterMixin




@require_torch
class 						lowercase__  (						unittest.TestCase     ,       _UpperCAmelCase  ):
	def      A_				(			self							:   Optional[int]							):
						SCREAMING_SNAKE_CASE__													= load_tool('text-to-speech'							)
						self.tool.setup()
	def      A_				(			self							:   List[Any]							):
						# SpeechT5 isn't deterministic
						torch.manual_seed(0							)
						SCREAMING_SNAKE_CASE__													= self.tool('hey'							)
						SCREAMING_SNAKE_CASE__													= result.to_raw()
						self.assertTrue(
						    torch.allclose(
						        resulting_tensor[:3]       ,   torch.tensor([-0.0_005_966_668_832_115_829, -0.0_003_657_640_190_795_064, -0.00_013_439_502_799_883_485]							)       ,   )							)





	def      A_				(			self							:   Tuple							):
						# SpeechT5 isn't deterministic
						torch.manual_seed(0							)
						SCREAMING_SNAKE_CASE__													= self.tool('hey'							)
						SCREAMING_SNAKE_CASE__													= result.to_raw()
						self.assertTrue(
						    torch.allclose(
						        resulting_tensor[:3]       ,   torch.tensor([-0.0_005_966_668_832_115_829, -0.0_003_657_640_190_795_064, -0.00_013_439_502_799_883_485]							)       ,   )							)







import os
import unittest

from transformers import LxmertTokenizer, LxmertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin




@require_tokenizers
class 						lowercase__  (						_UpperCAmelCase     ,       unittest.TestCase  ):
	A__    :   Dict				       =LxmertTokenizer
	A__    :   List[Any]				       =LxmertTokenizerFast
	A__    :   Any				       =True
	A__    :   List[Any]				       =True
	def      A_				(			self							:   Optional[Any]							):
						super().setUp()

						SCREAMING_SNAKE_CASE__													= [
						    '[UNK]',
						    '[CLS]',
						    '[SEP]',
						    'want',
						    '##want',
						    '##ed',
						    'wa',
						    'un',
						    'runn',
						    '##ing',
						    ',',
						    'low',
						    'lowest',
						]
						SCREAMING_SNAKE_CASE__													= os.path.join(self.tmpdirname       ,   VOCAB_FILES_NAMES['vocab_file']							)
						with open(self.vocab_file       ,   'w'       ,   encoding='utf-8'							) as vocab_writer:
											vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]							)							)
	def      A_				(			self							:   int       ,   UpperCAmelCase_							:   int							):
						SCREAMING_SNAKE_CASE__													= 'UNwant\u00E9d,running'
						SCREAMING_SNAKE_CASE__													= 'unwanted, running'
						return input_text, output_text
	def      A_				(			self							:   Optional[Any]							):
						SCREAMING_SNAKE_CASE__													= self.tokenizer_class(self.vocab_file							)

						SCREAMING_SNAKE_CASE__													= tokenizer.tokenize('UNwant\u00E9d,running'							)
						self.assertListEqual(UpperCAmelCase_       ,   ['un', '##want', '##ed', ',', 'runn', '##ing']							)
						self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCAmelCase_							)       ,   [7, 4, 5, 10, 8, 9]							)





	def      A_				(			self							:   List[str]							):
						if not self.test_rust_tokenizer:
											return

						SCREAMING_SNAKE_CASE__													= self.get_tokenizer()
						SCREAMING_SNAKE_CASE__													= self.get_rust_tokenizer()

						SCREAMING_SNAKE_CASE__													= 'I was born in 92000, and this is falsé.'

						SCREAMING_SNAKE_CASE__													= tokenizer.tokenize(UpperCAmelCase_							)
						SCREAMING_SNAKE_CASE__													= rust_tokenizer.tokenize(UpperCAmelCase_							)
						self.assertListEqual(UpperCAmelCase_       ,   UpperCAmelCase_							)

						SCREAMING_SNAKE_CASE__													= tokenizer.encode(UpperCAmelCase_       ,   add_special_tokens=UpperCAmelCase_							)
						SCREAMING_SNAKE_CASE__													= rust_tokenizer.encode(UpperCAmelCase_       ,   add_special_tokens=UpperCAmelCase_							)
						self.assertListEqual(UpperCAmelCase_       ,   UpperCAmelCase_							)

						SCREAMING_SNAKE_CASE__													= self.get_rust_tokenizer()
						SCREAMING_SNAKE_CASE__													= tokenizer.encode(UpperCAmelCase_							)
						SCREAMING_SNAKE_CASE__													= rust_tokenizer.encode(UpperCAmelCase_							)
						self.assertListEqual(UpperCAmelCase_       ,   UpperCAmelCase_							)





