


"""simple docstring"""



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


lowercase_							=							logging.get_logger(__name__)

lowercase_							=							{'vocab_file': 'vocab.json', 'merges_file': 'merges.txt', 'tokenizer_file': 'tokenizer.json'}

lowercase_							=							{
    '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',
    },
}

lowercase_							=							{
    'gpt2': 10_24,
    'gpt2-medium': 10_24,
    'gpt2-large': 10_24,
    'gpt2-xl': 10_24,
    'distilgpt2': 10_24,
}







class    __a						( __snake_case							):
				lowerCamelCase     :       Tuple			       =VOCAB_FILES_NAMES
				lowerCamelCase     :       Optional[Any]			       =PRETRAINED_VOCAB_FILES_MAP
				lowerCamelCase     :       Any			       =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowerCamelCase     :       Union[str, Any]			       =['input_ids', 'attention_mask']
				lowerCamelCase     :       List[str]			       =GPTaTokenizer







				def __init__( self      ,	UpperCAmelCase=None      ,	UpperCAmelCase=None      ,	UpperCAmelCase=None      ,	UpperCAmelCase="<|endoftext|>"      ,	UpperCAmelCase="<|endoftext|>"      ,	UpperCAmelCase="<|endoftext|>"      ,	UpperCAmelCase=False      ,	**UpperCAmelCase      ,	):

					'''simple docstring'''






					super().__init__(
					    UpperCAmelCase      ,	UpperCAmelCase      ,	tokenizer_file=UpperCAmelCase      ,	unk_token=UpperCAmelCase      ,	bos_token=UpperCAmelCase      ,	eos_token=UpperCAmelCase      ,	add_prefix_space=UpperCAmelCase      ,	**UpperCAmelCase      ,	)

					lowerCAmelCase_      							=			kwargs.pop('''add_bos_token'''      ,	UpperCAmelCase   )

					lowerCAmelCase_      							=			json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()   )
					if pre_tok_state.get('''add_prefix_space'''      ,	UpperCAmelCase   ) != add_prefix_space:
						lowerCAmelCase_      							=			getattr(UpperCAmelCase      ,	pre_tok_state.pop('''type'''   )   )
						lowerCAmelCase_      							=			add_prefix_space
						lowerCAmelCase_      							=			pre_tok_class(**UpperCAmelCase   )

					lowerCAmelCase_      							=			add_prefix_space







				def      lowerCamelCase_     ( self      ,	*UpperCAmelCase      ,	**UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			kwargs.get('''is_split_into_words'''      ,	UpperCAmelCase   )
					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(*UpperCAmelCase      ,	**UpperCAmelCase   )







				def      lowerCamelCase_     ( self      ,	*UpperCAmelCase      ,	**UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			kwargs.get('''is_split_into_words'''      ,	UpperCAmelCase   )

					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(*UpperCAmelCase      ,	**UpperCAmelCase   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase = None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self._tokenizer.model.save(UpperCAmelCase      ,	name=UpperCAmelCase   )
					return tuple(UpperCAmelCase   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			[]
					for is_user, text in conversation.iter_texts():
						input_ids.extend(self.encode(UpperCAmelCase      ,	add_special_tokens=UpperCAmelCase   ) + [self.eos_token_id]   )

					if len(UpperCAmelCase   ) > self.model_max_length:
						lowerCAmelCase_      							=			input_ids[-self.model_max_length :]
					return input_ids



"""simple docstring"""



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


lowercase_							=							logging.get_logger(__name__)

lowercase_							=							{
    's-JoL/Open-Llama-V1': 'https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json',
}







class    __a						( __snake_case							):
				lowerCamelCase     :       Union[str, Any]			       ='open-llama'







				def __init__( self      ,	UpperCAmelCase=10_0000      ,	UpperCAmelCase=4096      ,	UpperCAmelCase=1_1008      ,	UpperCAmelCase=32      ,	UpperCAmelCase=32      ,	UpperCAmelCase="silu"      ,	UpperCAmelCase=2048      ,	UpperCAmelCase=0.0_2      ,	UpperCAmelCase=1E-6      ,	UpperCAmelCase=True      ,	UpperCAmelCase=0      ,	UpperCAmelCase=1      ,	UpperCAmelCase=2      ,	UpperCAmelCase=False      ,	UpperCAmelCase=True      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=True      ,	UpperCAmelCase=True      ,	UpperCAmelCase=None      ,	**UpperCAmelCase      ,	):

					'''simple docstring'''






					lowerCAmelCase_      							=			vocab_size
					lowerCAmelCase_      							=			max_position_embeddings
					lowerCAmelCase_      							=			hidden_size
					lowerCAmelCase_      							=			intermediate_size
					lowerCAmelCase_      							=			num_hidden_layers
					lowerCAmelCase_      							=			num_attention_heads
					lowerCAmelCase_      							=			hidden_act
					lowerCAmelCase_      							=			initializer_range
					lowerCAmelCase_      							=			rms_norm_eps
					lowerCAmelCase_      							=			use_cache
					lowerCAmelCase_      							=			kwargs.pop(
					    '''use_memorry_efficient_attention'''      ,	UpperCAmelCase   )
					lowerCAmelCase_      							=			hidden_dropout_prob
					lowerCAmelCase_      							=			attention_dropout_prob
					lowerCAmelCase_      							=			use_stable_embedding
					lowerCAmelCase_      							=			shared_input_output_embedding
					lowerCAmelCase_      							=			rope_scaling
					self._rope_scaling_validation()

					super().__init__(
					    pad_token_id=UpperCAmelCase      ,	bos_token_id=UpperCAmelCase      ,	eos_token_id=UpperCAmelCase      ,	tie_word_embeddings=UpperCAmelCase      ,	**UpperCAmelCase      ,	)







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					if self.rope_scaling is None:
						return

					if not isinstance(self.rope_scaling      ,	UpperCAmelCase   ) or len(self.rope_scaling   ) != 2:
						raise ValueError(
						    '''`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '''
						    F"""got {self.rope_scaling}"""   )
					lowerCAmelCase_      							=			self.rope_scaling.get('''type'''      ,	UpperCAmelCase   )
					lowerCAmelCase_      							=			self.rope_scaling.get('''factor'''      ,	UpperCAmelCase   )
					if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
						raise ValueError(
						    F"""`rope_scaling`'s name field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"""   )
					if rope_scaling_factor is None or not isinstance(UpperCAmelCase      ,	UpperCAmelCase   ) or rope_scaling_factor <= 1.0:
						raise ValueError(F"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""   )