





"""simple docstring"""





import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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


if is_torch_available():
  import torch

  from transformers import (
      DebertaForMaskedLM,
      DebertaForQuestionAnswering,
      DebertaForSequenceClassification,
      DebertaForTokenClassification,
      DebertaModel,
  )
  from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       def __init__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase=1_3       ,					__UpperCAmelCase=7       ,					__UpperCAmelCase=True       ,					__UpperCAmelCase=True       ,					__UpperCAmelCase=True       ,					__UpperCAmelCase=True       ,					__UpperCAmelCase=9_9       ,					__UpperCAmelCase=3_2       ,					__UpperCAmelCase=5       ,					__UpperCAmelCase=4       ,					__UpperCAmelCase=3_7       ,					__UpperCAmelCase="gelu"       ,					__UpperCAmelCase=0.1       ,					__UpperCAmelCase=0.1       ,					__UpperCAmelCase=5_1_2       ,					__UpperCAmelCase=1_6       ,					__UpperCAmelCase=2       ,					__UpperCAmelCase=0.02       ,					__UpperCAmelCase=False       ,					__UpperCAmelCase=True       ,					__UpperCAmelCase="None"       ,					__UpperCAmelCase=3       ,					__UpperCAmelCase=4       ,					__UpperCAmelCase=None       ,					):



         '''simple docstring'''

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






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Tuple											=				ids_tensor([self.batch_size, self.seq_length]       ,					self.vocab_size )

         lowerCAmelCase__     :Union[str, Any]											=				None
         if self.use_input_mask:
           lowerCAmelCase__     :Tuple											=				ids_tensor([self.batch_size, self.seq_length]       ,					vocab_size=2 )

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

         lowerCAmelCase__     :Any											=				None
         lowerCAmelCase__     :int											=				None
         lowerCAmelCase__     :str											=				None
         if self.use_labels:
           lowerCAmelCase__     :Dict											=				ids_tensor([self.batch_size]       ,					self.type_sequence_label_size )
           lowerCAmelCase__     :str											=				ids_tensor([self.batch_size, self.seq_length]       ,					self.num_labels )
           lowerCAmelCase__     :Dict											=				ids_tensor([self.batch_size]       ,					self.num_choices )

         lowerCAmelCase__     :List[str]											=				self.get_config()

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






       def 	snake_case		(       self ):



         '''simple docstring'''

         return DebertaConfig(
             vocab_size=self.vocab_size       ,					hidden_size=self.hidden_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       ,					initializer_range=self.initializer_range       ,					relative_attention=self.relative_attention       ,					position_biased_input=self.position_biased_input       ,					pos_att_type=self.pos_att_type       ,					)






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[int]											=				self.get_config()
         lowerCAmelCase__     :List[Any]											=				3_0_0
         return config






       def 	snake_case		(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         self.parent.assertListEqual(list(result.loss.size() )       ,					[] )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :str											=				DebertaModel(config=__UpperCAmelCase )
         model.to(__UpperCAmelCase )
         model.eval()
         lowerCAmelCase__     :Dict											=				model(__UpperCAmelCase       ,					attention_mask=__UpperCAmelCase       ,					token_type_ids=__UpperCAmelCase )[0]
         lowerCAmelCase__     :List[str]											=				model(__UpperCAmelCase       ,					token_type_ids=__UpperCAmelCase )[0]
         lowerCAmelCase__     :str											=				model(__UpperCAmelCase )[0]

         self.parent.assertListEqual(list(sequence_output.size() )       ,					[self.batch_size, self.seq_length, self.hidden_size] )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Dict											=				DebertaForMaskedLM(config=__UpperCAmelCase )
         model.to(__UpperCAmelCase )
         model.eval()
         lowerCAmelCase__     :Tuple											=				model(__UpperCAmelCase       ,					attention_mask=__UpperCAmelCase       ,					token_type_ids=__UpperCAmelCase       ,					labels=__UpperCAmelCase )

         self.parent.assertEqual(result.logits.shape       ,					(self.batch_size, self.seq_length, self.vocab_size) )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Dict											=				self.num_labels
         lowerCAmelCase__     :List[str]											=				DebertaForSequenceClassification(__UpperCAmelCase )
         model.to(__UpperCAmelCase )
         model.eval()
         lowerCAmelCase__     :Tuple											=				model(__UpperCAmelCase       ,					attention_mask=__UpperCAmelCase       ,					token_type_ids=__UpperCAmelCase       ,					labels=__UpperCAmelCase )
         self.parent.assertListEqual(list(result.logits.size() )       ,					[self.batch_size, self.num_labels] )
         self.check_loss_output(__UpperCAmelCase )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Tuple											=				self.num_labels
         lowerCAmelCase__     :int											=				DebertaForTokenClassification(config=__UpperCAmelCase )
         model.to(__UpperCAmelCase )
         model.eval()
         lowerCAmelCase__     :Dict											=				model(__UpperCAmelCase       ,					attention_mask=__UpperCAmelCase       ,					token_type_ids=__UpperCAmelCase       ,					labels=__UpperCAmelCase )
         self.parent.assertEqual(result.logits.shape       ,					(self.batch_size, self.seq_length, self.num_labels) )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Dict											=				DebertaForQuestionAnswering(config=__UpperCAmelCase )
         model.to(__UpperCAmelCase )
         model.eval()
         lowerCAmelCase__     :Tuple											=				model(
             __UpperCAmelCase       ,					attention_mask=__UpperCAmelCase       ,					token_type_ids=__UpperCAmelCase       ,					start_positions=__UpperCAmelCase       ,					end_positions=__UpperCAmelCase       ,					)
         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 ):



         '''simple docstring'''

         lowerCAmelCase__     :int											=				self.prepare_config_and_inputs()
         (
             (
             lowerCAmelCase__
         )				,							(
             lowerCAmelCase__
         )				,							(
             lowerCAmelCase__
         )				,							(
             lowerCAmelCase__
         )				,							(
             lowerCAmelCase__
         )				,							(
             lowerCAmelCase__
         )				,							(
             lowerCAmelCase__
         )				,							
         )     :Optional[Any]											=				config_and_inputs
         lowerCAmelCase__     :Optional[int]											=				{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
         return config, inputs_dict






@require_torch
class    _lowerCAmelCase  (	a    ,  a    ,  unittest.TestCase			):
       """simple docstring"""




       __magic_name__	:List[Any]						    =   (
           (
               DebertaModel,
               DebertaForMaskedLM,
               DebertaForSequenceClassification,
               DebertaForTokenClassification,
               DebertaForQuestionAnswering,
           )
           if is_torch_available()
           else ()
       )
       __magic_name__	:List[str]						    =   (
           {
               """feature-extraction""": DebertaModel,
               """fill-mask""": DebertaForMaskedLM,
               """question-answering""": DebertaForQuestionAnswering,
               """text-classification""": DebertaForSequenceClassification,
               """token-classification""": DebertaForTokenClassification,
               """zero-shot""": DebertaForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )

       __magic_name__	:str						    =   True
       __magic_name__	:Tuple						    =   False
       __magic_name__	:int						    =   False
       __magic_name__	:Optional[int]						    =   False
       __magic_name__	:List[str]						    =   False






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[Any]											=				DebertaModelTester(self )
         lowerCAmelCase__     :Optional[Any]											=				ConfigTester(self       ,					config_class=__UpperCAmelCase       ,					hidden_size=3_7 )






       def 	snake_case		(       self ):



         '''simple docstring'''

         self.config_tester.run_common_tests()






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[int]											=				self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_model(*__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Dict											=				self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_for_sequence_classification(*__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Union[str, Any]											=				self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_for_masked_lm(*__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Tuple											=				self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_for_question_answering(*__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Tuple											=				self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_for_token_classification(*__UpperCAmelCase )






       @slow
       def 	snake_case		(       self ):



         '''simple docstring'''

         for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           lowerCAmelCase__     :Dict											=				DebertaModel.from_pretrained(__UpperCAmelCase )
           self.assertIsNotNone(__UpperCAmelCase )






@require_torch
@require_sentencepiece
@require_tokenizers
class    _lowerCAmelCase  (	unittest.TestCase			):
       """simple docstring"""




       @unittest.skip(reason='Model not available yet' )
       def 	snake_case		(       self ):



         '''simple docstring'''

         pass






       @slow
       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Union[str, Any]											=				DebertaModel.from_pretrained('microsoft/deberta-base' )

         lowerCAmelCase__     :Any											=				torch.tensor([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]] )
         lowerCAmelCase__     :List[Any]											=				torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
         with torch.no_grad():
           lowerCAmelCase__     :Optional[Any]											=				model(__UpperCAmelCase       ,					attention_mask=__UpperCAmelCase )[0]
         # compare the actual values for a slice.
         lowerCAmelCase__     :Any											=				torch.tensor(
             [[[-0.59_86, -0.80_55, -0.84_62], [1.44_84, -0.93_48, -0.80_59], [0.31_23, 0.00_32, -1.41_31]]] )
         self.assertTrue(torch.allclose(output[:, 1:4, 1:4]       ,					__UpperCAmelCase       ,					atol=1E-4 )       ,					F"{output[:, 1:4, 1:4]}" )







"""simple docstring"""





import random
import unittest

import numpy as np

from diffusers import (
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionImgaImgPipeline,
    PNDMScheduler,
)
from diffusers.utils import floats_tensor
from diffusers.utils.testing_utils import (
    is_onnx_available,
    load_image,
    nightly,
    require_onnxruntime,
    require_torch_gpu,
)

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
  import onnxruntime as ort






class    _lowerCAmelCase  (	a    ,  unittest.TestCase			):
       """simple docstring"""




       __magic_name__	:int						    =   """hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline"""






       def 	snake_case		(       self       ,					__UpperCAmelCase=0 ):



         '''simple docstring'''

         lowerCAmelCase__     :List[str]											=				floats_tensor((1, 3, 1_2_8, 1_2_8)       ,					rng=random.Random(__UpperCAmelCase ) )
         lowerCAmelCase__     :List[str]											=				np.random.RandomState(__UpperCAmelCase )
         lowerCAmelCase__     :List[str]											=				{
             'prompt': 'A painting of a squirrel eating a burger',
             'image': image,
             'generator': generator,
             'num_inference_steps': 3,
             'strength': 0.75,
             'guidance_scale': 7.5,
             'output_type': 'numpy',
         }
         return inputs






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[Any]											=				OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint       ,					provider='CPUExecutionProvider' )
         pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         lowerCAmelCase__     :Union[str, Any]											=				self.get_dummy_inputs()
         lowerCAmelCase__     :Optional[int]											=				pipe(**__UpperCAmelCase ).images
         lowerCAmelCase__     :Union[str, Any]											=				image[0, -3:, -3:, -1].flatten()

         assert image.shape == (1, 1_2_8, 1_2_8, 3)
         lowerCAmelCase__     :Union[str, Any]											=				np.array([0.6_96_43, 0.5_84_84, 0.5_03_14, 0.5_87_60, 0.5_53_68, 0.5_96_43, 0.5_15_29, 0.4_12_17, 0.4_90_87] )
         assert np.abs(image_slice - expected_slice ).max() < 1E-1






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[int]											=				OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint       ,					provider='CPUExecutionProvider' )
         lowerCAmelCase__     :str											=				PNDMScheduler.from_config(pipe.scheduler.config       ,					skip_prk_steps=__UpperCAmelCase )
         pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         lowerCAmelCase__     :Tuple											=				self.get_dummy_inputs()
         lowerCAmelCase__     :Optional[Any]											=				pipe(**__UpperCAmelCase ).images
         lowerCAmelCase__     :Any											=				image[0, -3:, -3:, -1]

         assert image.shape == (1, 1_2_8, 1_2_8, 3)
         lowerCAmelCase__     :int											=				np.array([0.6_17_37, 0.5_46_42, 0.5_31_83, 0.5_44_65, 0.5_27_42, 0.6_05_25, 0.4_99_69, 0.4_06_55, 0.4_81_54] )

         assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-1






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[int]											=				OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint       ,					provider='CPUExecutionProvider' )
         lowerCAmelCase__     :List[str]											=				LMSDiscreteScheduler.from_config(pipe.scheduler.config )
         pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         # warmup pass to apply optimizations
         lowerCAmelCase__     :List[Any]											=				pipe(**self.get_dummy_inputs() )

         lowerCAmelCase__     :Tuple											=				self.get_dummy_inputs()
         lowerCAmelCase__     :int											=				pipe(**__UpperCAmelCase ).images
         lowerCAmelCase__     :Any											=				image[0, -3:, -3:, -1]

         assert image.shape == (1, 1_2_8, 1_2_8, 3)
         lowerCAmelCase__     :Union[str, Any]											=				np.array([0.5_27_61, 0.5_99_77, 0.4_90_33, 0.4_96_19, 0.5_42_82, 0.5_03_11, 0.4_76_00, 0.4_09_18, 0.4_52_03] )

         assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-1






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[Any]											=				OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint       ,					provider='CPUExecutionProvider' )
         lowerCAmelCase__     :Dict											=				EulerDiscreteScheduler.from_config(pipe.scheduler.config )
         pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         lowerCAmelCase__     :Any											=				self.get_dummy_inputs()
         lowerCAmelCase__     :List[str]											=				pipe(**__UpperCAmelCase ).images
         lowerCAmelCase__     :List[str]											=				image[0, -3:, -3:, -1]

         assert image.shape == (1, 1_2_8, 1_2_8, 3)
         lowerCAmelCase__     :Optional[int]											=				np.array([0.5_29_11, 0.6_00_04, 0.4_92_29, 0.4_98_05, 0.5_45_02, 0.5_06_80, 0.4_77_77, 0.4_10_28, 0.4_53_04] )

         assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-1






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :str											=				OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint       ,					provider='CPUExecutionProvider' )
         lowerCAmelCase__     :str											=				EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config )
         pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         lowerCAmelCase__     :Tuple											=				self.get_dummy_inputs()
         lowerCAmelCase__     :Any											=				pipe(**__UpperCAmelCase ).images
         lowerCAmelCase__     :Optional[int]											=				image[0, -3:, -3:, -1]

         assert image.shape == (1, 1_2_8, 1_2_8, 3)
         lowerCAmelCase__     :int											=				np.array([0.5_29_11, 0.6_00_04, 0.4_92_29, 0.4_98_05, 0.5_45_02, 0.5_06_80, 0.4_77_77, 0.4_10_28, 0.4_53_04] )

         assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-1






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :List[Any]											=				OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint       ,					provider='CPUExecutionProvider' )
         lowerCAmelCase__     :List[Any]											=				DPMSolverMultistepScheduler.from_config(pipe.scheduler.config )
         pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         lowerCAmelCase__     :Any											=				self.get_dummy_inputs()
         lowerCAmelCase__     :List[Any]											=				pipe(**__UpperCAmelCase ).images
         lowerCAmelCase__     :int											=				image[0, -3:, -3:, -1]

         assert image.shape == (1, 1_2_8, 1_2_8, 3)
         lowerCAmelCase__     :Optional[Any]											=				np.array([0.6_53_31, 0.5_82_77, 0.4_82_04, 0.5_60_59, 0.5_36_65, 0.5_62_35, 0.5_09_69, 0.4_00_09, 0.4_65_52] )

         assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-1






