




import copy

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


UpperCamelCase__ :   str						=							logging.get_logger(__name__)

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







class 				lowerCAmelCase_       (					lowerCamelCase_							):
				__a     :       Union[str, Any]						=     "deta"
				__a     :       Optional[int]						=     {
				    "hidden_size": "d_model",
				    "num_attention_heads": "encoder_attention_heads",
				}






				def __init__(			self      ,snake_case__=None      ,snake_case__=900      ,snake_case__=2048      ,snake_case__=6      ,snake_case__=2048      ,snake_case__=8      ,snake_case__=6      ,snake_case__=1024      ,snake_case__=8      ,snake_case__=0.0      ,snake_case__=True      ,snake_case__="relu"      ,snake_case__=256      ,snake_case__=0.1      ,snake_case__=0.0      ,snake_case__=0.0      ,snake_case__=0.02      ,snake_case__=1.0      ,snake_case__=True      ,snake_case__=False      ,snake_case__="sine"      ,snake_case__=5      ,snake_case__=4      ,snake_case__=4      ,snake_case__=True      ,snake_case__=300      ,snake_case__=True      ,snake_case__=True      ,snake_case__=1      ,snake_case__=5      ,snake_case__=2      ,snake_case__=1      ,snake_case__=1      ,snake_case__=5      ,snake_case__=2      ,snake_case__=0.1      ,snake_case__=0.25      ,**snake_case__      ,):
							if backbone_config is None:
										logger.info('`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.' )
										SCREAMING_SNAKE_CASE_   : List[Any]					  =      CONFIG_MAPPING['resnet'](out_features=['stage2', 'stage3', 'stage4'] )
							else:
										if isinstance(snake_case__      ,snake_case__ ):
													SCREAMING_SNAKE_CASE_   : List[str]					  =      backbone_config.pop('model_type' )
													SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      CONFIG_MAPPING[backbone_model_type]
													SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      config_class.from_dict(snake_case__ )

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






				@property
				def 		snake_case	(			self ):
							return self.encoder_attention_heads






				@property
				def 		snake_case	(			self ):
							return self.d_model






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      copy.deepcopy(self.__dict__ )
							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      self.backbone_config.to_dict()
							SCREAMING_SNAKE_CASE_   : Any					  =      self.__class__.model_type
							return output









import argparse

import torch

from transformers import FunnelBaseModel, FunnelConfig, FunnelModel, load_tf_weights_in_funnel
from transformers.utils import logging


logging.set_verbosity_info()





def        __UpperCAmelCase						(							lowerCamelCase_ :     Dict  ,							lowerCamelCase_ :     Any  ,							lowerCamelCase_ :     int  ,							lowerCamelCase_ :     List[Any]  )       ->  int:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      FunnelConfig.from_json_file(lowerCamelCase_  )
			print(F'Building PyTorch model from configuration: {config}'  )
			SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      FunnelBaseModel(lowerCamelCase_  ) if base_model else FunnelModel(lowerCamelCase_  )

			# Load weights from tf checkpoint
			load_tf_weights_in_funnel(lowerCamelCase_  ,							lowerCamelCase_  ,							lowerCamelCase_  )

			# Save pytorch-model
			print(F'Save PyTorch model to {pytorch_dump_path}'  )
			torch.save(model.state_dict()  ,							lowerCamelCase_  )


if __name__ == "__main__":
						UpperCamelCase__ :   Optional[Any]						=							argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    '''--tf_checkpoint_path''', default=None, type=str, required=True, help='''Path to the TensorFlow checkpoint path.'''
						)
						parser.add_argument(
						    '''--config_file''',
						    default=None,
						    type=str,
						    required=True,
						    help='''The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.''',
						)
						parser.add_argument(
						    '''--pytorch_dump_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
						)
						parser.add_argument(
						    '''--base_model''', action='''store_true''', help='''Whether you want just the base model (no decoder) or not.'''
						)
						UpperCamelCase__ :   Tuple						=							parser.parse_args()
						convert_tf_checkpoint_to_pytorch(
						    args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.base_model
						)



