
import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers.models.esm.modeling_esmfold import EsmForProteinFolding







class  UpperCamelCase__		:







	'''simple docstring'''





	def __init__(			self				,       UpperCamelCase__				,       UpperCamelCase__=13				,       UpperCamelCase__=7				,       UpperCamelCase__=False				,       UpperCamelCase__=True				,       UpperCamelCase__=False				,       UpperCamelCase__=False				,       UpperCamelCase__=19				,       UpperCamelCase__=32				,       UpperCamelCase__=5				,       UpperCamelCase__=4				,       UpperCamelCase__=37				,       UpperCamelCase__="gelu"				,       UpperCamelCase__=0.1				,       UpperCamelCase__=0.1				,       UpperCamelCase__=512				,       UpperCamelCase__=16				,       UpperCamelCase__=2				,       UpperCamelCase__=0.0_2				,       UpperCamelCase__=3				,       UpperCamelCase__=4				,       UpperCamelCase__=None				,       ):
					A__  :	Optional[Any]         =							parent
					A__  :	Any         =							batch_size
					A__  :	Union[str, Any]         =							seq_length
					A__  :	Dict         =							is_training
					A__  :	int         =							use_input_mask
					A__  :	List[Any]         =							use_token_type_ids
					A__  :	Optional[Any]         =							use_labels
					A__  :	int         =							vocab_size
					A__  :	Optional[int]         =							hidden_size
					A__  :	Tuple         =							num_hidden_layers
					A__  :	Optional[Any]         =							num_attention_heads
					A__  :	int         =							intermediate_size
					A__  :	List[Any]         =							hidden_act
					A__  :	Dict         =							hidden_dropout_prob
					A__  :	Union[str, Any]         =							attention_probs_dropout_prob
					A__  :	Union[str, Any]         =							max_position_embeddings
					A__  :	Optional[Any]         =							type_vocab_size
					A__  :	Dict         =							type_sequence_label_size
					A__  :	Optional[int]         =							initializer_range
					A__  :	Union[str, Any]         =							num_labels
					A__  :	List[Any]         =							num_choices
					A__  :	Any         =							scope





	def   __snake_case				(			self		):
					A__  :	int         =							ids_tensor([self.batch_size, self.seq_length]				,       self.vocab_size		)

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

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

					A__  :	List[Any]         =							self.get_config()

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





	def   __snake_case				(			self		):
					A__  :	Optional[int]         =							EsmConfig(
					    vocab_size=33				,       hidden_size=self.hidden_size				,       pad_token_id=1				,       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				,       initializer_range=self.initializer_range				,       is_folding_model=UpperCamelCase__				,       esmfold_config={'''trunk''': {'''num_blocks''': 2}, '''fp16_esm''': False}				,       )
					return config





	def   __snake_case				(			self				,       UpperCamelCase__				,       UpperCamelCase__				,       UpperCamelCase__				,       UpperCamelCase__				,       UpperCamelCase__				,       UpperCamelCase__		):
					A__  :	Union[str, Any]         =							EsmForProteinFolding(config=UpperCamelCase__		).float()
					model.to(UpperCamelCase__		)
					model.eval()
					A__  :	Union[str, Any]         =							model(UpperCamelCase__				,       attention_mask=UpperCamelCase__		)
					A__  :	Any         =							model(UpperCamelCase__		)
					A__  :	Any         =							model(UpperCamelCase__		)

					self.parent.assertEqual(result.positions.shape				,       (8, self.batch_size, self.seq_length, 14, 3)		)
					self.parent.assertEqual(result.angles.shape				,       (8, self.batch_size, self.seq_length, 7, 2)		)





	def   __snake_case				(			self		):
					A__  :	Tuple         =							self.prepare_config_and_inputs()
					(
					    (
					    A__
					)       ,							(
					    A__
					)       ,							(
					    A__
					)       ,							(
					    A__
					)       ,							(
					    A__
					)       ,							(
					    A__
					)       ,							
					)  :	str         =							config_and_inputs
					A__  :	Dict         =							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
					return config, inputs_dict







