





"""simple docstring"""





import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
						import torch

						from transformers import MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation, MobileNetVaModel
						from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import MobileNetVaImageProcessor





class        _lowerCamelCase      (       _lowercase ):


						def     snake_case_   (self		) ->   List[str]:
								UpperCamelCase   =	self.config_class(**self.inputs_dict		)
								self.parent.assertTrue(hasattr(__a   ,							"tf_padding"		)		)
								self.parent.assertTrue(hasattr(__a   ,							"depth_multiplier"		)		)





class        _lowerCamelCase      :


						def __init__(self   ,							__a   ,							__a=13   ,							__a=3   ,							__a=32   ,							__a=0.25   ,							__a=8   ,							__a=8   ,							__a=6   ,							__a=32   ,							__a=True   ,							__a=True   ,							__a=True   ,							__a="relu6"   ,							__a=12_80   ,							__a=0.1   ,							__a=0.02   ,							__a=True   ,							__a=True   ,							__a=10   ,							__a=None   ,							) ->   Optional[int]:
								UpperCamelCase   =	parent
								UpperCamelCase   =	batch_size
								UpperCamelCase   =	num_channels
								UpperCamelCase   =	image_size
								UpperCamelCase   =	depth_multiplier
								UpperCamelCase   =	depth_divisible_by
								UpperCamelCase   =	min_depth
								UpperCamelCase   =	expand_ratio
								UpperCamelCase   =	tf_padding
								UpperCamelCase   =	output_stride
								UpperCamelCase   =	first_layer_is_expansion
								UpperCamelCase   =	finegrained_output
								UpperCamelCase   =	hidden_act
								UpperCamelCase   =	last_hidden_size if finegrained_output else int(last_hidden_size * depth_multiplier		)
								UpperCamelCase   =	classifier_dropout_prob
								UpperCamelCase   =	use_labels
								UpperCamelCase   =	is_training
								UpperCamelCase   =	num_labels
								UpperCamelCase   =	initializer_range
								UpperCamelCase   =	scope


						def     snake_case_   (self		) ->   Tuple:
								UpperCamelCase   =	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

								UpperCamelCase   =	None
								UpperCamelCase   =	None
								if self.use_labels:
										UpperCamelCase   =	ids_tensor([self.batch_size]   ,							self.num_labels		)
										UpperCamelCase   =	ids_tensor([self.batch_size, self.image_size, self.image_size]   ,							self.num_labels		)

								UpperCamelCase   =	self.get_config()

								return config, pixel_values, labels, pixel_labels


						def     snake_case_   (self		) ->   Optional[Any]:
								return MobileNetVaConfig(
								    num_channels=self.num_channels   ,							image_size=self.image_size   ,							depth_multiplier=self.depth_multiplier   ,							depth_divisible_by=self.depth_divisible_by   ,							min_depth=self.min_depth   ,							expand_ratio=self.expand_ratio   ,							output_stride=self.output_stride   ,							first_layer_is_expansion=self.first_layer_is_expansion   ,							finegrained_output=self.finegrained_output   ,							hidden_act=self.hidden_act   ,							tf_padding=self.tf_padding   ,							classifier_dropout_prob=self.classifier_dropout_prob   ,							initializer_range=self.initializer_range   ,							)


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a		) ->   Dict:
								UpperCamelCase   =	MobileNetVaModel(config=__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase   =	model(__a		)
								self.parent.assertEqual(
								    result.last_hidden_state.shape   ,							(
								        self.batch_size,
								        self.last_hidden_size,
								        self.image_size // self.output_stride,
								        self.image_size // self.output_stride,
								    )   ,							)
								self.parent.assertEqual(
								    result.pooler_output.shape   ,							(self.batch_size, self.last_hidden_size)   ,							)


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a		) ->   Optional[Any]:
								UpperCamelCase   =	self.num_labels
								UpperCamelCase   =	MobileNetVaForImageClassification(__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase   =	model(__a   ,							labels=__a		)
								self.parent.assertEqual(result.logits.shape   ,							(self.batch_size, self.num_labels)		)


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a		) ->   List[str]:
								UpperCamelCase   =	self.num_labels
								UpperCamelCase   =	MobileNetVaForSemanticSegmentation(__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase   =	model(__a		)
								self.parent.assertEqual(
								    result.logits.shape   ,							(
								        self.batch_size,
								        self.num_labels,
								        self.image_size // self.output_stride,
								        self.image_size // self.output_stride,
								    )   ,							)
								UpperCamelCase   =	model(__a   ,							labels=__a		)
								self.parent.assertEqual(
								    result.logits.shape   ,							(
								        self.batch_size,
								        self.num_labels,
								        self.image_size // self.output_stride,
								        self.image_size // self.output_stride,
								    )   ,							)




						def     snake_case_   (self		) ->   Optional[int]:
								UpperCamelCase   =	self.prepare_config_and_inputs()
								UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   =	config_and_inputs
								UpperCamelCase   =	{"pixel_values": pixel_values}
								return config, inputs_dict





@require_torch
class        _lowerCamelCase      (       _lowercase  ,			_lowercase  ,			unittest.TestCase ):
						UpperCAmelCase_ =			(
						    (MobileNetVaModel, MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation)
						    if is_torch_available()
						    else ()
						)
						UpperCAmelCase_ =			(
						    {
						        "feature-extraction": MobileNetVaModel,
						        "image-classification": MobileNetVaForImageClassification,
						        "image-segmentation": MobileNetVaForSemanticSegmentation,
						    }
						    if is_torch_available()
						    else {}
						)

						UpperCAmelCase_ =			False
						UpperCAmelCase_ =			False
						UpperCAmelCase_ =			False
						UpperCAmelCase_ =			False


						def     snake_case_   (self		) ->   Dict:
								UpperCamelCase   =	MobileNetVaModelTester(self		)
								UpperCamelCase   =	MobileNetVaConfigTester(self   ,							config_class=__a   ,							has_text_modality=__a		)


						def     snake_case_   (self		) ->   Any:
								self.config_tester.run_common_tests()


						@unittest.skip(reason="MobileNetV2 does not use inputs_embeds"		)
						def     snake_case_   (self		) ->   Union[str, Any]:
								pass


						@unittest.skip(reason="MobileNetV2 does not support input and output embeddings"		)
						def     snake_case_   (self		) ->   int:
								pass


						@unittest.skip(reason="MobileNetV2 does not output attentions"		)
						def     snake_case_   (self		) ->   Tuple:
								pass


						def     snake_case_   (self		) ->   List[Any]:
								UpperCamelCase   ,				UpperCamelCase   =	self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
										UpperCamelCase   =	model_class(__a		)
										UpperCamelCase   =	inspect.signature(model.forward		)
										# signature.parameters is an OrderedDict => so arg_names order is deterministic
										UpperCamelCase   =	[*signature.parameters.keys()]

										UpperCamelCase   =	["pixel_values"]
										self.assertListEqual(arg_names[:1]   ,							__a		)


						def     snake_case_   (self		) ->   str:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__a		)


						def     snake_case_   (self		) ->   List[Any]:
								def check_hidden_states_output(__a   ,							__a   ,							__a		):
										UpperCamelCase   =	model_class(__a		)
										model.to(__a		)
										model.eval()

										with torch.no_grad():
												UpperCamelCase   =	model(**self._prepare_for_class(__a   ,							__a		)		)

										UpperCamelCase   =	outputs.hidden_states

										UpperCamelCase   =	16
										self.assertEqual(len(__a		)   ,							__a		)

								UpperCamelCase   ,				UpperCamelCase   =	self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
										UpperCamelCase   =	True
										check_hidden_states_output(__a   ,							__a   ,							__a		)

										# check that output_hidden_states also work using config
										del inputs_dict["output_hidden_states"]
										UpperCamelCase   =	True

										check_hidden_states_output(__a   ,							__a   ,							__a		)


						def     snake_case_   (self		) ->   Optional[Any]:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*__a		)


						def     snake_case_   (self		) ->   List[Any]:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_semantic_segmentation(*__a		)




						@slow
						def     snake_case_   (self		) ->   Tuple:
								for model_name in MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										UpperCamelCase   =	MobileNetVaModel.from_pretrained(__a		)
										self.assertIsNotNone(__a		)



