





import gc
import random
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    EulerAncestralDiscreteScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionInstructPixaPixPipeline,
    UNetaDConditionModel,
)
from diffusers.image_processor import VaeImageProcessor
from diffusers.utils import floats_tensor, load_image, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import (
    IMAGE_TO_IMAGE_IMAGE_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()





class 			lowerCAmelCase__( __lowercase  ,     __lowercase  ,     __lowercase  ,     unittest.TestCase    ):






       '''simple docstring'''


       __snake_case 			=    StableDiffusionInstructPixaPixPipeline
       __snake_case 			=    TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'height', 'width', 'cross_attention_kwargs'}
       __snake_case 			=    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
       __snake_case 			=    IMAGE_TO_IMAGE_IMAGE_PARAMS
       __snake_case 			=    IMAGE_TO_IMAGE_IMAGE_PARAMS




       def     UpperCamelCase_			(      self							)			->     str:
            torch.manual_seed(0							)
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							UNetaDConditionModel(
                block_out_channels=(3_2, 6_4)    ,						layers_per_block=2    ,						sample_size=3_2    ,						in_channels=8    ,						out_channels=4    ,						down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")    ,						up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")    ,						cross_attention_dim=3_2    ,						)
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							PNDMScheduler(skip_prk_steps=__lowerCamelCase							)
            torch.manual_seed(0							)
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							AutoencoderKL(
                block_out_channels=[3_2, 6_4]    ,						in_channels=3    ,						out_channels=3    ,						down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]    ,						up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]    ,						latent_channels=4    ,						)
            torch.manual_seed(0							)
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							CLIPTextConfig(
                bos_token_id=0    ,						eos_token_id=2    ,						hidden_size=3_2    ,						intermediate_size=3_7    ,						layer_norm_eps=1E-05    ,						num_attention_heads=4    ,						num_hidden_layers=5    ,						pad_token_id=1    ,						vocab_size=1_0_0_0    ,						)
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							CLIPTextModel(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Any						    =							CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"							)

            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							{
                "unet": unet,
                "scheduler": scheduler,
                "vae": vae,
                "text_encoder": text_encoder,
                "tokenizer": tokenizer,
                "safety_checker": None,
                "feature_extractor": None,
            }
            return components




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase    ,						__lowerCamelCase=0							)			->     List[str]:
            _SCREAMING_SNAKE_CASE       :	str						    =							floats_tensor((1, 3, 3_2, 3_2)    ,						rng=random.Random(__lowerCamelCase							)							).to(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							image.cpu().permute(0    ,						2    ,						3    ,						1							)[0]
            _SCREAMING_SNAKE_CASE       :	int						    =							Image.fromarray(np.uinta(__lowerCamelCase							)							).convert("RGB"							)
            if str(__lowerCamelCase							).startswith("mps"							):
                 _SCREAMING_SNAKE_CASE       :	Tuple						    =							torch.manual_seed(__lowerCamelCase							)
            else:
                 _SCREAMING_SNAKE_CASE       :	List[str]						    =							torch.Generator(device=__lowerCamelCase							).manual_seed(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	int						    =							{
                "prompt": "A painting of a squirrel eating a burger",
                "image": image,
                "generator": generator,
                "num_inference_steps": 2,
                "guidance_scale": 6.0,
                "image_guidance_scale": 1,
                "output_type": "numpy",
            }
            return inputs




       def     UpperCamelCase_			(      self							)			->     List[Any]:
            _SCREAMING_SNAKE_CASE       :	str						    =							"cpu"  # ensure determinism for the device-dependent torch.Generator
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							self.get_dummy_components()
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							StableDiffusionInstructPixaPixPipeline(**__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							sd_pipe.to(__lowerCamelCase							)
            sd_pipe.set_progress_bar_config(disable=__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							self.get_dummy_inputs(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	int						    =							sd_pipe(**__lowerCamelCase							).images
            _SCREAMING_SNAKE_CASE       :	int						    =							image[0, -3:, -3:, -1]
            assert image.shape == (1, 3_2, 3_2, 3)
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							np.array([0.7526, 0.3750, 0.4547, 0.6117, 0.5866, 0.5016, 0.4327, 0.5642, 0.4815]							)

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




       def     UpperCamelCase_			(      self							)			->     str:
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							"cpu"  # ensure determinism for the device-dependent torch.Generator
            _SCREAMING_SNAKE_CASE       :	Dict						    =							self.get_dummy_components()
            _SCREAMING_SNAKE_CASE       :	str						    =							StableDiffusionInstructPixaPixPipeline(**__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							sd_pipe.to(__lowerCamelCase							)
            sd_pipe.set_progress_bar_config(disable=__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	Dict						    =							self.get_dummy_inputs(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							"french fries"
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							sd_pipe(**__lowerCamelCase    ,						negative_prompt=__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							output.images
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							image[0, -3:, -3:, -1]

            assert image.shape == (1, 3_2, 3_2, 3)
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							np.array([0.7511, 0.3642, 0.4553, 0.6236, 0.5797, 0.5013, 0.4343, 0.5611, 0.4831]							)

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




       def     UpperCamelCase_			(      self							)			->     int:
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							"cpu"  # ensure determinism for the device-dependent torch.Generator
            _SCREAMING_SNAKE_CASE       :	Dict						    =							self.get_dummy_components()
            _SCREAMING_SNAKE_CASE       :	str						    =							StableDiffusionInstructPixaPixPipeline(**__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	str						    =							sd_pipe.to(__lowerCamelCase							)
            sd_pipe.set_progress_bar_config(disable=__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	int						    =							self.get_dummy_inputs(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Dict						    =							[inputs["prompt"]] * 2

            _SCREAMING_SNAKE_CASE       :	List[str]						    =							np.array(inputs["image"]							).astype(np.floataa							) / 255.0
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							torch.from_numpy(__lowerCamelCase							).unsqueeze(0							).to(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Any						    =							image / 2 + 0.5
            _SCREAMING_SNAKE_CASE       :	Any						    =							image.permute(0    ,						3    ,						1    ,						2							)
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							image.repeat(2    ,						1    ,						1    ,						1							)

            _SCREAMING_SNAKE_CASE       :	Dict						    =							sd_pipe(**__lowerCamelCase							).images
            _SCREAMING_SNAKE_CASE       :	str						    =							image[-1, -3:, -3:, -1]

            assert image.shape == (2, 3_2, 3_2, 3)
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							np.array([0.5812, 0.5748, 0.5222, 0.5908, 0.5695, 0.7174, 0.6804, 0.5523, 0.5579]							)

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




       def     UpperCamelCase_			(      self							)			->     int:
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							"cpu"  # ensure determinism for the device-dependent torch.Generator
            _SCREAMING_SNAKE_CASE       :	str						    =							self.get_dummy_components()
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							EulerAncestralDiscreteScheduler(
                beta_start=0.0_0085    ,						beta_end=0.012    ,						beta_schedule="scaled_linear"							)
            _SCREAMING_SNAKE_CASE       :	Any						    =							StableDiffusionInstructPixaPixPipeline(**__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							sd_pipe.to(__lowerCamelCase							)
            sd_pipe.set_progress_bar_config(disable=__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	Tuple						    =							self.get_dummy_inputs(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							sd_pipe(**__lowerCamelCase							).images
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							image[0, -3:, -3:, -1]

            _SCREAMING_SNAKE_CASE       :	Any						    =							[round(__lowerCamelCase    ,						4							) for x in image_slice.flatten().tolist()]
            print(",".join([str(__lowerCamelCase							) for x in slice]							)							)

            assert image.shape == (1, 3_2, 3_2, 3)
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							np.array([0.7417, 0.3842, 0.4732, 0.5776, 0.5891, 0.5139, 0.4052, 0.5673, 0.4986]							)

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




       def     UpperCamelCase_			(      self							)			->     Optional[Any]:
            super().test_inference_batch_single_identical(expected_max_diff=3E-3							)







       def     UpperCamelCase_			(      self							)			->     Tuple:
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							self.get_dummy_components()
            _SCREAMING_SNAKE_CASE       :	Any						    =							StableDiffusionInstructPixaPixPipeline(**__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							VaeImageProcessor(do_resize=__lowerCamelCase    ,						do_normalize=__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	int						    =							pipe.to(__lowerCamelCase							)
            pipe.set_progress_bar_config(disable=__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	Dict						    =							pipe(**self.get_dummy_inputs_by_type(__lowerCamelCase    ,						input_image_type="pt"							)							)[0]

            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							components["vae"]
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							self.get_dummy_inputs_by_type(__lowerCamelCase    ,						input_image_type="pt"							)

            for image_param in self.image_latents_params:
                 if image_param in inputs.keys():
                      _SCREAMING_SNAKE_CASE       :	Tuple						    =							vae.encode(inputs[image_param]							).latent_dist.mode()

            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							pipe(**__lowerCamelCase							)[0]

            _SCREAMING_SNAKE_CASE       :	Dict						    =							np.abs(out - out_latents_inputs							).max()
            self.assertLess(__lowerCamelCase    ,						1E-4    ,						"passing latents as image input generate different result from passing image"							)





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






       '''simple docstring'''


       def     UpperCamelCase_			(      self							)			->     Optional[Any]:
            super().tearDown()
            gc.collect()
            torch.cuda.empty_cache()




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase=0							)			->     int:
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							torch.manual_seed(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							load_image(
                "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_pix2pix/example.jpg"							)
            _SCREAMING_SNAKE_CASE       :	str						    =							{
                "prompt": "turn him into a cyborg",
                "image": image,
                "generator": generator,
                "num_inference_steps": 3,
                "guidance_scale": 7.5,
                "image_guidance_scale": 1.0,
                "output_type": "numpy",
            }
            return inputs




       def     UpperCamelCase_			(      self							)			->     List[str]:
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							StableDiffusionInstructPixaPixPipeline.from_pretrained(
                "timbrooks/instruct-pix2pix"    ,						safety_checker=__lowerCamelCase							)
            pipe.to(__lowerCamelCase							)
            pipe.set_progress_bar_config(disable=__lowerCamelCase							)
            pipe.enable_attention_slicing()

            _SCREAMING_SNAKE_CASE       :	Tuple						    =							self.get_inputs()
            _SCREAMING_SNAKE_CASE       :	Any						    =							pipe(**__lowerCamelCase							).images
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							image[0, -3:, -3:, -1].flatten()

            assert image.shape == (1, 5_1_2, 5_1_2, 3)
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							np.array([0.5902, 0.6015, 0.6027, 0.5983, 0.6092, 0.6061, 0.5765, 0.5785, 0.5555]							)

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




       def     UpperCamelCase_			(      self							)			->     Optional[int]:
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							StableDiffusionInstructPixaPixPipeline.from_pretrained(
                "timbrooks/instruct-pix2pix"    ,						safety_checker=__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							LMSDiscreteScheduler.from_config(pipe.scheduler.config							)
            pipe.to(__lowerCamelCase							)
            pipe.set_progress_bar_config(disable=__lowerCamelCase							)
            pipe.enable_attention_slicing()

            _SCREAMING_SNAKE_CASE       :	List[str]						    =							self.get_inputs()
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							pipe(**__lowerCamelCase							).images
            _SCREAMING_SNAKE_CASE       :	str						    =							image[0, -3:, -3:, -1].flatten()

            assert image.shape == (1, 5_1_2, 5_1_2, 3)
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							np.array([0.6578, 0.6817, 0.6972, 0.6761, 0.6856, 0.6916, 0.6428, 0.6516, 0.6301]							)

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




       def     UpperCamelCase_			(      self							)			->     int:
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							StableDiffusionInstructPixaPixPipeline.from_pretrained(
                "timbrooks/instruct-pix2pix"    ,						safety_checker=__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							DDIMScheduler.from_config(pipe.scheduler.config							)
            pipe.to(__lowerCamelCase							)
            pipe.set_progress_bar_config(disable=__lowerCamelCase							)
            pipe.enable_attention_slicing()

            _SCREAMING_SNAKE_CASE       :	Dict						    =							self.get_inputs()
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							pipe(**__lowerCamelCase							).images
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							image[0, -3:, -3:, -1].flatten()

            assert image.shape == (1, 5_1_2, 5_1_2, 3)
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							np.array([0.3828, 0.3834, 0.3818, 0.3792, 0.3865, 0.3752, 0.3792, 0.3847, 0.3753]							)

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




       def     UpperCamelCase_			(      self							)			->     Any:
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							0

            def callback_fn(__lowerCamelCase    ,						__lowerCamelCase    ,						__lowerCamelCase							) -> None:
                 _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							True
                 nonlocal number_of_steps
                 number_of_steps += 1
                 if step == 1:
                      _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							latents.detach().cpu().numpy()
                      assert latents.shape == (1, 4, 6_4, 6_4)
                      _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							latents[0, -3:, -3:, -1]
                      _SCREAMING_SNAKE_CASE       :	Dict						    =							np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]							)

                      assert np.abs(latents_slice.flatten() - expected_slice							).max() < 5E-2
                 elif step == 2:
                      _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							latents.detach().cpu().numpy()
                      assert latents.shape == (1, 4, 6_4, 6_4)
                      _SCREAMING_SNAKE_CASE       :	List[Any]						    =							latents[0, -3:, -3:, -1]
                      _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]							)

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

            _SCREAMING_SNAKE_CASE       :	int						    =							False

            _SCREAMING_SNAKE_CASE       :	Dict						    =							StableDiffusionInstructPixaPixPipeline.from_pretrained(
                "timbrooks/instruct-pix2pix"    ,						safety_checker=__lowerCamelCase    ,						torch_dtype=torch.floataa							)
            _SCREAMING_SNAKE_CASE       :	Any						    =							pipe.to(__lowerCamelCase							)
            pipe.set_progress_bar_config(disable=__lowerCamelCase							)
            pipe.enable_attention_slicing()

            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							self.get_inputs()
            pipe(**__lowerCamelCase    ,						callback=__lowerCamelCase    ,						callback_steps=1							)
            assert callback_fn.has_been_called
            assert number_of_steps == 3




       def     UpperCamelCase_			(      self							)			->     str:
            torch.cuda.empty_cache()
            torch.cuda.reset_max_memory_allocated()
            torch.cuda.reset_peak_memory_stats()

            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							StableDiffusionInstructPixaPixPipeline.from_pretrained(
                "timbrooks/instruct-pix2pix"    ,						safety_checker=__lowerCamelCase    ,						torch_dtype=torch.floataa							)
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							pipe.to(__lowerCamelCase							)
            pipe.set_progress_bar_config(disable=__lowerCamelCase							)
            pipe.enable_attention_slicing(1							)
            pipe.enable_sequential_cpu_offload()

            _SCREAMING_SNAKE_CASE       :	Any						    =							self.get_inputs()
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							pipe(**__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	Any						    =							torch.cuda.max_memory_allocated()
            # make sure that less than 2.2 GB is allocated
            assert mem_bytes < 2.2 * 1_0**9







       def     UpperCamelCase_			(      self							)			->     int:
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							self.get_inputs()
            # resize to resolution that is divisible by 8 but not 16 or 32
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							inputs["image"].resize((5_0_4, 5_0_4)							)

            _SCREAMING_SNAKE_CASE       :	Any						    =							"timbrooks/instruct-pix2pix"
            _SCREAMING_SNAKE_CASE       :	Any						    =							StableDiffusionInstructPixaPixPipeline.from_pretrained(
                __lowerCamelCase    ,						safety_checker=__lowerCamelCase    ,						)
            pipe.to(__lowerCamelCase							)
            pipe.set_progress_bar_config(disable=__lowerCamelCase							)
            pipe.enable_attention_slicing()

            _SCREAMING_SNAKE_CASE       :	List[str]						    =							pipe(**__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	int						    =							output.images[0]

            _SCREAMING_SNAKE_CASE       :	Tuple						    =							image[2_5_5:2_5_8, 3_8_3:3_8_6, -1]

            assert image.shape == (5_0_4, 5_0_4, 3)
            _SCREAMING_SNAKE_CASE       :	str						    =							np.array([0.2726, 0.2529, 0.2664, 0.2655, 0.2641, 0.2642, 0.2591, 0.2649, 0.2590]							)

            assert np.abs(image_slice.flatten() - expected_slice							).max() < 5E-3






import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
       pass

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__      =logging.get_logger(__name__)

UpperCamelCase__      ={
    'kakaobrain/align-base': 'https://huggingface.co/kakaobrain/align-base/resolve/main/config.json',
}





class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       __snake_case 			=    'align_text_model'




       def __init__(      self    ,						__lowerCamelCase=3_0_5_2_2    ,						__lowerCamelCase=7_6_8    ,						__lowerCamelCase=1_2    ,						__lowerCamelCase=1_2    ,						__lowerCamelCase=3_0_7_2    ,						__lowerCamelCase="gelu"    ,						__lowerCamelCase=0.1    ,						__lowerCamelCase=0.1    ,						__lowerCamelCase=5_1_2    ,						__lowerCamelCase=2    ,						__lowerCamelCase=0.02    ,						__lowerCamelCase=1E-12    ,						__lowerCamelCase=0    ,						__lowerCamelCase="absolute"    ,						__lowerCamelCase=True    ,						**__lowerCamelCase    ,						)			->     List[Any]:
            super().__init__(**__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	Tuple						    =							vocab_size
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							hidden_size
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							num_hidden_layers
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							num_attention_heads
            _SCREAMING_SNAKE_CASE       :	int						    =							hidden_act
            _SCREAMING_SNAKE_CASE       :	Any						    =							intermediate_size
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							hidden_dropout_prob
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							attention_probs_dropout_prob
            _SCREAMING_SNAKE_CASE       :	Dict						    =							max_position_embeddings
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							type_vocab_size
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							initializer_range
            _SCREAMING_SNAKE_CASE       :	Dict						    =							layer_norm_eps
            _SCREAMING_SNAKE_CASE       :	str						    =							position_embedding_type
            _SCREAMING_SNAKE_CASE       :	Dict						    =							use_cache
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							pad_token_id







       @classmethod
       def     UpperCamelCase_			(      cls    ,						__lowerCamelCase    ,						**__lowerCamelCase							)			->     "PretrainedConfig":
            cls._set_token_in_kwargs(__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	List[Any]						    =							cls.get_config_dict(__lowerCamelCase    ,						**__lowerCamelCase							)

            # get the text config dict if we are loading from AlignConfig
            if config_dict.get("model_type"							) == "align":
                 _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							config_dict["text_config"]

            if "model_type" in config_dict and hasattr(cls    ,						"model_type"							) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     F"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
                     F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""							)

            return cls.from_dict(__lowerCamelCase    ,						**__lowerCamelCase							)





class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       __snake_case 			=    'align_vision_model'




       def __init__(      self    ,						__lowerCamelCase = 3    ,						__lowerCamelCase = 6_0_0    ,						__lowerCamelCase = 2.0    ,						__lowerCamelCase = 3.1    ,						__lowerCamelCase = 8    ,						__lowerCamelCase = [3, 3, 5, 3, 5, 5, 3]    ,						__lowerCamelCase = [3_2, 1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2]    ,						__lowerCamelCase = [1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2, 3_2_0]    ,						__lowerCamelCase = []    ,						__lowerCamelCase = [1, 2, 2, 2, 1, 2, 1]    ,						__lowerCamelCase = [1, 2, 2, 3, 3, 4, 1]    ,						__lowerCamelCase = [1, 6, 6, 6, 6, 6, 6]    ,						__lowerCamelCase = 0.25    ,						__lowerCamelCase = "swish"    ,						__lowerCamelCase = 2_5_6_0    ,						__lowerCamelCase = "mean"    ,						__lowerCamelCase = 0.02    ,						__lowerCamelCase = 0.001    ,						__lowerCamelCase = 0.99    ,						__lowerCamelCase = 0.2    ,						**__lowerCamelCase    ,						)			->     Dict:
            super().__init__(**__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	int						    =							num_channels
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							image_size
            _SCREAMING_SNAKE_CASE       :	Dict						    =							width_coefficient
            _SCREAMING_SNAKE_CASE       :	str						    =							depth_coefficient
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							depth_divisor
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							kernel_sizes
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							in_channels
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							out_channels
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							depthwise_padding
            _SCREAMING_SNAKE_CASE       :	str						    =							strides
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							num_block_repeats
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							expand_ratios
            _SCREAMING_SNAKE_CASE       :	int						    =							squeeze_expansion_ratio
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							hidden_act
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							hidden_dim
            _SCREAMING_SNAKE_CASE       :	Dict						    =							pooling_type
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							initializer_range
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							batch_norm_eps
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							batch_norm_momentum
            _SCREAMING_SNAKE_CASE       :	int						    =							drop_connect_rate
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							sum(__lowerCamelCase							) * 4







       @classmethod
       def     UpperCamelCase_			(      cls    ,						__lowerCamelCase    ,						**__lowerCamelCase							)			->     "PretrainedConfig":
            cls._set_token_in_kwargs(__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	int						    =							cls.get_config_dict(__lowerCamelCase    ,						**__lowerCamelCase							)

            # get the vision config dict if we are loading from AlignConfig
            if config_dict.get("model_type"							) == "align":
                 _SCREAMING_SNAKE_CASE       :	int						    =							config_dict["vision_config"]

            if "model_type" in config_dict and hasattr(cls    ,						"model_type"							) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     F"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
                     F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""							)

            return cls.from_dict(__lowerCamelCase    ,						**__lowerCamelCase							)





class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       __snake_case 			=    'align'
       __snake_case 			=    True




       def __init__(      self    ,						__lowerCamelCase=None    ,						__lowerCamelCase=None    ,						__lowerCamelCase=6_4_0    ,						__lowerCamelCase=1.0    ,						__lowerCamelCase=0.02    ,						**__lowerCamelCase    ,						)			->     List[Any]:
            super().__init__(**__lowerCamelCase							)

            if text_config is None:
                 _SCREAMING_SNAKE_CASE       :	List[Any]						    =							{}
                 logger.info("text_config is None. Initializing the AlignTextConfig with default values."							)

            if vision_config is None:
                 _SCREAMING_SNAKE_CASE       :	List[str]						    =							{}
                 logger.info("vision_config is None. Initializing the AlignVisionConfig with default values."							)

            _SCREAMING_SNAKE_CASE       :	Dict						    =							AlignTextConfig(**__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Any						    =							AlignVisionConfig(**__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	int						    =							projection_dim
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							temperature_init_value
            _SCREAMING_SNAKE_CASE       :	Any						    =							initializer_range




       @classmethod
       def     UpperCamelCase_			(      cls    ,						__lowerCamelCase    ,						__lowerCamelCase    ,						**__lowerCamelCase							)			->     List[str]:
            return cls(text_config=text_config.to_dict()    ,						vision_config=vision_config.to_dict()    ,						**__lowerCamelCase							)







       def     UpperCamelCase_			(      self							)			->     Union[str, Any]:
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							copy.deepcopy(self.__dict__							)
            _SCREAMING_SNAKE_CASE       :	Any						    =							self.text_config.to_dict()
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							self.vision_config.to_dict()
            _SCREAMING_SNAKE_CASE       :	Dict						    =							self.__class__.model_type
            return output