from collections.abc import Sequence
from queue import Queue
class 					snake_case	:

   """simple docstring"""







   def __init__(    self					,	lowerCAmelCase_					,	lowerCAmelCase_					,	lowerCAmelCase_					,	lowerCAmelCase_=None					,	lowerCAmelCase_=None	):
     __lowercase					=		start
     __lowercase					=		end
     __lowercase					=		val
     __lowercase					=		(start + end) // 2
     __lowercase					=		left
     __lowercase					=		right





   def __repr__(    self	):
     return f'''SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})'''







class 					snake_case	:

   """simple docstring"""







   def __init__(    self					,	lowerCAmelCase_					,	lowerCAmelCase_	):
     __lowercase					=		collection
     __lowercase					=		function
     if self.collection:
       __lowercase					=		self._build_tree(0					,	len(lowerCAmelCase_	) - 1	)





   def 				snake_case__							(    self					,	lowerCAmelCase_					,	lowerCAmelCase_	):
     self._update_tree(self.root					,	lowerCAmelCase_					,	lowerCAmelCase_	)





   def 				snake_case__							(    self					,	lowerCAmelCase_					,	lowerCAmelCase_	):
     return self._query_range(self.root					,	lowerCAmelCase_					,	lowerCAmelCase_	)





   def 				snake_case__							(    self					,	lowerCAmelCase_					,	lowerCAmelCase_	):






     if start == end:
       return SegmentTreeNode(lowerCAmelCase_					,	lowerCAmelCase_					,	self.collection[start]	)
     __lowercase					=		(start + end) // 2
     __lowercase					=		self._build_tree(lowerCAmelCase_					,	lowerCAmelCase_	)
     __lowercase					=		self._build_tree(mid + 1					,	lowerCAmelCase_	)
     return SegmentTreeNode(lowerCAmelCase_					,	lowerCAmelCase_					,	self.fn(left.val					,	right.val	)					,	lowerCAmelCase_					,	lowerCAmelCase_	)





   def 				snake_case__							(    self					,	lowerCAmelCase_					,	lowerCAmelCase_					,	lowerCAmelCase_	):






     if node.start == i and node.end == i:
       __lowercase					=		val
       return
     if i <= node.mid:
       self._update_tree(node.left					,	lowerCAmelCase_					,	lowerCAmelCase_	)
     else:
       self._update_tree(node.right					,	lowerCAmelCase_					,	lowerCAmelCase_	)
     __lowercase					=		self.fn(node.left.val					,	node.right.val	)





   def 				snake_case__							(    self					,	lowerCAmelCase_					,	lowerCAmelCase_					,	lowerCAmelCase_	):






     if node.start == i and node.end == j:
       return node.val

     if i <= node.mid:
       if j <= node.mid:
         # range in left child tree
         return self._query_range(node.left					,	lowerCAmelCase_					,	lowerCAmelCase_	)
       else:
         # range in left child tree and right child tree
         return self.fn(
             self._query_range(node.left					,	lowerCAmelCase_					,	node.mid	)					,	self._query_range(node.right					,	node.mid + 1					,	lowerCAmelCase_	)					,	)
     else:
       # range in right child tree
       return self._query_range(node.right					,	lowerCAmelCase_					,	lowerCAmelCase_	)





   def 				snake_case__							(    self	):






     if self.root is not None:
       __lowercase					=		Queue()
       queue.put(self.root	)
       while not queue.empty():
         __lowercase					=		queue.get()
         yield node

         if node.left is not None:
           queue.put(node.left	)

         if node.right is not None:
           queue.put(node.right	)


if __name__ == "__main__":
     import operator

     for fn in [operator.add, max, min]:
          print('*' * 50)
          lowerCAmelCase__	   =						SegmentTree([2, 1, 5, 3, 4], fn)
          for node in arr.traverse():
               print(node)
          print()

          arr.update(1, 5)
          for node in arr.traverse():
               print(node)
          print()

          print(arr.query_range(3, 4))  # 7
          print(arr.query_range(2, 2))  # 5
          print(arr.query_range(1, 3))  # 13
          print()





"""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}"""   )