





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     __magic_name__     (							unittest.TestCase							):





     """simple docstring"""



     __UpperCamelCase    			=   StableDiffusionLDMaDPipeline
     __UpperCamelCase    			=   TEXT_TO_IMAGE_PARAMS
     __UpperCamelCase    			=   TEXT_TO_IMAGE_BATCH_PARAMS
     __UpperCamelCase    			=   TEXT_TO_IMAGE_IMAGE_PARAMS



     def   SCREAMING_SNAKE_CASE						(							self				:int     ):





        '''simple docstring'''




        torch.manual_seed(0     )
        A_    : int								=	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	,					)
        A_    : Tuple								=	DDIMScheduler(
            beta_start=0.00085	,					beta_end=0.012	,					beta_schedule="scaled_linear"	,					clip_sample=__a	,					set_alpha_to_one=__a	,					)
        torch.manual_seed(0     )
        A_    : str								=	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     )
        A_    : Union[str, Any]								=	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=1_000	,					)
        A_    : List[Any]								=	CLIPTextModel(__a     )
        A_    : Union[str, Any]								=	CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"     )

        A_    : List[str]								=	{
            "unet": unet,
            "scheduler": scheduler,
            "vae": vae,
            "text_encoder": text_encoder,
            "tokenizer": tokenizer,
            "safety_checker": None,
            "feature_extractor": None,
        }
        return components



     def   SCREAMING_SNAKE_CASE						(							self				:Any	,					snake_case				:str	,					snake_case				:Any=0     ):





        '''simple docstring'''




        if str(__a     ).startswith("mps"     ):
           A_    : Any								=	torch.manual_seed(__a     )
        else:
           A_    : Optional[Any]								=	torch.Generator(device=__a     ).manual_seed(__a     )
        A_    : 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   SCREAMING_SNAKE_CASE						(							self				:List[str]     ):





        '''simple docstring'''




        A_    : int								=	"cpu"  # ensure determinism for the device-dependent torch.Generator

        A_    : List[str]								=	self.get_dummy_components()
        A_    : str								=	StableDiffusionLDMaDPipeline(**__a     )
        A_    : List[str]								=	ldmad_pipe.to(__a     )
        ldmad_pipe.set_progress_bar_config(disable=__a     )

        A_    : Optional[Any]								=	self.get_dummy_inputs(__a     )
        A_    : List[str]								=	ldmad_pipe(**__a     )
        A_					,  A_    : Optional[Any]								=	output.rgb, output.depth

        A_    : Optional[int]								=	rgb[0, -3:, -3:, -1]
        A_    : str								=	depth[0, -3:, -1]

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

        A_    : Dict								=	np.array(
            [0.37338176, 0.70247, 0.74203193, 0.51643604, 0.58256793, 0.60932136, 0.4181095, 0.48355877, 0.46535262]     )
        A_    : Any								=	np.array([103.46_727, 85.812004, 87.849236]     )

        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   SCREAMING_SNAKE_CASE						(							self				:Optional[int]     ):





        '''simple docstring'''




        A_    : Optional[Any]								=	self.get_dummy_components()
        A_    : Optional[int]								=	StableDiffusionLDMaDPipeline(**__a     )
        A_    : Tuple								=	ldmad_pipe.to(__a     )
        ldmad_pipe.set_progress_bar_config(disable=__a     )

        A_    : Optional[int]								=	self.get_dummy_inputs(__a     )
        A_    : List[Any]								=	3 * [inputs["prompt"]]

        # forward
        A_    : str								=	ldmad_pipe(**__a     )
        A_					,  A_    : int								=	output.rgb, output.depth
        A_    : List[str]								=	rgb_slice_a[0, -3:, -3:, -1]
        A_    : Union[str, Any]								=	depth_slice_a[0, -3:, -1]

        A_    : Union[str, Any]								=	self.get_dummy_inputs(__a     )
        A_    : Tuple								=	3 * [inputs.pop("prompt"     )]

        A_    : str								=	ldmad_pipe.tokenizer(
            __a	,					padding="max_length"	,					max_length=ldmad_pipe.tokenizer.model_max_length	,					truncation=__a	,					return_tensors="pt"	,					)
        A_    : Optional[Any]								=	text_inputs["input_ids"].to(__a     )

        A_    : List[str]								=	ldmad_pipe.text_encoder(__a     )[0]

        A_    : Tuple								=	prompt_embeds

        # forward
        A_    : str								=	ldmad_pipe(**__a     )
        A_					,  A_    : Tuple								=	output.rgb, output.depth
        A_    : Any								=	rgb_slice_a[0, -3:, -3:, -1]
        A_    : Union[str, 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   SCREAMING_SNAKE_CASE						(							self				:Optional[Any]     ):





        '''simple docstring'''




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

        A_    : Any								=	self.get_dummy_inputs(__a     )
        A_    : List[Any]								=	"french fries"
        A_    : Union[str, Any]								=	ldmad_pipe(**__a	,					negative_prompt=__a     )

        A_					,  A_    : int								=	output.rgb, output.depth
        A_    : Tuple								=	rgb[0, -3:, -3:, -1]
        A_    : Any								=	depth[0, -3:, -1]

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

        A_    : Optional[Any]								=	np.array(
            [0.37044, 0.71811503, 0.7223251, 0.48603675, 0.5638391, 0.6364948, 0.42833704, 0.4901315, 0.47926217]     )
        A_    : Dict								=	np.array([107.84_738, 84.62802, 89.962135]     )
        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     __magic_name__     (							unittest.TestCase							):





     """simple docstring"""



     def   SCREAMING_SNAKE_CASE						(							self				:str     ):





        '''simple docstring'''




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



     def   SCREAMING_SNAKE_CASE						(							self				:Union[str, Any]	,					snake_case				:List[Any]	,					snake_case				:int="cpu"	,					snake_case				:Dict=torch.floataa	,					snake_case				:Dict=0     ):





        '''simple docstring'''




        A_    : Any								=	torch.Generator(device=__a     ).manual_seed(__a     )
        A_    : Dict								=	np.random.RandomState(__a     ).standard_normal((1, 4, 64, 64)     )
        A_    : Optional[Any]								=	torch.from_numpy(__a     ).to(device=__a	,					dtype=__a     )
        A_    : Optional[Any]								=	{
            "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   SCREAMING_SNAKE_CASE						(							self				:Tuple     ):





        '''simple docstring'''




        A_    : int								=	StableDiffusionLDMaDPipeline.from_pretrained("Intel/ldm3d"     )
        A_    : Union[str, Any]								=	ldmad_pipe.to(__a     )
        ldmad_pipe.set_progress_bar_config(disable=__a     )

        A_    : str								=	self.get_inputs(__a     )
        A_    : Dict								=	ldmad_pipe(**__a     )
        A_					,  A_    : Union[str, Any]								=	output.rgb, output.depth
        A_    : Tuple								=	rgb[0, -3:, -3:, -1].flatten()
        A_    : str								=	rgb[0, -3:, -1].flatten()

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

        A_    : int								=	np.array(
            [0.53805465, 0.56707305, 0.5486515, 0.57012236, 0.5814511, 0.56253487, 0.54843014, 0.55092263, 0.6459706]     )
        A_    : Optional[int]								=	np.array(
            [0.9263781, 0.6678672, 0.5486515, 0.92202145, 0.67831135, 0.56253487, 0.9241694, 0.7551478, 0.6459706]     )
        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     __magic_name__     (							unittest.TestCase							):





     """simple docstring"""



     def   SCREAMING_SNAKE_CASE						(							self				:List[Any]     ):





        '''simple docstring'''




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



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





        '''simple docstring'''




        A_    : Optional[int]								=	torch.Generator(device=__a     ).manual_seed(__a     )
        A_    : Any								=	np.random.RandomState(__a     ).standard_normal((1, 4, 64, 64)     )
        A_    : Union[str, Any]								=	torch.from_numpy(__a     ).to(device=__a	,					dtype=__a     )
        A_    : Dict								=	{
            "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   SCREAMING_SNAKE_CASE						(							self				:Optional[int]     ):





        '''simple docstring'''




        A_    : Any								=	StableDiffusionLDMaDPipeline.from_pretrained("Intel/ldm3d"     ).to(__a     )
        ldmad_pipe.set_progress_bar_config(disable=__a     )

        A_    : str								=	self.get_inputs(__a     )
        A_    : Dict								=	ldmad_pipe(**__a     )
        A_					,  A_    : Union[str, Any]								=	output.rgb, output.depth

        A_    : Optional[int]								=	0.495586
        A_    : Dict								=	0.33795515
        A_    : List[Any]								=	112.48_518
        A_    : Any								=	98.489746
        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   SCREAMING_SNAKE_CASE						(							self				:Any     ):





        '''simple docstring'''




        A_    : Optional[Any]								=	StableDiffusionLDMaDPipeline.from_pretrained("Intel/ldm3d-4c"     ).to(__a     )
        ldmad_pipe.set_progress_bar_config(disable=__a     )

        A_    : List[Any]								=	self.get_inputs(__a     )
        A_    : Optional[Any]								=	ldmad_pipe(**__a     )
        A_					,  A_    : Dict								=	output.rgb, output.depth

        A_    : Optional[Any]								=	0.4194127
        A_    : Optional[int]								=	0.35375586
        A_    : List[Any]								=	0.5638502
        A_    : List[str]								=	0.34686103

        assert rgb.shape == (1, 512, 512, 3)
        assert depth.shape == (1, 512, 512, 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'''





import os
from math import logaa





def 	lowerCAmelCase_				(					snake_case_       : str = "base_exp.txt"			)    ->      int:


     '''simple docstring'''




     UpperCAmelCase_           =   0
     UpperCAmelCase_           =   0
     for i, line in enumerate(open(os.path.join(os.path.dirname(snake_case_			)					,    snake_case_			)			)			):
          UpperCAmelCase_    , UpperCAmelCase_           =   list(map(snake_case_					,    line.split(","			)			)			)
          if x * logaa(snake_case_			) > largest:
               UpperCAmelCase_           =   x * logaa(snake_case_			)
               UpperCAmelCase_           =   i + 1
     return result


if __name__ == "__main__":
    print(solution())




