





'''simple docstring'''




import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    PNDMScheduler,
    StableDiffusionLDMaDPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import nightly, 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


enable_full_determinism()




class      UpperCamelCase__					(					unittest.TestCase			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	StableDiffusionLDMaDPipeline
					SCREAMING_SNAKE_CASE__				=	TEXT_TO_IMAGE_PARAMS
					SCREAMING_SNAKE_CASE__				=	TEXT_TO_IMAGE_BATCH_PARAMS
					SCREAMING_SNAKE_CASE__				=	TEXT_TO_IMAGE_IMAGE_PARAMS


					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



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

							SCREAMING_SNAKE_CASE :				Optional[Any]		=			{
							    """unet""": unet,
							    """scheduler""": scheduler,
							    """vae""": vae,
							    """text_encoder""": text_encoder,
							    """tokenizer""": tokenizer,
							    """safety_checker""": None,
							    """feature_extractor""": None,
							}
							return components


					def lowerCamelCase_			(						self				:			Optional[int]      ,						lowerCamelCase_				:			Optional[Any]      ,						lowerCamelCase_				:			Dict=0						):

							'''simple docstring'''



							if str(lowerCamelCase_						).startswith("""mps"""						):
									SCREAMING_SNAKE_CASE :				List[Any]		=			torch.manual_seed(lowerCamelCase_						)
							else:
									SCREAMING_SNAKE_CASE :				Tuple		=			torch.Generator(device=lowerCamelCase_						).manual_seed(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Any		=			{
							    """prompt""": """A painting of a squirrel eating a burger""",
							    """generator""": generator,
							    """num_inference_steps""": 2,
							    """guidance_scale""": 6.0,
							    """output_type""": """numpy""",
							}
							return inputs


					def lowerCamelCase_			(						self				:			Union[str, Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[Any]		=			"""cpu"""  # ensure determinism for the device-dependent torch.Generator

							SCREAMING_SNAKE_CASE :				Dict		=			self.get_dummy_components()
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			StableDiffusionLDMaDPipeline(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			ldmad_pipe.to(lowerCamelCase_						)
							ldmad_pipe.set_progress_bar_config(disable=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Tuple		=			self.get_dummy_inputs(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Dict		=			ldmad_pipe(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Optional[Any]		=			output.rgb, output.depth

							SCREAMING_SNAKE_CASE :				int		=			rgb[0, -3:, -3:, -1]
							SCREAMING_SNAKE_CASE :				Any		=			depth[0, -3:, -1]

							assert rgb.shape == (1, 64, 64, 3)
							assert depth.shape == (1, 64, 64)

							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			np.array(
							    [0.37_338_176, 0.70_247, 0.74_203_193, 0.51_643_604, 0.58_256_793, 0.60_932_136, 0.4_181_095, 0.48_355_877, 0.46_535_262]						)
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			np.array([103.46_727, 85.812_004, 87.849_236]						)

							assert np.abs(image_slice_rgb.flatten() - expected_slice_rgb						).max() < 1e-2
							assert np.abs(image_slice_depth.flatten() - expected_slice_depth						).max() < 1e-2


					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Any		=			self.get_dummy_components()
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			StableDiffusionLDMaDPipeline(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Dict		=			ldmad_pipe.to(lowerCamelCase_						)
							ldmad_pipe.set_progress_bar_config(disable=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Tuple		=			self.get_dummy_inputs(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			3 * [inputs["""prompt"""]]

							# forward
							SCREAMING_SNAKE_CASE :				str		=			ldmad_pipe(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Any		=			output.rgb, output.depth
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			rgb_slice_a[0, -3:, -3:, -1]
							SCREAMING_SNAKE_CASE :				Dict		=			depth_slice_a[0, -3:, -1]

							SCREAMING_SNAKE_CASE :				int		=			self.get_dummy_inputs(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Dict		=			3 * [inputs.pop("""prompt"""						)]

							SCREAMING_SNAKE_CASE :				Tuple		=			ldmad_pipe.tokenizer(
							    lowerCamelCase_      ,						padding="""max_length"""      ,						max_length=ldmad_pipe.tokenizer.model_max_length      ,						truncation=lowerCamelCase_      ,						return_tensors="""pt"""      ,						)
							SCREAMING_SNAKE_CASE :				Optional[int]		=			text_inputs["""input_ids"""].to(lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				str		=			ldmad_pipe.text_encoder(lowerCamelCase_						)[0]

							SCREAMING_SNAKE_CASE :				Any		=			prompt_embeds

							# forward
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			ldmad_pipe(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				int		=			output.rgb, output.depth
							SCREAMING_SNAKE_CASE :				str		=			rgb_slice_a[0, -3:, -3:, -1]
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			depth_slice_a[0, -3:, -1]

							assert np.abs(rgb_slice_a.flatten() - rgb_slice_a.flatten()						).max() < 1e-4
							assert np.abs(depth_slice_a.flatten() - depth_slice_a.flatten()						).max() < 1e-4



					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			"""cpu"""  # ensure determinism for the device-dependent torch.Generator
							SCREAMING_SNAKE_CASE :				List[str]		=			self.get_dummy_components()
							SCREAMING_SNAKE_CASE :				List[str]		=			PNDMScheduler(skip_prk_steps=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Any		=			StableDiffusionLDMaDPipeline(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Any		=			ldmad_pipe.to(lowerCamelCase_						)
							ldmad_pipe.set_progress_bar_config(disable=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				List[Any]		=			self.get_dummy_inputs(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			"""french fries"""
							SCREAMING_SNAKE_CASE :				List[str]		=			ldmad_pipe(**lowerCamelCase_      ,						negative_prompt=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Optional[Any]		=			output.rgb, output.depth
							SCREAMING_SNAKE_CASE :				Tuple		=			rgb[0, -3:, -3:, -1]
							SCREAMING_SNAKE_CASE :				List[Any]		=			depth[0, -3:, -1]

							assert rgb.shape == (1, 64, 64, 3)
							assert depth.shape == (1, 64, 64)

							SCREAMING_SNAKE_CASE :				str		=			np.array(
							    [0.37_044, 0.71_811_503, 0.7_223_251, 0.48_603_675, 0.5_638_391, 0.6_364_948, 0.42_833_704, 0.4_901_315, 0.47_926_217]						)
							SCREAMING_SNAKE_CASE :				Any		=			np.array([107.84_738, 84.62_802, 89.962_135]						)
							assert np.abs(rgb_slice.flatten() - expected_slice_rgb						).max() < 1e-2
							assert np.abs(depth_slice.flatten() - expected_slice_depth						).max() < 1e-2







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




					"""simple docstring"""


					def lowerCamelCase_			(						self				:			List[Any]						):

							'''simple docstring'''



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


					def lowerCamelCase_			(						self				:			Optional[Any]      ,						lowerCamelCase_				:			Tuple      ,						lowerCamelCase_				:			Dict="cpu"      ,						lowerCamelCase_				:			int=torch.floataa      ,						lowerCamelCase_				:			int=0						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			torch.Generator(device=lowerCamelCase_						).manual_seed(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				str		=			np.random.RandomState(lowerCamelCase_						).standard_normal((1, 4, 64, 64)						)
							SCREAMING_SNAKE_CASE :				int		=			torch.from_numpy(lowerCamelCase_						).to(device=lowerCamelCase_      ,						dtype=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				str		=			{
							    """prompt""": """a photograph of an astronaut riding a horse""",
							    """latents""": latents,
							    """generator""": generator,
							    """num_inference_steps""": 3,
							    """guidance_scale""": 7.5,
							    """output_type""": """numpy""",
							}
							return inputs



					def lowerCamelCase_			(						self				:			Optional[int]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Dict		=			StableDiffusionLDMaDPipeline.from_pretrained("""Intel/ldm3d"""						)
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			ldmad_pipe.to(lowerCamelCase_						)
							ldmad_pipe.set_progress_bar_config(disable=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				List[str]		=			self.get_inputs(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				List[str]		=			ldmad_pipe(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Optional[Any]		=			output.rgb, output.depth
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			rgb[0, -3:, -3:, -1].flatten()
							SCREAMING_SNAKE_CASE :				int		=			rgb[0, -3:, -1].flatten()

							assert rgb.shape == (1, 5_12, 5_12, 3)
							assert depth.shape == (1, 5_12, 5_12)

							SCREAMING_SNAKE_CASE :				List[str]		=			np.array(
							    [0.53_805_465, 0.56_707_305, 0.5_486_515, 0.57_012_236, 0.5_814_511, 0.56_253_487, 0.54_843_014, 0.55_092_263, 0.6_459_706]						)
							SCREAMING_SNAKE_CASE :				List[Any]		=			np.array(
							    [0.9_263_781, 0.6_678_672, 0.5_486_515, 0.92_202_145, 0.67_831_135, 0.56_253_487, 0.9_241_694, 0.7_551_478, 0.6_459_706]						)
							assert np.abs(rgb_slice - expected_slice_rgb						).max() < 3e-3
							assert np.abs(depth_slice - expected_slice_depth						).max() < 3e-3







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




					"""simple docstring"""


					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



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


					def lowerCamelCase_			(						self				:			str      ,						lowerCamelCase_				:			int      ,						lowerCamelCase_				:			Tuple="cpu"      ,						lowerCamelCase_				:			List[Any]=torch.floataa      ,						lowerCamelCase_				:			Any=0						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			torch.Generator(device=lowerCamelCase_						).manual_seed(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Optional[int]		=			np.random.RandomState(lowerCamelCase_						).standard_normal((1, 4, 64, 64)						)
							SCREAMING_SNAKE_CASE :				int		=			torch.from_numpy(lowerCamelCase_						).to(device=lowerCamelCase_      ,						dtype=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Tuple		=			{
							    """prompt""": """a photograph of an astronaut riding a horse""",
							    """latents""": latents,
							    """generator""": generator,
							    """num_inference_steps""": 50,
							    """guidance_scale""": 7.5,
							    """output_type""": """numpy""",
							}
							return inputs


					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[Any]		=			StableDiffusionLDMaDPipeline.from_pretrained("""Intel/ldm3d"""						).to(lowerCamelCase_						)
							ldmad_pipe.set_progress_bar_config(disable=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Tuple		=			self.get_inputs(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				List[str]		=			ldmad_pipe(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Tuple		=			output.rgb, output.depth

							SCREAMING_SNAKE_CASE :				Optional[int]		=			0.495_586
							SCREAMING_SNAKE_CASE :				Tuple		=			0.33_795_515
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			112.48_518
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			98.489_746
							assert np.abs(expected_rgb_mean - rgb.mean()						) < 1e-3
							assert np.abs(expected_rgb_std - rgb.std()						) < 1e-3
							assert np.abs(expected_depth_mean - depth.mean()						) < 1e-3
							assert np.abs(expected_depth_std - depth.std()						) < 1e-3



					def lowerCamelCase_			(						self				:			Any						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[Any]		=			StableDiffusionLDMaDPipeline.from_pretrained("""Intel/ldm3d-4c"""						).to(lowerCamelCase_						)
							ldmad_pipe.set_progress_bar_config(disable=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Optional[Any]		=			self.get_inputs(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				List[Any]		=			ldmad_pipe(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				List[str]		=			output.rgb, output.depth

							SCREAMING_SNAKE_CASE :				str		=			0.4_194_127
							SCREAMING_SNAKE_CASE :				int		=			0.35_375_586
							SCREAMING_SNAKE_CASE :				List[str]		=			0.5_638_502
							SCREAMING_SNAKE_CASE :				Dict		=			0.34_686_103

							assert rgb.shape == (1, 5_12, 5_12, 3)
							assert depth.shape == (1, 5_12, 5_12, 1)
							assert np.abs(expected_rgb_mean - rgb.mean()						) < 1e-3
							assert np.abs(expected_rgb_std - rgb.std()						) < 1e-3
							assert np.abs(expected_depth_mean - depth.mean()						) < 1e-3
							assert np.abs(expected_depth_std - depth.std()						) < 1e-3










'''simple docstring'''




from math import factorial



def 		__A		(  lowerCamelCase_			,			lowerCamelCase_	):


		"""simple docstring"""



		if n < k or k < 0:
				raise ValueError("""Please enter positive integers for n and k where n >= k"""	)
		return factorial(lowerCamelCase_	) // (factorial(lowerCamelCase_	) * factorial(n - k	))


if __name__ == "__main__":
							print(
							    """The number of five-card hands possible from a standard""",
							    f'''fifty-two card deck is: {combinations(52, 5)}\n''',
							)

							print(
							    """If a class of 40 students must be arranged into groups of""",
							    f'''4 for group projects, there are {combinations(40, 4)} ways''',
							    """to arrange them.\n""",
							)

							print(
							    """If 10 teams are competing in a Formula One race, there""",
							    f'''are {combinations(10, 3)} ways that first, second and''',
							    """third place can be awarded.""",
							)



