






'''simple docstring'''



import collections
import os
from typing import List, Optional, Tuple

from transformers.utils import is_jieba_available, requires_backends


if is_jieba_available():
      import jieba

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


SCREAMING_SNAKE_CASE							=						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE							=						{'vocab_file': 'vocab.txt'}

SCREAMING_SNAKE_CASE							=						{
    'vocab_file': {
        'openbmb/cpm-ant-10b': 'https://huggingface.co/openbmb/cpm-ant-10b/blob/main/vocab.txt',
    },
}

SCREAMING_SNAKE_CASE							=						{
    'openbmb/cpm-ant-10b': 1_024,
}


def 				lowercase_					(     __A			:							Tuple      )							->   str:



 """simple docstring"""




 lowercase       : List[str]						=collections.OrderedDict()
 with open(__A       ,   '''r'''       ,   encoding='''utf-8'''      ) as reader:
  lowercase       : List[str]						=reader.readlines()
 for index, token in enumerate(__A      ):
  lowercase       : Optional[Any]						=token.rstrip('''\n'''      )
  lowercase       : Union[str, Any]						=index
 return vocab
class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      def __init__(			self      :		Optional[Any]  ,   UpperCAmelCase      :		List[Any]  ,   UpperCAmelCase      :		Dict="<unk>"  ,   UpperCAmelCase      :		Tuple=200		)	->	Union[str, Any]:


       '''simple docstring'''

       lowercase       : Optional[Any]						=vocab
       lowercase       : Any						=unk_token
       lowercase       : Any						=max_input_chars_per_word






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		Optional[int]		)	->	Optional[int]:


       '''simple docstring'''

       lowercase       : int						=list(UpperCAmelCase		)
       if len(UpperCAmelCase		) > self.max_input_chars_per_word:
        return [self.unk_token]

       lowercase       : Dict						=0
       lowercase       : Tuple						=[]
       while start < len(UpperCAmelCase		):
        lowercase       : List[Any]						=len(UpperCAmelCase		)
        lowercase       : Optional[Any]						=None
        while start < end:
         lowercase       : Optional[int]						=''''''.join(chars[start:end]		)
         if substr in self.vocab:
          lowercase       : List[str]						=substr
          break
         end -= 1
        if cur_substr is None:
         sub_tokens.append(self.unk_token		)
         start += 1
        else:
         sub_tokens.append(UpperCAmelCase		)
         lowercase       : List[Any]						=end

       return sub_tokens





