






'''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


a_					= logging.get_logger(__name__)

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

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

a_					= {
    'openbmb/cpm-ant-10b': 1_0_2_4,
}





def  _a(  UpperCamelCase__				:						Tuple							):




      '''simple docstring'''






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






class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase				):




 def __init__(      self	:							Optional[int]					,      __lowercase	:							Optional[Any]					,      __lowercase	:							Tuple="<unk>"					,      __lowercase	:							Any=2_00      )	->						Any:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=vocab
       SCREAMING_SNAKE_CASE__     :				int									=unk_token
       SCREAMING_SNAKE_CASE__     :				List[Any]									=max_input_chars_per_word




 def      __magic_name__	(      self	:							List[Any]					,      __lowercase	:							Any      )	->						Dict:
       SCREAMING_SNAKE_CASE__     :				str									=list(__lowercase      )
       if len(__lowercase      ) > self.max_input_chars_per_word:
             return [self.unk_token]

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

       return sub_tokens






class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase				):
 snake_case_  							=							VOCAB_FILES_NAMES
 snake_case_  							=							PRETRAINED_VOCAB_FILES_MAP
 snake_case_  							=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 snake_case_  							=							["""input_ids""", """attention_mask"""]
 snake_case_  							=							False




 def __init__(      self	:							List[Any]					,      __lowercase	:							Union[str, Any]					,      __lowercase	:							List[Any]="<d>"					,      __lowercase	:							Optional[int]="</d>"					,      __lowercase	:							List[str]="<s>"					,      __lowercase	:							Any="</s>"					,      __lowercase	:							Tuple="<pad>"					,      __lowercase	:							Tuple="<unk>"					,      __lowercase	:							str="</n>"					,      __lowercase	:							Optional[Any]="</_>"					,      __lowercase	:							str="left"					,      **__lowercase	:							str					,      )	->						Optional[Any]:
       requires_backends(self					,      ['''jieba''']      )
       super().__init__(
           bod_token=__lowercase					,      eod_token=__lowercase					,      bos_token=__lowercase					,      eos_token=__lowercase					,      pad_token=__lowercase					,      unk_token=__lowercase					,      line_token=__lowercase					,      space_token=__lowercase					,      padding_side=__lowercase					,      **__lowercase					,      )
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=bod_token
       SCREAMING_SNAKE_CASE__     :				List[Any]									=eod_token
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=load_vocab(__lowercase      )
       SCREAMING_SNAKE_CASE__     :				Any									=self.encoder[space_token]
       SCREAMING_SNAKE_CASE__     :				List[Any]									=self.encoder[line_token]

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

       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=collections.OrderedDict(sorted(self.encoder.items()					,      key=lambda __lowercase      : x[1]      )      )
       SCREAMING_SNAKE_CASE__     :				List[str]									={v: k for k, v in self.encoder.items()}

       SCREAMING_SNAKE_CASE__     :				str									=WordpieceTokenizer(vocab=self.encoder					,      unk_token=self.unk_token      )




 @property
 def      __magic_name__	(      self	:							Optional[Any]      )	->						Dict:
       return self.encoder[self.bod_token]




 @property
 def      __magic_name__	(      self	:							Union[str, Any]      )	->						Dict:
       return self.encoder[self.eod_token]




 @property
 def      __magic_name__	(      self	:							Tuple      )	->						Optional[int]:
       return self.encoder["\n"]




 @property
 def      __magic_name__	(      self	:							List[str]      )	->						int:
       return len(self.encoder      )




 def      __magic_name__	(      self	:							int      )	->						List[Any]:
       return dict(self.encoder					,      **self.added_tokens_encoder      )




 def      __magic_name__	(      self	:							Union[str, Any]					,      __lowercase	:							Optional[int]      )	->						int:
       SCREAMING_SNAKE_CASE__     :				List[Any]									=[]
       for x in jieba.cut(__lowercase					,      cut_all=__lowercase      ):
             output_tokens.extend(self.wordpiece_tokenizer.tokenize(__lowercase      )      )
       return output_tokens




 def      __magic_name__	(      self	:							Dict					,      __lowercase	:							Union[str, Any]					,      **__lowercase	:							Union[str, Any]      )	->						List[str]:
       SCREAMING_SNAKE_CASE__     :				List[str]									=[i for i in token_ids if i >= 0]
       SCREAMING_SNAKE_CASE__     :				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(__lowercase					,      **__lowercase      )




 def      __magic_name__	(      self	:							Optional[int]					,      __lowercase	:							Any      )	->						int:
       return token in self.encoder




 def      __magic_name__	(      self	:							int					,      __lowercase	:							List[str]      )	->						str:
       return "".join(__lowercase      )




 def      __magic_name__	(      self	:							List[Any]					,      __lowercase	:							List[Any]      )	->						List[Any]:
       return self.encoder.get(__lowercase					,      self.encoder.get(self.unk_token      )      )




 def      __magic_name__	(      self	:							Dict					,      __lowercase	:							List[Any]      )	->						Union[str, Any]:
       return self.decoder.get(__lowercase					,      self.unk_token      )




 def      __magic_name__	(      self	:							Any					,      __lowercase	:							str					,      __lowercase	:							Optional[str] = None      )	->						Tuple[str]:
       if os.path.isdir(__lowercase      ):
             SCREAMING_SNAKE_CASE__     :				List[str]									=os.path.join(
                 __lowercase					,      (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']      )
       else:
             SCREAMING_SNAKE_CASE__     :				Dict									=(filename_prefix + '''-''' if filename_prefix else '''''') + save_directory
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=0
       if " " in self.encoder:
             SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=self.encoder[''' ''']
             del self.encoder[" "]
       if "\n" in self.encoder:
             SCREAMING_SNAKE_CASE__     :				int									=self.encoder['''\n''']
             del self.encoder["\n"]
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=collections.OrderedDict(sorted(self.encoder.items()					,      key=lambda __lowercase      : x[1]      )      )
       with open(__lowercase					,      '''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!'''      )
                         SCREAMING_SNAKE_CASE__     :				int									=token_index
                   writer.write(token + '''\n'''      )
                   index += 1
       return (vocab_file,)




 def      __magic_name__	(      self	:							Optional[int]					,      __lowercase	:							List[int]					,      __lowercase	:							List[int] = None      )	->						List[int]:
       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      __magic_name__	(      self	:							Optional[Any]					,      __lowercase	:							List[int]					,      __lowercase	:							Optional[List[int]] = None					,      __lowercase	:							bool = False      )	->						List[int]:

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

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







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


a_					= logging.get_logger(__name__)

a_					= {
    'bigcode/gpt_bigcode-santacoder': 'https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json',
}






class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase				):
 snake_case_  							=							"""gpt_bigcode"""
 snake_case_  							=							["""past_key_values"""]
 snake_case_  							=							{
     """hidden_size""": """n_embd""",
     """max_position_embeddings""": """n_positions""",
     """num_attention_heads""": """n_head""",
     """num_hidden_layers""": """n_layer""",
 }




 def __init__(      self	:							Any					,      __lowercase	:							Any=5_02_57					,      __lowercase	:							int=10_24					,      __lowercase	:							List[str]=7_68					,      __lowercase	:							Optional[int]=12					,      __lowercase	:							Dict=12					,      __lowercase	:							List[str]=None					,      __lowercase	:							int="gelu_pytorch_tanh"					,      __lowercase	:							Union[str, Any]=0.1					,      __lowercase	:							Optional[int]=0.1					,      __lowercase	:							Optional[int]=0.1					,      __lowercase	:							Optional[Any]=1e-5					,      __lowercase	:							List[str]=0.02					,      __lowercase	:							Tuple=True					,      __lowercase	:							Optional[Any]=True					,      __lowercase	:							Union[str, Any]=5_02_56					,      __lowercase	:							List[Any]=5_02_56					,      __lowercase	:							Union[str, Any]=True					,      __lowercase	:							List[str]=True					,      __lowercase	:							Dict=True					,      **__lowercase	:							List[Any]					,      )	->						Optional[int]:
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=vocab_size
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=n_positions
       SCREAMING_SNAKE_CASE__     :				Dict									=n_embd
       SCREAMING_SNAKE_CASE__     :				Dict									=n_layer
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=n_head
       SCREAMING_SNAKE_CASE__     :				List[str]									=n_inner
       SCREAMING_SNAKE_CASE__     :				List[str]									=activation_function
       SCREAMING_SNAKE_CASE__     :				List[Any]									=resid_pdrop
       SCREAMING_SNAKE_CASE__     :				List[Any]									=embd_pdrop
       SCREAMING_SNAKE_CASE__     :				List[str]									=attn_pdrop
       SCREAMING_SNAKE_CASE__     :				Dict									=layer_norm_epsilon
       SCREAMING_SNAKE_CASE__     :				List[str]									=initializer_range
       SCREAMING_SNAKE_CASE__     :				List[Any]									=scale_attn_weights
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=use_cache
       SCREAMING_SNAKE_CASE__     :				Dict									=attention_softmax_in_fpaa
       SCREAMING_SNAKE_CASE__     :				int									=scale_attention_softmax_in_fpaa
       SCREAMING_SNAKE_CASE__     :				Dict									=multi_query

       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=bos_token_id
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=eos_token_id

       super().__init__(bos_token_id=__lowercase					,      eos_token_id=__lowercase					,      **__lowercase      )