@require_torch
class  UpperCamelCase__		(    SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			unittest.TestCase   ):







	'''simple docstring'''
	_lowerCAmelCase							       =				False

	_lowerCAmelCase							       =				(EsmForProteinFolding,) if is_torch_available() else ()
	_lowerCAmelCase							       =				()
	_lowerCAmelCase							       =				{} if is_torch_available() else {}
	_lowerCAmelCase							       =				False





	def   __snake_case				(			self		):
					A__  :	Optional[Any]         =							EsmFoldModelTester(self		)
					A__  :	List[str]         =							ConfigTester(self				,       config_class=UpperCamelCase__				,       hidden_size=37		)





	def   __snake_case				(			self		):
					self.config_tester.run_common_tests()





	def   __snake_case				(			self		):
					A__  :	List[str]         =							self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*UpperCamelCase__		)





	@unittest.skip('''Does not support attention outputs'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''Esm does not support embedding resizing'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''Esm does not support embedding resizing'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold does not support passing input embeds!'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold does not support head pruning.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold does not support head pruning.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold does not support head pruning.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold does not support head pruning.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold does not support head pruning.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold does not output hidden states in the normal way.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMfold does not output hidden states in the normal way.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold only has one output format.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''This test doesn\'t work for ESMFold and doesn\'t test core functionality'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold does not support input chunking.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''ESMFold doesn\'t support data parallel.'''		)
	def   __snake_case				(			self		):
					pass





	@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''		)
	def   __snake_case				(			self		):
					pass







@require_torch
class  UpperCamelCase__		(    SCREAMING_SNAKE_CASE_   ):







	'''simple docstring'''





	@slow
	def   __snake_case				(			self		):
					A__  :	Any         =							EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1'''		).float()
					model.eval()
					A__  :	List[Any]         =							torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]		)
					A__  :	List[Any]         =							model(UpperCamelCase__		)['''positions''']
					A__  :	Optional[int]         =							torch.tensor([2.5_8_2_8, 0.7_9_9_3, -1_0.9_3_3_4]				,       dtype=torch.floataa		)
					self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]				,       UpperCamelCase__				,       atol=1e-4		)		)

# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import torch

from ..models.speechta import SpeechTaForTextToSpeech, SpeechTaHifiGan, SpeechTaProcessor
from ..utils import is_datasets_available
from .base import PipelineTool


if is_datasets_available():
					from datasets import load_dataset







class  UpperCamelCase__		(    SCREAMING_SNAKE_CASE_   ):







	'''simple docstring'''
	_lowerCAmelCase							       =				"microsoft/speecht5_tts"
	_lowerCAmelCase							       =				(
	    "This is a tool that reads an English text out loud. It takes an input named `text` which should contain the "
	    "text to read (in English) and returns a waveform object containing the sound."
	)
	_lowerCAmelCase							       =				"text_reader"
	_lowerCAmelCase							       =				SpeechTaProcessor
	_lowerCAmelCase							       =				SpeechTaForTextToSpeech
	_lowerCAmelCase							       =				SpeechTaHifiGan

	_lowerCAmelCase							       =				["text"]
	_lowerCAmelCase							       =				["audio"]





	def   __snake_case				(			self		):
					if self.post_processor is None:
									A__  :	int         =							'''microsoft/speecht5_hifigan'''
					super().setup()





	def   __snake_case				(			self				,       UpperCamelCase__				,       UpperCamelCase__=None		):
					A__  :	List[Any]         =							self.pre_processor(text=UpperCamelCase__				,       return_tensors='''pt'''				,       truncation=UpperCamelCase__		)

					if speaker_embeddings is None:
									if not is_datasets_available():
													raise ImportError('''Datasets needs to be installed if not passing speaker embeddings.'''		)

									A__  :	List[Any]         =							load_dataset('''Matthijs/cmu-arctic-xvectors'''				,       split='''validation'''		)
									A__  :	Dict         =							torch.tensor(embeddings_dataset[7305]['''xvector''']		).unsqueeze(0		)

					return {"input_ids": inputs["input_ids"], "speaker_embeddings": speaker_embeddings}





	def   __snake_case				(			self				,       UpperCamelCase__		):
					with torch.no_grad():
									return self.model.generate_speech(**UpperCamelCase__		)





	def   __snake_case				(			self				,       UpperCamelCase__		):
					with torch.no_grad():
									return self.post_processor(UpperCamelCase__		).cpu().detach()