






"""simple docstring"""


import unittest

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


if is_torch_available():
		import torch

		from transformers import XLMRobertaModel




@require_sentencepiece
@require_tokenizers
@require_torch
class 						__UpperCamelCase     (     unittest.TestCase						):
					@slow
					def        UpperCAmelCase__ (							self							:	Tuple   )	->       List[str]:
											lowerCAmelCase   :Dict						=			XLMRobertaModel.from_pretrained('xlm-roberta-base'   )
											lowerCAmelCase   :Optional[Any]						=			torch.tensor([[0, 581, 1_0269, 83, 9_9942, 136, 6_0742, 23, 70, 8_0583, 1_8276, 2]]   )
											# The dog is cute and lives in the garden house

											lowerCAmelCase   :List[Any]						=			torch.Size((1, 12, 768)   )  # batch_size, sequence_length, embedding_vector_dim
											lowerCAmelCase   :str						=			torch.tensor(
											    [[-0.0_1_0_1, 0.1_2_1_8, -0.0_8_0_3, 0.0_8_0_1, 0.1_3_2_7, 0.0_7_7_6, -0.1_2_1_5, 0.2_3_8_3, 0.3_3_3_8, 0.3_1_0_6, 0.0_3_0_0, 0.0_2_5_2]]   )
											#  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')
											#  xlmr.eval()
											#  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
											with torch.no_grad():
																	lowerCAmelCase   :Any						=			model(UpperCAmelCase   )['last_hidden_state'].detach()
											self.assertEqual(output.shape     , UpperCAmelCase   )
											# compare the actual values for a slice of last dim
											self.assertTrue(torch.allclose(output[:, :, -1]     , UpperCAmelCase     , atol=1e-3   )   )
					@slow
					def        UpperCAmelCase__ (							self							:	Union[str, Any]   )	->       Optional[Any]:
											lowerCAmelCase   :Any						=			XLMRobertaModel.from_pretrained('xlm-roberta-large'   )
											lowerCAmelCase   :str						=			torch.tensor([[0, 581, 1_0269, 83, 9_9942, 136, 6_0742, 23, 70, 8_0583, 1_8276, 2]]   )
											# The dog is cute and lives in the garden house

											lowerCAmelCase   :Dict						=			torch.Size((1, 12, 1024)   )  # batch_size, sequence_length, embedding_vector_dim
											lowerCAmelCase   :Optional[Any]						=			torch.tensor(
											    [[-0.0_6_9_9, -0.0_3_1_8, 0.0_7_0_5, -0.1_2_4_1, 0.0_9_9_9, -0.0_5_2_0, 0.1_0_0_4, -0.1_8_3_8, -0.4_7_0_4, 0.1_4_3_7, 0.0_8_2_1, 0.0_1_2_6]]   )
											#  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.large')
											#  xlmr.eval()
											#  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
											with torch.no_grad():
																	lowerCAmelCase   :int						=			model(UpperCAmelCase   )['last_hidden_state'].detach()
											self.assertEqual(output.shape     , UpperCAmelCase   )
											# compare the actual values for a slice of last dim
											self.assertTrue(torch.allclose(output[:, :, -1]     , UpperCAmelCase     , atol=1e-3   )   )







"""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 						__UpperCamelCase     (     unittest.TestCase						):
					@property
					def        UpperCAmelCase__ (							self							:	Union[str, Any]   )	->       Dict:
											return (
											    "CUDAExecutionProvider",
											    {
											        "gpu_mem_limit": "15000000000",  # 15GB
											        "arena_extend_strategy": "kSameAsRequested",
											    },
											)
					@property
					def        UpperCAmelCase__ (							self							:	int   )	->       Optional[Any]:
											lowerCAmelCase   :Any						=			ort.SessionOptions()
											lowerCAmelCase   :Dict						=			False
											return options
					def        UpperCAmelCase__ (							self							:	Tuple   )	->       str:
											lowerCAmelCase   :Union[str, Any]						=			load_image(
											    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
											    '/in_paint/overture-creations-5sI6fQgYIuo.png'   )
											lowerCAmelCase   :str						=			load_image(
											    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
											    '/in_paint/overture-creations-5sI6fQgYIuo_mask.png'   )
											lowerCAmelCase   :List[Any]						=			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   :Tuple						=			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   )

											lowerCAmelCase   :Optional[Any]						=			'A red cat sitting on a park bench'

											lowerCAmelCase   :Optional[Any]						=			np.random.RandomState(0   )
											lowerCAmelCase   :Union[str, Any]						=			pipe(
											    prompt=UpperCAmelCase     , image=UpperCAmelCase     , mask_image=UpperCAmelCase     , strength=0.7_5     , guidance_scale=7.5     , num_inference_steps=15     , generator=UpperCAmelCase     , output_type='np'     , )

											lowerCAmelCase   :Optional[int]						=			output.images[0]

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