



"""simple docstring"""
import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard


class 							lowerCamelCase_(      unittest.TestCase			):





					'''simple docstring'''



					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = {
									    '''model_details''': {
									        '''Organization''': '''testing''',
									        '''Model date''': '''today''',
									        '''Model version''': '''v2.1, Developed by Test Corp in 2019.''',
									        '''Architecture''': '''Convolutional Neural Network.''',
									    },
									    '''metrics''': '''BLEU and ROUGE-1''',
									    '''evaluation_data''': {
									        '''Datasets''': {'''BLEU''': '''My-great-dataset-v1''', '''ROUGE-1''': '''My-short-dataset-v2.1'''},
									        '''Preprocessing''': '''See details on https://arxiv.org/pdf/1810.03993.pdf''',
									    },
									    '''training_data''': {
									        '''Dataset''': '''English Wikipedia dump dated 2018-12-01''',
									        '''Preprocessing''': (
									            '''Using SentencePiece vocabulary of size 52k tokens. See details on'''
									            ''' https://arxiv.org/pdf/1810.03993.pdf'''
									        ),
									    },
									    '''quantitative_analyses''': {'''BLEU''': 5_5.1, '''ROUGE-1''': 7_6},
									}

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = ModelCard.from_dict(self.inputs_dict      )
									self.assertTrue(hasattr(lowerCamelCase__ ,				'''model_details'''      )      )
									self.assertTrue(hasattr(lowerCamelCase__ ,				'''intended_use'''      )      )
									self.assertTrue(hasattr(lowerCamelCase__ ,				'''factors'''      )      )
									self.assertTrue(hasattr(lowerCamelCase__ ,				'''metrics'''      )      )
									self.assertTrue(hasattr(lowerCamelCase__ ,				'''evaluation_data'''      )      )
									self.assertTrue(hasattr(lowerCamelCase__ ,				'''training_data'''      )      )
									self.assertTrue(hasattr(lowerCamelCase__ ,				'''quantitative_analyses'''      )      )
									self.assertTrue(hasattr(lowerCamelCase__ ,				'''ethical_considerations'''      )      )
									self.assertTrue(hasattr(lowerCamelCase__ ,				'''caveats_and_recommendations'''      )      )

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = ModelCard.from_dict(self.inputs_dict      )
									_lowerCamelCase					     = json.loads(modelcard.to_json_string()      )
									for key, value in self.inputs_dict.items():
													self.assertEqual(obj[key] ,				lowerCamelCase__      )

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = ModelCard.from_dict(self.inputs_dict      )

									with tempfile.TemporaryDirectory() as tmpdirname:
													_lowerCamelCase					     = os.path.join(lowerCamelCase__ ,				'''modelcard.json'''      )
													model_card_first.to_json_file(lowerCamelCase__      )
													_lowerCamelCase					     = ModelCard.from_json_file(lowerCamelCase__      )

									self.assertEqual(model_card_second.to_dict() ,				model_card_first.to_dict()      )





					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = ModelCard.from_dict(self.inputs_dict      )

									with tempfile.TemporaryDirectory() as tmpdirname:
													model_card_first.save_pretrained(lowerCamelCase__      )
													_lowerCamelCase					     = ModelCard.from_pretrained(lowerCamelCase__      )

									self.assertEqual(model_card_second.to_dict() ,				model_card_first.to_dict()      )



"""simple docstring"""




import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A     :    str    =		logging.get_logger(__name__)

__A     :    Union[str, Any]    =		{
    'facebook/sam-vit-huge': 'https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json',
    'facebook/sam-vit-large': 'https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json',
    'facebook/sam-vit-base': 'https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json',
}





class 			__UpperCamelCase (   _A						):


		def __init__(self :		int     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=2_5_6     ,     __SCREAMING_SNAKE_CASE :		List[str]=1_0_2_4     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=1_6     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=1_6     ,     __SCREAMING_SNAKE_CASE :		List[str]=4     ,     __SCREAMING_SNAKE_CASE :		List[Any]="gelu"     ,     __SCREAMING_SNAKE_CASE :		str=1E-6     ,     **__SCREAMING_SNAKE_CASE :		Optional[int]     ,     ):
							super().__init__(**__SCREAMING_SNAKE_CASE)
							A			=					hidden_size
							A			=					image_size
							A			=					patch_size
							A			=					image_size // patch_size
							A			=					mask_input_channels
							A			=					num_point_embeddings
							A			=					hidden_act
							A			=					layer_norm_eps





