





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


UpperCamelCase__           =			logging.get_logger(__name__)

UpperCamelCase__           =			{
    "tiiuae/falcon-40b": "https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json",
    "tiiuae/falcon-7b": "https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json",
}

class 							__SCREAMING_SNAKE_CASE       (  _a							):
							snake_case  :   List[Any]      =							"""falcon"""
							snake_case  :   str      =							["""past_key_values"""]






							def __init__(    self	,			__lowerCAmelCase=65024	,			__lowerCAmelCase=4544	,			__lowerCAmelCase=32	,			__lowerCAmelCase=71	,			__lowerCAmelCase=1E-5	,			__lowerCAmelCase=0.02	,			__lowerCAmelCase=True	,			__lowerCAmelCase=0.0	,			__lowerCAmelCase=0.0	,			__lowerCAmelCase=None	,			__lowerCAmelCase=False	,			__lowerCAmelCase=False	,			__lowerCAmelCase=True	,			__lowerCAmelCase=True	,			__lowerCAmelCase=False	,			__lowerCAmelCase=11	,			__lowerCAmelCase=11	,			**__lowerCAmelCase	,			):
														UpperCamelCase__					  =      vocab_size
														# Backward compatibility with n_embed kwarg
														UpperCamelCase__					  =      kwargs.pop("""n_embed"""	,			__lowerCAmelCase	)
														UpperCamelCase__					  =      hidden_size if n_embed is None else n_embed
														UpperCamelCase__					  =      num_hidden_layers
														UpperCamelCase__					  =      num_attention_heads
														UpperCamelCase__					  =      layer_norm_epsilon
														UpperCamelCase__					  =      initializer_range
														UpperCamelCase__					  =      use_cache
														UpperCamelCase__					  =      hidden_dropout
														UpperCamelCase__					  =      attention_dropout

														UpperCamelCase__					  =      bos_token_id
														UpperCamelCase__					  =      eos_token_id
														UpperCamelCase__					  =      num_attention_heads if num_kv_heads is None else num_kv_heads
														UpperCamelCase__					  =      alibi
														UpperCamelCase__					  =      new_decoder_architecture
														UpperCamelCase__					  =      multi_query  # Ignored when new_decoder_architecture is True
														UpperCamelCase__					  =      parallel_attn
														UpperCamelCase__					  =      bias

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






							@property
							def 					_lowerCamelCase		(    self	):
														return self.hidden_size // self.num_attention_heads







							@property
							def 					_lowerCamelCase		(    self	):
														return not self.alibi











import copy
import random

from transformers import CLIPTokenizer

class 							__SCREAMING_SNAKE_CASE       (  _a							):






							def __init__(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														super().__init__(*__lowerCAmelCase	,			**__lowerCAmelCase	)
														UpperCamelCase__					  =      {}






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														UpperCamelCase__					  =      super().add_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
														if num_added_tokens == 0:
																					raise ValueError(
																					    f"""The tokenizer already contains the token {placeholder_token}. Please pass a different"""
																					    """ `placeholder_token` that is not already in the tokenizer."""	)






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=1	,			**__lowerCAmelCase	):
														UpperCamelCase__					  =      []
														if num_vec_per_token == 1:
																					self.try_adding_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
																					output.append(__lowerCAmelCase	)
														else:
																					UpperCamelCase__					  =      []
																					for i in range(__lowerCAmelCase	):
																												UpperCamelCase__					  =      placeholder_token + f"""_{i}"""
																												self.try_adding_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
																												output.append(__lowerCAmelCase	)
        # handle cases where there is a new placeholder token that contains the current placeholder token but is larger
														for token in self.token_map:
																					if token in placeholder_token:
																												raise ValueError(
																												    f"""The tokenizer already has placeholder token {token} that can get confused with"""
																												    f""" {placeholder_token}keep placeholder tokens independent"""	)
														UpperCamelCase__					  =      output






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	):
														if isinstance(__lowerCAmelCase	,			__lowerCAmelCase	):
																					UpperCamelCase__					  =      []
																					for i in range(len(__lowerCAmelCase	)	):
																												output.append(self.replace_placeholder_tokens_in_text(text[i]	,			vector_shuffle=__lowerCAmelCase	)	)
																					return output
														for placeholder_token in self.token_map:
																					if placeholder_token in text:
																												UpperCamelCase__					  =      self.token_map[placeholder_token]
																												UpperCamelCase__					  =      tokens[: 1 + int(len(__lowerCAmelCase	) * prop_tokens_to_load	)]
																												if vector_shuffle:
																																			UpperCamelCase__					  =      copy.copy(__lowerCAmelCase	)
																																			random.shuffle(__lowerCAmelCase	)
																												UpperCamelCase__					  =      text.replace(__lowerCAmelCase	,			""" """.join(__lowerCAmelCase	)	)
														return text






							def __call__(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	,			**__lowerCAmelCase	):
														return super().__call__(
														    self.replace_placeholder_tokens_in_text(
														        __lowerCAmelCase	,			vector_shuffle=__lowerCAmelCase	,			prop_tokens_to_load=__lowerCAmelCase	)	,			*__lowerCAmelCase	,			**__lowerCAmelCase	,			)







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	,			**__lowerCAmelCase	):
														return super().encode(
														    self.replace_placeholder_tokens_in_text(
														        __lowerCAmelCase	,			vector_shuffle=__lowerCAmelCase	,			prop_tokens_to_load=__lowerCAmelCase	)	,			*__lowerCAmelCase	,			**__lowerCAmelCase	,			)




