



import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


UpperCamelCase__ =						logging.get_logger(__name__)

UpperCamelCase__ =						{
    "ut/deta": "https://huggingface.co/ut/deta/resolve/main/config.json",
}
class 			_lowerCAmelCase   ( _UpperCAmelCase			):






			"""simple docstring"""





			lowercase__      :  Tuple      =			"""deta"""
			lowercase__      :  Union[str, Any]      =			{
			    """hidden_size""": """d_model""",
			    """num_attention_heads""": """encoder_attention_heads""",
			}





			def __init__(				self	:       Optional[Any]			,     lowercase	:       List[str]=None			,     lowercase	:       Dict=900			,     lowercase	:       int=2_048			,     lowercase	:       int=6			,     lowercase	:       str=2_048			,     lowercase	:       List[Any]=8			,     lowercase	:       List[Any]=6			,     lowercase	:       Tuple=1_024			,     lowercase	:       int=8			,     lowercase	:       Dict=0.0			,     lowercase	:       Dict=True			,     lowercase	:       Optional[int]="relu"			,     lowercase	:       Tuple=256			,     lowercase	:       List[str]=0.1			,     lowercase	:       int=0.0			,     lowercase	:       Optional[int]=0.0			,     lowercase	:       Any=0.02			,     lowercase	:       Optional[int]=1.0			,     lowercase	:       Any=True			,     lowercase	:       Union[str, Any]=False			,     lowercase	:       Dict="sine"			,     lowercase	:       Dict=5			,     lowercase	:       str=4			,     lowercase	:       List[str]=4			,     lowercase	:       Union[str, Any]=True			,     lowercase	:       Optional[int]=300			,     lowercase	:       Any=True			,     lowercase	:       List[str]=True			,     lowercase	:       List[Any]=1			,     lowercase	:       Tuple=5			,     lowercase	:       int=2			,     lowercase	:       int=1			,     lowercase	:       Dict=1			,     lowercase	:       List[str]=5			,     lowercase	:       Optional[Any]=2			,     lowercase	:       List[str]=0.1			,     lowercase	:       Tuple=0.25			,     **lowercase	:       Optional[Any]			,     )						->					int:
									"""simple docstring"""







									if backbone_config is None:
															logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""   )
															__lowercase					=				CONFIG_MAPPING["""resnet"""](out_features=["""stage2""", """stage3""", """stage4"""]   )
									else:
															if isinstance(lowercase			,     lowercase   ):
																					__lowercase					=				backbone_config.pop("""model_type"""   )
																					__lowercase					=				CONFIG_MAPPING[backbone_model_type]
																					__lowercase					=				config_class.from_dict(lowercase   )

									__lowercase					=				backbone_config
									__lowercase					=				num_queries
									__lowercase					=				max_position_embeddings
									__lowercase					=				d_model
									__lowercase					=				encoder_ffn_dim
									__lowercase					=				encoder_layers
									__lowercase					=				encoder_attention_heads
									__lowercase					=				decoder_ffn_dim
									__lowercase					=				decoder_layers
									__lowercase					=				decoder_attention_heads
									__lowercase					=				dropout
									__lowercase					=				attention_dropout
									__lowercase					=				activation_dropout
									__lowercase					=				activation_function
									__lowercase					=				init_std
									__lowercase					=				init_xavier_std
									__lowercase					=				encoder_layerdrop
									__lowercase					=				auxiliary_loss
									__lowercase					=				position_embedding_type
									# deformable attributes
									__lowercase					=				num_feature_levels
									__lowercase					=				encoder_n_points
									__lowercase					=				decoder_n_points
									__lowercase					=				two_stage
									__lowercase					=				two_stage_num_proposals
									__lowercase					=				with_box_refine
									__lowercase					=				assign_first_stage
									if two_stage is True and with_box_refine is False:
															raise ValueError("""If two_stage is True, with_box_refine must be True."""   )
									# Hungarian matcher
									__lowercase					=				class_cost
									__lowercase					=				bbox_cost
									__lowercase					=				giou_cost
									# Loss coefficients
									__lowercase					=				mask_loss_coefficient
									__lowercase					=				dice_loss_coefficient
									__lowercase					=				bbox_loss_coefficient
									__lowercase					=				giou_loss_coefficient
									__lowercase					=				eos_coefficient
									__lowercase					=				focal_alpha
									super().__init__(is_encoder_decoder=lowercase			,     **lowercase   )





			@property
			def 		snake_case__			(				self	:       Any   )						->					int:
									"""simple docstring"""







									return self.encoder_attention_heads





			@property
			def 		snake_case__			(				self	:       Union[str, Any]   )						->					int:
									"""simple docstring"""







									return self.d_model







			def 		snake_case__			(				self	:       List[Any]   )						->					Dict:
									"""simple docstring"""







									__lowercase					=				copy.deepcopy(self.__dict__   )
									__lowercase					=				self.backbone_config.to_dict()
									__lowercase					=				self.__class__.model_type
									return output










