





'''simple docstring'''







import copy
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
from ..auto import CONFIG_MAPPING


lowerCAmelCase_					:    Tuple      	=			logging.get_logger(__name__)

lowerCAmelCase_					:    Optional[int]      	=			{
    'microsoft/conditional-detr-resnet-50': (
        'https://huggingface.co/microsoft/conditional-detr-resnet-50/resolve/main/config.json'
    ),
}
class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				__a            ='conditional_detr'
				__a            =['past_key_values']
				__a            ={
				    'hidden_size': 'd_model',
				    'num_attention_heads': 'encoder_attention_heads',
				}




				def __init__(  self     :					Dict					,				__a     :					int=True					,				__a     :					Optional[Any]=None					,				__a     :					Optional[int]=3					,				__a     :					List[Any]=3_00					,				__a     :					Optional[Any]=6					,				__a     :					Tuple=20_48					,				__a     :					Tuple=8					,				__a     :					Optional[int]=6					,				__a     :					List[str]=20_48					,				__a     :					Dict=8					,				__a     :					Any=0.0					,				__a     :					List[Any]=0.0					,				__a     :					List[Any]=True					,				__a     :					Optional[Any]="relu"					,				__a     :					List[Any]=2_56					,				__a     :					Any=0.1					,				__a     :					Tuple=0.0					,				__a     :					Optional[int]=0.0					,				__a     :					int=0.02					,				__a     :					List[Any]=1.0					,				__a     :					List[str]=False					,				__a     :					Dict="sine"					,				__a     :					Optional[Any]="resnet50"					,				__a     :					Optional[Any]=True					,				__a     :					Union[str, Any]=False					,				__a     :					Optional[Any]=2					,				__a     :					Union[str, Any]=5					,				__a     :					int=2					,				__a     :					List[str]=1					,				__a     :					Tuple=1					,				__a     :					Any=2					,				__a     :					Optional[int]=5					,				__a     :					Any=2					,				__a     :					Optional[Any]=0.25					,				**__a     :					Optional[Any]					,				):
								if backbone_config is not None and use_timm_backbone:
												raise ValueError("You can't specify both `backbone_config` and `use_timm_backbone`."					)

								if not use_timm_backbone:
												if backbone_config is None:
																logger.info("`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."					)
																_a								= CONFIG_MAPPING["resnet"](out_features=["stage4"]					)
												elif isinstance(__a					,				__a					):
																_a								= backbone_config.get("model_type"					)
																_a								= CONFIG_MAPPING[backbone_model_type]
																_a								= config_class.from_dict(__a					)

								_a								= use_timm_backbone
								_a								= backbone_config
								_a								= num_channels
								_a								= num_queries
								_a								= d_model
								_a								= encoder_ffn_dim
								_a								= encoder_layers
								_a								= encoder_attention_heads
								_a								= decoder_ffn_dim
								_a								= decoder_layers
								_a								= decoder_attention_heads
								_a								= dropout
								_a								= attention_dropout
								_a								= activation_dropout
								_a								= activation_function
								_a								= init_std
								_a								= init_xavier_std
								_a								= encoder_layerdrop
								_a								= decoder_layerdrop
								_a								= encoder_layers
								_a								= auxiliary_loss
								_a								= position_embedding_type
								_a								= backbone
								_a								= use_pretrained_backbone
								_a								= dilation
								# Hungarian matcher
								_a								= class_cost
								_a								= bbox_cost
								_a								= giou_cost
								# Loss coefficients
								_a								= mask_loss_coefficient
								_a								= dice_loss_coefficient
								_a								= cls_loss_coefficient
								_a								= bbox_loss_coefficient
								_a								= giou_loss_coefficient
								_a								= focal_alpha
								super().__init__(is_encoder_decoder=__a					,				**__a					)




				@property
				def   UpperCamelCase__   (  self     :					Optional[Any]					):
								return self.encoder_attention_heads




				@property
				def   UpperCamelCase__   (  self     :					Dict					):
								return self.d_model




				def   UpperCamelCase__   (  self     :					Optional[int]					):
								_a								= copy.deepcopy(self.__dict__					)
								if self.backbone_config is not None:
												_a								= self.backbone_config.to_dict()
								_a								= self.__class__.model_type
								return output


class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				__a            =version.parse('1.11'      )




				@property
				def   UpperCamelCase__   (  self     :					Tuple					):
								return OrderedDict(
								    [
								        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
								        ("pixel_mask", {0: "batch"}),
								    ]					)




				@property
				def   UpperCamelCase__   (  self     :					int					):
								return 1e-5




				@property
				def   UpperCamelCase__   (  self     :					List[str]					):
								return 12







'''simple docstring'''







