code: 
  from __future__ import annotations
  
  from collections.abc import Iterable
  from dataclasses import dataclass
  from typing import Any
  
  
  
  
  
  
  
  class 					UpperCAmelCase_				:
      UpperCAmelCase_			:       Union[str, Any]						 =							('_front', '_back', '_len')
  
  
  
  
  
  
  
      @dataclass
      class 					UpperCAmelCase_				:
          UpperCAmelCase_			:       Dict						 =							None
          UpperCAmelCase_			:       Optional[Any]						 =							None
          UpperCAmelCase_			:       List[str]						 =							None
  
  
  
  
  
  
  
      class 					UpperCAmelCase_				:
          UpperCAmelCase_			:       Optional[Any]						 =							('_cur',)
  
  
  
  
          def __init__(					self  :   Tuple      ,      lowerCAmelCase  :   Deque._Node | None   )	-> str:
            a__     		=     cur
  
  
  
  
          def __iter__(					self  :   List[Any]   )	-> Optional[Any]:
            return self
  
  
  
  
          def 						__lowerCamelCase (					self  :   Any   )	-> Optional[Any]:
            if self._cur is None:
              # finished iterating
              raise StopIteration
            a__     		=     self._cur.val
            a__     		=     self._cur.next_node
  
            return val
  
  
  
  
      def __init__(					self  :   int      ,      lowerCAmelCase  :   Iterable[Any] | None = None   )	-> Optional[int]:
        a__     		=     None
        a__     		=     None
        a__     		=     0
  
        if iterable is not None:
          # append every value to the deque
          for val in iterable:
            self.append(SCREAMING_SNAKE_CASE_   )
  
  
  
  
      def 						__lowerCamelCase (					self  :   int      ,      lowerCAmelCase  :   Any   )	-> List[str]:
        a__     		=     self._Node(SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_   )
        if self.is_empty():
          # front = back
          a__     		=     a__     		=     node
          a__     		=     1
        else:
          # connect nodes
          a__     		=     node
          a__     		=     self._back
          a__     		=     node  # assign new back to the new node
  
          self._len += 1
  
          # make sure there were no errors
          assert not self.is_empty(), "Error on appending value."
  
  
  
  
      def 						__lowerCamelCase (					self  :   Tuple      ,      lowerCAmelCase  :   Any   )	-> Dict:
        a__     		=     self._Node(SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_   )
        if self.is_empty():
          # front = back
          a__     		=     a__     		=     node
          a__     		=     1
        else:
          # connect nodes
          a__     		=     self._front
          a__     		=     node
          a__     		=     node  # assign new front to the new node
  
          self._len += 1
  
          # make sure there were no errors
          assert not self.is_empty(), "Error on appending value."
  
  
  
  
      def 						__lowerCamelCase (					self  :   int      ,      lowerCAmelCase  :   Iterable[Any]   )	-> int:
        for val in iterable:
          self.append(SCREAMING_SNAKE_CASE_   )
  
  
  
  
      def 						__lowerCamelCase (					self  :   Optional[Any]      ,      lowerCAmelCase  :   Iterable[Any]   )	-> Optional[int]:
        for val in iterable:
          self.appendleft(SCREAMING_SNAKE_CASE_   )
  
  
  
  
      def 						__lowerCamelCase (					self  :   Tuple   )	-> Union[str, Any]:
        assert not self.is_empty(), "Deque is empty."
  
        a__     		=     self._back
        a__     		=     self._back.prev_node  # set new back
        # drop the last node - python will deallocate memory automatically
        a__     		=     None
  
        self._len -= 1
  
        return topop.val
  
  
  
  
      def 						__lowerCamelCase (					self  :   Union[str, Any]   )	-> Tuple:
        assert not self.is_empty(), "Deque is empty."
  
        a__     		=     self._front
        a__     		=     self._front.next_node  # set new front and drop the first node
        a__     		=     None
  
        self._len -= 1
  
        return topop.val
  
  
  
  
      def 						__lowerCamelCase (					self  :   Optional[int]   )	-> Optional[int]:
        return self._front is None
  
  
  
  
      def __len__(					self  :   Tuple   )	-> int:
        return self._len
  
  
  
  
      def __eq__(					self  :   Union[str, Any]      ,      lowerCAmelCase  :   object   )	-> List[str]:
  
        if not isinstance(SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_   ):
          return NotImplemented
  
        a__     		=     self._front
        a__     		=     other._front
  
        # if the length of the dequeues are not the same, they are not equal
        if len(self   ) != len(SCREAMING_SNAKE_CASE_   ):
          return False
  
        while me is not None and oth is not None:
          # compare every value
          if me.val != oth.val:
            return False
          a__     		=     me.next_node
          a__     		=     oth.next_node
  
        return True
  
  
  
  
      def __iter__(					self  :   Optional[int]   )	-> List[str]:
        return Deque._Iterator(self._front   )
  
  
  
  
      def __repr__(					self  :   int   )	-> Tuple:
        a__     		=     []
        a__     		=     self._front
        while aux is not None:
          # append the values in a list to display
          values_list.append(aux.val   )
          a__     		=     aux.next_node
  
        return f"[{', '.join(repr(SCREAMING_SNAKE_CASE_   ) for val in values_list   )}]"
  
  
  if __name__ == "__main__":
       import doctest
  
       doctest.testmod()
  
  
