





"""simple docstring"""





import argparse
import os
import re


lowerCAmelCase__     			=			"src/diffusers"

# Pattern that looks at the indentation in a line.
lowerCAmelCase__     			=			re.compile(r'''^(\s*)\S''')
# Pattern that matches `"key":" and puts `key` in group 0.
lowerCAmelCase__     			=			re.compile(r'''^\s*\"([^\"]+)\":''')
# Pattern that matches `_import_structure["key"]` and puts `key` in group 0.
lowerCAmelCase__     			=			re.compile(r'''^\s*_import_structure\[\"([^\"]+)\"\]''')
# Pattern that matches `"key",` and puts `key` in group 0.
lowerCAmelCase__     			=			re.compile(r'''^\s*\"([^\"]+)\",\s*$''')
# Pattern that matches any `[stuff]` and puts `stuff` in group 0.
lowerCAmelCase__     			=			re.compile(r'''\[([^\]]+)\]''')






def       a__					(					_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		UpperCamelCase   =	_re_indent.search(__lowerCAmelCase    )
		return "" if search is None else search.groups()[0]






def       a__					(					_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE=""  ,	_SCREAMING_SNAKE_CASE=None  ,	_SCREAMING_SNAKE_CASE=None    ):




		"""simple docstring"""


		UpperCamelCase   =	0
		UpperCamelCase   =	code.split("\n"    )
		if start_prompt is not None:
				while not lines[index].startswith(__lowerCAmelCase    ):
						index += 1
				UpperCamelCase   =	["""\n""".join(lines[:index]    )]
		else:
				UpperCamelCase   =	[]

		# We split into blocks until we get to the `end_prompt` (or the end of the block).
		UpperCamelCase   =	[lines[index]]
		index += 1
		while index < len(__lowerCAmelCase    ) and (end_prompt is None or not lines[index].startswith(__lowerCAmelCase    )):
				if len(lines[index]    ) > 0 and get_indent(lines[index]    ) == indent_level:
						if len(__lowerCAmelCase    ) > 0 and get_indent(current_block[-1]    ).startswith(indent_level + " "    ):
								current_block.append(lines[index]    )
								blocks.append("\n".join(__lowerCAmelCase    )    )
								if index < len(__lowerCAmelCase    ) - 1:
										UpperCamelCase   =	[lines[index + 1]]
										index += 1
								else:
										UpperCamelCase   =	[]
						else:
								blocks.append("\n".join(__lowerCAmelCase    )    )
								UpperCamelCase   =	[lines[index]]
				else:
						current_block.append(lines[index]    )
				index += 1

		# Adds current block if it's nonempty.
		if len(__lowerCAmelCase    ) > 0:
				blocks.append("\n".join(__lowerCAmelCase    )    )

		# Add final block after end_prompt if provided.
		if end_prompt is not None and index < len(__lowerCAmelCase    ):
				blocks.append("\n".join(lines[index:]    )    )

		return blocks






def       a__					(					_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		def _inner(_SCREAMING_SNAKE_CASE    ):
				return key(__lowerCAmelCase    ).lower().replace("_"  ,	""    )

		return _inner






def       a__					(					_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE=None    ):




		"""simple docstring"""


		def noop(_SCREAMING_SNAKE_CASE    ):
				return x

		if key is None:
				UpperCamelCase   =	noop
		# Constants are all uppercase, they go first.
		UpperCamelCase   =	[obj for obj in objects if key(__lowerCAmelCase    ).isupper()]
		# Classes are not all uppercase but start with a capital, they go second.
		UpperCamelCase   =	[obj for obj in objects if key(__lowerCAmelCase    )[0].isupper() and not key(__lowerCAmelCase    ).isupper()]
		# Functions begin with a lowercase, they go last.
		UpperCamelCase   =	[obj for obj in objects if not key(__lowerCAmelCase    )[0].isupper()]

		UpperCamelCase   =	ignore_underscore(__lowerCAmelCase    )
		return sorted(__lowerCAmelCase  ,	key=__lowerCAmelCase    ) + sorted(__lowerCAmelCase  ,	key=__lowerCAmelCase    ) + sorted(__lowerCAmelCase  ,	key=__lowerCAmelCase    )






def       a__					(					_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		def _replace(_SCREAMING_SNAKE_CASE    ):
				UpperCamelCase   =	match.groups()[0]
				if "," not in imports:
						return F"[{imports}]"
				UpperCamelCase   =	[part.strip().replace("\""  ,	""    ) for part in imports.split(","    )]
				# We will have a final empty element if the line finished with a comma.
				if len(keys[-1]    ) == 0:
						UpperCamelCase   =	keys[:-1]
				return "[" + ", ".join([F"\"{k}\"" for k in sort_objects(__lowerCAmelCase    )]    ) + "]"

		UpperCamelCase   =	import_statement.split("\n"    )
		if len(__lowerCAmelCase    ) > 3:
				# Here we have to sort internal imports that are on several lines (one per name):
				# key: [
				#     "object1",
				#     "object2",
				#     ...
				# ]

				# We may have to ignore one or two lines on each side.
				UpperCamelCase   =	2 if lines[1].strip() == """[""" else 1
				UpperCamelCase   =	[(i, _re_strip_line.search(__lowerCAmelCase    ).groups()[0]) for i, line in enumerate(lines[idx:-idx]    )]
				UpperCamelCase   =	sort_objects(__lowerCAmelCase  ,	key=lambda _SCREAMING_SNAKE_CASE    : x[1]    )
				UpperCamelCase   =	[lines[x[0] + idx] for x in sorted_indices]
				return "\n".join(lines[:idx] + sorted_lines + lines[-idx:]    )
		elif len(__lowerCAmelCase    ) == 3:
				# Here we have to sort internal imports that are on one separate line:
				# key: [
				#     "object1", "object2", ...
				# ]
				if _re_bracket_content.search(lines[1]    ) is not None:
						UpperCamelCase   =	_re_bracket_content.sub(_replace  ,	lines[1]    )
				else:
						UpperCamelCase   =	[part.strip().replace("\""  ,	""    ) for part in lines[1].split(","    )]
						# We will have a final empty element if the line finished with a comma.
						if len(keys[-1]    ) == 0:
								UpperCamelCase   =	keys[:-1]
						UpperCamelCase   =	get_indent(lines[1]    ) + """, """.join([F"\"{k}\"" for k in sort_objects(__lowerCAmelCase    )]    )
				return "\n".join(__lowerCAmelCase    )
		else:
				# Finally we have to deal with imports fitting on one line
				UpperCamelCase   =	_re_bracket_content.sub(_replace  ,	__lowerCAmelCase    )
				return import_statement






def       a__					(					_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE=True    ):




		"""simple docstring"""


		with open(__lowerCAmelCase  ,	"r"    ) as f:
				UpperCamelCase   =	f.read()

		if "_import_structure" not in code:
				return

		# Blocks of indent level 0
		UpperCamelCase   =	split_code_in_indented_blocks(
		    __lowerCAmelCase  ,	start_prompt="_import_structure = {"  ,	end_prompt="if TYPE_CHECKING:"    )

		# We ignore block 0 (everything until start_prompt) and the last block (everything after end_prompt).
		for block_idx in range(1  ,	len(__lowerCAmelCase    ) - 1    ):
				# Check if the block contains some `_import_structure`s thingy to sort.
				UpperCamelCase   =	main_blocks[block_idx]
				UpperCamelCase   =	block.split("\n"    )

				# Get to the start of the imports.
				UpperCamelCase   =	0
				while line_idx < len(__lowerCAmelCase    ) and "_import_structure" not in block_lines[line_idx]:
						# Skip dummy import blocks
						if "import dummy" in block_lines[line_idx]:
								UpperCamelCase   =	len(__lowerCAmelCase    )
						else:
								line_idx += 1
				if line_idx >= len(__lowerCAmelCase    ):
						continue

				# Ignore beginning and last line: they don't contain anything.
				UpperCamelCase   =	"""\n""".join(block_lines[line_idx:-1]    )
				UpperCamelCase   =	get_indent(block_lines[1]    )
				# Slit the internal block into blocks of indent level 1.
				UpperCamelCase   =	split_code_in_indented_blocks(__lowerCAmelCase  ,	indent_level=__lowerCAmelCase    )
				# We have two categories of import key: list or _import_structure[key].append/extend
				UpperCamelCase   =	_re_direct_key if """_import_structure""" in block_lines[0] else _re_indirect_key
				# Grab the keys, but there is a trap: some lines are empty or just comments.
				UpperCamelCase   =	[(pattern.search(__lowerCAmelCase    ).groups()[0] if pattern.search(__lowerCAmelCase    ) is not None else None) for b in internal_blocks]
				# We only sort the lines with a key.
				UpperCamelCase   =	[(i, key) for i, key in enumerate(__lowerCAmelCase    ) if key is not None]
				UpperCamelCase   =	[x[0] for x in sorted(__lowerCAmelCase  ,	key=lambda _SCREAMING_SNAKE_CASE    : x[1]    )]

				# We reorder the blocks by leaving empty lines/comments as they were and reorder the rest.
				UpperCamelCase   =	0
				UpperCamelCase   =	[]
				for i in range(len(__lowerCAmelCase    )    ):
						if keys[i] is None:
								reordered_blocks.append(internal_blocks[i]    )
						else:
								UpperCamelCase   =	sort_objects_in_import(internal_blocks[sorted_indices[count]]    )
								reordered_blocks.append(__lowerCAmelCase    )
								count += 1

        # And we put our main block back together with its first and last line.
				UpperCamelCase   =	"""\n""".join(block_lines[:line_idx] + reordered_blocks + [block_lines[-1]]    )

		if code != "\n".join(__lowerCAmelCase    ):
				if check_only:
						return True
				else:
						print(F"Overwriting {file}."    )
						with open(__lowerCAmelCase  ,	"w"    ) as f:
								f.write("\n".join(__lowerCAmelCase    )    )






def       a__					(					_SCREAMING_SNAKE_CASE=True    ):




		"""simple docstring"""


		UpperCamelCase   =	[]
		for root, _, files in os.walk(__lowerCAmelCase    ):
				if "__init__.py" in files:
						UpperCamelCase   =	sort_imports(os.path.join(__lowerCAmelCase  ,	"__init__.py"    )  ,	check_only=__lowerCAmelCase    )
						if result:
								UpperCamelCase   =	[os.path.join(__lowerCAmelCase  ,	"__init__.py"    )]
		if len(__lowerCAmelCase    ) > 0:
				raise ValueError(F"Would overwrite {len(__lowerCAmelCase    )} files, run `make style`."    )


if __name__ == "__main__":
						lowerCAmelCase__     			=			argparse.ArgumentParser()
						parser.add_argument('''--check_only''', action='''store_true''', help='''Whether to only check or fix style.''')
						lowerCAmelCase__     			=			parser.parse_args()

						sort_imports_in_all_inits(check_only=args.check_only)













"""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






