





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


_snake_case  :   Union[str, Any]						   =  logging.get_logger(__name__)

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



class     _UpperCAmelCase   (   A_   ):

  """simple docstring"""


  a_      =			"open-llama"






  def __init__(    self			:		List[str] ,  lowerCAmelCase_			:		Tuple=1_0_0_0_0_0 ,  lowerCAmelCase_			:		Dict=4_0_9_6 ,  lowerCAmelCase_			:		str=1_1_0_0_8 ,  lowerCAmelCase_			:		int=3_2 ,  lowerCAmelCase_			:		Union[str, Any]=3_2 ,  lowerCAmelCase_			:		str="silu" ,  lowerCAmelCase_			:		str=2_0_4_8 ,  lowerCAmelCase_			:		List[str]=0.02 ,  lowerCAmelCase_			:		Any=1e-6 ,  lowerCAmelCase_			:		Dict=True ,  lowerCAmelCase_			:		Union[str, Any]=0 ,  lowerCAmelCase_			:		Dict=1 ,  lowerCAmelCase_			:		List[str]=2 ,  lowerCAmelCase_			:		Optional[Any]=False ,  lowerCAmelCase_			:		List[Any]=True ,  lowerCAmelCase_			:		str=0.1 ,  lowerCAmelCase_			:		Optional[int]=0.1 ,  lowerCAmelCase_			:		int=True ,  lowerCAmelCase_			:		str=True ,  lowerCAmelCase_			:		Optional[Any]=None ,  **lowerCAmelCase_			:		Any ,  )							->						Dict:
     __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' ,  snake_case__					)
     __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=snake_case__ ,  bos_token_id=snake_case__ ,  eos_token_id=snake_case__ ,  tie_word_embeddings=snake_case__ ,  **snake_case__ ,  )






  def     lowercase		(    self			:		Union[str, Any]					)							->						Union[str, Any]:


     if self.rope_scaling is None:
        return

     if not isinstance(self.rope_scaling ,  snake_case__					) 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' ,  snake_case__					)
     __lowerCAmelCase							     =     self.rope_scaling.get('factor' ,  snake_case__					)
     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(snake_case__ ,  snake_case__					) or rope_scaling_factor <= 1.0:
        raise ValueError(f"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""					)








import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


_snake_case  :   Union[str, Any]						   =  False
try:
     _snake_case  :   Tuple						   =  _is_package_available('google.colab')
except ModuleNotFoundError:
     pass



@input.register
class     _UpperCAmelCase   :

  """simple docstring"""


  def __init__(    self			:		Union[str, Any] ,  lowerCAmelCase_			:		str = None ,  lowerCAmelCase_			:		list = []					)							->						Optional[int]:
     __lowerCAmelCase							     =     0
     __lowerCAmelCase							     =     choices
     __lowerCAmelCase							     =     prompt
     if sys.platform == "win32":
        __lowerCAmelCase							     =     '*'
     else:
        __lowerCAmelCase							     =     '➔ '






  def     lowercase		(    self			:		Dict ,  lowerCAmelCase_			:		Dict ,  lowerCAmelCase_			:		str = ""					)							->						Any:
     if sys.platform != "win32":
        writeColor(self.choices[index] ,  3_2 ,  lowerCAmelCase_					)
     else:
        forceWrite(self.choices[index] ,  lowerCAmelCase_					)






  def     lowercase		(    self			:		List[Any] ,  lowerCAmelCase_			:		int					)							->						List[Any]:
     if index == self.position:
        forceWrite(f""" {self.arrow_char} """					)
        self.write_choice(lowerCAmelCase_					)
     else:
        forceWrite(f"""    {self.choices[index]}"""					)
     reset_cursor()






  def     lowercase		(    self			:		Dict ,  lowerCAmelCase_			:		Direction ,  lowerCAmelCase_			:		int = 1					)							->						Union[str, Any]:
     __lowerCAmelCase							     =     self.position
     if direction == Direction.DOWN:
        if self.position + 1 >= len(self.choices					):
           return
        self.position += num_spaces
     else:
        if self.position - 1 < 0:
           return
        self.position -= num_spaces
     clear_line()
     self.print_choice(lowerCAmelCase_					)
     move_cursor(lowerCAmelCase_ ,  direction.name					)
     self.print_choice(self.position					)






  @input.mark(KEYMAP['up']					)
  def     lowercase		(    self			:		Optional[int]					)							->						Tuple:
     self.move_direction(Direction.UP					)






  @input.mark(KEYMAP['down']					)
  def     lowercase		(    self			:		str					)							->						Optional[Any]:
     self.move_direction(Direction.DOWN					)






  @input.mark(KEYMAP['newline']					)
  def     lowercase		(    self			:		str					)							->						Any:
     move_cursor(len(self.choices					) - self.position ,  'DOWN'					)
     return self.position






  @input.mark(KEYMAP['interrupt']					)
  def     lowercase		(    self			:		Dict					)							->						Optional[Any]:
     move_cursor(len(self.choices					) - self.position ,  'DOWN'					)
     raise KeyboardInterrupt






  @input.mark_multiple(*[KEYMAP[str(lowerCAmelCase_					)] for number in range(1_0					)]					)
  def     lowercase		(    self			:		List[Any]					)							->						Optional[int]:
     __lowerCAmelCase							     =     int(chr(self.current_selection					)					)
     __lowerCAmelCase							     =     index - self.position
     if index == self.position:
        return
     if index < len(self.choices					):
        if self.position > index:
           self.move_direction(Direction.UP ,  -movement					)
        elif self.position < index:
           self.move_direction(Direction.DOWN ,  lowerCAmelCase_					)
        else:
           return
     else:
        return






  def     lowercase		(    self			:		Any ,  lowerCAmelCase_			:		int = 0					)							->						int:
     if self.prompt:
        linebreak()
        forceWrite(self.prompt ,  '\n'					)
        if in_colab:
           forceWrite('Please input a choice index (starting from 0), and press enter' ,  '\n'					)
        else:
           forceWrite('Please select a choice using the arrow or number keys, and selecting with enter' ,  '\n'					)
     __lowerCAmelCase							     =     default_choice
     for i in range(len(self.choices					)					):
        self.print_choice(lowerCAmelCase_					)
        forceWrite('\n'					)
     move_cursor(len(self.choices					) - self.position ,  'UP'					)
     with cursor.hide():
        while True:
           if in_colab:
              try:
                 __lowerCAmelCase							     =     int(builtins.input()					)
              except ValueError:
                 __lowerCAmelCase							     =     default_choice
           else:
              __lowerCAmelCase							     =     self.handle_input()
           if choice is not None:
              reset_cursor()
              for _ in range(len(self.choices					) + 1					):
                 move_cursor(1 ,  'UP'					)
                 clear_line()
              self.write_choice(lowerCAmelCase_ ,  '\n'					)
              return choice