class 			__UpperCamelCase (   _A						):


		def __init__(self :		List[Any]     ,     __SCREAMING_SNAKE_CASE :		Tuple=2_5_6     ,     __SCREAMING_SNAKE_CASE :		str="relu"     ,     __SCREAMING_SNAKE_CASE :		List[Any]=2_0_4_8     ,     __SCREAMING_SNAKE_CASE :		Tuple=2     ,     __SCREAMING_SNAKE_CASE :		Any=8     ,     __SCREAMING_SNAKE_CASE :		Union[str, Any]=2     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=3     ,     __SCREAMING_SNAKE_CASE :		List[Any]=3     ,     __SCREAMING_SNAKE_CASE :		Tuple=2_5_6     ,     __SCREAMING_SNAKE_CASE :		int=1E-6     ,     **__SCREAMING_SNAKE_CASE :		int     ,     ):
							super().__init__(**__SCREAMING_SNAKE_CASE)
							A			=					hidden_size
							A			=					hidden_act
							A			=					mlp_dim
							A			=					num_hidden_layers
							A			=					num_attention_heads
							A			=					attention_downsample_rate
							A			=					num_multimask_outputs
							A			=					iou_head_depth
							A			=					iou_head_hidden_dim
							A			=					layer_norm_eps





class 			__UpperCamelCase (   _A						):


		def __init__(self :		List[str]     ,     __SCREAMING_SNAKE_CASE :		List[Any]=7_6_8     ,     __SCREAMING_SNAKE_CASE :		int=2_5_6     ,     __SCREAMING_SNAKE_CASE :		Tuple=1_2     ,     __SCREAMING_SNAKE_CASE :		str=1_2     ,     __SCREAMING_SNAKE_CASE :		Any=3     ,     __SCREAMING_SNAKE_CASE :		Dict=1_0_2_4     ,     __SCREAMING_SNAKE_CASE :		str=1_6     ,     __SCREAMING_SNAKE_CASE :		Tuple="gelu"     ,     __SCREAMING_SNAKE_CASE :		int=1E-06     ,     __SCREAMING_SNAKE_CASE :		Dict=0.0     ,     __SCREAMING_SNAKE_CASE :		str=1E-10     ,     __SCREAMING_SNAKE_CASE :		List[str]=True     ,     __SCREAMING_SNAKE_CASE :		Union[str, Any]=4.0     ,     __SCREAMING_SNAKE_CASE :		str=True     ,     __SCREAMING_SNAKE_CASE :		Any=True     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=1_4     ,     __SCREAMING_SNAKE_CASE :		Tuple=[2, 5, 8, 1_1]     ,     __SCREAMING_SNAKE_CASE :		str=1_2_8     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=None     ,     **__SCREAMING_SNAKE_CASE :		Optional[Any]     ,     ):
							super().__init__(**__SCREAMING_SNAKE_CASE)

							A			=					hidden_size
							A			=					output_channels
							A			=					num_hidden_layers
							A			=					num_attention_heads
							A			=					num_channels
							A			=					image_size
							A			=					patch_size
							A			=					hidden_act
							A			=					layer_norm_eps
							A			=					attention_dropout
							A			=					initializer_range
							A			=					qkv_bias
							A			=					mlp_ratio
							A			=					use_abs_pos
							A			=					use_rel_pos
							A			=					window_size
							A			=					global_attn_indexes
							A			=					num_pos_feats
							A			=					int(hidden_size * mlp_ratio) if mlp_dim is None else mlp_dim





class 			__UpperCamelCase (   _A						):
		SCREAMING_SNAKE_CASE								=    "sam"
		SCREAMING_SNAKE_CASE								=    True


		def __init__(self :		Optional[int]     ,     __SCREAMING_SNAKE_CASE :		Dict=None     ,     __SCREAMING_SNAKE_CASE :		Union[str, Any]=None     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=None     ,     __SCREAMING_SNAKE_CASE :		List[Any]=0.0_2     ,     **__SCREAMING_SNAKE_CASE :		Optional[Any]     ,     ):
							super().__init__(**__SCREAMING_SNAKE_CASE)
							A			=					vision_config if vision_config is not None else {}
							A			=					prompt_encoder_config if prompt_encoder_config is not None else {}
							A			=					mask_decoder_config if mask_decoder_config is not None else {}

							if isinstance(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE):
												A			=					vision_config.to_dict()
							if isinstance(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE):
												A			=					prompt_encoder_config.to_dict()
							if isinstance(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE):
												A			=					mask_decoder_config.to_dict()

							A			=					SamVisionConfig(**__SCREAMING_SNAKE_CASE)
							A			=					SamPromptEncoderConfig(**__SCREAMING_SNAKE_CASE)
							A			=					SamMaskDecoderConfig(**__SCREAMING_SNAKE_CASE)
							A			=					initializer_range


		def 					SCREAMING_SNAKE_CASE__   (self :		List[str]):
							A			=					copy.deepcopy(self.__dict__)
							A			=					self.vision_config.to_dict()
							A			=					self.prompt_encoder_config.to_dict()
							A			=					self.mask_decoder_config.to_dict()
							A			=					self.__class__.model_type
							return output





