'''simple docstring'''







import unittest

from transformers import (
    MODEL_FOR_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
    TextGenerationPipeline,
    logging,
    pipeline,
)
from transformers.testing_utils import (
    CaptureLogger,
    is_pipeline_test,
    require_accelerate,
    require_tf,
    require_torch,
    require_torch_gpu,
    require_torch_or_tf,
)

from .test_pipelines_common import ANY




@is_pipeline_test
@require_torch_or_tf
class _SCREAMING_SNAKE_CASE(							unittest.TestCase					):
						A_			:							Tuple     		= MODEL_FOR_CAUSAL_LM_MAPPING
						A_			:							List[Any]     		= TF_MODEL_FOR_CAUSAL_LM_MAPPING




						@require_torch
						def      __lowerCamelCase       (    self :       Tuple      )     ->				List[Any]:
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = pipeline(task='text-generation'							,							model='sshleifer/tiny-ctrl'							,							framework='pt'      )
													# Using `do_sample=False` to force deterministic output
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = text_generator('This is a test'							,							do_sample=UpperCamelCase_      )
													self.assertEqual(
													    UpperCamelCase_							,							[
													        {
													            'generated_text': (
													                'This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope.'
													                ' oscope. FiliFili@@'
													            )
													        }
													    ]							,							)

													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = text_generator(['This is a test', 'This is a second test']      )
													self.assertEqual(
													    UpperCamelCase_							,							[
													        [
													            {
													                'generated_text': (
													                    'This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope.'
													                    ' oscope. FiliFili@@'
													                )
													            }
													        ],
													        [
													            {
													                'generated_text': (
													                    'This is a second test ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy'
													                    ' oscope. oscope. FiliFili@@'
													                )
													            }
													        ],
													    ]							,							)

													SCREAMING_SNAKE_CASE__     :Tuple						    = text_generator('This is a test'							,							do_sample=UpperCamelCase_							,							num_return_sequences=2							,							return_tensors=UpperCamelCase_      )
													self.assertEqual(
													    UpperCamelCase_							,							[
													        {'generated_token_ids': ANY(UpperCamelCase_      )},
													        {'generated_token_ids': ANY(UpperCamelCase_      )},
													    ]							,							)
													SCREAMING_SNAKE_CASE__     :int						    = text_generator.model.config.eos_token_id
													SCREAMING_SNAKE_CASE__     :Tuple						    = '<pad>'
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = text_generator(
													    ['This is a test', 'This is a second test']							,							do_sample=UpperCamelCase_							,							num_return_sequences=2							,							batch_size=2							,							return_tensors=UpperCamelCase_							,							)
													self.assertEqual(
													    UpperCamelCase_							,							[
													        [
													            {'generated_token_ids': ANY(UpperCamelCase_      )},
													            {'generated_token_ids': ANY(UpperCamelCase_      )},
													        ],
													        [
													            {'generated_token_ids': ANY(UpperCamelCase_      )},
													            {'generated_token_ids': ANY(UpperCamelCase_      )},
													        ],
													    ]							,							)




						@require_tf
						def      __lowerCamelCase       (    self :       Tuple      )     ->				Tuple:
													SCREAMING_SNAKE_CASE__     :str						    = pipeline(task='text-generation'							,							model='sshleifer/tiny-ctrl'							,							framework='tf'      )

													# Using `do_sample=False` to force deterministic output
													SCREAMING_SNAKE_CASE__     :Dict						    = text_generator('This is a test'							,							do_sample=UpperCamelCase_      )
													self.assertEqual(
													    UpperCamelCase_							,							[
													        {
													            'generated_text': (
													                'This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵'
													                ' please,'
													            )
													        }
													    ]							,							)

													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = text_generator(['This is a test', 'This is a second test']							,							do_sample=UpperCamelCase_      )
													self.assertEqual(
													    UpperCamelCase_							,							[
													        [
													            {
													                'generated_text': (
													                    'This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵'
													                    ' please,'
													                )
													            }
													        ],
													        [
													            {
													                'generated_text': (
													                    'This is a second test Chieftain Chieftain prefecture prefecture prefecture Cannes Cannes'
													                    ' Cannes 閲閲Cannes Cannes Cannes 攵 please,'
													                )
													            }
													        ],
													    ]							,							)




						def      __lowerCamelCase       (    self :       str							,							UpperCamelCase_ :       Optional[Any]							,							UpperCamelCase_ :       List[Any]							,							UpperCamelCase_ :       Tuple      )     ->				int:
													SCREAMING_SNAKE_CASE__     :str						    = TextGenerationPipeline(model=UpperCamelCase_							,							tokenizer=UpperCamelCase_      )
													return text_generator, ["This is a test", "Another test"]




						def      __lowerCamelCase       (    self :       Any      )     ->				Dict:
													SCREAMING_SNAKE_CASE__     :Any						    = 'Hello I believe in'
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = pipeline('text-generation'							,							model='hf-internal-testing/tiny-random-gpt2'      )
													SCREAMING_SNAKE_CASE__     :Dict						    = text_generator(UpperCamelCase_      )
													self.assertEqual(
													    UpperCamelCase_							,							[{'generated_text': 'Hello I believe in fe fe fe fe fe fe fe fe fe fe fe fe'}]							,							)

													SCREAMING_SNAKE_CASE__     :Dict						    = text_generator(UpperCamelCase_							,							stop_sequence=' fe'      )
													self.assertEqual(UpperCamelCase_							,							[{'generated_text': 'Hello I believe in fe'}]      )




						def      __lowerCamelCase       (    self :       Dict							,							UpperCamelCase_ :       Dict							,							UpperCamelCase_ :       Optional[int]      )     ->				str:
													SCREAMING_SNAKE_CASE__     :Dict						    = text_generator.model
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = text_generator.tokenizer

													SCREAMING_SNAKE_CASE__     :str						    = text_generator('This is a test'      )
													self.assertEqual(UpperCamelCase_							,							[{'generated_text': ANY(UpperCamelCase_      )}]      )
													self.assertTrue(outputs[0]['generated_text'].startswith('This is a test'      )      )

													SCREAMING_SNAKE_CASE__     :int						    = text_generator('This is a test'							,							return_full_text=UpperCamelCase_      )
													self.assertEqual(UpperCamelCase_							,							[{'generated_text': ANY(UpperCamelCase_      )}]      )
													self.assertNotIn('This is a test'							,							outputs[0]['generated_text']      )

													SCREAMING_SNAKE_CASE__     :str						    = pipeline(task='text-generation'							,							model=UpperCamelCase_							,							tokenizer=UpperCamelCase_							,							return_full_text=UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Any						    = text_generator('This is a test'      )
													self.assertEqual(UpperCamelCase_							,							[{'generated_text': ANY(UpperCamelCase_      )}]      )
													self.assertNotIn('This is a test'							,							outputs[0]['generated_text']      )

													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = text_generator('This is a test'							,							return_full_text=UpperCamelCase_      )
													self.assertEqual(UpperCamelCase_							,							[{'generated_text': ANY(UpperCamelCase_      )}]      )
													self.assertTrue(outputs[0]['generated_text'].startswith('This is a test'      )      )

													SCREAMING_SNAKE_CASE__     :Any						    = text_generator(['This is great !', 'Something else']							,							num_return_sequences=2							,							do_sample=UpperCamelCase_      )
													self.assertEqual(
													    UpperCamelCase_							,							[
													        [{'generated_text': ANY(UpperCamelCase_      )}, {'generated_text': ANY(UpperCamelCase_      )}],
													        [{'generated_text': ANY(UpperCamelCase_      )}, {'generated_text': ANY(UpperCamelCase_      )}],
													    ]							,							)

													if text_generator.tokenizer.pad_token is not None:
																				SCREAMING_SNAKE_CASE__     :int						    = text_generator(
																				    ['This is great !', 'Something else']							,							num_return_sequences=2							,							batch_size=2							,							do_sample=UpperCamelCase_      )
																				self.assertEqual(
																				    UpperCamelCase_							,							[
																				        [{'generated_text': ANY(UpperCamelCase_      )}, {'generated_text': ANY(UpperCamelCase_      )}],
																				        [{'generated_text': ANY(UpperCamelCase_      )}, {'generated_text': ANY(UpperCamelCase_      )}],
																				    ]							,							)

													with self.assertRaises(UpperCamelCase_      ):
																				SCREAMING_SNAKE_CASE__     :Optional[int]						    = text_generator('test'							,							return_full_text=UpperCamelCase_							,							return_text=UpperCamelCase_      )
													with self.assertRaises(UpperCamelCase_      ):
																				SCREAMING_SNAKE_CASE__     :Dict						    = text_generator('test'							,							return_full_text=UpperCamelCase_							,							return_tensors=UpperCamelCase_      )
													with self.assertRaises(UpperCamelCase_      ):
																				SCREAMING_SNAKE_CASE__     :Tuple						    = text_generator('test'							,							return_text=UpperCamelCase_							,							return_tensors=UpperCamelCase_      )

													# Empty prompt is slighly special
													# it requires BOS token to exist.
													# Special case for Pegasus which will always append EOS so will
													# work even without BOS.
													if (
													    text_generator.tokenizer.bos_token_id is not None
													    or "Pegasus" in tokenizer.__class__.__name__
													    or "Git" in model.__class__.__name__
													):
																				SCREAMING_SNAKE_CASE__     :Any						    = text_generator(''      )
																				self.assertEqual(UpperCamelCase_							,							[{'generated_text': ANY(UpperCamelCase_      )}]      )
													else:
																				with self.assertRaises((ValueError, AssertionError)      ):
																											SCREAMING_SNAKE_CASE__     :Tuple						    = text_generator(''      )

													if text_generator.framework == "tf":
																				# TF generation does not support max_new_tokens, and it's impossible
																				# to control long generation with only max_length without
																				# fancy calculation, dismissing tests for now.
																				return
													# We don't care about infinite range models.
													# They already work.
													# Skip this test for XGLM, since it uses sinusoidal positional embeddings which are resized on-the-fly.
													SCREAMING_SNAKE_CASE__     :List[str]						    = ['RwkvForCausalLM', 'XGLMForCausalLM', 'GPTNeoXForCausalLM']
													if (
													    tokenizer.model_max_length < 1_00_00
													    and text_generator.model.__class__.__name__ not in EXTRA_MODELS_CAN_HANDLE_LONG_INPUTS
													):
																				# Handling of large generations
																				with self.assertRaises((RuntimeError, IndexError, ValueError, AssertionError)      ):
																											text_generator('This is a test' * 5_00							,							max_new_tokens=20      )

																				SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = text_generator('This is a test' * 5_00							,							handle_long_generation='hole'							,							max_new_tokens=20      )
																				# Hole strategy cannot work
																				with self.assertRaises(UpperCamelCase_      ):
																											text_generator(
																											    'This is a test' * 5_00							,							handle_long_generation='hole'							,							max_new_tokens=tokenizer.model_max_length + 10							,							)




						@require_torch
						@require_accelerate
						@require_torch_gpu
						def      __lowerCamelCase       (    self :       List[str]      )     ->				Union[str, Any]:
													import torch

													# Classic `model_kwargs`
													SCREAMING_SNAKE_CASE__     :Dict						    = pipeline(
													    model='hf-internal-testing/tiny-random-bloom'							,							model_kwargs={'device_map': 'auto', 'torch_dtype': torch.bfloataa}							,							)
													self.assertEqual(pipe.model.device							,							torch.device(0      )      )
													self.assertEqual(pipe.model.lm_head.weight.dtype							,							torch.bfloataa      )
													SCREAMING_SNAKE_CASE__     :Tuple						    = pipe('This is a test'      )
													self.assertEqual(
													    UpperCamelCase_							,							[
													        {
													            'generated_text': (
													                'This is a test test test test test test test test test test test test test test test test'
													                ' test'
													            )
													        }
													    ]							,							)

													# Upgraded those two to real pipeline arguments (they just get sent for the model as they're unlikely to mean anything else.)
													SCREAMING_SNAKE_CASE__     :List[str]						    = pipeline(model='hf-internal-testing/tiny-random-bloom'							,							device_map='auto'							,							torch_dtype=torch.bfloataa      )
													self.assertEqual(pipe.model.device							,							torch.device(0      )      )
													self.assertEqual(pipe.model.lm_head.weight.dtype							,							torch.bfloataa      )
													SCREAMING_SNAKE_CASE__     :str						    = pipe('This is a test'      )
													self.assertEqual(
													    UpperCamelCase_							,							[
													        {
													            'generated_text': (
													                'This is a test test test test test test test test test test test test test test test test'
													                ' test'
													            )
													        }
													    ]							,							)

													# torch_dtype will be automatically set to float32 if not provided - check: https://github.com/huggingface/transformers/pull/20602
													SCREAMING_SNAKE_CASE__     :Optional[int]						    = pipeline(model='hf-internal-testing/tiny-random-bloom'							,							device_map='auto'      )
													self.assertEqual(pipe.model.device							,							torch.device(0      )      )
													self.assertEqual(pipe.model.lm_head.weight.dtype							,							torch.floataa      )
													SCREAMING_SNAKE_CASE__     :Optional[int]						    = pipe('This is a test'      )
													self.assertEqual(
													    UpperCamelCase_							,							[
													        {
													            'generated_text': (
													                'This is a test test test test test test test test test test test test test test test test'
													                ' test'
													            )
													        }
													    ]							,							)




						@require_torch
						@require_torch_gpu
						def      __lowerCamelCase       (    self :       List[Any]      )     ->				Dict:
													import torch

													SCREAMING_SNAKE_CASE__     :Tuple						    = pipeline(model='hf-internal-testing/tiny-random-bloom'							,							device=0							,							torch_dtype=torch.floataa      )
													pipe('This is a test'      )




						@require_torch
						@require_accelerate
						@require_torch_gpu
						def      __lowerCamelCase       (    self :       List[str]      )     ->				Optional[Any]:
													import torch

													SCREAMING_SNAKE_CASE__     :Any						    = pipeline(model='hf-internal-testing/tiny-random-bloom'							,							device_map='auto'							,							torch_dtype=torch.floataa      )
													pipe('This is a test'							,							do_sample=UpperCamelCase_							,							top_p=0.5      )




						def      __lowerCamelCase       (    self :       Optional[Any]      )     ->				Dict:
													SCREAMING_SNAKE_CASE__     :int						    = 'Hello world'
													SCREAMING_SNAKE_CASE__     :int						    = pipeline('text-generation'							,							model='hf-internal-testing/tiny-random-gpt2'      )
													if text_generator.model.framework == "tf":
																				SCREAMING_SNAKE_CASE__     :Tuple						    = logging.get_logger('transformers.generation.tf_utils'      )
													else:
																				SCREAMING_SNAKE_CASE__     :Any						    = logging.get_logger('transformers.generation.utils'      )
													SCREAMING_SNAKE_CASE__     :str						    = 'Both `max_new_tokens`'  # The beggining of the message to be checked in this test

													# Both are set by the user -> log warning
													with CaptureLogger(UpperCamelCase_      ) as cl:
																				SCREAMING_SNAKE_CASE__     :Dict						    = text_generator(UpperCamelCase_							,							max_length=10							,							max_new_tokens=1      )
													self.assertIn(UpperCamelCase_							,							cl.out      )

													# The user only sets one -> no warning
													with CaptureLogger(UpperCamelCase_      ) as cl:
																				SCREAMING_SNAKE_CASE__     :Optional[Any]						    = text_generator(UpperCamelCase_							,							max_new_tokens=1      )
													self.assertNotIn(UpperCamelCase_							,							cl.out      )

													with CaptureLogger(UpperCamelCase_      ) as cl:
																				SCREAMING_SNAKE_CASE__     :int						    = text_generator(UpperCamelCase_							,							max_length=10      )
													self.assertNotIn(UpperCamelCase_							,							cl.out      )







'''simple docstring'''







import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, LDMTextToImagePipeline, UNetaDConditionModel
from diffusers.utils.testing_utils import (
    enable_full_determinism,
    load_numpy,
    nightly,
    require_torch_gpu,
    slow,
    torch_device,
)

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()




class _SCREAMING_SNAKE_CASE(							_SCREAMING_SNAKE_CASE						,						unittest.TestCase					):
						A_			:							Any     		= LDMTextToImagePipeline
						A_			:							Dict     		= TEXT_TO_IMAGE_PARAMS - {
						    'negative_prompt',
						    'negative_prompt_embeds',
						    'cross_attention_kwargs',
						    'prompt_embeds',
						}
						A_			:							Optional[Any]     		= PipelineTesterMixin.required_optional_params - {
						    'num_images_per_prompt',
						    'callback',
						    'callback_steps',
						}
						A_			:							Any     		= TEXT_TO_IMAGE_BATCH_PARAMS
						A_			:							Optional[int]     		= False




						def      __lowerCamelCase       (    self :       str      )     ->				List[str]:
													torch.manual_seed(0      )
													SCREAMING_SNAKE_CASE__     :List[str]						    = UNetaDConditionModel(
													    block_out_channels=(32, 64)							,							layers_per_block=2							,							sample_size=32							,							in_channels=4							,							out_channels=4							,							down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')							,							up_block_types=('CrossAttnUpBlock2D', 'UpBlock2D')							,							cross_attention_dim=32							,							)
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = DDIMScheduler(
													    beta_start=0.0_0085							,							beta_end=0.012							,							beta_schedule='scaled_linear'							,							clip_sample=UpperCamelCase_							,							set_alpha_to_one=UpperCamelCase_							,							)
													torch.manual_seed(0      )
													SCREAMING_SNAKE_CASE__     :Tuple						    = AutoencoderKL(
													    block_out_channels=(32, 64)							,							in_channels=3							,							out_channels=3							,							down_block_types=('DownEncoderBlock2D', 'DownEncoderBlock2D')							,							up_block_types=('UpDecoderBlock2D', 'UpDecoderBlock2D')							,							latent_channels=4							,							)
													torch.manual_seed(0      )
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = CLIPTextConfig(
													    bos_token_id=0							,							eos_token_id=2							,							hidden_size=32							,							intermediate_size=37							,							layer_norm_eps=1e-05							,							num_attention_heads=4							,							num_hidden_layers=5							,							pad_token_id=1							,							vocab_size=10_00							,							)
													SCREAMING_SNAKE_CASE__     :List[str]						    = CLIPTextModel(UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :List[str]						    = CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'      )

													SCREAMING_SNAKE_CASE__     :List[Any]						    = {
													    'unet': unet,
													    'scheduler': scheduler,
													    'vqvae': vae,
													    'bert': text_encoder,
													    'tokenizer': tokenizer,
													}
													return components




						def      __lowerCamelCase       (    self :       Dict							,							UpperCamelCase_ :       str							,							UpperCamelCase_ :       str=0      )     ->				List[Any]:
													if str(UpperCamelCase_      ).startswith('mps'      ):
																				SCREAMING_SNAKE_CASE__     :int						    = torch.manual_seed(UpperCamelCase_      )
													else:
																				SCREAMING_SNAKE_CASE__     :Dict						    = torch.Generator(device=UpperCamelCase_      ).manual_seed(UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Any						    = {
													    'prompt': 'A painting of a squirrel eating a burger',
													    'generator': generator,
													    'num_inference_steps': 2,
													    'guidance_scale': 6.0,
													    'output_type': 'numpy',
													}
													return inputs




						def      __lowerCamelCase       (    self :       List[Any]      )     ->				Optional[int]:
													SCREAMING_SNAKE_CASE__     :Optional[int]						    = 'cpu'  # ensure determinism for the device-dependent torch.Generator

													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = self.get_dummy_components()
													SCREAMING_SNAKE_CASE__     :Tuple						    = LDMTextToImagePipeline(**UpperCamelCase_      )
													pipe.to(UpperCamelCase_      )
													pipe.set_progress_bar_config(disable=UpperCamelCase_      )

													SCREAMING_SNAKE_CASE__     :Any						    = self.get_dummy_inputs(UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Dict						    = pipe(**UpperCamelCase_      ).images
													SCREAMING_SNAKE_CASE__     :int						    = image[0, -3:, -3:, -1]

													assert image.shape == (1, 16, 16, 3)
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = np.array([0.6101, 0.6156, 0.5622, 0.4895, 0.6661, 0.3804, 0.5748, 0.6136, 0.5014]      )

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




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




						def      __lowerCamelCase       (    self :       str      )     ->				Union[str, Any]:
													super().tearDown()
													gc.collect()
													torch.cuda.empty_cache()




						def      __lowerCamelCase       (    self :       Optional[Any]							,							UpperCamelCase_ :       Union[str, Any]							,							UpperCamelCase_ :       Optional[Any]=torch.floataa							,							UpperCamelCase_ :       int=0      )     ->				str:
													SCREAMING_SNAKE_CASE__     :str						    = torch.manual_seed(UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Optional[int]						    = np.random.RandomState(UpperCamelCase_      ).standard_normal((1, 4, 32, 32)      )
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = torch.from_numpy(UpperCamelCase_      ).to(device=UpperCamelCase_							,							dtype=UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = {
													    'prompt': 'A painting of a squirrel eating a burger',
													    'latents': latents,
													    'generator': generator,
													    'num_inference_steps': 3,
													    'guidance_scale': 6.0,
													    'output_type': 'numpy',
													}
													return inputs




						def      __lowerCamelCase       (    self :       Tuple      )     ->				Any:
													SCREAMING_SNAKE_CASE__     :Optional[int]						    = LDMTextToImagePipeline.from_pretrained('CompVis/ldm-text2im-large-256'      ).to(UpperCamelCase_      )
													pipe.set_progress_bar_config(disable=UpperCamelCase_      )

													SCREAMING_SNAKE_CASE__     :Optional[int]						    = self.get_inputs(UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Any						    = pipe(**UpperCamelCase_      ).images
													SCREAMING_SNAKE_CASE__     :Tuple						    = image[0, -3:, -3:, -1].flatten()

													assert image.shape == (1, 2_56, 2_56, 3)
													SCREAMING_SNAKE_CASE__     :str						    = np.array([0.5_1825, 0.5_2850, 0.5_2543, 0.5_4258, 0.5_2304, 0.5_2569, 0.5_4363, 0.5_5276, 0.5_6878]      )
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = np.abs(expected_slice - image_slice      ).max()
													assert max_diff < 1e-3




@nightly
@require_torch_gpu
class _SCREAMING_SNAKE_CASE(							unittest.TestCase					):




						def      __lowerCamelCase       (    self :       Optional[Any]      )     ->				Optional[Any]:
													super().tearDown()
													gc.collect()
													torch.cuda.empty_cache()




						def      __lowerCamelCase       (    self :       Optional[int]							,							UpperCamelCase_ :       Any							,							UpperCamelCase_ :       Any=torch.floataa							,							UpperCamelCase_ :       List[str]=0      )     ->				str:
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = torch.manual_seed(UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = np.random.RandomState(UpperCamelCase_      ).standard_normal((1, 4, 32, 32)      )
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = torch.from_numpy(UpperCamelCase_      ).to(device=UpperCamelCase_							,							dtype=UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = {
													    'prompt': 'A painting of a squirrel eating a burger',
													    'latents': latents,
													    'generator': generator,
													    'num_inference_steps': 50,
													    'guidance_scale': 6.0,
													    'output_type': 'numpy',
													}
													return inputs




						def      __lowerCamelCase       (    self :       int      )     ->				Dict:
													SCREAMING_SNAKE_CASE__     :str						    = LDMTextToImagePipeline.from_pretrained('CompVis/ldm-text2im-large-256'      ).to(UpperCamelCase_      )
													pipe.set_progress_bar_config(disable=UpperCamelCase_      )

													SCREAMING_SNAKE_CASE__     :List[Any]						    = self.get_inputs(UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Any						    = pipe(**UpperCamelCase_      ).images[0]

													SCREAMING_SNAKE_CASE__     :List[Any]						    = load_numpy(
													    'https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/ldm_text2img/ldm_large_256_ddim.npy'      )
													SCREAMING_SNAKE_CASE__     :str						    = np.abs(expected_image - image      ).max()
													assert max_diff < 1e-3






