



"""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 				lowercase__       :







       '''simple docstring'''


       def __init__(							self      :  Optional[int]		,    _UpperCAmelCase      :  str		,    _UpperCAmelCase      :  Union[str, Any]=13		,    _UpperCAmelCase      :  List[str]=7		,    _UpperCAmelCase      :  Any=False		,    _UpperCAmelCase      :  str=True		,    _UpperCAmelCase      :  Dict=False		,    _UpperCAmelCase      :  Union[str, Any]=False		,    _UpperCAmelCase      :  List[str]=19		,    _UpperCAmelCase      :  Union[str, Any]=32		,    _UpperCAmelCase      :  List[str]=5		,    _UpperCAmelCase      :  Union[str, Any]=4		,    _UpperCAmelCase      :  str=37		,    _UpperCAmelCase      :  List[Any]="gelu"		,    _UpperCAmelCase      :  Optional[int]=0.1		,    _UpperCAmelCase      :  List[str]=0.1		,    _UpperCAmelCase      :  Tuple=512		,    _UpperCAmelCase      :  Optional[int]=16		,    _UpperCAmelCase      :  List[Any]=2		,    _UpperCAmelCase      :  Any=0.02		,    _UpperCAmelCase      :  Optional[int]=3		,    _UpperCAmelCase      :  Union[str, Any]=4		,    _UpperCAmelCase      :  int=None		,    )			->						Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_      			=							parent
             UpperCAmelCase_      			=							batch_size
             UpperCAmelCase_      			=							seq_length
             UpperCAmelCase_      			=							is_training
             UpperCAmelCase_      			=							use_input_mask
             UpperCAmelCase_      			=							use_token_type_ids
             UpperCAmelCase_      			=							use_labels
             UpperCAmelCase_      			=							vocab_size
             UpperCAmelCase_      			=							hidden_size
             UpperCAmelCase_      			=							num_hidden_layers
             UpperCAmelCase_      			=							num_attention_heads
             UpperCAmelCase_      			=							intermediate_size
             UpperCAmelCase_      			=							hidden_act
             UpperCAmelCase_      			=							hidden_dropout_prob
             UpperCAmelCase_      			=							attention_probs_dropout_prob
             UpperCAmelCase_      			=							max_position_embeddings
             UpperCAmelCase_      			=							type_vocab_size
             UpperCAmelCase_      			=							type_sequence_label_size
             UpperCAmelCase_      			=							initializer_range
             UpperCAmelCase_      			=							num_labels
             UpperCAmelCase_      			=							num_choices
             UpperCAmelCase_      			=							scope



       def 					lowercase__    (							self      :  int   )			->						Any:


             '''simple docstring'''




             UpperCAmelCase_      			=							ids_tensor([self.batch_size, self.seq_length]		,    self.vocab_size   )

             UpperCAmelCase_      			=							None
             if self.use_input_mask:
                   UpperCAmelCase_      			=							random_attention_mask([self.batch_size, self.seq_length]   )

             UpperCAmelCase_      			=							None
             UpperCAmelCase_      			=							None
             UpperCAmelCase_      			=							None
             if self.use_labels:
                   UpperCAmelCase_      			=							ids_tensor([self.batch_size]		,    self.type_sequence_label_size   )
                   UpperCAmelCase_      			=							ids_tensor([self.batch_size, self.seq_length]		,    self.num_labels   )
                   UpperCAmelCase_      			=							ids_tensor([self.batch_size]		,    self.num_choices   )

             UpperCAmelCase_      			=							self.get_config()

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



       def 					lowercase__    (							self      :  List[Any]   )			->						str:


             '''simple docstring'''




             UpperCAmelCase_      			=							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 					lowercase__    (							self      :  List[Any]		,    _UpperCAmelCase      :  Tuple		,    _UpperCAmelCase      :  List[str]		,    _UpperCAmelCase      :  Union[str, Any]		,    _UpperCAmelCase      :  Optional[int]		,    _UpperCAmelCase      :  List[Any]		,    _UpperCAmelCase      :  List[Any]   )			->						Dict:


             '''simple docstring'''




             UpperCAmelCase_      			=							EsmForProteinFolding(config=_UpperCAmelCase   ).float()
             model.to(_UpperCAmelCase   )
             model.eval()
             UpperCAmelCase_      			=							model(_UpperCAmelCase		,    attention_mask=_UpperCAmelCase   )
             UpperCAmelCase_      			=							model(_UpperCAmelCase   )
             UpperCAmelCase_      			=							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 					lowercase__    (							self      :  Optional[Any]   )			->						Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_      			=							self.prepare_config_and_inputs()
             (
                 (
                 UpperCAmelCase_
             )			,   (
                 UpperCAmelCase_
             )			,   (
                 UpperCAmelCase_
             )			,   (
                 UpperCAmelCase_
             )			,   (
                 UpperCAmelCase_
             )			,   (
                 UpperCAmelCase_
             )			,   
             )      			=							config_and_inputs
             UpperCAmelCase_      			=							{"input_ids": input_ids, "attention_mask": input_mask}
             return config, inputs_dict



@require_torch
class 				lowercase__       (   SCREAMING_SNAKE_CASE    , SCREAMING_SNAKE_CASE    , unittest.TestCase				):







       '''simple docstring'''


       UpperCamelCase						=					False

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



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


             '''simple docstring'''




             UpperCAmelCase_      			=							EsmFoldModelTester(self   )
             UpperCAmelCase_      			=							ConfigTester(self		,    config_class=_UpperCAmelCase		,    hidden_size=37   )



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


             '''simple docstring'''




             self.config_tester.run_common_tests()



       def 					lowercase__    (							self      :  int   )			->						Tuple:


             '''simple docstring'''




             UpperCAmelCase_      			=							self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*_UpperCAmelCase   )



       @unittest.skip("Does not support attention outputs"   )
       def 					lowercase__    (							self      :  List[Any]   )			->						Any:


             '''simple docstring'''




             pass



       @unittest.skip
       def 					lowercase__    (							self      :  Optional[int]   )			->						List[str]:


             '''simple docstring'''




             pass



       @unittest.skip("Esm does not support embedding resizing"   )
       def 					lowercase__    (							self      :  Optional[int]   )			->						str:


             '''simple docstring'''




             pass



       @unittest.skip("Esm does not support embedding resizing"   )
       def 					lowercase__    (							self      :  List[Any]   )			->						Any:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold does not support passing input embeds!"   )
       def 					lowercase__    (							self      :  Any   )			->						Optional[Any]:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold does not support head pruning."   )
       def 					lowercase__    (							self      :  Union[str, Any]   )			->						Optional[int]:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold does not support head pruning."   )
       def 					lowercase__    (							self      :  int   )			->						str:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold does not support head pruning."   )
       def 					lowercase__    (							self      :  Union[str, Any]   )			->						List[Any]:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold does not support head pruning."   )
       def 					lowercase__    (							self      :  Tuple   )			->						List[str]:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold does not support head pruning."   )
       def 					lowercase__    (							self      :  Optional[Any]   )			->						Tuple:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold does not output hidden states in the normal way."   )
       def 					lowercase__    (							self      :  Optional[Any]   )			->						str:


             '''simple docstring'''




             pass



       @unittest.skip("ESMfold does not output hidden states in the normal way."   )
       def 					lowercase__    (							self      :  Any   )			->						Union[str, Any]:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold only has one output format."   )
       def 					lowercase__    (							self      :  Optional[Any]   )			->						Union[str, Any]:


             '''simple docstring'''




             pass



       @unittest.skip("This test doesn't work for ESMFold and doesn't test core functionality"   )
       def 					lowercase__    (							self      :  List[Any]   )			->						str:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold does not support input chunking."   )
       def 					lowercase__    (							self      :  Any   )			->						Optional[int]:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments."   )
       def 					lowercase__    (							self      :  int   )			->						List[str]:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold doesn't support torchscript compilation."   )
       def 					lowercase__    (							self      :  Optional[Any]   )			->						Tuple:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold doesn't support torchscript compilation."   )
       def 					lowercase__    (							self      :  Union[str, Any]   )			->						List[Any]:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold doesn't support torchscript compilation."   )
       def 					lowercase__    (							self      :  str   )			->						Optional[Any]:


             '''simple docstring'''




             pass



       @unittest.skip("ESMFold doesn't support data parallel."   )
       def 					lowercase__    (							self      :  Dict   )			->						List[str]:


             '''simple docstring'''




             pass







       @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."   )
       def 					lowercase__    (							self      :  str   )			->						Tuple:


             '''simple docstring'''




             pass



@require_torch
class 				lowercase__       (   SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       @slow
       def 					lowercase__    (							self      :  Any   )			->						str:


             '''simple docstring'''




             UpperCAmelCase_      			=							EsmForProteinFolding.from_pretrained("facebook/esmfold_v1"   ).float()
             model.eval()
             UpperCAmelCase_      			=							torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]   )
             UpperCAmelCase_      			=							model(_UpperCAmelCase   )["positions"]
             UpperCAmelCase_      			=							torch.tensor([2.5828, 0.7993, -10.9334]		,    dtype=torch.floataa   )
             self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]		,    _UpperCAmelCase		,    atol=1e-4   )   )









"""simple docstring"""





import unittest

import numpy as np

from diffusers import OnnxStableDiffusionInpaintPipelineLegacy
from diffusers.utils.testing_utils import (
    is_onnx_available,
    load_image,
    load_numpy,
    nightly,
    require_onnxruntime,
    require_torch_gpu,
)


if is_onnx_available():
  import onnxruntime as ort
@nightly
@require_onnxruntime
@require_torch_gpu
class 				lowercase__       (   unittest.TestCase				):







       '''simple docstring'''


       @property
       def 					lowercase__    (							self      :  Tuple   )			->						Any:


             '''simple docstring'''




             return (
                 "CUDAExecutionProvider",
                 {
                     "gpu_mem_limit": "15000000000",  # 15GB
                     "arena_extend_strategy": "kSameAsRequested",
                 },
             )



       @property
       def 					lowercase__    (							self      :  List[str]   )			->						int:


             '''simple docstring'''




             UpperCAmelCase_      			=							ort.SessionOptions()
             UpperCAmelCase_      			=							False
             return options







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


             '''simple docstring'''




             UpperCAmelCase_      			=							load_image(
                 "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
                 "/in_paint/overture-creations-5sI6fQgYIuo.png"   )
             UpperCAmelCase_      			=							load_image(
                 "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
                 "/in_paint/overture-creations-5sI6fQgYIuo_mask.png"   )
             UpperCAmelCase_      			=							load_numpy(
                 "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
                 "/in_paint/red_cat_sitting_on_a_park_bench_onnx.npy"   )

             # using the PNDM scheduler by default
             UpperCAmelCase_      			=							OnnxStableDiffusionInpaintPipelineLegacy.from_pretrained(
                 "CompVis/stable-diffusion-v1-4"		,    revision="onnx"		,    safety_checker=_UpperCAmelCase		,    feature_extractor=_UpperCAmelCase		,    provider=self.gpu_provider		,    sess_options=self.gpu_options		,    )
             pipe.set_progress_bar_config(disable=_UpperCAmelCase   )

             UpperCAmelCase_      			=							"A red cat sitting on a park bench"

             UpperCAmelCase_      			=							np.random.RandomState(0   )
             UpperCAmelCase_      			=							pipe(
                 prompt=_UpperCAmelCase		,    image=_UpperCAmelCase		,    mask_image=_UpperCAmelCase		,    strength=0.75		,    guidance_scale=7.5		,    num_inference_steps=15		,    generator=_UpperCAmelCase		,    output_type="np"		,    )

             UpperCAmelCase_      			=							output.images[0]

             assert image.shape == (512, 512, 3)
             assert np.abs(expected_image - image   ).max() < 1e-2




