
'''simple docstring'''
import copy

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


a_     =  logging.get_logger(__name__)

a_     =  {
    "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_			(		snake_case__   ):





 def __init__(      self	,    lowercase_=2_56	,    lowercase_=10_24	,    lowercase_=16	,    lowercase_=16	,    lowercase_=4	,    lowercase_="gelu"	,    lowercase_=1E-6	,    **lowercase_	,    ):
     super().__init__(**lowercase_)
     snake_case_	:      int            =  hidden_size
     snake_case_	:      Optional[int]            =  image_size
     snake_case_	:      List[Any]            =  patch_size
     snake_case_	:      List[str]            =  image_size // patch_size
     snake_case_	:      Optional[int]            =  mask_input_channels
     snake_case_	:      str            =  num_point_embeddings
     snake_case_	:      Tuple            =  hidden_act
     snake_case_	:      List[Any]            =  layer_norm_eps






class 				UpperCAmelCase_			(		snake_case__   ):





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






class 				UpperCAmelCase_			(		snake_case__   ):





 def __init__(      self	,    lowercase_=7_68	,    lowercase_=2_56	,    lowercase_=12	,    lowercase_=12	,    lowercase_=3	,    lowercase_=10_24	,    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_=1_28	,    lowercase_=None	,    **lowercase_	,    ):
     super().__init__(**lowercase_)

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






class 				UpperCAmelCase_			(		snake_case__   ):
 UpperCAmelCase_						      =  """sam"""
 UpperCAmelCase_						      =  True





 def __init__(      self	,    lowercase_=None	,    lowercase_=None	,    lowercase_=None	,    lowercase_=0.02	,    **lowercase_	,    ):
     super().__init__(**lowercase_)
     snake_case_	:      List[str]            =  vision_config if vision_config is not None else {}
     snake_case_	:      Optional[Any]            =  prompt_encoder_config if prompt_encoder_config is not None else {}
     snake_case_	:      Optional[int]            =  mask_decoder_config if mask_decoder_config is not None else {}

     if isinstance(lowercase_	,    lowercase_):
         snake_case_	:      List[str]            =  vision_config.to_dict()
     if isinstance(lowercase_	,    lowercase_):
         snake_case_	:      Dict            =  prompt_encoder_config.to_dict()
     if isinstance(lowercase_	,    lowercase_):
         snake_case_	:      Any            =  mask_decoder_config.to_dict()

     snake_case_	:      Union[str, Any]            =  SamVisionConfig(**lowercase_)
     snake_case_	:      List[str]            =  SamPromptEncoderConfig(**lowercase_)
     snake_case_	:      Dict            =  SamMaskDecoderConfig(**lowercase_)
     snake_case_	:      int            =  initializer_range





 def     snake_case__						(      self):
     snake_case_	:      Optional[int]            =  copy.deepcopy(self.__dict__)
     snake_case_	:      int            =  self.vision_config.to_dict()
     snake_case_	:      Optional[int]            =  self.prompt_encoder_config.to_dict()
     snake_case_	:      Any            =  self.mask_decoder_config.to_dict()
     snake_case_	:      Any            =  self.__class__.model_type
     return output







'''simple docstring'''
import importlib.metadata
import sys

from transformers.testing_utils import TestCasePlus
from transformers.utils.versions import require_version, require_version_core


a_     =  importlib.metadata.version("numpy")
a_     =  ".".join([str(x) for x in sys.version_info[:3]])






class 				UpperCAmelCase_			(		snake_case__   ):





 def     snake_case__						(      self):
     # lt + different version strings
     require_version_core("numpy<1000.4.5")
     require_version_core("numpy<1000.4")
     require_version_core("numpy<1000")

     # le
     require_version_core("numpy<=1000.4.5")
     require_version_core(F'numpy<={numpy_ver}')

     # eq
     require_version_core(F'numpy=={numpy_ver}')

     # ne
     require_version_core("numpy!=1000.4.5")

     # ge
     require_version_core("numpy>=1.0")
     require_version_core("numpy>=1.0.0")
     require_version_core(F'numpy>={numpy_ver}')

     # gt
     require_version_core("numpy>1.0.0")

     # mix
     require_version_core("numpy>1.0.0,<1000")

     # requirement w/o version
     require_version_core("numpy")

     # unmet requirements due to version conflict
     for req in ["numpy==1.0.0", "numpy>=1000.0.0", F'numpy<{numpy_ver}']:
         try:
             require_version_core(lowercase_)
         except ImportError as e:
             self.assertIn(F'{req} is required'	,    str(lowercase_))
             self.assertIn("but found"	,    str(lowercase_))

        # unmet requirements due to missing module
     for req in ["numpipypie>1", "numpipypie2"]:
         try:
             require_version_core(lowercase_)
         except importlib.metadata.PackageNotFoundError as e:
             self.assertIn(F'The \'{req}\' distribution was not found and is required by this application'	,    str(lowercase_))
             self.assertIn("Try: pip install transformers -U"	,    str(lowercase_))

        # bogus requirements formats:
        # 1. whole thing
     for req in ["numpy??1.0.0", "numpy1.0.0"]:
         try:
             require_version_core(lowercase_)
         except ValueError as e:
             self.assertIn("requirement needs to be in the pip package format"	,    str(lowercase_))
        # 2. only operators
     for req in ["numpy=1.0.0", "numpy == 1.00", "numpy<>1.0.0", "numpy><1.00", "numpy>>1.0.0"]:
         try:
             require_version_core(lowercase_)
         except ValueError as e:
             self.assertIn("need one of "	,    str(lowercase_))





 def     snake_case__						(      self):
     # matching requirement
     require_version("python>=3.6.0")

     # not matching requirements
     for req in ["python>9.9.9", "python<3.0.0"]:
         try:
             require_version_core(lowercase_)
         except ImportError as e:
             self.assertIn(F'{req} is required'	,    str(lowercase_))
             self.assertIn(F'but found python=={python_ver}'	,    str(lowercase_))




