






import os
from shutil import copyfile
from typing import List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


_a        =			logging.get_logger(__name__)

_a        =			{"""vocab_file""": """sentencepiece.model"""}

_a        =			{
    """vocab_file""": {
        """google/rembert""": """https://huggingface.co/google/rembert/resolve/main/sentencepiece.model""",
    },
}

_a        =			{
    """google/rembert""": 256,
}







class 	_UpperCAmelCase  (  _lowercase		):




      """simple docstring"""



      A          =    VOCAB_FILES_NAMES
      A          =    PRETRAINED_VOCAB_FILES_MAP
      A          =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      def __init__(   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase=False    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase="[CLS]"    ,	_lowerCAmelCase="[SEP]"    ,	_lowerCAmelCase="[UNK]"    ,	_lowerCAmelCase="[SEP]"    ,	_lowerCAmelCase="[PAD]"    ,	_lowerCAmelCase="[CLS]"    ,	_lowerCAmelCase="[MASK]"    ,	**_lowerCAmelCase    ,	):



          '''simple docstring'''
          super().__init__(
              do_lower_case=A_    ,	remove_space=A_    ,	keep_accents=A_    ,	bos_token=A_    ,	eos_token=A_    ,	unk_token=A_    ,	sep_token=A_    ,	pad_token=A_    ,	cls_token=A_    ,	mask_token=A_    ,	**A_    ,	)

          lowerCAmelCase__   :Any      							=				do_lower_case
          lowerCAmelCase__   :Optional[int]      							=				remove_space
          lowerCAmelCase__   :int      							=				keep_accents
          lowerCAmelCase__   :Tuple      							=				vocab_file

          lowerCAmelCase__   :Union[str, Any]      							=				spm.SentencePieceProcessor()
          self.sp_model.Load(A_		)
      @property
      def 			snake_case_      (   self		):



          '''simple docstring'''
          return len(self.sp_model		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :List[Any]      							=				{self.convert_ids_to_tokens(A_		): i for i in range(self.vocab_size		)}
          vocab.update(self.added_tokens_encoder		)
          return vocab
      def __getstate__(   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Union[str, Any]      							=				self.__dict__.copy()
          lowerCAmelCase__   :List[Any]      							=				None
          return state
      def __setstate__(   self    ,	_lowerCAmelCase		):



          '''simple docstring'''
          lowerCAmelCase__   :Dict      							=				d
          lowerCAmelCase__   :Optional[Any]      							=				spm.SentencePieceProcessor()
          self.sp_model.Load(self.vocab_file		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase=False		):



          '''simple docstring'''
          lowerCAmelCase__   :List[Any]      							=				self.sp_model.EncodeAsPieces(A_		)
          return pieces
      def 			snake_case_      (   self    ,	_lowerCAmelCase		):



          '''simple docstring'''
          return self.sp_model.PieceToId(A_		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase		):



          '''simple docstring'''
          return self.sp_model.IdToPiece(A_		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase		):



          '''simple docstring'''
          lowerCAmelCase__   :str      							=				self.sp_model.decode_pieces(A_		)
          return out_string
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase = None		):



          '''simple docstring'''
          lowerCAmelCase__   :List[Any]      							=				[self.sep_token_id]
          lowerCAmelCase__   :Optional[int]      							=				[self.cls_token_id]
          if token_ids_a is None:
              return cls + token_ids_a + sep
          return cls + token_ids_a + sep + token_ids_a + sep
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase = None    ,	_lowerCAmelCase = False		):



          '''simple docstring'''

          if already_has_special_tokens:
              if token_ids_a is not None:
                  raise ValueError(
                      "You should not supply a second sequence if the provided sequence of "
                      "ids is already formatted with special tokens for the model."		)
              return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

          if token_ids_a is not None:
              return [1] + ([0] * len(A_		)) + [1] + ([0] * len(A_		)) + [1]
          return [1] + ([0] * len(A_		)) + [1]
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase = None		):



          '''simple docstring'''
          lowerCAmelCase__   :List[str]      							=				[self.sep_token_id]
          lowerCAmelCase__   :List[str]      							=				[self.cls_token_id]

          if token_ids_a is None:
              return len(cls + token_ids_a + sep		) * [0]
          return len(cls + token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1]



      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase = None		):



          '''simple docstring'''
          if not os.path.isdir(A_		):
              logger.error("Vocabulary path ({}) should be a directory".format(A_		)		)
              return
          lowerCAmelCase__   :Any      							=				os.path.join(
              A_    ,	(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]		)

          if os.path.abspath(self.vocab_file		) != os.path.abspath(A_		):
              copyfile(self.vocab_file    ,	A_		)

          return (out_vocab_file,)











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


