



"""simple docstring"""

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


a_			   =					logging.get_logger(__name__)

a_			   =					{}







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							Tuple							       =		"""llama"""
						_A		:							List[str]							       =		["""past_key_values"""]







						def __init__(self   ,		lowercase__=3_20_00   ,		lowercase__=40_96   ,		lowercase__=1_10_08   ,		lowercase__=32   ,		lowercase__=32   ,		lowercase__=None   ,		lowercase__="silu"   ,		lowercase__=20_48   ,		lowercase__=0.02   ,		lowercase__=1e-6   ,		lowercase__=True   ,		lowercase__=0   ,		lowercase__=1   ,		lowercase__=2   ,		lowercase__=1   ,		lowercase__=False   ,		lowercase__=None   ,		**lowercase__   ,		):
											snake_case_					:		Tuple 					=					vocab_size
											snake_case_					:		Dict 					=					max_position_embeddings
											snake_case_					:		List[Any] 					=					hidden_size
											snake_case_					:		List[Any] 					=					intermediate_size
											snake_case_					:		int 					=					num_hidden_layers
											snake_case_					:		Union[str, Any] 					=					num_attention_heads

											# for backward compatibility
											if num_key_value_heads is None:
																snake_case_					:		int 					=					num_attention_heads

											snake_case_					:		Tuple 					=					num_key_value_heads
											snake_case_					:		Optional[Any] 					=					hidden_act
											snake_case_					:		Any 					=					initializer_range
											snake_case_					:		Any 					=					rms_norm_eps
											snake_case_					:		Tuple 					=					pretraining_tp
											snake_case_					:		List[Any] 					=					use_cache
											snake_case_					:		str 					=					rope_scaling
											self._rope_scaling_validation()

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







						def 						__UpperCamelCase							(self       ):
											if self.rope_scaling is None:
																return

											if not isinstance(self.rope_scaling   ,		lowercase__       ) 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}'       )
											snake_case_					:		int 					=					self.rope_scaling.get("""type"""   ,		lowercase__       )
											snake_case_					:		Optional[Any] 					=					self.rope_scaling.get("""factor"""   ,		lowercase__       )
											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(lowercase__   ,		lowercase__       ) or rope_scaling_factor <= 1.0:
																raise ValueError(f'`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}'       )









"""simple docstring"""

from copy import deepcopy







class    __lowercase     :







						"""simple docstring"""







						def __init__(self   ,		lowercase__ = None   ,		lowercase__ = None       ):

											if arr is None and size is not None:
																snake_case_					:		str 					=					size
																snake_case_					:		Optional[Any] 					=					[0] * size
											elif arr is not None:
																self.init(lowercase__       )
											else:
																raise ValueError("""Either arr or size must be specified"""       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											snake_case_					:		Optional[Any] 					=					len(lowercase__       )
											snake_case_					:		int 					=					deepcopy(lowercase__       )
											for i in range(1   ,		self.size       ):
																snake_case_					:		Optional[Any] 					=					self.next_(lowercase__       )
																if j < self.size:
																					self.tree[j] += self.tree[i]







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Dict 					=					self.tree[:]
											for i in range(self.size - 1   ,		0   ,		-1       ):
																snake_case_					:		Optional[int] 					=					self.next_(lowercase__       )
																if j < self.size:
																					arr[j] -= arr[i]
											return arr







						@staticmethod
						def 						__UpperCamelCase							(lowercase__       ):
											return index + (index & (-index))







						@staticmethod
						def 						__UpperCamelCase							(lowercase__       ):
											return index - (index & (-index))







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											if index == 0:
																self.tree[0] += value
																return
											while index < self.size:
																self.tree[index] += value
																snake_case_					:		Tuple 					=					self.next_(lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											self.add(lowercase__   ,		value - self.get(lowercase__       )       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											if right == 0:
																return 0
											snake_case_					:		List[str] 					=					self.tree[0]
											right -= 1  # make right inclusive
											while right > 0:
																result += self.tree[right]
																snake_case_					:		Optional[int] 					=					self.prev(lowercase__       )
											return result







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											return self.prefix(lowercase__       ) - self.prefix(lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											return self.query(lowercase__   ,		index + 1       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											value -= self.tree[0]
											if value < 0:
																return -1

											snake_case_					:		Tuple 					=					1  # Largest power of 2 <= size
											while j * 2 < self.size:
																j *= 2

											snake_case_					:		Tuple 					=					0

											while j > 0:
																if i + j < self.size and self.tree[i + j] <= value:
																					value -= self.tree[i + j]
																					i += j
																j //= 2
											return i


if __name__ == "__main__":
			import doctest

			doctest.testmod()




