


import gc
import random
import tempfile
import unittest

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

from diffusers import AutoencoderKL, DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.semantic_stable_diffusion import SemanticStableDiffusionPipeline as StableDiffusionPipeline
from diffusers.utils import floats_tensor, nightly, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()

class   A__							(						unittest.TestCase     ):




						def 							__UpperCamelCase (				self    :					Optional[int]     )							->   Tuple:


										"""simple docstring"""





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




						@property
						def 							__UpperCamelCase (				self    :					Union[str, Any]     )							->   Union[str, Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =1
										_SCREAMING_SNAKE_CASE	     =3
										_SCREAMING_SNAKE_CASE	     =(32, 32)

										_SCREAMING_SNAKE_CASE	     =floats_tensor((batch_size, num_channels) + sizes ,			rng=random.Random(0     )     ).to(_a     )
										return image




						@property
						def 							__UpperCamelCase (				self    :					List[str]     )							->   str:


										"""simple docstring"""





										torch.manual_seed(0     )
										_SCREAMING_SNAKE_CASE	     =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 ,			)
										return model




						@property
						def 							__UpperCamelCase (				self    :					List[Any]     )							->   List[Any]:


										"""simple docstring"""





										torch.manual_seed(0     )
										_SCREAMING_SNAKE_CASE	     =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 ,			)
										return model




						@property
						def 							__UpperCamelCase (				self    :					Dict     )							->   Optional[int]:


										"""simple docstring"""





										torch.manual_seed(0     )
										_SCREAMING_SNAKE_CASE	     =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=1000 ,			)
										return CLIPTextModel(_a     )




						@property
						def 							__UpperCamelCase (				self    :					Dict     )							->   List[str]:


										"""simple docstring"""





										def extract(*_a    :					Any ,			**_a    :					List[str]     ):

														class   A__							:




																				def __init__(				self    :					Optional[int]     )							->   int:


																								"""simple docstring"""





																								_SCREAMING_SNAKE_CASE	     =torch.ones([0]     )




																				def 							__UpperCamelCase (				self    :					Optional[Any] ,			_a    :					Dict     )							->   Dict:


																								"""simple docstring"""





																								self.pixel_values.to(_a     )
																								return self
														return Out()

										return extract




						def 							__UpperCamelCase (				self    :					List[str]     )							->   Optional[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     ='''cpu'''  # ensure determinism for the device-dependent torch.Generator
										_SCREAMING_SNAKE_CASE	     =self.dummy_cond_unet
										_SCREAMING_SNAKE_CASE	     =DDIMScheduler(
										    beta_start=0.0_00_85 ,			beta_end=0.0_12 ,			beta_schedule='''scaled_linear''' ,			clip_sample=_a ,			set_alpha_to_one=_a ,			)

										_SCREAMING_SNAKE_CASE	     =self.dummy_vae
										_SCREAMING_SNAKE_CASE	     =self.dummy_text_encoder
										_SCREAMING_SNAKE_CASE	     =CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''     )

										# make sure here that pndm scheduler skips prk
										_SCREAMING_SNAKE_CASE	     =StableDiffusionPipeline(
										    unet=_a ,			scheduler=_a ,			vae=_a ,			text_encoder=_a ,			tokenizer=_a ,			safety_checker=_a ,			feature_extractor=self.dummy_extractor ,			)
										_SCREAMING_SNAKE_CASE	     =sd_pipe.to(_a     )
										sd_pipe.set_progress_bar_config(disable=_a     )

										_SCREAMING_SNAKE_CASE	     ='''A painting of a squirrel eating a burger'''

										_SCREAMING_SNAKE_CASE	     =torch.Generator(device=_a     ).manual_seed(0     )
										_SCREAMING_SNAKE_CASE	     =sd_pipe([prompt] ,			generator=_a ,			guidance_scale=6.0 ,			num_inference_steps=2 ,			output_type='''np'''     )
										_SCREAMING_SNAKE_CASE	     =output.images

										_SCREAMING_SNAKE_CASE	     =torch.Generator(device=_a     ).manual_seed(0     )
										_SCREAMING_SNAKE_CASE	     =sd_pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=6.0 ,			num_inference_steps=2 ,			output_type='''np''' ,			return_dict=_a ,			)[0]

										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =image_from_tuple[0, -3:, -3:, -1]

										assert image.shape == (1, 64, 64, 3)
										_SCREAMING_SNAKE_CASE	     =np.array([0.57_53, 0.61_14, 0.50_01, 0.50_34, 0.54_70, 0.47_29, 0.49_71, 0.48_67, 0.48_67]     )

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




						def 							__UpperCamelCase (				self    :					Dict     )							->   Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     ='''cpu'''  # ensure determinism for the device-dependent torch.Generator
										_SCREAMING_SNAKE_CASE	     =self.dummy_cond_unet
										_SCREAMING_SNAKE_CASE	     =PNDMScheduler(skip_prk_steps=_a     )
										_SCREAMING_SNAKE_CASE	     =self.dummy_vae
										_SCREAMING_SNAKE_CASE	     =self.dummy_text_encoder
										_SCREAMING_SNAKE_CASE	     =CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''     )

										# make sure here that pndm scheduler skips prk
										_SCREAMING_SNAKE_CASE	     =StableDiffusionPipeline(
										    unet=_a ,			scheduler=_a ,			vae=_a ,			text_encoder=_a ,			tokenizer=_a ,			safety_checker=_a ,			feature_extractor=self.dummy_extractor ,			)
										_SCREAMING_SNAKE_CASE	     =sd_pipe.to(_a     )
										sd_pipe.set_progress_bar_config(disable=_a     )

										_SCREAMING_SNAKE_CASE	     ='''A painting of a squirrel eating a burger'''
										_SCREAMING_SNAKE_CASE	     =torch.Generator(device=_a     ).manual_seed(0     )
										_SCREAMING_SNAKE_CASE	     =sd_pipe([prompt] ,			generator=_a ,			guidance_scale=6.0 ,			num_inference_steps=2 ,			output_type='''np'''     )

										_SCREAMING_SNAKE_CASE	     =output.images

										_SCREAMING_SNAKE_CASE	     =torch.Generator(device=_a     ).manual_seed(0     )
										_SCREAMING_SNAKE_CASE	     =sd_pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=6.0 ,			num_inference_steps=2 ,			output_type='''np''' ,			return_dict=_a ,			)[0]

										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =image_from_tuple[0, -3:, -3:, -1]

										assert image.shape == (1, 64, 64, 3)
										_SCREAMING_SNAKE_CASE	     =np.array([0.51_22, 0.57_12, 0.48_25, 0.50_53, 0.56_46, 0.47_69, 0.51_79, 0.48_94, 0.49_94]     )

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




						def 							__UpperCamelCase (				self    :					str     )							->   int:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =StableDiffusionPipeline.from_pretrained(
										    '''hf-internal-testing/tiny-stable-diffusion-lms-pipe''' ,			safety_checker=_a     )
										assert isinstance(_a ,			_a     )
										assert isinstance(pipe.scheduler ,			_a     )
										assert pipe.safety_checker is None

										_SCREAMING_SNAKE_CASE	     =pipe('''example prompt''' ,			num_inference_steps=2     ).images[0]
										assert image is not None

										# check that there's no error when saving a pipeline with one of the models being None
										with tempfile.TemporaryDirectory() as tmpdirname:
														pipe.save_pretrained(_a     )
														_SCREAMING_SNAKE_CASE	     =StableDiffusionPipeline.from_pretrained(_a     )

										# sanity check that the pipeline still works
										assert pipe.safety_checker is None
										_SCREAMING_SNAKE_CASE	     =pipe('''example prompt''' ,			num_inference_steps=2     ).images[0]
										assert image is not None




						@unittest.skipIf(torch_device != '''cuda''' ,			'''This test requires a GPU'''     )
						def 							__UpperCamelCase (				self    :					Dict     )							->   Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =self.dummy_cond_unet
										_SCREAMING_SNAKE_CASE	     =PNDMScheduler(skip_prk_steps=_a     )
										_SCREAMING_SNAKE_CASE	     =self.dummy_vae
										_SCREAMING_SNAKE_CASE	     =self.dummy_text_encoder
										_SCREAMING_SNAKE_CASE	     =CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''     )

										# put models in fp16
										_SCREAMING_SNAKE_CASE	     =unet.half()
										_SCREAMING_SNAKE_CASE	     =vae.half()
										_SCREAMING_SNAKE_CASE	     =bert.half()

										# make sure here that pndm scheduler skips prk
										_SCREAMING_SNAKE_CASE	     =StableDiffusionPipeline(
										    unet=_a ,			scheduler=_a ,			vae=_a ,			text_encoder=_a ,			tokenizer=_a ,			safety_checker=_a ,			feature_extractor=self.dummy_extractor ,			)
										_SCREAMING_SNAKE_CASE	     =sd_pipe.to(_a     )
										sd_pipe.set_progress_bar_config(disable=_a     )

										_SCREAMING_SNAKE_CASE	     ='''A painting of a squirrel eating a burger'''
										_SCREAMING_SNAKE_CASE	     =sd_pipe([prompt] ,			num_inference_steps=2 ,			output_type='''np'''     ).images

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

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




						def 							__UpperCamelCase (				self    :					str     )							->   List[str]:


										"""simple docstring"""





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




						def 							__UpperCamelCase (				self    :					Optional[int]     )							->   List[str]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     ='''cuda'''
										_SCREAMING_SNAKE_CASE	     =StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''     )
										_SCREAMING_SNAKE_CASE	     =pipe.to(_a     )
										pipe.set_progress_bar_config(disable=_a     )

										_SCREAMING_SNAKE_CASE	     ='''a photo of a cat'''
										_SCREAMING_SNAKE_CASE	     ={
										    '''editing_prompt''': ['''sunglasses'''],
										    '''reverse_editing_direction''': [False],
										    '''edit_warmup_steps''': 10,
										    '''edit_guidance_scale''': 6,
										    '''edit_threshold''': 0.95,
										    '''edit_momentum_scale''': 0.5,
										    '''edit_mom_beta''': 0.6,
										}

										_SCREAMING_SNAKE_CASE	     =3
										_SCREAMING_SNAKE_CASE	     =7

										# no sega enabled
										_SCREAMING_SNAKE_CASE	     =torch.Generator(_a     )
										generator.manual_seed(_a     )
										_SCREAMING_SNAKE_CASE	     =pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=_a ,			num_inference_steps=50 ,			output_type='''np''' ,			width=512 ,			height=512 ,			)

										_SCREAMING_SNAKE_CASE	     =output.images
										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =[
										    0.34_67_31_13,
										    0.38_49_27_33,
										    0.37_59_73_52,
										    0.34_08_63_35,
										    0.35_65_07_48,
										    0.35_57_92_05,
										    0.3_38_47_63,
										    0.34_34_02_36,
										    0.3_57_32_71,
										]

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

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

										# with sega enabled
										# generator = torch.manual_seed(seed)
										generator.manual_seed(_a     )
										_SCREAMING_SNAKE_CASE	     =pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=_a ,			num_inference_steps=50 ,			output_type='''np''' ,			width=512 ,			height=512 ,			**_a ,			)

										_SCREAMING_SNAKE_CASE	     =output.images
										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =[
										    0.41_88_78_26,
										    0.37_72_87_66,
										    0.30_13_82_72,
										    0.41_41_63_35,
										    0.41_66_49_85,
										    0.36_28_33_92,
										    0.36_19_12_46,
										    0.43_36_44_65,
										    0.43_00_17_32,
										]

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

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




						def 							__UpperCamelCase (				self    :					int     )							->   Optional[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     ='''cuda'''
										_SCREAMING_SNAKE_CASE	     =StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''     )
										_SCREAMING_SNAKE_CASE	     =pipe.to(_a     )
										pipe.set_progress_bar_config(disable=_a     )

										_SCREAMING_SNAKE_CASE	     ='''an image of a crowded boulevard, realistic, 4k'''
										_SCREAMING_SNAKE_CASE	     ={
										    '''editing_prompt''': '''crowd, crowded, people''',
										    '''reverse_editing_direction''': True,
										    '''edit_warmup_steps''': 10,
										    '''edit_guidance_scale''': 8.3,
										    '''edit_threshold''': 0.9,
										    '''edit_momentum_scale''': 0.5,
										    '''edit_mom_beta''': 0.6,
										}

										_SCREAMING_SNAKE_CASE	     =9
										_SCREAMING_SNAKE_CASE	     =7

										# no sega enabled
										_SCREAMING_SNAKE_CASE	     =torch.Generator(_a     )
										generator.manual_seed(_a     )
										_SCREAMING_SNAKE_CASE	     =pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=_a ,			num_inference_steps=50 ,			output_type='''np''' ,			width=512 ,			height=512 ,			)

										_SCREAMING_SNAKE_CASE	     =output.images
										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =[
										    0.43_49_79_98,
										    0.91_81_40_65,
										    0.7_54_07_39,
										    0.55_58_02_05,
										    0.8_46_72_65,
										    0.5_38_96_91,
										    0.62_57_45_06,
										    0.58_89_77_63,
										    0.50_92_67_57,
										]

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

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

										# with sega enabled
										# generator = torch.manual_seed(seed)
										generator.manual_seed(_a     )
										_SCREAMING_SNAKE_CASE	     =pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=_a ,			num_inference_steps=50 ,			output_type='''np''' ,			width=512 ,			height=512 ,			**_a ,			)

										_SCREAMING_SNAKE_CASE	     =output.images
										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =[
										    0.3_08_97_19,
										    0.30_50_01_44,
										    0.29_01_60_42,
										    0.30_63_09_64,
										    0.32_56_87,
										    0.29_41_92_25,
										    0.2_90_80_91,
										    0.28_72_35_98,
										    0.27_69_62_94,
										]

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

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




						def 							__UpperCamelCase (				self    :					int     )							->   Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     ='''cuda'''
										_SCREAMING_SNAKE_CASE	     =StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''     )
										_SCREAMING_SNAKE_CASE	     =pipe.to(_a     )
										pipe.set_progress_bar_config(disable=_a     )

										_SCREAMING_SNAKE_CASE	     ='''a castle next to a river'''
										_SCREAMING_SNAKE_CASE	     ={
										    '''editing_prompt''': ['''boat on a river, boat''', '''monet, impression, sunrise'''],
										    '''reverse_editing_direction''': False,
										    '''edit_warmup_steps''': [15, 18],
										    '''edit_guidance_scale''': 6,
										    '''edit_threshold''': [0.9, 0.8],
										    '''edit_momentum_scale''': 0.5,
										    '''edit_mom_beta''': 0.6,
										}

										_SCREAMING_SNAKE_CASE	     =48
										_SCREAMING_SNAKE_CASE	     =7

										# no sega enabled
										_SCREAMING_SNAKE_CASE	     =torch.Generator(_a     )
										generator.manual_seed(_a     )
										_SCREAMING_SNAKE_CASE	     =pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=_a ,			num_inference_steps=50 ,			output_type='''np''' ,			width=512 ,			height=512 ,			)

										_SCREAMING_SNAKE_CASE	     =output.images
										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =[
										    0.75_16_35_55,
										    0.76_03_71_45,
										    0.6_17_85,
										    0.9_18_96_73,
										    0.8_62_77_01,
										    0.85_18_96_94,
										    0.8_51_28_13,
										    0.87_01_20_76,
										    0.8_31_28_57,
										]

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

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

										# with sega enabled
										# generator = torch.manual_seed(seed)
										generator.manual_seed(_a     )
										_SCREAMING_SNAKE_CASE	     =pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=_a ,			num_inference_steps=50 ,			output_type='''np''' ,			width=512 ,			height=512 ,			**_a ,			)

										_SCREAMING_SNAKE_CASE	     =output.images
										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =[
										    0.73_55_33_65,
										    0.7_53_72_71,
										    0.74_34_19_05,
										    0.66_48_03_56,
										    0.6_47_29_25,
										    0.63_03_94_16,
										    0.64_81_29_05,
										    0.6_74_97_17,
										    0.6_51_71_02,
										]

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

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




						def 							__UpperCamelCase (				self    :					Optional[Any]     )							->   int:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     ='''cuda'''
										_SCREAMING_SNAKE_CASE	     =StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5''' ,			torch_dtype=torch.floataa     )
										_SCREAMING_SNAKE_CASE	     =pipe.to(_a     )
										pipe.set_progress_bar_config(disable=_a     )

										_SCREAMING_SNAKE_CASE	     ='''a photo of a cat'''
										_SCREAMING_SNAKE_CASE	     ={
										    '''editing_prompt''': ['''sunglasses'''],
										    '''reverse_editing_direction''': [False],
										    '''edit_warmup_steps''': 10,
										    '''edit_guidance_scale''': 6,
										    '''edit_threshold''': 0.95,
										    '''edit_momentum_scale''': 0.5,
										    '''edit_mom_beta''': 0.6,
										}

										_SCREAMING_SNAKE_CASE	     =3
										_SCREAMING_SNAKE_CASE	     =7

										# no sega enabled
										_SCREAMING_SNAKE_CASE	     =torch.Generator(_a     )
										generator.manual_seed(_a     )
										_SCREAMING_SNAKE_CASE	     =pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=_a ,			num_inference_steps=50 ,			output_type='''np''' ,			width=512 ,			height=512 ,			)

										_SCREAMING_SNAKE_CASE	     =output.images
										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =[
										    0.34_88_76_95,
										    0.3_87_69_53,
										    0.3_75,
										    0.34_42_38_28,
										    0.3_58_15_43,
										    0.35_71_77_73,
										    0.3_38_37_89,
										    0.34_57_03_12,
										    0.35_93_75,
										]

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

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

										# with sega enabled
										# generator = torch.manual_seed(seed)
										generator.manual_seed(_a     )
										_SCREAMING_SNAKE_CASE	     =pipe(
										    [prompt] ,			generator=_a ,			guidance_scale=_a ,			num_inference_steps=50 ,			output_type='''np''' ,			width=512 ,			height=512 ,			**_a ,			)

										_SCREAMING_SNAKE_CASE	     =output.images
										_SCREAMING_SNAKE_CASE	     =image[0, -3:, -3:, -1]
										_SCREAMING_SNAKE_CASE	     =[
										    0.42_28_51_56,
										    0.36_91_40_62,
										    0.29_07_71_48,
										    0.42_04_10_16,
										    0.41_91_89_45,
										    0.35_49_80_47,
										    0.3_61_81_64,
										    0.4_42_38_28,
										    0.43_11_52_34,
										]

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

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



from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


snake_case_  :	Any							  =							logging.get_logger(__name__)

snake_case_  :	Any							  =							{
    '''apple/mobilevit-small''': '''https://huggingface.co/apple/mobilevit-small/resolve/main/config.json''',
    '''apple/mobilevit-x-small''': '''https://huggingface.co/apple/mobilevit-x-small/resolve/main/config.json''',
    '''apple/mobilevit-xx-small''': '''https://huggingface.co/apple/mobilevit-xx-small/resolve/main/config.json''',
    '''apple/deeplabv3-mobilevit-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-small/resolve/main/config.json'''
    ),
    '''apple/deeplabv3-mobilevit-x-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-x-small/resolve/main/config.json'''
    ),
    '''apple/deeplabv3-mobilevit-xx-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-xx-small/resolve/main/config.json'''
    ),
    # See all MobileViT models at https://huggingface.co/models?filter=mobilevit
}

