




import copy

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


UpperCAmelCase_   							=      logging.get_logger(__name__)

UpperCAmelCase_   							=      {
    '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        lowerCamelCase__(   lowercase__):
      def __init__(							self:					Optional[int]       ,			UpperCamelCase_:					Optional[int]=2_56       ,			UpperCamelCase_:					List[str]=10_24       ,			UpperCamelCase_:					Optional[int]=16       ,			UpperCamelCase_:					List[Any]=16       ,			UpperCamelCase_:					Dict=4       ,			UpperCamelCase_:					str="gelu"       ,			UpperCamelCase_:					Optional[int]=1E-6       ,			**UpperCamelCase_:					Union[str, Any]       ,			):
             super().__init__(**UpperCamelCase_  )
             __lowerCamelCase  =		hidden_size
             __lowerCamelCase  =		image_size
             __lowerCamelCase  =		patch_size
             __lowerCamelCase  =		image_size // patch_size
             __lowerCamelCase  =		mask_input_channels
             __lowerCamelCase  =		num_point_embeddings
             __lowerCamelCase  =		hidden_act
             __lowerCamelCase  =		layer_norm_eps





class        lowerCamelCase__(   lowercase__):
      def __init__(							self:					str       ,			UpperCamelCase_:					Union[str, Any]=2_56       ,			UpperCamelCase_:					Tuple="relu"       ,			UpperCamelCase_:					Dict=20_48       ,			UpperCamelCase_:					Union[str, Any]=2       ,			UpperCamelCase_:					List[Any]=8       ,			UpperCamelCase_:					str=2       ,			UpperCamelCase_:					Tuple=3       ,			UpperCamelCase_:					List[str]=3       ,			UpperCamelCase_:					Union[str, Any]=2_56       ,			UpperCamelCase_:					Union[str, Any]=1E-6       ,			**UpperCamelCase_:					Optional[int]       ,			):
             super().__init__(**UpperCamelCase_  )
             __lowerCamelCase  =		hidden_size
             __lowerCamelCase  =		hidden_act
             __lowerCamelCase  =		mlp_dim
             __lowerCamelCase  =		num_hidden_layers
             __lowerCamelCase  =		num_attention_heads
             __lowerCamelCase  =		attention_downsample_rate
             __lowerCamelCase  =		num_multimask_outputs
             __lowerCamelCase  =		iou_head_depth
             __lowerCamelCase  =		iou_head_hidden_dim
             __lowerCamelCase  =		layer_norm_eps





class        lowerCamelCase__(   lowercase__):
      def __init__(							self:					Any       ,			UpperCamelCase_:					List[str]=7_68       ,			UpperCamelCase_:					List[str]=2_56       ,			UpperCamelCase_:					Optional[Any]=12       ,			UpperCamelCase_:					str=12       ,			UpperCamelCase_:					int=3       ,			UpperCamelCase_:					List[str]=10_24       ,			UpperCamelCase_:					int=16       ,			UpperCamelCase_:					Tuple="gelu"       ,			UpperCamelCase_:					Dict=1E-06       ,			UpperCamelCase_:					Optional[Any]=0.0       ,			UpperCamelCase_:					Optional[int]=1E-10       ,			UpperCamelCase_:					str=True       ,			UpperCamelCase_:					str=4.0       ,			UpperCamelCase_:					Tuple=True       ,			UpperCamelCase_:					Tuple=True       ,			UpperCamelCase_:					Union[str, Any]=14       ,			UpperCamelCase_:					int=[2, 5, 8, 11]       ,			UpperCamelCase_:					Union[str, Any]=1_28       ,			UpperCamelCase_:					Any=None       ,			**UpperCamelCase_:					Optional[Any]       ,			):
             super().__init__(**UpperCamelCase_  )

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





class        lowerCamelCase__(   lowercase__):
      UpperCAmelCase__ :      int       						=  'sam'
      UpperCAmelCase__ :      Tuple       						=  True
      def __init__(							self:					Optional[Any]       ,			UpperCamelCase_:					Any=None       ,			UpperCamelCase_:					int=None       ,			UpperCamelCase_:					Optional[Any]=None       ,			UpperCamelCase_:					Tuple=0.02       ,			**UpperCamelCase_:					Dict       ,			):
             super().__init__(**UpperCamelCase_  )
             __lowerCamelCase  =		vision_config if vision_config is not None else {}
             __lowerCamelCase  =		prompt_encoder_config if prompt_encoder_config is not None else {}
             __lowerCamelCase  =		mask_decoder_config if mask_decoder_config is not None else {}

             if isinstance(UpperCamelCase_       ,			UpperCamelCase_  ):
                    __lowerCamelCase  =		vision_config.to_dict()
             if isinstance(UpperCamelCase_       ,			UpperCamelCase_  ):
                    __lowerCamelCase  =		prompt_encoder_config.to_dict()
             if isinstance(UpperCamelCase_       ,			UpperCamelCase_  ):
                    __lowerCamelCase  =		mask_decoder_config.to_dict()

             __lowerCamelCase  =		SamVisionConfig(**UpperCamelCase_  )
             __lowerCamelCase  =		SamPromptEncoderConfig(**UpperCamelCase_  )
             __lowerCamelCase  =		SamMaskDecoderConfig(**UpperCamelCase_  )
             __lowerCamelCase  =		initializer_range




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






import os
import unittest

import pytest
from parameterized import parameterized

from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device


# skipping in unittest tests

__lowerCamelCase								=      [(1,)]







def  _snake_case			(							)  ->  str:






      '''simple docstring'''







      UpperCAmelCase_	:						Optional[Any]					   =		bool(os.getenv("RUN_SLOW"       ,	0     )     )
      if run_slow:
            assert True
      else:
            assert False, "should have been skipped"







def  _snake_case			(							)  ->  Tuple:






      '''simple docstring'''







      UpperCAmelCase_	:						Union[str, Any]					   =		bool(os.getenv("RUN_SLOW"       ,	0     )     )
      if run_slow and torch_device == "cuda":
            assert True
      else:
            assert False, "should have been skipped"


@require_torch
class 	snake_case_			(unittest.TestCase	):




       """simple docstring"""






       @slow
       @require_torch_gpu
       def 			A_ (  self):

             """simple docstring"""





             check_slow_torch_cuda()



       @require_torch_gpu
       @slow
       def 			A_ (  self):

             """simple docstring"""





             check_slow_torch_cuda()



       @parameterized.expand(lowercase)
       @slow
       def 			A_ (  self  ,lowercase=None):

             """simple docstring"""





             check_slow()







@slow
@require_torch_gpu
def  _snake_case			(							)  ->  str:






      '''simple docstring'''







      check_slow_torch_cuda()







@require_torch_gpu
@slow
def  _snake_case			(							)  ->  Union[str, Any]:






      '''simple docstring'''







      check_slow_torch_cuda()







@slow
@pytest.mark.parametrize("param"       ,	[1]     )
def  _snake_case			(							__snake_case     )  ->  Optional[Any]:






      '''simple docstring'''







      check_slow()







@pytest.mark.parametrize("param"       ,	[1]     )
@slow
def  _snake_case			(							__snake_case     )  ->  Any:






      '''simple docstring'''







      check_slow()
