


'''simple docstring'''
import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ConvNextConfig, UperNetConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import UperNetForSemanticSegmentation
		from transformers.models.upernet.modeling_upernet import UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import AutoImageProcessor
class        lowercase     :

		"""simple docstring"""

		def __init__(		self   ,       UpperCamelCase_   ,       UpperCamelCase_=13   ,       UpperCamelCase_=32   ,       UpperCamelCase_=3   ,       UpperCamelCase_=4   ,       UpperCamelCase_=[10, 20, 30, 40]   ,       UpperCamelCase_=[2, 2, 3, 2]   ,       UpperCamelCase_=True   ,       UpperCamelCase_=True   ,       UpperCamelCase_=37   ,       UpperCamelCase_="gelu"   ,       UpperCamelCase_=10   ,       UpperCamelCase_=0.02   ,       UpperCamelCase_=["stage2", "stage3", "stage4"]   ,       UpperCamelCase_=3   ,       UpperCamelCase_=None   ,       ):

							'''simple docstring'''


							UpperCamelCase__       :Union[str, Any]							 =			parent
							UpperCamelCase__       :str							 =			batch_size
							UpperCamelCase__       :Union[str, Any]							 =			image_size
							UpperCamelCase__       :List[Any]							 =			num_channels
							UpperCamelCase__       :List[str]							 =			num_stages
							UpperCamelCase__       :int							 =			hidden_sizes
							UpperCamelCase__       :Dict							 =			depths
							UpperCamelCase__       :int							 =			is_training
							UpperCamelCase__       :Union[str, Any]							 =			use_labels
							UpperCamelCase__       :Optional[int]							 =			intermediate_size
							UpperCamelCase__       :Any							 =			hidden_act
							UpperCamelCase__       :List[str]							 =			type_sequence_label_size
							UpperCamelCase__       :Optional[int]							 =			initializer_range
							UpperCamelCase__       :Union[str, Any]							 =			out_features
							UpperCamelCase__       :Union[str, Any]							 =			num_labels
							UpperCamelCase__       :str							 =			scope
							UpperCamelCase__       :List[str]							 =			num_stages




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Tuple							 =			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

							UpperCamelCase__       :Dict							 =			None
							if self.use_labels:
												UpperCamelCase__       :str							 =			ids_tensor([self.batch_size]   ,       self.type_sequence_label_size							)

							UpperCamelCase__       :Dict							 =			self.get_config()

							return config, pixel_values, labels




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return ConvNextConfig(
							    num_channels=self.num_channels   ,       num_stages=self.num_stages   ,       hidden_sizes=self.hidden_sizes   ,       depths=self.depths   ,       is_training=self.is_training   ,       intermediate_size=self.intermediate_size   ,       hidden_act=self.hidden_act   ,       out_features=self.out_features   ,       )




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return UperNetConfig(
							    backbone_config=self.get_backbone_config()   ,       hidden_size=512   ,       pool_scales=[1, 2, 3, 6]   ,       use_auxiliary_head=UpperCamelCase_   ,       auxiliary_loss_weight=0.4   ,       auxiliary_in_channels=40   ,       auxiliary_channels=256   ,       auxiliary_num_convs=1   ,       auxiliary_concat_input=UpperCamelCase_   ,       loss_ignore_index=255   ,       num_labels=self.num_labels   ,       )




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__       :Tuple							 =			UperNetForSemanticSegmentation(config=UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__       :Optional[Any]							 =			model(UpperCamelCase_							)
							self.parent.assertEqual(
							    result.logits.shape   ,       (self.batch_size, self.num_labels, self.image_size, self.image_size)							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :List[str]							 =			self.prepare_config_and_inputs()
							(
							    UpperCamelCase__    
							)       :Tuple							 =			config_and_inputs
							UpperCamelCase__       :Any							 =			{'''pixel_values''': pixel_values}
							return config, inputs_dict



@require_torch
class        lowercase     (							A__     ,		A__     ,		unittest.TestCase ):

		"""simple docstring"""

		_a   			=    (UperNetForSemanticSegmentation,) if is_torch_available() else ()
		_a   			=    {'image-segmentation': UperNetForSemanticSegmentation} if is_torch_available() else {}
		_a   			=    False
		_a   			=    False
		_a   			=    False
		_a   			=    False
		_a   			=    False
		_a   			=    False




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :List[str]							 =			UperNetModelTester(self							)
							UpperCamelCase__       :str							 =			ConfigTester(self   ,       config_class=UpperCamelCase_   ,       has_text_modality=UpperCamelCase_   ,       hidden_size=37							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							self.create_and_test_config_common_properties()
							self.config_tester.create_and_test_config_to_json_string()
							self.config_tester.create_and_test_config_to_json_file()
							self.config_tester.create_and_test_config_from_and_save_pretrained()
							self.config_tester.create_and_test_config_with_num_labels()
							self.config_tester.check_config_can_be_init_without_params()
							self.config_tester.check_config_arguments_init()




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Union[str, Any]							 =			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__       :Union[str, Any]							 =			model_class(UpperCamelCase_							)
												UpperCamelCase__       :List[Any]							 =			inspect.signature(model.forward							)
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												UpperCamelCase__       :Union[str, Any]							 =			[*signature.parameters.keys()]

												UpperCamelCase__       :Dict							 =			['''pixel_values''']
												self.assertListEqual(arg_names[:1]   ,       UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Optional[int]							 =			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_semantic_segmentation(*UpperCamelCase_							)




		@unittest.skip(reason='''UperNet does not use inputs_embeds'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							pass




		@unittest.skip(reason='''UperNet does not support input and output embeddings'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							pass




		@unittest.skip(reason='''UperNet does not have a base model'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							pass




		@unittest.skip(reason='''UperNet does not have a base model'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							pass




		@require_torch_multi_gpu
		@unittest.skip(reason='''UperNet has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							pass




		@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							pass




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							def check_hidden_states_output(UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							):
												UpperCamelCase__       :List[str]							 =			model_class(UpperCamelCase_							)
												model.to(UpperCamelCase_							)
												model.eval()

												with torch.no_grad():
																	UpperCamelCase__       :List[str]							 =			model(**self._prepare_for_class(UpperCamelCase_   ,       UpperCamelCase_							)							)

												UpperCamelCase__       :str							 =			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

												UpperCamelCase__       :int							 =			self.model_tester.num_stages
												self.assertEqual(len(UpperCamelCase_							)   ,       expected_num_stages + 1							)

												# ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
												self.assertListEqual(
												    list(hidden_states[0].shape[-2:]							)   ,       [self.model_tester.image_size // 4, self.model_tester.image_size // 4]   ,       )

							UpperCamelCase__       :Optional[Any]							 =			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__       :int							 =			True
												check_hidden_states_output(UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							)

												# check that output_hidden_states also work using config
												del inputs_dict["output_hidden_states"]
												UpperCamelCase__       :Dict							 =			True

												check_hidden_states_output(UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Optional[Any]							 =			self.model_tester.prepare_config_and_inputs_for_common()

							UpperCamelCase__       :Dict							 =			_config_zero_init(UpperCamelCase_							)
							UpperCamelCase__       :Optional[int]							 =			_config_zero_init(configs_no_init.backbone_config							)
							for model_class in self.all_model_classes:
												UpperCamelCase__       :Dict							 =			model_class(config=UpperCamelCase_							)
												for name, param in model.named_parameters():
																	if param.requires_grad:
																						self.assertIn(
																						    ((param.data.mean() * 1e9).round() / 1e9).item()   ,       [0.0, 1.0]   ,       msg=F'''Parameter {name} of model {model_class} seems not properly initialized'''   ,       )




		@unittest.skip(reason='''UperNet does not have tied weights'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							pass




		@slow
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							for model_name in UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCamelCase__       :Optional[int]							 =			UperNetForSemanticSegmentation.from_pretrained(UpperCamelCase_							)
												self.assertIsNotNone(UpperCamelCase_							)



def       a				(      )  ->     List[str]:



					'''simple docstring'''






					UpperCamelCase__       :List[str]							 =			hf_hub_download(
					    repo_id='''hf-internal-testing/fixtures_ade20k'''			, repo_type='''dataset'''			, filename='''ADE_val_00000001.jpg'''       )
					UpperCamelCase__       :Optional[int]							 =			Image.open(__a       ).convert('''RGB'''       )
					return image







@require_torch
@require_vision
@slow
class        lowercase     (							unittest.TestCase ):

		"""simple docstring"""

		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Optional[Any]							 =			AutoImageProcessor.from_pretrained('''openmmlab/upernet-swin-tiny'''							)
							UpperCamelCase__       :Dict							 =			UperNetForSemanticSegmentation.from_pretrained('''openmmlab/upernet-swin-tiny'''							).to(UpperCamelCase_							)

							UpperCamelCase__       :Union[str, Any]							 =			prepare_img()
							UpperCamelCase__       :List[str]							 =			processor(images=UpperCamelCase_   ,       return_tensors='''pt'''							).to(UpperCamelCase_							)

							with torch.no_grad():
												UpperCamelCase__       :Any							 =			model(**UpperCamelCase_							)

							UpperCamelCase__       :Tuple							 =			torch.Size((1, model.config.num_labels, 512, 512)							)
							self.assertEqual(outputs.logits.shape   ,       UpperCamelCase_							)

							UpperCamelCase__       :Optional[Any]							 =			torch.tensor(
							    [[-7.5958, -7.5958, -7.4302], [-7.5958, -7.5958, -7.4302], [-7.4797, -7.4797, -7.3068]]							).to(UpperCamelCase_							)
							self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]   ,       UpperCamelCase_   ,       atol=1e-4							)							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Union[str, Any]							 =			AutoImageProcessor.from_pretrained('''openmmlab/upernet-convnext-tiny'''							)
							UpperCamelCase__       :Optional[int]							 =			UperNetForSemanticSegmentation.from_pretrained('''openmmlab/upernet-convnext-tiny'''							).to(UpperCamelCase_							)

							UpperCamelCase__       :Dict							 =			prepare_img()
							UpperCamelCase__       :List[Any]							 =			processor(images=UpperCamelCase_   ,       return_tensors='''pt'''							).to(UpperCamelCase_							)

							with torch.no_grad():
												UpperCamelCase__       :str							 =			model(**UpperCamelCase_							)

							UpperCamelCase__       :Optional[int]							 =			torch.Size((1, model.config.num_labels, 512, 512)							)
							self.assertEqual(outputs.logits.shape   ,       UpperCamelCase_							)

							UpperCamelCase__       :Any							 =			torch.tensor(
							    [[-8.8110, -8.8110, -8.6521], [-8.8110, -8.8110, -8.6521], [-8.7746, -8.7746, -8.6130]]							).to(UpperCamelCase_							)
							self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]   ,       UpperCamelCase_   ,       atol=1e-4							)							)



'''simple docstring'''
import gc
import unittest

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

from diffusers import AltDiffusionPipeline, AutoencoderKL, DDIMScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.alt_diffusion.modeling_roberta_series import (
    RobertaSeriesConfig,
    RobertaSeriesModelWithTransformation,
)
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 PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()
class        lowercase     (							A__     ,		A__     ,		A__     ,		unittest.TestCase ):

		"""simple docstring"""

		_a   			=    AltDiffusionPipeline
		_a   			=    TEXT_TO_IMAGE_PARAMS
		_a   			=    TEXT_TO_IMAGE_BATCH_PARAMS
		_a   			=    TEXT_TO_IMAGE_IMAGE_PARAMS
		_a   			=    TEXT_TO_IMAGE_IMAGE_PARAMS




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							torch.manual_seed(0							)
							UpperCamelCase__       :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   ,       )
							UpperCamelCase__       :int							 =			DDIMScheduler(
							    beta_start=0.00085   ,       beta_end=0.012   ,       beta_schedule='''scaled_linear'''   ,       clip_sample=UpperCamelCase_   ,       set_alpha_to_one=UpperCamelCase_   ,       )
							torch.manual_seed(0							)
							UpperCamelCase__       :List[str]							 =			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   ,       )

							# TODO: address the non-deterministic text encoder (fails for save-load tests)
							# torch.manual_seed(0)
							# text_encoder_config = RobertaSeriesConfig(
							#     hidden_size=32,
							#     project_dim=32,
							#     intermediate_size=37,
							#     layer_norm_eps=1e-05,
							#     num_attention_heads=4,
							#     num_hidden_layers=5,
							#     vocab_size=5002,
							# )
							# text_encoder = RobertaSeriesModelWithTransformation(text_encoder_config)

							torch.manual_seed(0							)
							UpperCamelCase__       :Union[str, Any]							 =			CLIPTextConfig(
							    bos_token_id=0   ,       eos_token_id=2   ,       hidden_size=32   ,       projection_dim=32   ,       intermediate_size=37   ,       layer_norm_eps=1e-05   ,       num_attention_heads=4   ,       num_hidden_layers=5   ,       pad_token_id=1   ,       vocab_size=5002   ,       )
							UpperCamelCase__       :Optional[Any]							 =			CLIPTextModel(UpperCamelCase_							)

							UpperCamelCase__       :int							 =			XLMRobertaTokenizer.from_pretrained('''hf-internal-testing/tiny-xlm-roberta'''							)
							UpperCamelCase__       :Dict							 =			77

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




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_=0							):

							'''simple docstring'''


							if str(UpperCamelCase_							).startswith('''mps'''							):
												UpperCamelCase__       :Dict							 =			torch.manual_seed(UpperCamelCase_							)
							else:
												UpperCamelCase__       :List[str]							 =			torch.Generator(device=UpperCamelCase_							).manual_seed(UpperCamelCase_							)
							UpperCamelCase__       :Optional[int]							 =			{
							    '''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							):

							'''simple docstring'''


							super().test_attention_slicing_forward_pass(expected_max_diff=3e-3							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							super().test_inference_batch_single_identical(expected_max_diff=3e-3							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :str							 =			'''cpu'''  # ensure determinism for the device-dependent torch.Generator

							UpperCamelCase__       :Tuple							 =			self.get_dummy_components()
							torch.manual_seed(0							)
							UpperCamelCase__       :Dict							 =			RobertaSeriesConfig(
							    hidden_size=32   ,       project_dim=32   ,       intermediate_size=37   ,       layer_norm_eps=1e-05   ,       num_attention_heads=4   ,       num_hidden_layers=5   ,       vocab_size=5002   ,       )
							# TODO: remove after fixing the non-deterministic text encoder
							UpperCamelCase__       :Union[str, Any]							 =			RobertaSeriesModelWithTransformation(UpperCamelCase_							)
							UpperCamelCase__       :Union[str, Any]							 =			text_encoder

							UpperCamelCase__       :Any							 =			AltDiffusionPipeline(**UpperCamelCase_							)
							UpperCamelCase__       :List[Any]							 =			alt_pipe.to(UpperCamelCase_							)
							alt_pipe.set_progress_bar_config(disable=UpperCamelCase_							)

							UpperCamelCase__       :int							 =			self.get_dummy_inputs(UpperCamelCase_							)
							UpperCamelCase__       :Dict							 =			'''A photo of an astronaut'''
							UpperCamelCase__       :Union[str, Any]							 =			alt_pipe(**UpperCamelCase_							)
							UpperCamelCase__       :Any							 =			output.images
							UpperCamelCase__       :List[Any]							 =			image[0, -3:, -3:, -1]

							assert image.shape == (1, 64, 64, 3)
							UpperCamelCase__       :List[Any]							 =			np.array(
							    [0.5748162, 0.60447145, 0.48821217, 0.50100636, 0.5431185, 0.45763683, 0.49657696, 0.48132733, 0.47573093]							)

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




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :str							 =			'''cpu'''  # ensure determinism for the device-dependent torch.Generator

							UpperCamelCase__       :int							 =			self.get_dummy_components()
							UpperCamelCase__       :Union[str, Any]							 =			PNDMScheduler(skip_prk_steps=UpperCamelCase_							)
							torch.manual_seed(0							)
							UpperCamelCase__       :Dict							 =			RobertaSeriesConfig(
							    hidden_size=32   ,       project_dim=32   ,       intermediate_size=37   ,       layer_norm_eps=1e-05   ,       num_attention_heads=4   ,       num_hidden_layers=5   ,       vocab_size=5002   ,       )
							# TODO: remove after fixing the non-deterministic text encoder
							UpperCamelCase__       :str							 =			RobertaSeriesModelWithTransformation(UpperCamelCase_							)
							UpperCamelCase__       :Union[str, Any]							 =			text_encoder
							UpperCamelCase__       :Union[str, Any]							 =			AltDiffusionPipeline(**UpperCamelCase_							)
							UpperCamelCase__       :Optional[int]							 =			alt_pipe.to(UpperCamelCase_							)
							alt_pipe.set_progress_bar_config(disable=UpperCamelCase_							)

							UpperCamelCase__       :List[str]							 =			self.get_dummy_inputs(UpperCamelCase_							)
							UpperCamelCase__       :Optional[Any]							 =			alt_pipe(**UpperCamelCase_							)
							UpperCamelCase__       :str							 =			output.images
							UpperCamelCase__       :int							 =			image[0, -3:, -3:, -1]

							assert image.shape == (1, 64, 64, 3)
							UpperCamelCase__       :List[Any]							 =			np.array(
							    [0.51605093, 0.5707241, 0.47365507, 0.50578886, 0.5633877, 0.4642503, 0.5182081, 0.48763484, 0.49084237]							)

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



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

		"""simple docstring"""

		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


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




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Optional[Any]							 =			AltDiffusionPipeline.from_pretrained('''BAAI/AltDiffusion'''   ,       safety_checker=UpperCamelCase_							)
							UpperCamelCase__       :str							 =			alt_pipe.to(UpperCamelCase_							)
							alt_pipe.set_progress_bar_config(disable=UpperCamelCase_							)

							UpperCamelCase__       :int							 =			'''A painting of a squirrel eating a burger'''
							UpperCamelCase__       :int							 =			torch.manual_seed(0							)
							UpperCamelCase__       :Optional[Any]							 =			alt_pipe([prompt]   ,       generator=UpperCamelCase_   ,       guidance_scale=6.0   ,       num_inference_steps=20   ,       output_type='''np'''							)

							UpperCamelCase__       :Union[str, Any]							 =			output.images

							UpperCamelCase__       :Optional[Any]							 =			image[0, -3:, -3:, -1]

							assert image.shape == (1, 512, 512, 3)
							UpperCamelCase__       :Union[str, Any]							 =			np.array([0.1010, 0.0800, 0.0794, 0.0885, 0.0843, 0.0762, 0.0769, 0.0729, 0.0586]							)

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




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Any							 =			DDIMScheduler.from_pretrained('''BAAI/AltDiffusion'''   ,       subfolder='''scheduler'''							)

							UpperCamelCase__       :List[str]							 =			AltDiffusionPipeline.from_pretrained('''BAAI/AltDiffusion'''   ,       scheduler=UpperCamelCase_   ,       safety_checker=UpperCamelCase_							)
							UpperCamelCase__       :Dict							 =			alt_pipe.to(UpperCamelCase_							)
							alt_pipe.set_progress_bar_config(disable=UpperCamelCase_							)

							UpperCamelCase__       :List[Any]							 =			'''A painting of a squirrel eating a burger'''
							UpperCamelCase__       :str							 =			torch.manual_seed(0							)

							UpperCamelCase__       :Optional[int]							 =			alt_pipe([prompt]   ,       generator=UpperCamelCase_   ,       num_inference_steps=2   ,       output_type='''numpy'''							)
							UpperCamelCase__       :Any							 =			output.images

							UpperCamelCase__       :int							 =			image[0, -3:, -3:, -1]

							assert image.shape == (1, 512, 512, 3)
							UpperCamelCase__       :int							 =			np.array([0.4019, 0.4052, 0.3810, 0.4119, 0.3916, 0.3982, 0.4651, 0.4195, 0.5323]							)

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