






from typing import Dict, List, Optional, Tuple

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


A__     :      List[str]             =			logging.get_logger(__name__)
class 				_UpperCAmelCase (	UpperCamelCase__     ):
				lowercase__    							=	["""input_ids""", """attention_mask"""]




				def __init__(					self						:   Dict,  lowerCamelCase						:   int="[PAD]",  lowerCamelCase						:   str="[BOS]",  lowerCamelCase						:   Any="[EOS]",  lowerCamelCase						:   List[str]="[MASK]",  lowerCamelCase						:   Union[str, Any]="[CLS]",  lowerCamelCase						:   Any="[SEP]",  lowerCamelCase						:   List[Any]=2_048,  **lowerCamelCase						:   List[Any],  ):

								'''simple docstring'''
								lowercase__       			=      AddedToken(__lowerCamelCase,  lstrip=__lowerCamelCase,  rstrip=__lowerCamelCase  ) if isinstance(__lowerCamelCase,  __lowerCamelCase  ) else pad_token
								lowercase__       			=      AddedToken(__lowerCamelCase,  lstrip=__lowerCamelCase,  rstrip=__lowerCamelCase  ) if isinstance(__lowerCamelCase,  __lowerCamelCase  ) else bos_token
								lowercase__       			=      AddedToken(__lowerCamelCase,  lstrip=__lowerCamelCase,  rstrip=__lowerCamelCase  ) if isinstance(__lowerCamelCase,  __lowerCamelCase  ) else eos_token
								lowercase__       			=      AddedToken(__lowerCamelCase,  lstrip=__lowerCamelCase,  rstrip=__lowerCamelCase  ) if isinstance(__lowerCamelCase,  __lowerCamelCase  ) else mask_token
								lowercase__       			=      AddedToken(__lowerCamelCase,  lstrip=__lowerCamelCase,  rstrip=__lowerCamelCase  ) if isinstance(__lowerCamelCase,  __lowerCamelCase  ) else cls_token
								lowercase__       			=      AddedToken(__lowerCamelCase,  lstrip=__lowerCamelCase,  rstrip=__lowerCamelCase  ) if isinstance(__lowerCamelCase,  __lowerCamelCase  ) else sep_token

								super().__init__(
								    pad_token=__lowerCamelCase,  bos_token=__lowerCamelCase,  eos_token=__lowerCamelCase,  mask_token=__lowerCamelCase,  cls_token=__lowerCamelCase,  sep_token=__lowerCamelCase,  model_max_length=__lowerCamelCase,  **__lowerCamelCase,  )

								lowercase__       			=      2**8  # utf is 8 bits

								# define special tokens dict
								lowercase__       			=      {
								    self.pad_token: 0,
								    self.bos_token: 1,
								    self.eos_token: 2,
								    self.mask_token: 3,
								    self.cls_token: 4,
								    self.sep_token: 5,
								}
								lowercase__       			=      len(self.special_tokens_encoder  )
								lowercase__       			=      {v: k for k, v in self.special_tokens_encoder.items()}




				def     lowercase__       (					self						:   int  ):

								'''simple docstring'''
								lowercase__       			=      self.special_tokens_encoder.copy()
								vocab.update(self.added_tokens_encoder  )
								for i in range(self._utf_vocab_size  ):
												lowercase__       			=      chr(__lowerCamelCase  )
												lowercase__       			=      i + len(self.special_tokens_encoder  )
								return vocab




				@property
				def     lowercase__       (					self						:   Union[str, Any]  ):

								'''simple docstring'''
								return self._utf_vocab_size + self._num_special_tokens




				def     lowercase__       (					self						:   Any,  lowerCamelCase						:   List[int],  lowerCamelCase						:   Optional[List[int]] = None,  lowerCamelCase						:   bool = False  ):

								'''simple docstring'''


								if already_has_special_tokens:
												return super().get_special_tokens_mask(
												    token_ids_a=__lowerCamelCase,  token_ids_a=__lowerCamelCase,  already_has_special_tokens=__lowerCamelCase  )

								# normal case: some special tokens
								if token_ids_a is None:
												return [1] + [0] * len(__lowerCamelCase  ) + [1]
								return [1] + ([0] * len(__lowerCamelCase  )) + [1] + ([0] * len(__lowerCamelCase  )) + [1]




				def     lowercase__       (					self						:   List[str],  lowerCamelCase						:   List[int],  lowerCamelCase						:   Optional[List[int]] = None  ):

								'''simple docstring'''


								if token_ids_a is None:
												return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
								else:
												return [self.cls_token_id] + token_ids_a + [self.sep_token_id] + token_ids_a + [self.sep_token_id]




				def     lowercase__       (					self						:   Optional[int],  lowerCamelCase						:   str  ):

								'''simple docstring'''
								lowercase__       			=      [chr(__lowerCamelCase  ) for i in text.encode('''utf-8'''  )]
								return tokens




				def     lowercase__       (					self						:   int,  lowerCamelCase						:   Optional[int]  ):

								'''simple docstring'''


								if token in self.special_tokens_encoder:
												lowercase__       			=      self.special_tokens_encoder[token]
								elif token in self.added_tokens_encoder:
												lowercase__       			=      self.added_tokens_encoder[token]
								elif len(__lowerCamelCase  ) != 1:
												lowercase__       			=      self.unk_token_id
								else:
												lowercase__       			=      ord(__lowerCamelCase  ) + self._num_special_tokens
								return token_id




				def     lowercase__       (					self						:   Optional[Any],  lowerCamelCase						:   Tuple  ):

								'''simple docstring'''


								if index in self.special_tokens_decoder:
												lowercase__       			=      self.special_tokens_decoder[index]
								elif index in self.added_tokens_decoder:
												lowercase__       			=      self.added_tokens_decoder[index]
								else:
												lowercase__       			=      chr(index - self._num_special_tokens  )
								return token




				def     lowercase__       (					self						:   Optional[Any],  lowerCamelCase						:   List[str]  ):

								'''simple docstring'''
								lowercase__       			=      B""
								for token in tokens:
												if token in self.special_tokens_decoder:
																lowercase__       			=      self.special_tokens_decoder[token].encode('''utf-8'''  )
												elif token in self.added_tokens_decoder:
																lowercase__       			=      self.special_tokens_decoder[token].encode('''utf-8'''  )
												elif token in self.special_tokens_encoder:
																lowercase__       			=      token.encode('''utf-8'''  )
												elif token in self.added_tokens_encoder:
																lowercase__       			=      token.encode('''utf-8'''  )
												else:
																lowercase__       			=      bytes([ord(__lowerCamelCase  )]  )
												bstring += tok_string
								lowercase__       			=      bstring.decode('''utf-8''',  errors='''replace'''  )
								return string




				def     lowercase__       (					self						:   List[str],  lowerCamelCase						:   str,  lowerCamelCase						:   Optional[str] = None  ):

								'''simple docstring'''
								return ()












from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


A__     :      int             =			{
    'configuration_sam': [
        'SAM_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'SamConfig',
        'SamMaskDecoderConfig',
        'SamPromptEncoderConfig',
        'SamVisionConfig',
    ],
    'processing_sam': ['SamProcessor'],
}


try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							A__     :      List[Any]             =			[
							    'SAM_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'SamModel',
							    'SamPreTrainedModel',
							]
try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							A__     :      int             =			[
							    'TF_SAM_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'TFSamModel',
							    'TFSamPreTrainedModel',
							]
try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							A__     :      Tuple             =			['SamImageProcessor']


if TYPE_CHECKING:
							from .configuration_sam import (
							    SAM_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    SamConfig,
							    SamMaskDecoderConfig,
							    SamPromptEncoderConfig,
							    SamVisionConfig,
							)
							from .processing_sam import SamProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_sam import SAM_PRETRAINED_MODEL_ARCHIVE_LIST, SamModel, SamPreTrainedModel

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_sam import TF_SAM_PRETRAINED_MODEL_ARCHIVE_LIST, TFSamModel, TFSamPreTrainedModel

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .image_processing_sam import SamImageProcessor

else:
							import sys

							A__     :      Dict             =			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