def       a__					(					):




		"""simple docstring"""


		UpperCamelCase   =	Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"    )
		return image






@require_torch
@require_vision
class        _lowerCamelCase      (       unittest.TestCase ):


						@cached_property
						def     snake_case_   (self		) ->   Dict:
								return (
								    MobileNetVaImageProcessor.from_pretrained("google/mobilenet_v2_1.0_224"		) if is_vision_available() else None
								)


						@slow
						def     snake_case_   (self		) ->   str:
								UpperCamelCase   =	MobileNetVaForImageClassification.from_pretrained("google/mobilenet_v2_1.0_224"		).to(__a		)

								UpperCamelCase   =	self.default_image_processor
								UpperCamelCase   =	prepare_img()
								UpperCamelCase   =	image_processor(images=__a   ,							return_tensors="pt"		).to(__a		)

								# forward pass
								with torch.no_grad():
										UpperCamelCase   =	model(**__a		)

								# verify the logits
								UpperCamelCase   =	torch.Size((1, 10_01)		)
								self.assertEqual(outputs.logits.shape   ,							__a		)

								UpperCamelCase   =	torch.tensor([0.2445, -1.1993, 0.1905]		).to(__a		)

								self.assertTrue(torch.allclose(outputs.logits[0, :3]   ,							__a   ,							atol=1e-4		)		)




						@slow
						def     snake_case_   (self		) ->   str:
								UpperCamelCase   =	MobileNetVaForSemanticSegmentation.from_pretrained("google/deeplabv3_mobilenet_v2_1.0_513"		)
								UpperCamelCase   =	model.to(__a		)

								UpperCamelCase   =	MobileNetVaImageProcessor.from_pretrained("google/deeplabv3_mobilenet_v2_1.0_513"		)

								UpperCamelCase   =	prepare_img()
								UpperCamelCase   =	image_processor(images=__a   ,							return_tensors="pt"		).to(__a		)

								# forward pass
								with torch.no_grad():
										UpperCamelCase   =	model(**__a		)
								UpperCamelCase   =	outputs.logits

								# verify the logits
								UpperCamelCase   =	torch.Size((1, 21, 65, 65)		)
								self.assertEqual(logits.shape   ,							__a		)

								UpperCamelCase   =	torch.tensor(
								    [
								        [[17.5790, 17.7581, 18.3355], [18.3257, 18.4230, 18.8973], [18.6169, 18.8650, 19.2187]],
								        [[-2.1595, -2.0977, -2.3741], [-2.4226, -2.3028, -2.6835], [-2.7819, -2.5991, -2.7706]],
								        [[4.2058, 4.8317, 4.7638], [4.4136, 5.0361, 4.9383], [4.5028, 4.9644, 4.8734]],
								    ]   ,							device=__a   ,							)

								self.assertTrue(torch.allclose(logits[0, :3, :3, :3]   ,							__a   ,							atol=1e-4		)		)