import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible
class 				__SCREAMING_SNAKE_CASE  (unittest.TestCase      ):






				"""simple docstring"""







				def   UpperCamelCase__   (  self     :					str					):
								_a								= [
								    "safety_checker/pytorch_model.bin",
								    "safety_checker/model.safetensors",
								    "vae/diffusion_pytorch_model.bin",
								    "vae/diffusion_pytorch_model.safetensors",
								    "text_encoder/pytorch_model.bin",
								    "text_encoder/model.safetensors",
								    "unet/diffusion_pytorch_model.bin",
								    "unet/diffusion_pytorch_model.safetensors",
								]
								self.assertTrue(is_safetensors_compatible(__a					)					)




				def   UpperCamelCase__   (  self     :					List[str]					):
								_a								= [
								    "unet/diffusion_pytorch_model.bin",
								    "unet/diffusion_pytorch_model.safetensors",
								]
								self.assertTrue(is_safetensors_compatible(__a					)					)




				def   UpperCamelCase__   (  self     :					List[str]					):
								_a								= [
								    "safety_checker/pytorch_model.bin",
								    "safety_checker/model.safetensors",
								    "vae/diffusion_pytorch_model.bin",
								    "vae/diffusion_pytorch_model.safetensors",
								    "text_encoder/pytorch_model.bin",
								    "text_encoder/model.safetensors",
								    "unet/diffusion_pytorch_model.bin",
								    # Removed: 'unet/diffusion_pytorch_model.safetensors',
								]
								self.assertFalse(is_safetensors_compatible(__a					)					)




				def   UpperCamelCase__   (  self     :					List[str]					):
								_a								= [
								    "text_encoder/pytorch_model.bin",
								    "text_encoder/model.safetensors",
								]
								self.assertTrue(is_safetensors_compatible(__a					)					)




				def   UpperCamelCase__   (  self     :					Optional[Any]					):
								_a								= [
								    "safety_checker/pytorch_model.bin",
								    "safety_checker/model.safetensors",
								    "vae/diffusion_pytorch_model.bin",
								    "vae/diffusion_pytorch_model.safetensors",
								    "text_encoder/pytorch_model.bin",
								    # Removed: 'text_encoder/model.safetensors',
								    "unet/diffusion_pytorch_model.bin",
								    "unet/diffusion_pytorch_model.safetensors",
								]
								self.assertFalse(is_safetensors_compatible(__a					)					)




				def   UpperCamelCase__   (  self     :					str					):
								_a								= [
								    "safety_checker/pytorch_model.fp16.bin",
								    "safety_checker/model.fp16.safetensors",
								    "vae/diffusion_pytorch_model.fp16.bin",
								    "vae/diffusion_pytorch_model.fp16.safetensors",
								    "text_encoder/pytorch_model.fp16.bin",
								    "text_encoder/model.fp16.safetensors",
								    "unet/diffusion_pytorch_model.fp16.bin",
								    "unet/diffusion_pytorch_model.fp16.safetensors",
								]
								_a								= "fp16"
								self.assertTrue(is_safetensors_compatible(__a					,				variant=__a					)					)




				def   UpperCamelCase__   (  self     :					Any					):
								_a								= [
								    "unet/diffusion_pytorch_model.fp16.bin",
								    "unet/diffusion_pytorch_model.fp16.safetensors",
								]
								_a								= "fp16"
								self.assertTrue(is_safetensors_compatible(__a					,				variant=__a					)					)




				def   UpperCamelCase__   (  self     :					Any					):
								# pass variant but use the non-variant filenames
								_a								= [
								    "unet/diffusion_pytorch_model.bin",
								    "unet/diffusion_pytorch_model.safetensors",
								]
								_a								= "fp16"
								self.assertTrue(is_safetensors_compatible(__a					,				variant=__a					)					)




				def   UpperCamelCase__   (  self     :					Optional[Any]					):
								_a								= [
								    "safety_checker/pytorch_model.fp16.bin",
								    "safety_checker/model.fp16.safetensors",
								    "vae/diffusion_pytorch_model.fp16.bin",
								    "vae/diffusion_pytorch_model.fp16.safetensors",
								    "text_encoder/pytorch_model.fp16.bin",
								    "text_encoder/model.fp16.safetensors",
								    "unet/diffusion_pytorch_model.fp16.bin",
								    # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
								]
								_a								= "fp16"
								self.assertFalse(is_safetensors_compatible(__a					,				variant=__a					)					)




				def   UpperCamelCase__   (  self     :					Dict					):
								_a								= [
								    "text_encoder/pytorch_model.fp16.bin",
								    "text_encoder/model.fp16.safetensors",
								]
								_a								= "fp16"
								self.assertTrue(is_safetensors_compatible(__a					,				variant=__a					)					)




				def   UpperCamelCase__   (  self     :					List[str]					):
								# pass variant but use the non-variant filenames
								_a								= [
								    "text_encoder/pytorch_model.bin",
								    "text_encoder/model.safetensors",
								]
								_a								= "fp16"
								self.assertTrue(is_safetensors_compatible(__a					,				variant=__a					)					)




				def   UpperCamelCase__   (  self     :					Optional[int]					):
								_a								= [
								    "safety_checker/pytorch_model.fp16.bin",
								    "safety_checker/model.fp16.safetensors",
								    "vae/diffusion_pytorch_model.fp16.bin",
								    "vae/diffusion_pytorch_model.fp16.safetensors",
								    "text_encoder/pytorch_model.fp16.bin",
								    # 'text_encoder/model.fp16.safetensors',
								    "unet/diffusion_pytorch_model.fp16.bin",
								    "unet/diffusion_pytorch_model.fp16.safetensors",
								]
								_a								= "fp16"
								self.assertFalse(is_safetensors_compatible(__a					,				variant=__a					)					)