import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin
@skip_mps
class 			_lowerCAmelCase   ( _UpperCAmelCase    ,					_UpperCAmelCase    ,					unittest.TestCase			):






			"""simple docstring"""





			lowercase__      :  int      =			IFImgaImgSuperResolutionPipeline
			lowercase__      :  Optional[int]      =			TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
			lowercase__      :  Optional[int]      =			TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({"""original_image"""}			)
			lowercase__      :  Tuple      =			PipelineTesterMixin.required_optional_params - {"""latents"""}





			def 		snake_case__			(				self	:       Tuple   )						->					Any:
									"""simple docstring"""







									return self._get_superresolution_dummy_components()





			def 		snake_case__			(				self	:       List[str]			,     lowercase	:       Optional[int]			,     lowercase	:       Optional[Any]=0   )						->					Union[str, Any]:
									"""simple docstring"""







									if str(lowercase   ).startswith("""mps"""   ):
															__lowercase					=				torch.manual_seed(lowercase   )
									else:
															__lowercase					=				torch.Generator(device=lowercase   ).manual_seed(lowercase   )

									__lowercase					=				floats_tensor((1, 3, 32, 32)			,     rng=random.Random(lowercase   )   ).to(lowercase   )
									__lowercase					=				floats_tensor((1, 3, 16, 16)			,     rng=random.Random(lowercase   )   ).to(lowercase   )

									__lowercase					=				{
									    """prompt""": """A painting of a squirrel eating a burger""",
									    """image""": image,
									    """original_image""": original_image,
									    """generator""": generator,
									    """num_inference_steps""": 2,
									    """output_type""": """numpy""",
									}

									return inputs





			@unittest.skipIf(
			    torch_device != """cuda""" or not is_xformers_available()			,     reason="""XFormers attention is only available with CUDA and `xformers` installed"""			,     )
			def 		snake_case__			(				self	:       Optional[Any]   )						->					Tuple:
									"""simple docstring"""







									self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3   )





			def 		snake_case__			(				self	:       List[Any]   )						->					Union[str, Any]:
									"""simple docstring"""







									self._test_save_load_optional_components()





			@unittest.skipIf(torch_device != """cuda"""			,     reason="""float16 requires CUDA"""   )
			def 		snake_case__			(				self	:       List[Any]   )						->					Dict:
									"""simple docstring"""







									super().test_save_load_floataa(expected_max_diff=1E-1   )





			def 		snake_case__			(				self	:       Dict   )						->					int:
									"""simple docstring"""







									self._test_attention_slicing_forward_pass(expected_max_diff=1E-2   )





			def 		snake_case__			(				self	:       Optional[Any]   )						->					int:
									"""simple docstring"""







									self._test_save_load_local()







			def 		snake_case__			(				self	:       Optional[int]   )						->					Optional[int]:
									"""simple docstring"""







									self._test_inference_batch_single_identical(
									    expected_max_diff=1E-2			,     )