"""simple docstring"""





import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    EulerAncestralDiscreteScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPanoramaPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

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()





@skip_mps
class        _lowerCamelCase      (       _lowercase  ,			_lowercase  ,			unittest.TestCase ):
						UpperCAmelCase_ =			StableDiffusionPanoramaPipeline
						UpperCAmelCase_ =			TEXT_TO_IMAGE_PARAMS
						UpperCAmelCase_ =			TEXT_TO_IMAGE_BATCH_PARAMS
						UpperCAmelCase_ =			TEXT_TO_IMAGE_IMAGE_PARAMS
						UpperCAmelCase_ =			TEXT_TO_IMAGE_IMAGE_PARAMS


						def     snake_case_   (self		) ->   int:
								torch.manual_seed(0		)
								UpperCamelCase   =	UNetaDConditionModel(
								    block_out_channels=(32, 64)   ,							layers_per_block=1   ,							sample_size=32   ,							in_channels=4   ,							out_channels=4   ,							down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")   ,							up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")   ,							cross_attention_dim=32   ,							)
								UpperCamelCase   =	DDIMScheduler()
								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   ,							)
								torch.manual_seed(0		)
								UpperCamelCase   =	CLIPTextConfig(
								    bos_token_id=0   ,							eos_token_id=2   ,							hidden_size=32   ,							intermediate_size=37   ,							layer_norm_eps=1e-0_5   ,							num_attention_heads=4   ,							num_hidden_layers=5   ,							pad_token_id=1   ,							vocab_size=10_00   ,							)
								UpperCamelCase   =	CLIPTextModel(__a		)
								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     snake_case_   (self   ,							__a   ,							__a=0		) ->   List[str]:
								UpperCamelCase   =	torch.manual_seed(__a		)
								UpperCamelCase   =	{
								    "prompt": "a photo of the dolomites",
								    "generator": generator,
								    # Setting height and width to None to prevent OOMs on CPU.
								    "height": None,
								    "width": None,
								    "num_inference_steps": 1,
								    "guidance_scale": 6.0,
								    "output_type": "numpy",
								}
								return inputs


						def     snake_case_   (self		) ->   int:
								UpperCamelCase   =	"cpu"  # ensure determinism for the device-dependent torch.Generator
								UpperCamelCase   =	self.get_dummy_components()
								UpperCamelCase   =	StableDiffusionPanoramaPipeline(**__a		)
								UpperCamelCase   =	sd_pipe.to(__a		)
								sd_pipe.set_progress_bar_config(disable=__a		)

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

								UpperCamelCase   =	np.array([0.6186, 0.5374, 0.4915, 0.4135, 0.4114, 0.4563, 0.5128, 0.4977, 0.4757]		)

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


						def     snake_case_   (self		) ->   Optional[int]:
								super().test_inference_batch_consistent(batch_sizes=[1, 2]		)


						def     snake_case_   (self		) ->   Tuple:
								super().test_inference_batch_single_identical(batch_size=2   ,							expected_max_diff=3.2_5e-3		)


						def     snake_case_   (self		) ->   Tuple:
								UpperCamelCase   =	"cpu"  # ensure determinism for the device-dependent torch.Generator
								UpperCamelCase   =	self.get_dummy_components()
								UpperCamelCase   =	StableDiffusionPanoramaPipeline(**__a		)
								UpperCamelCase   =	sd_pipe.to(__a		)
								sd_pipe.set_progress_bar_config(disable=__a		)

								UpperCamelCase   =	self.get_dummy_inputs(__a		)
								UpperCamelCase   =	"french fries"
								UpperCamelCase   =	sd_pipe(**__a   ,							negative_prompt=__a		)
								UpperCamelCase   =	output.images
								UpperCamelCase   =	image[0, -3:, -3:, -1]

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

								UpperCamelCase   =	np.array([0.6187, 0.5375, 0.4915, 0.4136, 0.4114, 0.4563, 0.5128, 0.4976, 0.4757]		)

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


						def     snake_case_   (self		) ->   Tuple:
								UpperCamelCase   =	"cpu"  # ensure determinism for the device-dependent torch.Generator
								UpperCamelCase   =	self.get_dummy_components()
								UpperCamelCase   =	StableDiffusionPanoramaPipeline(**__a		)
								UpperCamelCase   =	sd_pipe.to(__a		)
								sd_pipe.set_progress_bar_config(disable=__a		)

								UpperCamelCase   =	self.get_dummy_inputs(__a		)
								UpperCamelCase   =	sd_pipe(**__a   ,							view_batch_size=2		)
								UpperCamelCase   =	output.images
								UpperCamelCase   =	image[0, -3:, -3:, -1]

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

								UpperCamelCase   =	np.array([0.6187, 0.5375, 0.4915, 0.4136, 0.4114, 0.4563, 0.5128, 0.4976, 0.4757]		)

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


						def     snake_case_   (self		) ->   Optional[int]:
								UpperCamelCase   =	"cpu"  # ensure determinism for the device-dependent torch.Generator
								UpperCamelCase   =	self.get_dummy_components()
								UpperCamelCase   =	EulerAncestralDiscreteScheduler(
								    beta_start=0.00085   ,							beta_end=0.012   ,							beta_schedule="scaled_linear"		)
								UpperCamelCase   =	StableDiffusionPanoramaPipeline(**__a		)
								UpperCamelCase   =	sd_pipe.to(__a		)
								sd_pipe.set_progress_bar_config(disable=__a		)

								UpperCamelCase   =	self.get_dummy_inputs(__a		)
								UpperCamelCase   =	sd_pipe(**__a		).images
								UpperCamelCase   =	image[0, -3:, -3:, -1]

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

								UpperCamelCase   =	np.array([0.4024, 0.6510, 0.4901, 0.5378, 0.5813, 0.5622, 0.4795, 0.4467, 0.4952]		)

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




						def     snake_case_   (self		) ->   Optional[Any]:
								UpperCamelCase   =	"cpu"  # ensure determinism for the device-dependent torch.Generator
								UpperCamelCase   =	self.get_dummy_components()
								UpperCamelCase   =	PNDMScheduler(
								    beta_start=0.00085   ,							beta_end=0.012   ,							beta_schedule="scaled_linear"   ,							skip_prk_steps=__a		)
								UpperCamelCase   =	StableDiffusionPanoramaPipeline(**__a		)
								UpperCamelCase   =	sd_pipe.to(__a		)
								sd_pipe.set_progress_bar_config(disable=__a		)

								UpperCamelCase   =	self.get_dummy_inputs(__a		)
								UpperCamelCase   =	sd_pipe(**__a		).images
								UpperCamelCase   =	image[0, -3:, -3:, -1]

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

								UpperCamelCase   =	np.array([0.6391, 0.6291, 0.4861, 0.5134, 0.5552, 0.4578, 0.5032, 0.5023, 0.4539]		)

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





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


						def     snake_case_   (self		) ->   List[str]:
								super().tearDown()
								gc.collect()
								torch.cuda.empty_cache()


						def     snake_case_   (self   ,							__a=0		) ->   List[str]:
								UpperCamelCase   =	torch.manual_seed(__a		)
								UpperCamelCase   =	{
								    "prompt": "a photo of the dolomites",
								    "generator": generator,
								    "num_inference_steps": 3,
								    "guidance_scale": 7.5,
								    "output_type": "numpy",
								}
								return inputs


						def     snake_case_   (self		) ->   Union[str, Any]:
								UpperCamelCase   =	"stabilityai/stable-diffusion-2-base"
								UpperCamelCase   =	DDIMScheduler.from_pretrained(__a   ,							subfolder="scheduler"		)
								UpperCamelCase   =	StableDiffusionPanoramaPipeline.from_pretrained(__a   ,							scheduler=__a   ,							safety_checker=__a		)
								pipe.to(__a		)
								pipe.set_progress_bar_config(disable=__a		)
								pipe.enable_attention_slicing()

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

								assert image.shape == (1, 5_12, 20_48, 3)

								UpperCamelCase   =	np.array(
								    [
								        0.36968392,
								        0.27025372,
								        0.32446766,
								        0.28379387,
								        0.36363274,
								        0.30733347,
								        0.27100027,
								        0.27054125,
								        0.25536096,
								    ]		)

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


						def     snake_case_   (self		) ->   Union[str, Any]:
								UpperCamelCase   =	StableDiffusionPanoramaPipeline.from_pretrained(
								    "stabilityai/stable-diffusion-2-base"   ,							safety_checker=__a		)
								UpperCamelCase   =	LMSDiscreteScheduler.from_config(pipe.scheduler.config		)
								pipe.to(__a		)
								pipe.set_progress_bar_config(disable=__a		)
								pipe.enable_attention_slicing()

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

								assert image.shape == (1, 5_12, 20_48, 3)

								UpperCamelCase   =	np.array(
								    [
								        [
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								        ]
								    ]		)

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


						def     snake_case_   (self		) ->   Tuple:
								UpperCamelCase   =	0

								def callback_fn(__a   ,							__a   ,							__a		) -> None:
										UpperCamelCase   =	True
										nonlocal number_of_steps
										number_of_steps += 1
										if step == 1:
												UpperCamelCase   =	latents.detach().cpu().numpy()
												assert latents.shape == (1, 4, 64, 2_56)
												UpperCamelCase   =	latents[0, -3:, -3:, -1]

												UpperCamelCase   =	np.array(
												    [
												        0.18681869,
												        0.33907816,
												        0.5361276,
												        0.14432865,
												        -0.02856611,
												        -0.73941123,
												        0.23397987,
												        0.47322682,
												        -0.37823164,
												    ]		)
												assert np.abs(latents_slice.flatten() - expected_slice		).max() < 5e-2
										elif step == 2:
												UpperCamelCase   =	latents.detach().cpu().numpy()
												assert latents.shape == (1, 4, 64, 2_56)
												UpperCamelCase   =	latents[0, -3:, -3:, -1]

												UpperCamelCase   =	np.array(
												    [
												        0.18539645,
												        0.33987248,
												        0.5378559,
												        0.14437142,
												        -0.02455261,
												        -0.7338317,
												        0.23990755,
												        0.47356272,
												        -0.3786505,
												    ]		)

												assert np.abs(latents_slice.flatten() - expected_slice		).max() < 5e-2

								UpperCamelCase   =	False

								UpperCamelCase   =	"stabilityai/stable-diffusion-2-base"
								UpperCamelCase   =	DDIMScheduler.from_pretrained(__a   ,							subfolder="scheduler"		)
								UpperCamelCase   =	StableDiffusionPanoramaPipeline.from_pretrained(__a   ,							scheduler=__a   ,							safety_checker=__a		)
								UpperCamelCase   =	pipe.to(__a		)
								pipe.set_progress_bar_config(disable=__a		)
								pipe.enable_attention_slicing()

								UpperCamelCase   =	self.get_inputs()
								pipe(**__a   ,							callback=__a   ,							callback_steps=1		)
								assert callback_fn.has_been_called
								assert number_of_steps == 3




						def     snake_case_   (self		) ->   List[Any]:
								torch.cuda.empty_cache()
								torch.cuda.reset_max_memory_allocated()
								torch.cuda.reset_peak_memory_stats()

								UpperCamelCase   =	"stabilityai/stable-diffusion-2-base"
								UpperCamelCase   =	DDIMScheduler.from_pretrained(__a   ,							subfolder="scheduler"		)
								UpperCamelCase   =	StableDiffusionPanoramaPipeline.from_pretrained(__a   ,							scheduler=__a   ,							safety_checker=__a		)
								UpperCamelCase   =	pipe.to(__a		)
								pipe.set_progress_bar_config(disable=__a		)
								pipe.enable_attention_slicing(1		)
								pipe.enable_sequential_cpu_offload()

								UpperCamelCase   =	self.get_inputs()
								UpperCamelCase   =	pipe(**__a		)

								UpperCamelCase   =	torch.cuda.max_memory_allocated()
								# make sure that less than 5.2 GB is allocated
								assert mem_bytes < 5.5 * 10**9