class   A__							(						UpperCamelCase__     ):
						UpperCAmelCase									=  "mobilevit"




						def __init__(				self    :					Tuple ,			_a    :					Any=3 ,			_a    :					Any=256 ,			_a    :					Any=2 ,			_a    :					List[str]=[144, 192, 240] ,			_a    :					Optional[int]=[16, 32, 64, 96, 128, 160, 640] ,			_a    :					Union[str, Any]=4 ,			_a    :					Any=2.0 ,			_a    :					List[str]=4.0 ,			_a    :					Tuple="silu" ,			_a    :					Optional[Any]=3 ,			_a    :					List[str]=32 ,			_a    :					Union[str, Any]=0.1 ,			_a    :					Tuple=0.0 ,			_a    :					Union[str, Any]=0.1 ,			_a    :					Union[str, Any]=0.02 ,			_a    :					Tuple=1E-5 ,			_a    :					Any=True ,			_a    :					str=256 ,			_a    :					Tuple=[6, 12, 18] ,			_a    :					int=0.1 ,			_a    :					str=255 ,			**_a    :					Any ,			)							->   Optional[int]:


										"""simple docstring"""





										super().__init__(**_a     )

										_SCREAMING_SNAKE_CASE	     =num_channels
										_SCREAMING_SNAKE_CASE	     =image_size
										_SCREAMING_SNAKE_CASE	     =patch_size
										_SCREAMING_SNAKE_CASE	     =hidden_sizes
										_SCREAMING_SNAKE_CASE	     =neck_hidden_sizes
										_SCREAMING_SNAKE_CASE	     =num_attention_heads
										_SCREAMING_SNAKE_CASE	     =mlp_ratio
										_SCREAMING_SNAKE_CASE	     =expand_ratio
										_SCREAMING_SNAKE_CASE	     =hidden_act
										_SCREAMING_SNAKE_CASE	     =conv_kernel_size
										_SCREAMING_SNAKE_CASE	     =output_stride
										_SCREAMING_SNAKE_CASE	     =hidden_dropout_prob
										_SCREAMING_SNAKE_CASE	     =attention_probs_dropout_prob
										_SCREAMING_SNAKE_CASE	     =classifier_dropout_prob
										_SCREAMING_SNAKE_CASE	     =initializer_range
										_SCREAMING_SNAKE_CASE	     =layer_norm_eps
										_SCREAMING_SNAKE_CASE	     =qkv_bias

										# decode head attributes for semantic segmentation
										_SCREAMING_SNAKE_CASE	     =aspp_out_channels
										_SCREAMING_SNAKE_CASE	     =atrous_rates
										_SCREAMING_SNAKE_CASE	     =aspp_dropout_prob
										_SCREAMING_SNAKE_CASE	     =semantic_loss_ignore_index

class   A__							(						UpperCamelCase__     ):
						UpperCAmelCase									=  version.parse("1.11"     )




						@property
						def 							__UpperCamelCase (				self    :					Union[str, Any]     )							->   Mapping[str, Mapping[int, str]]:


										"""simple docstring"""





										return OrderedDict([('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''})]     )




						@property
						def 							__UpperCamelCase (				self    :					Dict     )							->   Mapping[str, Mapping[int, str]]:


										"""simple docstring"""





										if self.task == "image-classification":
														return OrderedDict([('''logits''', {0: '''batch'''})]     )
										else:
														return OrderedDict([('''last_hidden_state''', {0: '''batch'''}), ('''pooler_output''', {0: '''batch'''})]     )




						@property
						def 							__UpperCamelCase (				self    :					List[Any]     )							->   float:


										"""simple docstring"""





										return 1E-4