
'''simple docstring'''







import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()


@slow
@require_torch_gpu
class 						__UpperCAmelCase      (					unittest.TestCase						):


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								super().tearDown()
								gc.collect()
								torch.cuda.empty_cache()


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		StableDiffusionKDiffusionPipeline.from_pretrained('CompVis/stable-diffusion-v1-4'  )
								_snake_case   						=		sd_pipe.to(lowerCAmelCase_  )
								sd_pipe.set_progress_bar_config(disable=lowerCAmelCase_  )

								sd_pipe.set_scheduler('sample_euler'  )

								_snake_case   						=		'A painting of a squirrel eating a burger'
								_snake_case   						=		torch.manual_seed(0  )
								_snake_case   						=		sd_pipe([prompt]    ,   generator=lowerCAmelCase_    ,   guidance_scale=9.0    ,   num_inference_steps=20    ,   output_type='np'  )

								_snake_case   						=		output.images

								_snake_case   						=		image[0, -3:, -3:, -1]

								assert image.shape == (1, 5_12, 5_12, 3)
								_snake_case   						=		np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]  )

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


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'  )
								_snake_case   						=		sd_pipe.to(lowerCAmelCase_  )
								sd_pipe.set_progress_bar_config(disable=lowerCAmelCase_  )

								sd_pipe.set_scheduler('sample_euler'  )

								_snake_case   						=		'A painting of a squirrel eating a burger'
								_snake_case   						=		torch.manual_seed(0  )
								_snake_case   						=		sd_pipe([prompt]    ,   generator=lowerCAmelCase_    ,   guidance_scale=9.0    ,   num_inference_steps=20    ,   output_type='np'  )

								_snake_case   						=		output.images

								_snake_case   						=		image[0, -3:, -3:, -1]

								assert image.shape == (1, 5_12, 5_12, 3)
								_snake_case   						=		np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]  )

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




							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'  )
								_snake_case   						=		sd_pipe.to(lowerCAmelCase_  )
								sd_pipe.set_progress_bar_config(disable=lowerCAmelCase_  )

								sd_pipe.set_scheduler('sample_dpmpp_2m'  )

								_snake_case   						=		'A painting of a squirrel eating a burger'
								_snake_case   						=		torch.manual_seed(0  )
								_snake_case   						=		sd_pipe(
								    [prompt]    ,   generator=lowerCAmelCase_    ,   guidance_scale=7.5    ,   num_inference_steps=15    ,   output_type='np'    ,   use_karras_sigmas=lowerCAmelCase_    ,   )

								_snake_case   						=		output.images

								_snake_case   						=		image[0, -3:, -3:, -1]

								assert image.shape == (1, 5_12, 5_12, 3)
								_snake_case   						=		np.array(
								    [0.11381689, 0.12112921, 0.1389457, 0.12549606, 0.1244964, 0.10831517, 0.11562866, 0.10867816, 0.10499048]  )

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



import unittest

from transformers import AutoTokenizer, is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, slow


if is_flax_available():
			import jax.numpy as jnp

			from transformers import FlaxXLMRobertaModel




@require_sentencepiece
@require_tokenizers
@require_flax
class    SCREAMING_SNAKE_CASE__     (	unittest.TestCase					):





	'''simple docstring'''



	@slow
	def  A							(  self	:    int	):


				'''simple docstring'''


				_snake_case		=			FlaxXLMRobertaModel.from_pretrained('xlm-roberta-base'	)
				_snake_case		=			AutoTokenizer.from_pretrained('xlm-roberta-base'	)
				_snake_case		=			'The dog is cute and lives in the garden house'
				_snake_case		=			jnp.array([tokenizer.encode(lowercase	)]	)

				_snake_case		=			(1, 12, 768)  # batch_size, sequence_length, embedding_vector_dim
				_snake_case		=			jnp.array(
				    [[-0.0101, 0.1218, -0.0803, 0.0801, 0.1327, 0.0776, -0.1215, 0.2383, 0.3338, 0.3106, 0.0300, 0.0252]]	)

				_snake_case		=			model(lowercase	)['last_hidden_state']
				self.assertEqual(output.shape			,  lowercase	)
				# compare the actual values for a slice of last dim
				self.assertTrue(jnp.allclose(output[:, :, -1]			,  lowercase			,  atol=1E-3	)	)