





'''simple docstring'''






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 		lowerCamelCase  :



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



	def   _lowerCamelCase    (   self	):
			lowerCAmelCase     :    Union[str, Any]						=   ids_tensor([self.batch_size, self.seq_length]		,      self.vocab_size	)

			lowerCAmelCase     :    Optional[int]						=   None
			if self.use_input_mask:
					lowerCAmelCase     :    Union[str, Any]						=   random_attention_mask([self.batch_size, self.seq_length]	)

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

			lowerCAmelCase     :    Optional[Any]						=   self.get_config()

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



	def   _lowerCamelCase    (   self	):
			lowerCAmelCase     :    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=a_		,      esmfold_config={"trunk": {"num_blocks": 2}, "fp16_esm": False}		,      )
			return config



	def   _lowerCamelCase    (   self		,      a_		,      a_		,      a_		,      a_		,      a_		,      a_	):
			lowerCAmelCase     :    Any						=   EsmForProteinFolding(config=a_	).float()
			model.to(a_	)
			model.eval()
			lowerCAmelCase     :    str						=   model(a_		,      attention_mask=a_	)
			lowerCAmelCase     :    Optional[int]						=   model(a_	)
			lowerCAmelCase     :    Optional[Any]						=   model(a_	)

			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   _lowerCamelCase    (   self	):
			lowerCAmelCase     :    int						=   self.prepare_config_and_inputs()
			(
			    (
			    lowerCAmelCase
			)	,		(
			    lowerCAmelCase
			)	,		(
			    lowerCAmelCase
			)	,		(
			    lowerCAmelCase
			)	,		(
			    lowerCAmelCase
			)	,		(
			    lowerCAmelCase
			)	,		
			)     :    Optional[Any]						=   config_and_inputs
			lowerCAmelCase     :    Dict						=   {"input_ids": input_ids, "attention_mask": input_mask}
			return config, inputs_dict






@require_torch
class 		lowerCamelCase  (      _A      ,   _A      ,   unittest.TestCase       ):
	snake_case_      =   False

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



	def   _lowerCamelCase    (   self	):
			lowerCAmelCase     :    Tuple						=   EsmFoldModelTester(self	)
			lowerCAmelCase     :    Union[str, Any]						=   ConfigTester(self		,      config_class=a_		,      hidden_size=37	)



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



	def   _lowerCamelCase    (   self	):
			lowerCAmelCase     :    str						=   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*a_	)



	@unittest.skip("Does not support attention outputs"	)
	def   _lowerCamelCase    (   self	):
			pass



	@unittest.skip
	def   _lowerCamelCase    (   self	):
			pass



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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





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






@require_torch
class 		lowerCamelCase  (      _A       ):



	@slow
	def   _lowerCamelCase    (   self	):
			lowerCAmelCase     :    int						=   EsmForProteinFolding.from_pretrained("facebook/esmfold_v1"	).float()
			model.eval()
			lowerCAmelCase     :    List[Any]						=   torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]	)
			lowerCAmelCase     :    List[str]						=   model(a_	)["positions"]
			lowerCAmelCase     :    str						=   torch.tensor([2.5828, 0.7993, -10.9334]		,      dtype=torch.floataa	)
			self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]		,      a_		,      atol=1e-4	)	)










'''simple docstring'''






# 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 		lowerCamelCase  (      _A       ):
	snake_case_      =   "microsoft/speecht5_tts"
	snake_case_      =   (
	    "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."
	)
	snake_case_      =   "text_reader"
	snake_case_      =   SpeechTaProcessor
	snake_case_      =   SpeechTaForTextToSpeech
	snake_case_      =   SpeechTaHifiGan

	snake_case_      =   ["text"]
	snake_case_      =   ["audio"]



	def   _lowerCamelCase    (   self	):
			if self.post_processor is None:
					lowerCAmelCase     :    str						=   "microsoft/speecht5_hifigan"
			super().setup()



	def   _lowerCamelCase    (   self		,      a_		,      a_=None	):
			lowerCAmelCase     :    str						=   self.pre_processor(text=a_		,      return_tensors="pt"		,      truncation=a_	)

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

					lowerCAmelCase     :    Tuple						=   load_dataset("Matthijs/cmu-arctic-xvectors"		,      split="validation"	)
					lowerCAmelCase     :    Union[str, Any]						=   torch.tensor(embeddings_dataset[7_305]["xvector"]	).unsqueeze(0	)

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



	def   _lowerCamelCase    (   self		,      a_	):
			with torch.no_grad():
					return self.model.generate_speech(**a_	)





	def   _lowerCamelCase    (   self		,      a_	):
			with torch.no_grad():
					return self.post_processor(a_	).cpu().detach()