@nightly
@require_onnxruntime
@require_torch_gpu
class    _lowerCAmelCase  (	unittest.TestCase			):
       """simple docstring"""




       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

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






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Tuple											=				ort.SessionOptions()
         lowerCAmelCase__     :Optional[int]											=				False
         return options






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Any											=				load_image(
             'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
             '/img2img/sketch-mountains-input.jpg' )
         lowerCAmelCase__     :Any											=				init_image.resize((7_6_8, 5_1_2) )
         # using the PNDM scheduler by default
         lowerCAmelCase__     :Optional[int]											=				OnnxStableDiffusionImgaImgPipeline.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 )

         lowerCAmelCase__     :List[Any]											=				'A fantasy landscape, trending on artstation'

         lowerCAmelCase__     :Optional[Any]											=				np.random.RandomState(0 )
         lowerCAmelCase__     :List[str]											=				pipe(
             prompt=__UpperCAmelCase       ,					image=__UpperCAmelCase       ,					strength=0.75       ,					guidance_scale=7.5       ,					num_inference_steps=1_0       ,					generator=__UpperCAmelCase       ,					output_type='np'       ,					)
         lowerCAmelCase__     :Any											=				output.images
         lowerCAmelCase__     :List[str]											=				images[0, 2_5_5:2_5_8, 3_8_3:3_8_6, -1]

         assert images.shape == (1, 5_1_2, 7_6_8, 3)
         lowerCAmelCase__     :List[Any]											=				np.array([0.49_09, 0.50_59, 0.53_72, 0.46_23, 0.48_76, 0.50_49, 0.48_20, 0.49_56, 0.50_19] )
         # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

         assert np.abs(image_slice.flatten() - expected_slice ).max() < 2E-2






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Union[str, Any]											=				load_image(
             'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
             '/img2img/sketch-mountains-input.jpg' )
         lowerCAmelCase__     :Optional[Any]											=				init_image.resize((7_6_8, 5_1_2) )
         lowerCAmelCase__     :List[Any]											=				LMSDiscreteScheduler.from_pretrained(
             'runwayml/stable-diffusion-v1-5'       ,					subfolder='scheduler'       ,					revision='onnx' )
         lowerCAmelCase__     :Optional[Any]											=				OnnxStableDiffusionImgaImgPipeline.from_pretrained(
             'runwayml/stable-diffusion-v1-5'       ,					revision='onnx'       ,					scheduler=__UpperCAmelCase       ,					safety_checker=__UpperCAmelCase       ,					feature_extractor=__UpperCAmelCase       ,					provider=self.gpu_provider       ,					sess_options=self.gpu_options       ,					)
         pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         lowerCAmelCase__     :List[Any]											=				'A fantasy landscape, trending on artstation'

         lowerCAmelCase__     :List[Any]											=				np.random.RandomState(0 )
         lowerCAmelCase__     :List[Any]											=				pipe(
             prompt=__UpperCAmelCase       ,					image=__UpperCAmelCase       ,					strength=0.75       ,					guidance_scale=7.5       ,					num_inference_steps=2_0       ,					generator=__UpperCAmelCase       ,					output_type='np'       ,					)
         lowerCAmelCase__     :Optional[Any]											=				output.images
         lowerCAmelCase__     :int											=				images[0, 2_5_5:2_5_8, 3_8_3:3_8_6, -1]

         assert images.shape == (1, 5_1_2, 7_6_8, 3)
         lowerCAmelCase__     :List[Any]											=				np.array([0.80_43, 0.9_26, 0.95_81, 0.81_19, 0.89_54, 0.9_13, 0.72_09, 0.74_63, 0.74_31] )
         # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

         assert np.abs(image_slice.flatten() - expected_slice ).max() < 2E-2
