






import unittest
import warnings
from dataclasses import dataclass

from transformers.convert_slow_tokenizer import SpmConverter
from transformers.testing_utils import get_tests_dir



@dataclass
class 							A					:
					'''simple docstring'''






					A__    =				42






class 							A					( unittest.TestCase							):
					'''simple docstring'''






					def 						lowerCamelCase__  (self					:		List[Any]	)		->     Dict:




							"""simple docstring"""


							lowercase__      =	get_tests_dir("""fixtures/test_sentencepiece.model"""	)
							lowercase__      =	get_tests_dir("""fixtures/test_sentencepiece_with_bytefallback.model"""	)

							lowercase__      =	FakeOriginalTokenizer(vocab_file=_UpperCAmelCase	)

							with warnings.catch_warnings(record=_UpperCAmelCase	) as w:
									lowercase__      =	SpmConverter(_UpperCAmelCase	)
							self.assertEqual(len(_UpperCAmelCase	)   ,      0	)

							lowercase__      =	FakeOriginalTokenizer(vocab_file=_UpperCAmelCase	)

							with warnings.catch_warnings(record=_UpperCAmelCase	) as w:
									lowercase__      =	SpmConverter(_UpperCAmelCase	)
							self.assertEqual(len(_UpperCAmelCase	)   ,      1	)

							self.assertIn(
							    """The sentencepiece tokenizer that you are converting to a fast tokenizer uses the byte fallback option"""
							    """ which is not implemented in the fast tokenizers."""   ,      str(w[0].message	)   ,      )





import copy

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


A :	Optional[Any]												=     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 							A					( UpperCAmelCase__							):
					'''simple docstring'''






					def __init__(self					:		Dict   ,      _UpperCAmelCase					:		List[str]=256   ,      _UpperCAmelCase					:		Tuple=1024   ,      _UpperCAmelCase					:		List[str]=16   ,      _UpperCAmelCase					:		Optional[Any]=16   ,      _UpperCAmelCase					:		Union[str, Any]=4   ,      _UpperCAmelCase					:		str="gelu"   ,      _UpperCAmelCase					:		List[str]=1E-6   ,      **_UpperCAmelCase					:		List[Any]   ,      )		->     Tuple:




							"""simple docstring"""


							super().__init__(**_UpperCAmelCase	)
							lowercase__      =	hidden_size
							lowercase__      =	image_size
							lowercase__      =	patch_size
							lowercase__      =	image_size // patch_size
							lowercase__      =	mask_input_channels
							lowercase__      =	num_point_embeddings
							lowercase__      =	hidden_act
							lowercase__      =	layer_norm_eps






class 							A					( UpperCAmelCase__							):
					'''simple docstring'''






					def __init__(self					:		List[str]   ,      _UpperCAmelCase					:		Optional[int]=256   ,      _UpperCAmelCase					:		int="relu"   ,      _UpperCAmelCase					:		Union[str, Any]=2048   ,      _UpperCAmelCase					:		int=2   ,      _UpperCAmelCase					:		Optional[Any]=8   ,      _UpperCAmelCase					:		Any=2   ,      _UpperCAmelCase					:		Tuple=3   ,      _UpperCAmelCase					:		List[str]=3   ,      _UpperCAmelCase					:		List[str]=256   ,      _UpperCAmelCase					:		Tuple=1E-6   ,      **_UpperCAmelCase					:		int   ,      )		->     Tuple:




							"""simple docstring"""


							super().__init__(**_UpperCAmelCase	)
							lowercase__      =	hidden_size
							lowercase__      =	hidden_act
							lowercase__      =	mlp_dim
							lowercase__      =	num_hidden_layers
							lowercase__      =	num_attention_heads
							lowercase__      =	attention_downsample_rate
							lowercase__      =	num_multimask_outputs
							lowercase__      =	iou_head_depth
							lowercase__      =	iou_head_hidden_dim
							lowercase__      =	layer_norm_eps






class 							A					( UpperCAmelCase__							):
					'''simple docstring'''






					def __init__(self					:		Optional[int]   ,      _UpperCAmelCase					:		List[Any]=768   ,      _UpperCAmelCase					:		Union[str, Any]=256   ,      _UpperCAmelCase					:		Union[str, Any]=12   ,      _UpperCAmelCase					:		Optional[Any]=12   ,      _UpperCAmelCase					:		Tuple=3   ,      _UpperCAmelCase					:		Optional[int]=1024   ,      _UpperCAmelCase					:		str=16   ,      _UpperCAmelCase					:		Tuple="gelu"   ,      _UpperCAmelCase					:		Any=1E-0_6   ,      _UpperCAmelCase					:		Any=0.0   ,      _UpperCAmelCase					:		str=1E-1_0   ,      _UpperCAmelCase					:		Tuple=True   ,      _UpperCAmelCase					:		Tuple=4.0   ,      _UpperCAmelCase					:		Optional[Any]=True   ,      _UpperCAmelCase					:		Optional[int]=True   ,      _UpperCAmelCase					:		Optional[Any]=14   ,      _UpperCAmelCase					:		Optional[int]=[2, 5, 8, 11]   ,      _UpperCAmelCase					:		List[Any]=128   ,      _UpperCAmelCase					:		int=None   ,      **_UpperCAmelCase					:		int   ,      )		->     Dict:




							"""simple docstring"""


							super().__init__(**_UpperCAmelCase	)

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






class 							A					( UpperCAmelCase__							):
					'''simple docstring'''






					A__    =				'''sam'''
					A__    =				True

					def __init__(self					:		List[str]   ,      _UpperCAmelCase					:		Any=None   ,      _UpperCAmelCase					:		List[Any]=None   ,      _UpperCAmelCase					:		List[Any]=None   ,      _UpperCAmelCase					:		List[Any]=0.02   ,      **_UpperCAmelCase					:		Optional[Any]   ,      )		->     Dict:




							"""simple docstring"""


							super().__init__(**_UpperCAmelCase	)
							lowercase__      =	vision_config if vision_config is not None else {}
							lowercase__      =	prompt_encoder_config if prompt_encoder_config is not None else {}
							lowercase__      =	mask_decoder_config if mask_decoder_config is not None else {}

							if isinstance(_UpperCAmelCase   ,      _UpperCAmelCase	):
									lowercase__      =	vision_config.to_dict()
							if isinstance(_UpperCAmelCase   ,      _UpperCAmelCase	):
									lowercase__      =	prompt_encoder_config.to_dict()
							if isinstance(_UpperCAmelCase   ,      _UpperCAmelCase	):
									lowercase__      =	mask_decoder_config.to_dict()

							lowercase__      =	SamVisionConfig(**_UpperCAmelCase	)
							lowercase__      =	SamPromptEncoderConfig(**_UpperCAmelCase	)
							lowercase__      =	SamMaskDecoderConfig(**_UpperCAmelCase	)
							lowercase__      =	initializer_range


					def 						lowerCamelCase__  (self					:		Union[str, Any]	)		->     Tuple:




							"""simple docstring"""


							lowercase__      =	copy.deepcopy(self.__dict__	)
							lowercase__      =	self.vision_config.to_dict()
							lowercase__      =	self.prompt_encoder_config.to_dict()
							lowercase__      =	self.mask_decoder_config.to_dict()
							lowercase__      =	self.__class__.model_type
							return output

