





import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_gpta import GPTaTokenizer


if TYPE_CHECKING:
      from transformers.pipelines.conversational import Conversation


__UpperCAmelCase	:       Tuple    	=							logging.get_logger(__name__)

__UpperCAmelCase	:       List[str]    	=							{"vocab_file": "vocab.json", "merges_file": "merges.txt", "tokenizer_file": "tokenizer.json"}

__UpperCAmelCase	:       Optional[Any]    	=							{
    "vocab_file": {
        "gpt2": "https://huggingface.co/gpt2/resolve/main/vocab.json",
        "gpt2-medium": "https://huggingface.co/gpt2-medium/resolve/main/vocab.json",
        "gpt2-large": "https://huggingface.co/gpt2-large/resolve/main/vocab.json",
        "gpt2-xl": "https://huggingface.co/gpt2-xl/resolve/main/vocab.json",
        "distilgpt2": "https://huggingface.co/distilgpt2/resolve/main/vocab.json",
    },
    "merges_file": {
        "gpt2": "https://huggingface.co/gpt2/resolve/main/merges.txt",
        "gpt2-medium": "https://huggingface.co/gpt2-medium/resolve/main/merges.txt",
        "gpt2-large": "https://huggingface.co/gpt2-large/resolve/main/merges.txt",
        "gpt2-xl": "https://huggingface.co/gpt2-xl/resolve/main/merges.txt",
        "distilgpt2": "https://huggingface.co/distilgpt2/resolve/main/merges.txt",
    },
    "tokenizer_file": {
        "gpt2": "https://huggingface.co/gpt2/resolve/main/tokenizer.json",
        "gpt2-medium": "https://huggingface.co/gpt2-medium/resolve/main/tokenizer.json",
        "gpt2-large": "https://huggingface.co/gpt2-large/resolve/main/tokenizer.json",
        "gpt2-xl": "https://huggingface.co/gpt2-xl/resolve/main/tokenizer.json",
        "distilgpt2": "https://huggingface.co/distilgpt2/resolve/main/tokenizer.json",
    },
}

__UpperCAmelCase	:       Any    	=							{
    "gpt2": 1_024,
    "gpt2-medium": 1_024,
    "gpt2-large": 1_024,
    "gpt2-xl": 1_024,
    "distilgpt2": 1_024,
}







class    __snake_case	(							__lowerCamelCase      ):





       '''simple docstring'''







       lowerCAmelCase__						=					VOCAB_FILES_NAMES
       lowerCAmelCase__						=					PRETRAINED_VOCAB_FILES_MAP
       lowerCAmelCase__						=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       lowerCAmelCase__						=					["""input_ids""", """attention_mask"""]
       lowerCAmelCase__						=					GPTaTokenizer




       def __init__(  self			:   List[str]							,    A			:   int=None							,    A			:   Optional[int]=None							,    A			:   str=None							,    A			:   Optional[Any]="<|endoftext|>"							,    A			:   Union[str, Any]="<|endoftext|>"							,    A			:   Tuple="<|endoftext|>"							,    A			:   Any=False							,    **A			:   List[str]							,    ):
         super().__init__(
             A							,    A							,    tokenizer_file=A							,    unk_token=A							,    bos_token=A							,    eos_token=A							,    add_prefix_space=A							,    **A							,    )

         __snake_case:						Union[str, Any]			  =						kwargs.pop("""add_bos_token"""							,    A		)

         __snake_case:						List[Any]			  =						json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()		)
         if pre_tok_state.get("""add_prefix_space"""							,    A		) != add_prefix_space:
           __snake_case:						Tuple			  =						getattr(A							,    pre_tok_state.pop("""type"""		)		)
           __snake_case:						List[str]			  =						add_prefix_space
           __snake_case:						Dict			  =						pre_tok_class(**A		)

         __snake_case:						str			  =						add_prefix_space




       def 							UpperCAmelCase__			(  self			:   str							,    *A			:   Dict							,    **A			:   Tuple		):
         __snake_case:						str			  =						kwargs.get("""is_split_into_words"""							,    A		)
         assert self.add_prefix_space or not is_split_into_words, (
             f'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True '''
             "to use it with pretokenized inputs."
         )

         return super()._batch_encode_plus(*A							,    **A		)




       def 							UpperCAmelCase__			(  self			:   Tuple							,    *A			:   Optional[Any]							,    **A			:   str		):
         __snake_case:						Any			  =						kwargs.get("""is_split_into_words"""							,    A		)

         assert self.add_prefix_space or not is_split_into_words, (
             f'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True '''
             "to use it with pretokenized inputs."
         )

         return super()._encode_plus(*A							,    **A		)




       def 							UpperCAmelCase__			(  self			:   Optional[Any]							,    A			:   str							,    A			:   Optional[str] = None		):
         __snake_case:						Union[str, Any]			  =						self._tokenizer.model.save(A							,    name=A		)
         return tuple(A		)






       def 							UpperCAmelCase__			(  self			:   Tuple							,    A			:   "Conversation"		):
         __snake_case:						Any			  =						[]
         for is_user, text in conversation.iter_texts():
           input_ids.extend(self.encode(A							,    add_special_tokens=A		) + [self.eos_token_id]		)

         if len(A		) > self.model_max_length:
           __snake_case:						List[Any]			  =						input_ids[-self.model_max_length :]
         return input_ids













import math







def       A__							(   SCREAMING_SNAKE_CASE__)       ->   int:

  if not isinstance(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__):
    __snake_case:						Optional[int]			  =						F'''Input value of [number={number}] must be an integer'''
    raise TypeError(SCREAMING_SNAKE_CASE__)

  if number < 1:
    __snake_case:						Optional[int]			  =						F'''Input value of [number={number}] must be > 0'''
    raise ValueError(SCREAMING_SNAKE_CASE__)
  elif number == 1:
    return 3
  elif number == 2:
    return 5
  else:
    __snake_case:						List[Any]			  =						int(math.log(number // 3 , 2)) + 2

    __snake_case:						str			  =						[3, 5]
    __snake_case:						int			  =						2
    __snake_case:						List[str]			  =						3
    for block in range(1 , SCREAMING_SNAKE_CASE__):
      for _ in range(SCREAMING_SNAKE_CASE__):
        proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1])
        proth_index += 1
      increment *= 2

  return proth_list[number - 1]


if __name__ == "__main__":
      import doctest

      doctest.testmod()

      for number in range(11):
            __UpperCAmelCase	:       Optional[int]    	=							0
            try:
                  __UpperCAmelCase	:       int    	=							proth(number)
            except ValueError:
                  print(f'ValueError: there is no {number}th Proth number')
                  continue

            print(f'The {number}th Proth number: {value}')






