





import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
     from transformers.models.roberta.modeling_flax_roberta import (
         FlaxRobertaForCausalLM,
         FlaxRobertaForMaskedLM,
         FlaxRobertaForMultipleChoice,
         FlaxRobertaForQuestionAnswering,
         FlaxRobertaForSequenceClassification,
         FlaxRobertaForTokenClassification,
         FlaxRobertaModel,
     )



class     _UpperCAmelCase   (   unittest.TestCase   ):

  """simple docstring"""


  def __init__(    self			:		str ,  lowerCAmelCase_			:		Optional[int] ,  lowerCAmelCase_			:		Optional[Any]=1_3 ,  lowerCAmelCase_			:		Tuple=7 ,  lowerCAmelCase_			:		Tuple=True ,  lowerCAmelCase_			:		str=True ,  lowerCAmelCase_			:		Optional[int]=True ,  lowerCAmelCase_			:		int=True ,  lowerCAmelCase_			:		Any=9_9 ,  lowerCAmelCase_			:		Dict=3_2 ,  lowerCAmelCase_			:		Tuple=5 ,  lowerCAmelCase_			:		List[str]=4 ,  lowerCAmelCase_			:		Optional[int]=3_7 ,  lowerCAmelCase_			:		Dict="gelu" ,  lowerCAmelCase_			:		int=0.1 ,  lowerCAmelCase_			:		int=0.1 ,  lowerCAmelCase_			:		Optional[int]=5_1_2 ,  lowerCAmelCase_			:		Any=1_6 ,  lowerCAmelCase_			:		List[Any]=2 ,  lowerCAmelCase_			:		Dict=0.02 ,  lowerCAmelCase_			:		Dict=4 ,  )							->						List[str]:
     __lowerCAmelCase							     =     parent
     __lowerCAmelCase							     =     batch_size
     __lowerCAmelCase							     =     seq_length
     __lowerCAmelCase							     =     is_training
     __lowerCAmelCase							     =     use_attention_mask
     __lowerCAmelCase							     =     use_token_type_ids
     __lowerCAmelCase							     =     use_labels
     __lowerCAmelCase							     =     vocab_size
     __lowerCAmelCase							     =     hidden_size
     __lowerCAmelCase							     =     num_hidden_layers
     __lowerCAmelCase							     =     num_attention_heads
     __lowerCAmelCase							     =     intermediate_size
     __lowerCAmelCase							     =     hidden_act
     __lowerCAmelCase							     =     hidden_dropout_prob
     __lowerCAmelCase							     =     attention_probs_dropout_prob
     __lowerCAmelCase							     =     max_position_embeddings
     __lowerCAmelCase							     =     type_vocab_size
     __lowerCAmelCase							     =     type_sequence_label_size
     __lowerCAmelCase							     =     initializer_range
     __lowerCAmelCase							     =     num_choices






  def     lowercase		(    self			:		List[str]					)							->						Union[str, Any]:
     __lowerCAmelCase							     =     ids_tensor([self.batch_size, self.seq_length] ,  self.vocab_size					)

     __lowerCAmelCase							     =     None
     if self.use_attention_mask:
        __lowerCAmelCase							     =     random_attention_mask([self.batch_size, self.seq_length]					)

     __lowerCAmelCase							     =     None
     if self.use_token_type_ids:
        __lowerCAmelCase							     =     ids_tensor([self.batch_size, self.seq_length] ,  self.type_vocab_size					)

     __lowerCAmelCase							     =     RobertaConfig(
         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 ,  is_decoder=lowerCAmelCase_ ,  initializer_range=self.initializer_range ,  )

     return config, input_ids, token_type_ids, attention_mask






  def     lowercase		(    self			:		Union[str, Any]					)							->						List[Any]:
     __lowerCAmelCase							     =     self.prepare_config_and_inputs()
     __lowerCAmelCase     ,     __lowerCAmelCase     ,     __lowerCAmelCase     ,     __lowerCAmelCase							     =     config_and_inputs
     __lowerCAmelCase							     =     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
     return config, inputs_dict






  def     lowercase		(    self			:		Any					)							->						Dict:
     __lowerCAmelCase							     =     self.prepare_config_and_inputs()
     __lowerCAmelCase     ,     __lowerCAmelCase     ,     __lowerCAmelCase     ,     __lowerCAmelCase							     =     config_and_inputs

     __lowerCAmelCase							     =     True
     __lowerCAmelCase							     =     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]					)
     __lowerCAmelCase							     =     ids_tensor([self.batch_size, self.seq_length] ,  vocab_size=2					)

     return (
         config,
         input_ids,
         token_type_ids,
         encoder_hidden_states,
         encoder_attention_mask,
     )