_a    :   Dict        =			logging.get_logger(__name__)

_a    :   Optional[Any]        =			{
    """caidas/swin2sr-classicalsr-x2-64""": (
        """https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json"""
    ),
}







class 	_UpperCAmelCase  (  _A		):




      """simple docstring"""



      A          =    '''swin2sr'''

      A          =    {
          '''hidden_size''': '''embed_dim''',
          '''num_attention_heads''': '''num_heads''',
          '''num_hidden_layers''': '''num_layers''',
      }
      def __init__(   self    ,	_lowerCAmelCase=64    ,	_lowerCAmelCase=1    ,	_lowerCAmelCase=3    ,	_lowerCAmelCase=180    ,	_lowerCAmelCase=[6, 6, 6, 6, 6, 6]    ,	_lowerCAmelCase=[6, 6, 6, 6, 6, 6]    ,	_lowerCAmelCase=8    ,	_lowerCAmelCase=2.0    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase=0.0    ,	_lowerCAmelCase=0.0    ,	_lowerCAmelCase=0.1    ,	_lowerCAmelCase="gelu"    ,	_lowerCAmelCase=False    ,	_lowerCAmelCase=0.02    ,	_lowerCAmelCase=1e-5    ,	_lowerCAmelCase=2    ,	_lowerCAmelCase=1.0    ,	_lowerCAmelCase="1conv"    ,	_lowerCAmelCase="pixelshuffle"    ,	**_lowerCAmelCase    ,	):



          '''simple docstring'''
          super().__init__(**_lowerCAmelCase		)

          lowerCAmelCase__   :Union[str, Any]      							=				image_size
          lowerCAmelCase__   :List[Any]      							=				patch_size
          lowerCAmelCase__   :Any      							=				num_channels
          lowerCAmelCase__   :Union[str, Any]      							=				embed_dim
          lowerCAmelCase__   :Optional[int]      							=				depths
          lowerCAmelCase__   :int      							=				len(_lowerCAmelCase		)
          lowerCAmelCase__   :List[str]      							=				num_heads
          lowerCAmelCase__   :str      							=				window_size
          lowerCAmelCase__   :List[str]      							=				mlp_ratio
          lowerCAmelCase__   :List[Any]      							=				qkv_bias
          lowerCAmelCase__   :Union[str, Any]      							=				hidden_dropout_prob
          lowerCAmelCase__   :Optional[int]      							=				attention_probs_dropout_prob
          lowerCAmelCase__   :Dict      							=				drop_path_rate
          lowerCAmelCase__   :Tuple      							=				hidden_act
          lowerCAmelCase__   :Dict      							=				use_absolute_embeddings
          lowerCAmelCase__   :Tuple      							=				layer_norm_eps
          lowerCAmelCase__   :Dict      							=				initializer_range
          lowerCAmelCase__   :Optional[int]      							=				upscale
          lowerCAmelCase__   :Optional[Any]      							=				img_range
          lowerCAmelCase__   :List[str]      							=				resi_connection
          lowerCAmelCase__   :Union[str, Any]      							=				upsampler



