
import copy

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


lowercase__				:				str						=      logging.get_logger(__name__)

lowercase__				:				Dict						=      {
    "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 							SCREAMING_SNAKE_CASE__     (				A__     ):

							"""simple docstring"""






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





													'''simple docstring'''






													super().__init__(**SCREAMING_SNAKE_CASE_      )
													__UpperCamelCase  	=      hidden_size
													__UpperCamelCase  	=      image_size
													__UpperCamelCase  	=      patch_size
													__UpperCamelCase  	=      image_size // patch_size
													__UpperCamelCase  	=      mask_input_channels
													__UpperCamelCase  	=      num_point_embeddings
													__UpperCamelCase  	=      hidden_act
													__UpperCamelCase  	=      layer_norm_eps






class 							SCREAMING_SNAKE_CASE__     (				A__     ):

							"""simple docstring"""






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





													'''simple docstring'''






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






class 							SCREAMING_SNAKE_CASE__     (				A__     ):

							"""simple docstring"""






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





													'''simple docstring'''






													super().__init__(**SCREAMING_SNAKE_CASE_      )

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






class 							SCREAMING_SNAKE_CASE__     (				A__     ):

							"""simple docstring"""






							_snake_case  		=	'''sam'''
							_snake_case  		=	True



							def __init__(	self  ,						SCREAMING_SNAKE_CASE_=None  ,						SCREAMING_SNAKE_CASE_=None  ,						SCREAMING_SNAKE_CASE_=None  ,						SCREAMING_SNAKE_CASE_=0.0_2  ,						**SCREAMING_SNAKE_CASE_  ,						)-> int:





													'''simple docstring'''






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

													if isinstance(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      ):
																			__UpperCamelCase  	=      vision_config.to_dict()
													if isinstance(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      ):
																			__UpperCamelCase  	=      prompt_encoder_config.to_dict()
													if isinstance(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      ):
																			__UpperCamelCase  	=      mask_decoder_config.to_dict()

													__UpperCamelCase  	=      SamVisionConfig(**SCREAMING_SNAKE_CASE_      )
													__UpperCamelCase  	=      SamPromptEncoderConfig(**SCREAMING_SNAKE_CASE_      )
													__UpperCamelCase  	=      SamMaskDecoderConfig(**SCREAMING_SNAKE_CASE_      )
													__UpperCamelCase  	=      initializer_range



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





													'''simple docstring'''






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






'''simple docstring'''







from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
    import torch

lowerCAmelCase_      =   logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
    from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):







    def   lowerCAmelCase(  cls    :  Dict      ):







           '''simple docstring'''






           return cls







def   lowerCAmelCase(  a__    :  Union[Tuple, List]      , a__    :  Optional[Union[List["torch.Generator"], "torch.Generator"]] = None      , a__    :  Optional["torch.device"] = None      , a__    :  Optional["torch.dtype"] = None      , a__    :  Optional["torch.layout"] = None      , ):







       '''simple docstring'''






       lowerCamelCase__				   =      device
       lowerCamelCase__				   =      shape[0]

       lowerCamelCase__				   =      layout or torch.strided
       lowerCamelCase__				   =      device or torch.device("cpu"      )

       if generator is not None:
              lowerCamelCase__				   =      generator.device.type if not isinstance(a__      , a__      ) else generator[0].device.type
              if gen_device_type != device.type and gen_device_type == "cpu":
                     lowerCamelCase__				   =      "cpu"
                     if device != "mps":
                            logger.info(
                                f"""The passed generator was created on 'cpu' even though a tensor on {device} was expected."""
                                f""" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"""
                                f""" slighly speed up this function by passing a generator that was created on the {device} device."""      )
              elif gen_device_type != device.type and gen_device_type == "cuda":
                     raise ValueError(f"""Cannot generate a {device} tensor from a generator of type {gen_device_type}."""      )

       if isinstance(a__      , a__      ):
              lowerCamelCase__				   =      (1,) + shape[1:]
              lowerCamelCase__				   =      [
                  torch.randn(a__      , generator=generator[i]      , device=a__      , dtype=a__      , layout=a__      )
                  for i in range(a__      )
              ]
              lowerCamelCase__				   =      torch.cat(a__      , dim=0      ).to(a__      )
       else:
              lowerCamelCase__				   =      torch.randn(a__      , generator=a__      , device=a__      , dtype=a__      , layout=a__      ).to(a__      )

       return latents







def   lowerCAmelCase(  a__    :  Union[str, Any]      ):







       '''simple docstring'''






       if is_torch_version("<"      , "2.0.0"      ) or not hasattr(a__      , "_dynamo"      ):
              return False
       return isinstance(a__      , torch._dynamo.eval_frame.OptimizedModule      )