style_context: import copy
  
  from ...configuration_utils import PretrainedConfig
  from ...utils import logging
  
  
  _SCREAMING_SNAKE_CASE   						=    logging.get_logger(__name__)
  
  _SCREAMING_SNAKE_CASE   						=    {
      """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_				(							_a    ):
  
  
  
  
      def __init__(					self  :   List[str]      ,      lowerCAmelCase  :   str=256      ,      lowerCAmelCase  :   Any=1024      ,      lowerCAmelCase  :   List[str]=16      ,      lowerCAmelCase  :   Union[str, Any]=16      ,      lowerCAmelCase  :   int=4      ,      lowerCAmelCase  :   List[Any]="gelu"      ,      lowerCAmelCase  :   str=1e-6      ,      **lowerCAmelCase  :   Union[str, Any]      ,      )	-> Union[str, Any]:
        super().__init__(**lowerCAmelCase   )
        a__     		=     hidden_size
        a__     		=     image_size
        a__     		=     patch_size
        a__     		=     image_size // patch_size
        a__     		=     mask_input_channels
        a__     		=     num_point_embeddings
        a__     		=     hidden_act
        a__     		=     layer_norm_eps
  
  
  
  
  
  
  
  class 					UpperCAmelCase_				(							_a    ):
  
  
  
  
      def __init__(					self  :   Dict      ,      lowerCAmelCase  :   str=256      ,      lowerCAmelCase  :   Union[str, Any]="relu"      ,      lowerCAmelCase  :   Optional[int]=2048      ,      lowerCAmelCase  :   Any=2      ,      lowerCAmelCase  :   Any=8      ,      lowerCAmelCase  :   Optional[Any]=2      ,      lowerCAmelCase  :   Optional[Any]=3      ,      lowerCAmelCase  :   Union[str, Any]=3      ,      lowerCAmelCase  :   List[str]=256      ,      lowerCAmelCase  :   Optional[Any]=1e-6      ,      **lowerCAmelCase  :   Any      ,      )	-> int:
        super().__init__(**lowerCAmelCase   )
        a__     		=     hidden_size
        a__     		=     hidden_act
        a__     		=     mlp_dim
        a__     		=     num_hidden_layers
        a__     		=     num_attention_heads
        a__     		=     attention_downsample_rate
        a__     		=     num_multimask_outputs
        a__     		=     iou_head_depth
        a__     		=     iou_head_hidden_dim
        a__     		=     layer_norm_eps
  
  
  
  
  
  
  
  class 					UpperCAmelCase_				(							_a    ):
  
  
  
  
      def __init__(					self  :   Optional[Any]      ,      lowerCAmelCase  :   Optional[Any]=768      ,      lowerCAmelCase  :   int=256      ,      lowerCAmelCase  :   Tuple=12      ,      lowerCAmelCase  :   List[str]=12      ,      lowerCAmelCase  :   Tuple=3      ,      lowerCAmelCase  :   Any=1024      ,      lowerCAmelCase  :   Dict=16      ,      lowerCAmelCase  :   Dict="gelu"      ,      lowerCAmelCase  :   List[Any]=1e-0_6      ,      lowerCAmelCase  :   Any=0.0      ,      lowerCAmelCase  :   Optional[Any]=1e-1_0      ,      lowerCAmelCase  :   Tuple=True      ,      lowerCAmelCase  :   Tuple=4.0      ,      lowerCAmelCase  :   Optional[Any]=True      ,      lowerCAmelCase  :   List[str]=True      ,      lowerCAmelCase  :   Dict=14      ,      lowerCAmelCase  :   Optional[int]=[2, 5, 8, 11]      ,      lowerCAmelCase  :   List[str]=128      ,      lowerCAmelCase  :   List[str]=None      ,      **lowerCAmelCase  :   str      ,      )	-> Optional[int]:
        super().__init__(**lowerCAmelCase   )
  
        a__     		=     hidden_size
        a__     		=     output_channels
        a__     		=     num_hidden_layers
        a__     		=     num_attention_heads
        a__     		=     num_channels
        a__     		=     image_size
        a__     		=     patch_size
        a__     		=     hidden_act
        a__     		=     layer_norm_eps
        a__     		=     attention_dropout
        a__     		=     initializer_range
        a__     		=     qkv_bias
        a__     		=     mlp_ratio
        a__     		=     use_abs_pos
        a__     		=     use_rel_pos
        a__     		=     window_size
        a__     		=     global_attn_indexes
        a__     		=     num_pos_feats
        a__     		=     int(hidden_size * mlp_ratio   ) if mlp_dim is None else mlp_dim
  
  
  
  
  
  
  
  class 					UpperCAmelCase_				(							_a    ):
      UpperCAmelCase_			:       Optional[Any]						 =							'sam'
      UpperCAmelCase_			:       List[Any]						 =							True
  
  
  
  
      def __init__(					self  :   Dict      ,      lowerCAmelCase  :   Any=None      ,      lowerCAmelCase  :   Optional[Any]=None      ,      lowerCAmelCase  :   Optional[Any]=None      ,      lowerCAmelCase  :   str=0.02      ,      **lowerCAmelCase  :   int      ,      )	-> Dict:
        super().__init__(**lowerCAmelCase   )
        a__     		=     vision_config if vision_config is not None else {}
        a__     		=     prompt_encoder_config if prompt_encoder_config is not None else {}
        a__     		=     mask_decoder_config if mask_decoder_config is not None else {}
  
        if isinstance(lowerCAmelCase      ,      lowerCAmelCase   ):
          a__     		=     vision_config.to_dict()
        if isinstance(lowerCAmelCase      ,      lowerCAmelCase   ):
          a__     		=     prompt_encoder_config.to_dict()
        if isinstance(lowerCAmelCase      ,      lowerCAmelCase   ):
          a__     		=     mask_decoder_config.to_dict()
  
        a__     		=     SamVisionConfig(**lowerCAmelCase   )
        a__     		=     SamPromptEncoderConfig(**lowerCAmelCase   )
        a__     		=     SamMaskDecoderConfig(**lowerCAmelCase   )
        a__     		=     initializer_range
  
  
  
  
      def 						__lowerCamelCase (					self  :   Optional[Any]   )	-> Union[str, Any]:
        a__     		=     copy.deepcopy(self.__dict__   )
        a__     		=     self.vision_config.to_dict()
        a__     		=     self.prompt_encoder_config.to_dict()
        a__     		=     self.mask_decoder_config.to_dict()
        a__     		=     self.__class__.model_type
        return output
  
  