



'''simple docstring'''




import copy

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


UpperCamelCase__       :	Union[str, Any]    = logging.get_logger(__name__)

UpperCamelCase__       :	int    = {
    '''ut/deta''': '''https://huggingface.co/ut/deta/resolve/main/config.json''',
}






class 						_UpperCamelCase  (							lowerCamelCase__    ):


			'''simple docstring'''

			_A      :		Union[str, Any]			    =		'''deta'''
			_A      :		int			    =		{
			    '''hidden_size''': '''d_model''',
			    '''num_attention_heads''': '''encoder_attention_heads''',
			}

			def __init__(							self     : Tuple							,     lowerCAmelCase__     : List[str]=None							,     lowerCAmelCase__     : Tuple=9_0_0							,     lowerCAmelCase__     : str=2_0_4_8							,     lowerCAmelCase__     : Optional[int]=6							,     lowerCAmelCase__     : str=2_0_4_8							,     lowerCAmelCase__     : Dict=8							,     lowerCAmelCase__     : Dict=6							,     lowerCAmelCase__     : List[Any]=1_0_2_4							,     lowerCAmelCase__     : Tuple=8							,     lowerCAmelCase__     : Optional[int]=0.0							,     lowerCAmelCase__     : Dict=True							,     lowerCAmelCase__     : Tuple="relu"							,     lowerCAmelCase__     : Optional[Any]=2_5_6							,     lowerCAmelCase__     : Dict=0.1							,     lowerCAmelCase__     : Optional[int]=0.0							,     lowerCAmelCase__     : Optional[Any]=0.0							,     lowerCAmelCase__     : Optional[int]=0.02							,     lowerCAmelCase__     : Tuple=1.0							,     lowerCAmelCase__     : int=True							,     lowerCAmelCase__     : Any=False							,     lowerCAmelCase__     : Any="sine"							,     lowerCAmelCase__     : Optional[Any]=5							,     lowerCAmelCase__     : Any=4							,     lowerCAmelCase__     : List[str]=4							,     lowerCAmelCase__     : str=True							,     lowerCAmelCase__     : Dict=3_0_0							,     lowerCAmelCase__     : Optional[int]=True							,     lowerCAmelCase__     : Optional[Any]=True							,     lowerCAmelCase__     : Dict=1							,     lowerCAmelCase__     : int=5							,     lowerCAmelCase__     : str=2							,     lowerCAmelCase__     : Tuple=1							,     lowerCAmelCase__     : Optional[int]=1							,     lowerCAmelCase__     : List[str]=5							,     lowerCAmelCase__     : Optional[Any]=2							,     lowerCAmelCase__     : Tuple=0.1							,     lowerCAmelCase__     : Tuple=0.25							,     **lowerCAmelCase__     : Tuple							,     ):





					"""simple docstring"""






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

					__SCREAMING_SNAKE_CASE       :		List[str]           =		backbone_config
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		num_queries
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		max_position_embeddings
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		d_model
					__SCREAMING_SNAKE_CASE       :		Any           =		encoder_ffn_dim
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		encoder_layers
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		encoder_attention_heads
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		decoder_ffn_dim
					__SCREAMING_SNAKE_CASE       :		Tuple           =		decoder_layers
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		decoder_attention_heads
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		dropout
					__SCREAMING_SNAKE_CASE       :		Tuple           =		attention_dropout
					__SCREAMING_SNAKE_CASE       :		Any           =		activation_dropout
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		activation_function
					__SCREAMING_SNAKE_CASE       :		int           =		init_std
					__SCREAMING_SNAKE_CASE       :		int           =		init_xavier_std
					__SCREAMING_SNAKE_CASE       :		Any           =		encoder_layerdrop
					__SCREAMING_SNAKE_CASE       :		int           =		auxiliary_loss
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		position_embedding_type
					# deformable attributes
					__SCREAMING_SNAKE_CASE       :		Tuple           =		num_feature_levels
					__SCREAMING_SNAKE_CASE       :		str           =		encoder_n_points
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		decoder_n_points
					__SCREAMING_SNAKE_CASE       :		List[str]           =		two_stage
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		two_stage_num_proposals
					__SCREAMING_SNAKE_CASE       :		Dict           =		with_box_refine
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		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
					__SCREAMING_SNAKE_CASE       :		str           =		class_cost
					__SCREAMING_SNAKE_CASE       :		int           =		bbox_cost
					__SCREAMING_SNAKE_CASE       :		Tuple           =		giou_cost
					# Loss coefficients
					__SCREAMING_SNAKE_CASE       :		Any           =		mask_loss_coefficient
					__SCREAMING_SNAKE_CASE       :		List[str]           =		dice_loss_coefficient
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		bbox_loss_coefficient
					__SCREAMING_SNAKE_CASE       :		int           =		giou_loss_coefficient
					__SCREAMING_SNAKE_CASE       :		Any           =		eos_coefficient
					__SCREAMING_SNAKE_CASE       :		Tuple           =		focal_alpha
					super().__init__(is_encoder_decoder=lowerCAmelCase__							,     **lowerCAmelCase__						)

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





					"""simple docstring"""






					return self.encoder_attention_heads

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





					"""simple docstring"""






					return self.d_model



			def UpperCamelCase__					(							self     : Any						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		List[str]           =		copy.deepcopy(self.__dict__						)
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		self.backbone_config.to_dict()
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		self.__class__.model_type
					return output




'''simple docstring'''




# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse

from ...utils.dataclasses import (
    ComputeEnvironment,
    DistributedType,
    DynamoBackend,
    PrecisionType,
    SageMakerDistributedType,
)
from ..menu import BulletMenu


UpperCamelCase__       :	List[Any]    = [
    '''EAGER''',
    '''AOT_EAGER''',
    '''INDUCTOR''',
    '''NVFUSER''',
    '''AOT_NVFUSER''',
    '''AOT_CUDAGRAPHS''',
    '''OFI''',
    '''FX2TRT''',
    '''ONNXRT''',
    '''IPEX''',
]


def 				lowerCAmelCase_   (	_lowerCamelCase:   str       ,      _lowerCamelCase:   Union[str, Any]=None       ,      _lowerCamelCase:   Optional[int]=None       ,      _lowerCamelCase:   str=None					):
		__SCREAMING_SNAKE_CASE       :		Optional[int]           =		True
		while ask_again:
				__SCREAMING_SNAKE_CASE       :		Tuple           =		input(_lowerCamelCase					)
				try:
						if default is not None and len(_lowerCamelCase					) == 0:
								return default
						return convert_value(_lowerCamelCase					) if convert_value is not None else result
				except Exception:
						if error_message is not None:
								print(_lowerCamelCase					)


def 				lowerCAmelCase_   (	_lowerCamelCase:   Tuple       ,      _lowerCamelCase:   Union[str, Any]=[]       ,      _lowerCamelCase:   List[Any]=None       ,      _lowerCamelCase:   Optional[Any]=0					):
		__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		BulletMenu(_lowerCamelCase       ,      _lowerCamelCase					)
		__SCREAMING_SNAKE_CASE       :		Dict           =		menu.run(default_choice=_lowerCamelCase					)
		return convert_value(_lowerCamelCase					) if convert_value is not None else result


def 				lowerCAmelCase_   (	_lowerCamelCase:   Optional[Any]					):
		__SCREAMING_SNAKE_CASE       :		List[str]           =		int(_lowerCamelCase					)
		return ComputeEnvironment(["""LOCAL_MACHINE""", """AMAZON_SAGEMAKER"""][value]					)


def 				lowerCAmelCase_   (	_lowerCamelCase:   Any					):
		__SCREAMING_SNAKE_CASE       :		str           =		int(_lowerCamelCase					)
		return DistributedType(["""NO""", """MULTI_CPU""", """MULTI_XPU""", """MULTI_GPU""", """MULTI_NPU""", """TPU"""][value]					)


def 				lowerCAmelCase_   (	_lowerCamelCase:   Tuple					):
		__SCREAMING_SNAKE_CASE       :		Tuple           =		int(_lowerCamelCase					)
		return DynamoBackend(DYNAMO_BACKENDS[value]					).value


def 				lowerCAmelCase_   (	_lowerCamelCase:   Union[str, Any]					):
		__SCREAMING_SNAKE_CASE       :		List[str]           =		int(_lowerCamelCase					)
		return PrecisionType(["""no""", """fp16""", """bf16""", """fp8"""][value]					)


def 				lowerCAmelCase_   (	_lowerCamelCase:   Tuple					):
		__SCREAMING_SNAKE_CASE       :		int           =		int(_lowerCamelCase					)
		return SageMakerDistributedType(["""NO""", """DATA_PARALLEL""", """MODEL_PARALLEL"""][value]					)


def 				lowerCAmelCase_   (	_lowerCamelCase:   List[Any]					):
		return {"yes": True, "no": False}[value.lower()]






class 						_UpperCamelCase  (							argparse.RawDescriptionHelpFormatter    ):


			'''simple docstring'''

			def UpperCamelCase__					(							self     : Tuple							,     lowerCAmelCase__     : Optional[Any]							,     lowerCAmelCase__     : Dict							,     lowerCAmelCase__     : List[Any]							,     lowerCAmelCase__     : List[Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		super()._format_usage(lowerCAmelCase__							,     lowerCAmelCase__							,     lowerCAmelCase__							,     lowerCAmelCase__						)
					__SCREAMING_SNAKE_CASE       :		Any           =		usage.replace("""<command> [<args>] """							,     """"""						)
					return usage