
"""simple docstring"""




from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import tensorflow as tf

				from transformers import TF_MODEL_FOR_PRETRAINING_MAPPING
				from transformers.models.albert.modeling_tf_albert import (
				    TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFAlbertForMaskedLM,
				    TFAlbertForMultipleChoice,
				    TFAlbertForPreTraining,
				    TFAlbertForQuestionAnswering,
				    TFAlbertForSequenceClassification,
				    TFAlbertForTokenClassification,
				    TFAlbertModel,
				)






class     SCREAMING_SNAKE_CASE__      :

							"""simple docstring"""






							def __init__(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_=13       ,		SCREAMING_SNAKE_CASE_=7       ,		SCREAMING_SNAKE_CASE_=True       ,		SCREAMING_SNAKE_CASE_=True       ,		SCREAMING_SNAKE_CASE_=True       ,		SCREAMING_SNAKE_CASE_=True       ,		SCREAMING_SNAKE_CASE_=99       ,		SCREAMING_SNAKE_CASE_=16       ,		SCREAMING_SNAKE_CASE_=32       ,		SCREAMING_SNAKE_CASE_=2       ,		SCREAMING_SNAKE_CASE_=4       ,		SCREAMING_SNAKE_CASE_=37       ,		SCREAMING_SNAKE_CASE_="gelu"       ,		SCREAMING_SNAKE_CASE_=0.1       ,		SCREAMING_SNAKE_CASE_=0.1       ,		SCREAMING_SNAKE_CASE_=512       ,		SCREAMING_SNAKE_CASE_=16       ,		SCREAMING_SNAKE_CASE_=2       ,		SCREAMING_SNAKE_CASE_=0.0_2       ,		SCREAMING_SNAKE_CASE_=3       ,		SCREAMING_SNAKE_CASE_=4       ,		SCREAMING_SNAKE_CASE_=None       ,		)->				int:





													'''simple docstring'''






													__UpperCamelCase       					=     parent
													__UpperCamelCase       					=     13
													__UpperCamelCase       					=     7
													__UpperCamelCase       					=     True
													__UpperCamelCase       					=     True
													__UpperCamelCase       					=     True
													__UpperCamelCase       					=     True
													__UpperCamelCase       					=     99
													__UpperCamelCase       					=     16
													__UpperCamelCase       					=     32
													__UpperCamelCase       					=     2
													__UpperCamelCase       					=     4
													__UpperCamelCase       					=     37
													__UpperCamelCase       					=     '''gelu'''
													__UpperCamelCase       					=     0.1
													__UpperCamelCase       					=     0.1
													__UpperCamelCase       					=     512
													__UpperCamelCase       					=     16
													__UpperCamelCase       					=     2
													__UpperCamelCase       					=     0.0_2
													__UpperCamelCase       					=     3
													__UpperCamelCase       					=     4
													__UpperCamelCase       					=     None



							def       A__						(					self     )->				List[Any]:





													'''simple docstring'''






													__UpperCamelCase       					=     ids_tensor([self.batch_size, self.seq_length]       ,		self.vocab_size     )

													__UpperCamelCase       					=     None
													if self.use_input_mask:
																			__UpperCamelCase       					=     random_attention_mask([self.batch_size, self.seq_length]     )

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

													__UpperCamelCase       					=     None
													__UpperCamelCase       					=     None
													__UpperCamelCase       					=     None
													if self.use_labels:
																			__UpperCamelCase       					=     ids_tensor([self.batch_size]       ,		self.type_sequence_label_size     )
																			__UpperCamelCase       					=     ids_tensor([self.batch_size, self.seq_length]       ,		self.num_labels     )
																			__UpperCamelCase       					=     ids_tensor([self.batch_size]       ,		self.num_choices     )

													__UpperCamelCase       					=     AlbertConfig(
													    vocab_size=self.vocab_size       ,		hidden_size=self.hidden_size       ,		embedding_size=self.embedding_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       ,		)

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



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				Any:





													'''simple docstring'''






													__UpperCamelCase       					=     TFAlbertModel(config=SCREAMING_SNAKE_CASE_     )
													# inputs = {'input_ids': input_ids,
													#           'attention_mask': input_mask,
													#           'token_type_ids': token_type_ids}
													# sequence_output, pooled_output = model(**inputs)
													__UpperCamelCase       					=     {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )

													__UpperCamelCase       					=     [input_ids, input_mask]
													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )

													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )

													self.parent.assertEqual(result.last_hidden_state.shape       ,		(self.batch_size, self.seq_length, self.hidden_size)     )
													self.parent.assertEqual(result.pooler_output.shape       ,		(self.batch_size, self.hidden_size)     )



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				str:





													'''simple docstring'''






													__UpperCamelCase       					=     self.num_labels
													__UpperCamelCase       					=     TFAlbertForPreTraining(config=SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )
													self.parent.assertEqual(result.prediction_logits.shape       ,		(self.batch_size, self.seq_length, self.vocab_size)     )
													self.parent.assertEqual(result.sop_logits.shape       ,		(self.batch_size, self.num_labels)     )



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				Union[str, Any]:





													'''simple docstring'''






													__UpperCamelCase       					=     TFAlbertForMaskedLM(config=SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )
													self.parent.assertEqual(result.logits.shape       ,		(self.batch_size, self.seq_length, self.vocab_size)     )



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				Optional[Any]:





													'''simple docstring'''






													__UpperCamelCase       					=     self.num_labels
													__UpperCamelCase       					=     TFAlbertForSequenceClassification(config=SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )
													self.parent.assertEqual(result.logits.shape       ,		(self.batch_size, self.num_labels)     )



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				int:





													'''simple docstring'''






													__UpperCamelCase       					=     TFAlbertForQuestionAnswering(config=SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )
													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       A__						(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				int:





													'''simple docstring'''






													__UpperCamelCase       					=     self.num_choices
													__UpperCamelCase       					=     TFAlbertForMultipleChoice(config=SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_       ,		1     )       ,		(1, self.num_choices, 1)     )
													__UpperCamelCase       					=     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_       ,		1     )       ,		(1, self.num_choices, 1)     )
													__UpperCamelCase       					=     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_       ,		1     )       ,		(1, self.num_choices, 1)     )
													__UpperCamelCase       					=     {
													    '''input_ids''': multiple_choice_inputs_ids,
													    '''attention_mask''': multiple_choice_input_mask,
													    '''token_type_ids''': multiple_choice_token_type_ids,
													}
													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )
													self.parent.assertListEqual(list(result['''logits'''].shape     )       ,		[self.batch_size, self.num_choices]     )



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				Optional[int]:





													'''simple docstring'''






													__UpperCamelCase       					=     self.num_labels
													__UpperCamelCase       					=     TFAlbertForTokenClassification(config=SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     {
													    '''input_ids''': input_ids,
													    '''attention_mask''': input_mask,
													    '''token_type_ids''': token_type_ids,
													}
													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )
													self.parent.assertListEqual(list(result['''logits'''].shape     )       ,		[self.batch_size, self.seq_length, self.num_labels]     )



							def       A__						(					self     )->				List[Any]:





													'''simple docstring'''






													__UpperCamelCase       					=     self.prepare_config_and_inputs()
													(
													    (
													    __UpperCamelCase							
													)					,							(
													    __UpperCamelCase							
													)					,							(
													    __UpperCamelCase							
													)					,							(
													    __UpperCamelCase							
													)					,							(
													    __UpperCamelCase							
													)					,							(
													    __UpperCamelCase							
													)					,							(
													    __UpperCamelCase							
													)					,														
													)       					=     config_and_inputs
													__UpperCamelCase       					=     {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
													return config, inputs_dict






@require_tf
class     SCREAMING_SNAKE_CASE__      (							SCREAMING_SNAKE_CASE_				,						SCREAMING_SNAKE_CASE_				,						unittest.TestCase      ):

							"""simple docstring"""






							_snake_case       						=					(
							    (
							        TFAlbertModel,
							        TFAlbertForPreTraining,
							        TFAlbertForMaskedLM,
							        TFAlbertForSequenceClassification,
							        TFAlbertForQuestionAnswering,
							        TFAlbertForTokenClassification,
							        TFAlbertForMultipleChoice,
							    )
							    if is_tf_available()
							    else ()
							)
							_snake_case       						=					(
							    {
							        'feature-extraction': TFAlbertModel,
							        'fill-mask': TFAlbertForMaskedLM,
							        'question-answering': TFAlbertForQuestionAnswering,
							        'text-classification': TFAlbertForSequenceClassification,
							        'token-classification': TFAlbertForTokenClassification,
							        'zero-shot': TFAlbertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							_snake_case       						=					False
							_snake_case       						=					False



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_=False     )->				Optional[int]:





													'''simple docstring'''






													__UpperCamelCase       					=     super()._prepare_for_class(SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		return_labels=SCREAMING_SNAKE_CASE_     )

													if return_labels:
																			if model_class in get_values(SCREAMING_SNAKE_CASE_     ):
																									__UpperCamelCase       					=     tf.zeros(self.model_tester.batch_size       ,		dtype=tf.intaa     )

													return inputs_dict



							def       A__						(					self     )->				List[str]:





													'''simple docstring'''






													__UpperCamelCase       					=     TFAlbertModelTester(self     )
													__UpperCamelCase       					=     ConfigTester(self       ,		config_class=SCREAMING_SNAKE_CASE_       ,		hidden_size=37     )



							def       A__						(					self     )->				Dict:





													'''simple docstring'''






													self.config_tester.run_common_tests()



							def       A__						(					self     )->				Optional[int]:





													'''simple docstring'''






													__UpperCamelCase       					=     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_model(*SCREAMING_SNAKE_CASE_     )



							def       A__						(					self     )->				List[Any]:





													'''simple docstring'''






													__UpperCamelCase       					=     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_pretraining(*SCREAMING_SNAKE_CASE_     )



							def       A__						(					self     )->				Dict:





													'''simple docstring'''






													__UpperCamelCase       					=     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_masked_lm(*SCREAMING_SNAKE_CASE_     )



							def       A__						(					self     )->				Dict:





													'''simple docstring'''






													__UpperCamelCase       					=     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_multiple_choice(*SCREAMING_SNAKE_CASE_     )



							def       A__						(					self     )->				int:





													'''simple docstring'''






													__UpperCamelCase       					=     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_sequence_classification(*SCREAMING_SNAKE_CASE_     )



							def       A__						(					self     )->				int:





													'''simple docstring'''






													__UpperCamelCase       					=     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_question_answering(*SCREAMING_SNAKE_CASE_     )



							@slow
							def       A__						(					self     )->				List[Any]:





													'''simple docstring'''






													for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			__UpperCamelCase       					=     TFAlbertModel.from_pretrained(SCREAMING_SNAKE_CASE_     )
																			self.assertIsNotNone(SCREAMING_SNAKE_CASE_     )






@require_tf
class     SCREAMING_SNAKE_CASE__      (							unittest.TestCase      ):

							"""simple docstring"""






							@slow
							def       A__						(					self     )->				Tuple:





													'''simple docstring'''






													__UpperCamelCase       					=     TFAlbertForPreTraining.from_pretrained('''albert-base-v2'''     )
													__UpperCamelCase       					=     tf.constant([[0, 1, 2, 3, 4, 5]]     )
													__UpperCamelCase       					=     model(SCREAMING_SNAKE_CASE_     )[0]

													__UpperCamelCase       					=     [1, 6, 30000]
													self.assertEqual(output.shape       ,		SCREAMING_SNAKE_CASE_     )

													__UpperCamelCase       					=     tf.constant(
													    [
													        [
													            [4.5_9_5_6_6_8, 0.7_4_4_6_2_7_5_4, -1.8_1_8_1_4_7],
													            [4.5_9_5_4_3_4_7, 0.7_4_5_4_1_8_4, -1.8_1_8_8_2_5_8],
													            [4.5_9_5_4_9_0_5, 0.7_4_4_8_2_3_5, -1.8_1_8_2_3_1_6],
													        ]
													    ]     )
													tf.debugging.assert_near(output[:, :3, :3]       ,		SCREAMING_SNAKE_CASE_       ,		atol=1E-4     )






import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMParallelScheduler,
    DDPMParallelScheduler,
    StableDiffusionParadigmsPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import (
    enable_full_determinism,
    require_torch_gpu,
)

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


enable_full_determinism()






class     SCREAMING_SNAKE_CASE__      (							SCREAMING_SNAKE_CASE_				,						SCREAMING_SNAKE_CASE_				,						unittest.TestCase      ):

							"""simple docstring"""






							_snake_case       						=					StableDiffusionParadigmsPipeline
							_snake_case       						=					TEXT_TO_IMAGE_PARAMS
							_snake_case       						=					TEXT_TO_IMAGE_BATCH_PARAMS
							_snake_case       						=					TEXT_TO_IMAGE_IMAGE_PARAMS
							_snake_case       						=					TEXT_TO_IMAGE_IMAGE_PARAMS



							def       A__						(					self     )->				List[Any]:





													'''simple docstring'''






													torch.manual_seed(0     )
													__UpperCamelCase       					=     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       ,		attention_head_dim=(2, 4)       ,		use_linear_projection=SCREAMING_SNAKE_CASE_       ,		)
													__UpperCamelCase       					=     DDIMParallelScheduler(
													    beta_start=0.0_0_0_8_5       ,		beta_end=0.0_1_2       ,		beta_schedule='''scaled_linear'''       ,		clip_sample=SCREAMING_SNAKE_CASE_       ,		set_alpha_to_one=SCREAMING_SNAKE_CASE_       ,		)
													torch.manual_seed(0     )
													__UpperCamelCase       					=     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       ,		sample_size=128       ,		)
													torch.manual_seed(0     )
													__UpperCamelCase       					=     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=1000       ,		hidden_act='''gelu'''       ,		projection_dim=512       ,		)
													__UpperCamelCase       					=     CLIPTextModel(SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''     )

													__UpperCamelCase       					=     {
													    '''unet''': unet,
													    '''scheduler''': scheduler,
													    '''vae''': vae,
													    '''text_encoder''': text_encoder,
													    '''tokenizer''': tokenizer,
													    '''safety_checker''': None,
													    '''feature_extractor''': None,
													}
													return components



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_=0     )->				List[Any]:





													'''simple docstring'''






													if str(SCREAMING_SNAKE_CASE_     ).startswith('''mps'''     ):
																			__UpperCamelCase       					=     torch.manual_seed(SCREAMING_SNAKE_CASE_     )
													else:
																			__UpperCamelCase       					=     torch.Generator(device=SCREAMING_SNAKE_CASE_     ).manual_seed(SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     {
													    '''prompt''': '''a photograph of an astronaut riding a horse''',
													    '''generator''': generator,
													    '''num_inference_steps''': 10,
													    '''guidance_scale''': 6.0,
													    '''output_type''': '''numpy''',
													    '''parallel''': 3,
													    '''debug''': True,
													}
													return inputs



							def       A__						(					self     )->				Optional[Any]:





													'''simple docstring'''






													__UpperCamelCase       					=     '''cpu'''  # ensure determinism for the device-dependent torch.Generator
													__UpperCamelCase       					=     self.get_dummy_components()
													__UpperCamelCase       					=     StableDiffusionParadigmsPipeline(**SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     sd_pipe.to(SCREAMING_SNAKE_CASE_     )
													sd_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_     )

													__UpperCamelCase       					=     self.get_dummy_inputs(SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     sd_pipe(**SCREAMING_SNAKE_CASE_     ).images
													__UpperCamelCase       					=     image[0, -3:, -3:, -1]
													assert image.shape == (1, 64, 64, 3)

													__UpperCamelCase       					=     np.array([0.4_7_7_3, 0.5_4_1_7, 0.4_7_2_3, 0.4_9_2_5, 0.5_6_3_1, 0.4_7_5_2, 0.5_2_4_0, 0.4_9_3_5, 0.5_0_2_3]     )

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



							def       A__						(					self     )->				List[str]:





													'''simple docstring'''






													__UpperCamelCase       					=     '''cpu'''  # ensure determinism for the device-dependent torch.Generator
													__UpperCamelCase       					=     self.get_dummy_components()
													torch.manual_seed(0     )
													__UpperCamelCase       					=     DDPMParallelScheduler()
													torch.manual_seed(0     )
													__UpperCamelCase       					=     StableDiffusionParadigmsPipeline(**SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     sd_pipe.to(SCREAMING_SNAKE_CASE_     )
													sd_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_     )

													__UpperCamelCase       					=     self.get_dummy_inputs(SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     sd_pipe(**SCREAMING_SNAKE_CASE_     ).images
													__UpperCamelCase       					=     image[0, -3:, -3:, -1]
													assert image.shape == (1, 64, 64, 3)

													__UpperCamelCase       					=     np.array([0.3_5_7_3, 0.4_4_2_0, 0.4_9_6_0, 0.4_7_9_9, 0.3_7_9_6, 0.3_8_7_9, 0.4_8_1_9, 0.4_3_6_5, 0.4_4_6_8]     )

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



							def       A__						(					self     )->				Union[str, Any]:





													'''simple docstring'''






													super().test_inference_batch_consistent(batch_sizes=[1, 2]     )



							def       A__						(					self     )->				Union[str, Any]:





													'''simple docstring'''






													super().test_inference_batch_single_identical(batch_size=2       ,		expected_max_diff=3E-3     )



							def       A__						(					self     )->				Optional[int]:





													'''simple docstring'''






													__UpperCamelCase       					=     '''cpu'''  # ensure determinism for the device-dependent torch.Generator
													__UpperCamelCase       					=     self.get_dummy_components()
													__UpperCamelCase       					=     StableDiffusionParadigmsPipeline(**SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     sd_pipe.to(SCREAMING_SNAKE_CASE_     )
													sd_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_     )

													__UpperCamelCase       					=     self.get_dummy_inputs(SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     '''french fries'''
													__UpperCamelCase       					=     sd_pipe(**SCREAMING_SNAKE_CASE_       ,		negative_prompt=SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     output.images
													__UpperCamelCase       					=     image[0, -3:, -3:, -1]

													assert image.shape == (1, 64, 64, 3)

													__UpperCamelCase       					=     np.array([0.4_7_7_1, 0.5_4_2_0, 0.4_6_8_3, 0.4_9_1_8, 0.5_6_3_6, 0.4_7_2_5, 0.5_2_3_0, 0.4_9_2_3, 0.5_0_1_5]     )

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






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

							"""simple docstring"""






							def       A__						(					self     )->				Any:





													'''simple docstring'''






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



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_=0     )->				Optional[Any]:





													'''simple docstring'''






													__UpperCamelCase       					=     torch.Generator(device=SCREAMING_SNAKE_CASE_     ).manual_seed(SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     {
													    '''prompt''': '''a photograph of an astronaut riding a horse''',
													    '''generator''': generator,
													    '''num_inference_steps''': 10,
													    '''guidance_scale''': 7.5,
													    '''output_type''': '''numpy''',
													    '''parallel''': 3,
													    '''debug''': True,
													}
													return inputs



							def       A__						(					self     )->				str:





													'''simple docstring'''






													__UpperCamelCase       					=     '''stabilityai/stable-diffusion-2-base'''
													__UpperCamelCase       					=     DDIMParallelScheduler.from_pretrained(SCREAMING_SNAKE_CASE_       ,		subfolder='''scheduler'''     )
													__UpperCamelCase       					=     StableDiffusionParadigmsPipeline.from_pretrained(SCREAMING_SNAKE_CASE_       ,		scheduler=SCREAMING_SNAKE_CASE_       ,		safety_checker=SCREAMING_SNAKE_CASE_     )
													pipe.to(SCREAMING_SNAKE_CASE_     )
													pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_     )
													pipe.enable_attention_slicing()

													__UpperCamelCase       					=     self.get_inputs()
													__UpperCamelCase       					=     pipe(**SCREAMING_SNAKE_CASE_     ).images
													__UpperCamelCase       					=     image[0, -3:, -3:, -1].flatten()

													assert image.shape == (1, 512, 512, 3)

													__UpperCamelCase       					=     np.array([0.9_6_2_2, 0.9_6_0_2, 0.9_7_4_8, 0.9_5_9_1, 0.9_6_3_0, 0.9_6_9_1, 0.9_6_6_1, 0.9_6_3_1, 0.9_7_4_1]     )

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