class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      UpperCamelCase_             =      VOCAB_FILES_NAMES
      UpperCamelCase_             =      PRETRAINED_VOCAB_FILES_MAP
      UpperCamelCase_             =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      UpperCamelCase_             =      ['''input_ids''', '''attention_mask''']
      UpperCamelCase_             =      False






      def __init__(			self      :		str  ,   UpperCAmelCase      :		List[Any]  ,   UpperCAmelCase      :		str="<d>"  ,   UpperCAmelCase      :		List[Any]="</d>"  ,   UpperCAmelCase      :		str="<s>"  ,   UpperCAmelCase      :		Optional[Any]="</s>"  ,   UpperCAmelCase      :		Optional[int]="<pad>"  ,   UpperCAmelCase      :		Dict="<unk>"  ,   UpperCAmelCase      :		Union[str, Any]="</n>"  ,   UpperCAmelCase      :		Optional[Any]="</_>"  ,   UpperCAmelCase      :		Tuple="left"  ,   **UpperCAmelCase      :		Optional[Any]  ,   )	->	List[Any]:


       '''simple docstring'''

       requires_backends(self  ,   ['''jieba''']		)
       super().__init__(
           bod_token=UpperCAmelCase  ,   eod_token=UpperCAmelCase  ,   bos_token=UpperCAmelCase  ,   eos_token=UpperCAmelCase  ,   pad_token=UpperCAmelCase  ,   unk_token=UpperCAmelCase  ,   line_token=UpperCAmelCase  ,   space_token=UpperCAmelCase  ,   padding_side=UpperCAmelCase  ,   **UpperCAmelCase  ,   )
       lowercase       : Tuple						=bod_token
       lowercase       : Any						=eod_token
       lowercase       : List[Any]						=load_vocab(UpperCAmelCase		)
       lowercase       : Union[str, Any]						=self.encoder[space_token]
       lowercase       : Union[str, Any]						=self.encoder[line_token]

       del self.encoder[space_token]
       del self.encoder[line_token]

       lowercase       : Tuple						=collections.OrderedDict(sorted(self.encoder.items()  ,   key=lambda UpperCAmelCase		: x[1]		)		)
       lowercase       : Optional[int]						={v: k for k, v in self.encoder.items()}

       lowercase       : Union[str, Any]						=WordpieceTokenizer(vocab=self.encoder  ,   unk_token=self.unk_token		)






      @property
      def 					A__   (			self      :		Tuple		)	->	int:


       '''simple docstring'''

       return self.encoder[self.bod_token]






      @property
      def 					A__   (			self      :		Dict		)	->	Optional[Any]:


       '''simple docstring'''

       return self.encoder[self.eod_token]






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


       '''simple docstring'''

       return self.encoder["\n"]






      @property
      def 					A__   (			self      :		str		)	->	int:


       '''simple docstring'''

       return len(self.encoder		)






      def 					A__   (			self      :		Dict		)	->	Optional[int]:


       '''simple docstring'''

       return dict(self.encoder  ,   **self.added_tokens_encoder		)






      def 					A__   (			self      :		Optional[Any]  ,   UpperCAmelCase      :		Tuple		)	->	Optional[Any]:


       '''simple docstring'''

       lowercase       : Any						=[]
       for x in jieba.cut(UpperCAmelCase  ,   cut_all=UpperCAmelCase		):
        output_tokens.extend(self.wordpiece_tokenizer.tokenize(UpperCAmelCase		)		)
       return output_tokens






      def 					A__   (			self      :		str  ,   UpperCAmelCase      :		Optional[int]  ,   **UpperCAmelCase      :		Union[str, Any]		)	->	Optional[int]:


       '''simple docstring'''

       lowercase       : str						=[i for i in token_ids if i >= 0]
       lowercase       : Optional[Any]						=[
           x for x in token_ids if x != self.pad_token_id and x != self.eos_token_id and x != self.bos_token_id
       ]
       return super()._decode(UpperCAmelCase  ,   **UpperCAmelCase		)






      def 					A__   (			self      :		Tuple  ,   UpperCAmelCase      :		List[str]		)	->	Tuple:


       '''simple docstring'''

       return token in self.encoder






      def 					A__   (			self      :		str  ,   UpperCAmelCase      :		List[str]		)	->	str:


       '''simple docstring'''

       return "".join(UpperCAmelCase		)






      def 					A__   (			self      :		Dict  ,   UpperCAmelCase      :		Optional[int]		)	->	str:


       '''simple docstring'''

       return self.encoder.get(UpperCAmelCase  ,   self.encoder.get(self.unk_token		)		)






      def 					A__   (			self      :		Tuple  ,   UpperCAmelCase      :		List[Any]		)	->	str:


       '''simple docstring'''

       return self.decoder.get(UpperCAmelCase  ,   self.unk_token		)






      def 					A__   (			self      :		str  ,   UpperCAmelCase      :		str  ,   UpperCAmelCase      :		Optional[str] = None		)	->	Tuple[str]:


       '''simple docstring'''

       if os.path.isdir(UpperCAmelCase		):
        lowercase       : Dict						=os.path.join(
            UpperCAmelCase  ,   (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']		)
       else:
        lowercase       : Any						=(filename_prefix + '''-''' if filename_prefix else '''''') + save_directory
       lowercase       : Any						=0
       if " " in self.encoder:
        lowercase       : Optional[int]						=self.encoder[''' ''']
        del self.encoder[" "]
       if "\n" in self.encoder:
        lowercase       : str						=self.encoder['''\n''']
        del self.encoder["\n"]
       lowercase       : Dict						=collections.OrderedDict(sorted(self.encoder.items()  ,   key=lambda UpperCAmelCase		: x[1]		)		)
       with open(UpperCAmelCase  ,   '''w'''  ,   encoding='''utf-8'''		) as writer:
        for token, token_index in self.encoder.items():
         if index != token_index:
          logger.warning(
              f'Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive.'
              ''' Please check that the vocabulary is not corrupted!'''		)
          lowercase       : int						=token_index
         writer.write(token + '''\n'''		)
         index += 1
       return (vocab_file,)






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		List[int]  ,   UpperCAmelCase      :		List[int] = None		)	->	List[int]:


       '''simple docstring'''

       if token_ids_a is None:
        return [self.bos_token_id] + token_ids_a
       return [self.bos_token_id] + token_ids_a + [self.bos_token_id] + token_ids_a






      def 					A__   (			self      :		str  ,   UpperCAmelCase      :		List[int]  ,   UpperCAmelCase      :		Optional[List[int]] = None  ,   UpperCAmelCase      :		bool = False		)	->	List[int]:


       '''simple docstring'''

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

       if token_ids_a is not None:
        return [1] + ([0] * len(UpperCAmelCase		)) + [1] + ([0] * len(UpperCAmelCase		))
       return [1] + ([0] * len(UpperCAmelCase		))











"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase__    						=			logging.get_logger(__name__)

lowerCAmelCase__    						=			{
    'caidas/swin2sr-classicalsr-x2-64': (
        'https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json'
    ),
}


class _lowerCAmelCase						(    __UpperCAmelCase       ):
						SCREAMING_SNAKE_CASE_:					Any 					=				'swin2sr'

						SCREAMING_SNAKE_CASE_:					Dict 					=				{
						    'hidden_size': 'embed_dim',
						    'num_attention_heads': 'num_heads',
						    'num_hidden_layers': 'num_layers',
						}







						def __init__(    self   ,				lowerCAmelCase_=6_4   ,				lowerCAmelCase_=1   ,				lowerCAmelCase_=3   ,				lowerCAmelCase_=1_8_0   ,				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_   ,				)		->							Dict:
										super().__init__(**lowerCAmelCase_							)

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