@require_flax
class     _UpperCAmelCase   (   _UpperCamelCase		,   unittest.TestCase   ):

  """simple docstring"""


  a_      =			True

  a_      =			(
      (
          FlaxRobertaModel,
          FlaxRobertaForCausalLM,
          FlaxRobertaForMaskedLM,
          FlaxRobertaForSequenceClassification,
          FlaxRobertaForTokenClassification,
          FlaxRobertaForMultipleChoice,
          FlaxRobertaForQuestionAnswering,
      )
      if is_flax_available()
      else ()
  )






  def     lowercase		(    self			:		Any					)							->						Any:
     __lowerCAmelCase							     =     FlaxRobertaModelTester(self					)






  @slow
  def     lowercase		(    self			:		List[str]					)							->						Optional[int]:
     for model_class_name in self.all_model_classes:
        __lowerCAmelCase							     =     model_class_name.from_pretrained('roberta-base' ,  from_pt=lowerCAmelCase_					)
        __lowerCAmelCase							     =     model(np.ones((1, 1)					)					)
        self.assertIsNotNone(lowerCAmelCase_					)








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     _UpperCAmelCase   (   unittest.TestCase   ):

  """simple docstring"""


  @property
  def     lowercase		(    self			:		Union[str, Any]					)							->						Tuple:
     return (
         "CUDAExecutionProvider",
         {
             "gpu_mem_limit": "15000000000",  # 15GB
             "arena_extend_strategy": "kSameAsRequested",
         },
     )






  @property
  def     lowercase		(    self			:		List[Any]					)							->						int:
     __lowerCAmelCase							     =     ort.SessionOptions()
     __lowerCAmelCase							     =     False
     return options






  def     lowercase		(    self			:		Tuple					)							->						List[Any]:
     __lowerCAmelCase							     =     load_image(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
         '/in_paint/overture-creations-5sI6fQgYIuo.png'					)
     __lowerCAmelCase							     =     load_image(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
         '/in_paint/overture-creations-5sI6fQgYIuo_mask.png'					)
     __lowerCAmelCase							     =     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
     __lowerCAmelCase							     =     OnnxStableDiffusionInpaintPipelineLegacy.from_pretrained(
         'CompVis/stable-diffusion-v1-4' ,  revision='onnx' ,  safety_checker=lowerCAmelCase_ ,  feature_extractor=lowerCAmelCase_ ,  provider=self.gpu_provider ,  sess_options=self.gpu_options ,  )
     pipe.set_progress_bar_config(disable=lowerCAmelCase_					)

     __lowerCAmelCase							     =     'A red cat sitting on a park bench'

     __lowerCAmelCase							     =     np.random.RandomState(0					)
     __lowerCAmelCase							     =     pipe(
         prompt=lowerCAmelCase_ ,  image=lowerCAmelCase_ ,  mask_image=lowerCAmelCase_ ,  strength=0.75 ,  guidance_scale=7.5 ,  num_inference_steps=1_5 ,  generator=lowerCAmelCase_ ,  output_type='np' ,  )

     __lowerCAmelCase							     =     output.images[0]

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

