





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


lowerCAmelCase_        =							logging.get_logger(__name__)

lowerCAmelCase_        =							{
    '''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    __lowerCAmelCase			(     _a	):
			lowerCamelCase_	:	List[Any]			     = '''falcon'''
			lowerCamelCase_	:	Any			     = ['''past_key_values''']






			def __init__(self   ,				__magic_name__=6_5024   ,				__magic_name__=4544   ,				__magic_name__=32   ,				__magic_name__=71   ,				__magic_name__=1e-5   ,				__magic_name__=0.02   ,				__magic_name__=True   ,				__magic_name__=0.0   ,				__magic_name__=0.0   ,				__magic_name__=None   ,				__magic_name__=False   ,				__magic_name__=False   ,				__magic_name__=True   ,				__magic_name__=True   ,				__magic_name__=False   ,				__magic_name__=11   ,				__magic_name__=11   ,				**__magic_name__   ,				)	->  Optional[int]:


							'''simple docstring'''



							snake_case_		:       Optional[Any]           =    vocab_size
							# Backward compatibility with n_embed kwarg
							snake_case_		:       Dict           =    kwargs.pop('''n_embed'''   ,				__magic_name__       )
							snake_case_		:       Optional[int]           =    hidden_size if n_embed is None else n_embed
							snake_case_		:       List[str]           =    num_hidden_layers
							snake_case_		:       List[str]           =    num_attention_heads
							snake_case_		:       Optional[Any]           =    layer_norm_epsilon
							snake_case_		:       List[str]           =    initializer_range
							snake_case_		:       List[str]           =    use_cache
							snake_case_		:       Optional[int]           =    hidden_dropout
							snake_case_		:       List[Any]           =    attention_dropout

							snake_case_		:       Any           =    bos_token_id
							snake_case_		:       Dict           =    eos_token_id
							snake_case_		:       Optional[Any]           =    num_attention_heads if num_kv_heads is None else num_kv_heads
							snake_case_		:       Optional[Any]           =    alibi
							snake_case_		:       Optional[int]           =    new_decoder_architecture
							snake_case_		:       str           =    multi_query  # Ignored when new_decoder_architecture is True
							snake_case_		:       List[str]           =    parallel_attn
							snake_case_		:       List[str]           =    bias

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






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


							'''simple docstring'''



							return self.hidden_size // self.num_attention_heads






			@property
			def      lowerCamelCase    (self       )	->  List[Any]:


							'''simple docstring'''



							return not self.alibi






import numpy as np
from numpy import ndarray
from scipy.optimize import Bounds, LinearConstraint, minimize


def 					_a							(					lowerCAmelCase )->	float:
		return np.dot(lowerCAmelCase    ,						lowerCAmelCase )



class    lowercase_		:



						def __init__(			self	:   int					,							*,
						    snake_case__	:   float = np.inf					,							snake_case__	:   str = "linear"					,							snake_case__	:   float = 0.0					,							):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_					      =							regularization
								SCREAMING_SNAKE_CASE_					      =							gamma
								if kernel == "linear":
										SCREAMING_SNAKE_CASE_					      =							self.__linear
								elif kernel == "rbf":
										if self.gamma == 0:
												raise ValueError('rbf kernel requires gamma'  )
										if not isinstance(self.gamma					,							(float, int)  ):
												raise ValueError('gamma must be float or int'  )
										if not self.gamma > 0:
												raise ValueError('gamma must be > 0'  )
										SCREAMING_SNAKE_CASE_					      =							self.__rbf
										# in the future, there could be a default value like in sklearn
										# sklear: def_gamma = 1/(n_features * X.var()) (wiki)
										# previously it was 1/(n_features)
								else:
										SCREAMING_SNAKE_CASE_					      =							f'''Unknown kernel: {kernel}'''
										raise ValueError(snake_case__  )



						def 	__a					(			self	:   Tuple					,							snake_case__	:   ndarray					,							snake_case__	:   ndarray  ):

								"""simple docstring"""

								return np.dot(snake_case__					,							snake_case__  )



						def 	__a					(			self	:   int					,							snake_case__	:   ndarray					,							snake_case__	:   ndarray  ):

								"""simple docstring"""

								return np.exp(-(self.gamma * norm_squared(vectora - vectora  ))  )



						def 	__a					(			self	:   int					,							snake_case__	:   list[ndarray]					,							snake_case__	:   ndarray  ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_					      =							observations
								SCREAMING_SNAKE_CASE_					      =							classes

								# using Wolfe's Dual to calculate w.
								# Primal problem: minimize 1/2*norm_squared(w)
								#   constraint: yn(w . xn + b) >= 1
								#
								# With l a vector
								# Dual problem: maximize sum_n(ln) -
								#       1/2 * sum_n(sum_m(ln*lm*yn*ym*xn . xm))
								#   constraint: self.C >= ln >= 0
								#           and sum_n(ln*yn) = 0
								# Then we get w using w = sum_n(ln*yn*xn)
								# At the end we can get b ~= mean(yn - w . xn)
								#
								# Since we use kernels, we only need l_star to calculate b
								# and to classify observations

								((SCREAMING_SNAKE_CASE_)      ,				)					      =							np.shape(snake_case__  )

								def to_minimize(snake_case__	:   ndarray  ) -> float:
										SCREAMING_SNAKE_CASE_					      =							0
										((SCREAMING_SNAKE_CASE_)      ,				)					      =							np.shape(snake_case__  )
										for i in range(snake_case__  ):
												for j in range(snake_case__  ):
														s += (
														    candidate[i]
														    * candidate[j]
														    * classes[i]
														    * classes[j]
														    * self.kernel(observations[i]					,							observations[j]  )
														)
										return 1 / 2 * s - sum(snake_case__  )

								SCREAMING_SNAKE_CASE_					      =							LinearConstraint(snake_case__					,							0					,							0  )
								SCREAMING_SNAKE_CASE_					      =							Bounds(0					,							self.regularization  )

								SCREAMING_SNAKE_CASE_					      =							minimize(
								    snake_case__					,							np.ones(snake_case__  )					,							bounds=snake_case__					,							constraints=[ly_contraint]  ).x
								SCREAMING_SNAKE_CASE_					      =							l_star

								# calculating mean offset of separation plane to points
								SCREAMING_SNAKE_CASE_					      =							0
								for i in range(snake_case__  ):
										for j in range(snake_case__  ):
												s += classes[i] - classes[i] * self.optimum[i] * self.kernel(
												    observations[i]					,							observations[j]  )
								SCREAMING_SNAKE_CASE_					      =							s / n






						def 	__a					(			self	:   Any					,							snake_case__	:   ndarray  ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_					      =							sum(
								    self.optimum[n]
								    * self.classes[n]
								    * self.kernel(self.observations[n]					,							snake_case__  )
								    for n in range(len(self.classes  )  )  )
								return 1 if s + self.offset >= 0 else -1


if __name__ == "__main__":
						import doctest

						doctest.testmod()