



import copy

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


__lowerCamelCase								=      logging.get_logger(__name__)

__lowerCamelCase								=      {
    '''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 	snake_case_			(lowercase__	):




       """simple docstring"""






       def __init__(  self  ,lowercase=256  ,lowercase=1024  ,lowercase=16  ,lowercase=16  ,lowercase=4  ,lowercase="gelu"  ,lowercase=1E-6  ,**lowercase  ,):

             """simple docstring"""





             super().__init__(**lowercase)
             UpperCAmelCase_	:						List[str]					   =		hidden_size
             UpperCAmelCase_	:						Optional[int]					   =		image_size
             UpperCAmelCase_	:						str					   =		patch_size
             UpperCAmelCase_	:						Union[str, Any]					   =		image_size // patch_size
             UpperCAmelCase_	:						Union[str, Any]					   =		mask_input_channels
             UpperCAmelCase_	:						Optional[Any]					   =		num_point_embeddings
             UpperCAmelCase_	:						Any					   =		hidden_act
             UpperCAmelCase_	:						List[str]					   =		layer_norm_eps


class 	snake_case_			(lowercase__	):




       """simple docstring"""






       def __init__(  self  ,lowercase=256  ,lowercase="relu"  ,lowercase=2048  ,lowercase=2  ,lowercase=8  ,lowercase=2  ,lowercase=3  ,lowercase=3  ,lowercase=256  ,lowercase=1E-6  ,**lowercase  ,):

             """simple docstring"""





             super().__init__(**lowercase)
             UpperCAmelCase_	:						Optional[int]					   =		hidden_size
             UpperCAmelCase_	:						int					   =		hidden_act
             UpperCAmelCase_	:						List[str]					   =		mlp_dim
             UpperCAmelCase_	:						Any					   =		num_hidden_layers
             UpperCAmelCase_	:						Tuple					   =		num_attention_heads
             UpperCAmelCase_	:						str					   =		attention_downsample_rate
             UpperCAmelCase_	:						Optional[Any]					   =		num_multimask_outputs
             UpperCAmelCase_	:						Any					   =		iou_head_depth
             UpperCAmelCase_	:						Dict					   =		iou_head_hidden_dim
             UpperCAmelCase_	:						str					   =		layer_norm_eps


class 	snake_case_			(lowercase__	):




       """simple docstring"""






       def __init__(  self  ,lowercase=768  ,lowercase=256  ,lowercase=12  ,lowercase=12  ,lowercase=3  ,lowercase=1024  ,lowercase=16  ,lowercase="gelu"  ,lowercase=1E-06  ,lowercase=0.0  ,lowercase=1E-10  ,lowercase=True  ,lowercase=4.0  ,lowercase=True  ,lowercase=True  ,lowercase=14  ,lowercase=[2, 5, 8, 11]  ,lowercase=128  ,lowercase=None  ,**lowercase  ,):

             """simple docstring"""





             super().__init__(**lowercase)

             UpperCAmelCase_	:						int					   =		hidden_size
             UpperCAmelCase_	:						str					   =		output_channels
             UpperCAmelCase_	:						List[Any]					   =		num_hidden_layers
             UpperCAmelCase_	:						int					   =		num_attention_heads
             UpperCAmelCase_	:						Optional[int]					   =		num_channels
             UpperCAmelCase_	:						Tuple					   =		image_size
             UpperCAmelCase_	:						Any					   =		patch_size
             UpperCAmelCase_	:						int					   =		hidden_act
             UpperCAmelCase_	:						Dict					   =		layer_norm_eps
             UpperCAmelCase_	:						str					   =		attention_dropout
             UpperCAmelCase_	:						str					   =		initializer_range
             UpperCAmelCase_	:						Any					   =		qkv_bias
             UpperCAmelCase_	:						Optional[int]					   =		mlp_ratio
             UpperCAmelCase_	:						Dict					   =		use_abs_pos
             UpperCAmelCase_	:						Dict					   =		use_rel_pos
             UpperCAmelCase_	:						Optional[Any]					   =		window_size
             UpperCAmelCase_	:						Any					   =		global_attn_indexes
             UpperCAmelCase_	:						List[Any]					   =		num_pos_feats
             UpperCAmelCase_	:						List[str]					   =		int(hidden_size * mlp_ratio) if mlp_dim is None else mlp_dim


class 	snake_case_			(lowercase__	):




       """simple docstring"""






       _lowerCamelCase           =					"""sam"""
       _lowerCamelCase           =					True



       def __init__(  self  ,lowercase=None  ,lowercase=None  ,lowercase=None  ,lowercase=0.02  ,**lowercase  ,):

             """simple docstring"""





             super().__init__(**lowercase)
             UpperCAmelCase_	:						Optional[Any]					   =		vision_config if vision_config is not None else {}
             UpperCAmelCase_	:						Any					   =		prompt_encoder_config if prompt_encoder_config is not None else {}
             UpperCAmelCase_	:						Optional[Any]					   =		mask_decoder_config if mask_decoder_config is not None else {}

             if isinstance(lowercase  ,lowercase):
                   UpperCAmelCase_	:						str					   =		vision_config.to_dict()
             if isinstance(lowercase  ,lowercase):
                   UpperCAmelCase_	:						Optional[int]					   =		prompt_encoder_config.to_dict()
             if isinstance(lowercase  ,lowercase):
                   UpperCAmelCase_	:						Any					   =		mask_decoder_config.to_dict()

             UpperCAmelCase_	:						Optional[int]					   =		SamVisionConfig(**lowercase)
             UpperCAmelCase_	:						Any					   =		SamPromptEncoderConfig(**lowercase)
             UpperCAmelCase_	:						List[str]					   =		SamMaskDecoderConfig(**lowercase)
             UpperCAmelCase_	:						str					   =		initializer_range



       def 			A_ (  self):

             """simple docstring"""





             UpperCAmelCase_	:						List[str]					   =		copy.deepcopy(self.__dict__)
             UpperCAmelCase_	:						Union[str, Any]					   =		self.vision_config.to_dict()
             UpperCAmelCase_	:						Any					   =		self.prompt_encoder_config.to_dict()
             UpperCAmelCase_	:						List[Any]					   =		self.mask_decoder_config.to_dict()
             UpperCAmelCase_	:						Tuple					   =		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()
