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


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

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





class 					lowercase__						(   __A):
						UpperCamelCase_     =		"open-llama"


						def __init__(       self	:				Tuple    ,		UpperCamelCase__	:				str=10_0000    ,		UpperCamelCase__	:				Any=4096    ,		UpperCamelCase__	:				Dict=1_1008    ,		UpperCamelCase__	:				Union[str, Any]=32    ,		UpperCamelCase__	:				int=32    ,		UpperCamelCase__	:				Tuple="silu"    ,		UpperCamelCase__	:				Any=2048    ,		UpperCamelCase__	:				int=0.02    ,		UpperCamelCase__	:				Any=1E-6    ,		UpperCamelCase__	:				int=True    ,		UpperCamelCase__	:				Optional[Any]=0    ,		UpperCamelCase__	:				Optional[Any]=1    ,		UpperCamelCase__	:				Any=2    ,		UpperCamelCase__	:				Any=False    ,		UpperCamelCase__	:				int=True    ,		UpperCamelCase__	:				Union[str, Any]=0.1    ,		UpperCamelCase__	:				Optional[int]=0.1    ,		UpperCamelCase__	:				Optional[int]=True    ,		UpperCamelCase__	:				Union[str, Any]=True    ,		UpperCamelCase__	:				Any=None    ,		**UpperCamelCase__	:				Any    ,		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Tuple							=							vocab_size
												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							max_position_embeddings
												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							hidden_size
												SCREAMING_SNAKE_CASE							:    Any							=							intermediate_size
												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							num_hidden_layers
												SCREAMING_SNAKE_CASE							:    Dict							=							num_attention_heads
												SCREAMING_SNAKE_CASE							:    List[str]							=							hidden_act
												SCREAMING_SNAKE_CASE							:    Any							=							initializer_range
												SCREAMING_SNAKE_CASE							:    List[Any]							=							rms_norm_eps
												SCREAMING_SNAKE_CASE							:    Optional[int]							=							use_cache
												SCREAMING_SNAKE_CASE							:    Tuple							=							kwargs.pop(
												    '''use_memorry_efficient_attention'''    ,		lowercase_						)
												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							hidden_dropout_prob
												SCREAMING_SNAKE_CASE							:    str							=							attention_dropout_prob
												SCREAMING_SNAKE_CASE							:    Tuple							=							use_stable_embedding
												SCREAMING_SNAKE_CASE							:    Dict							=							shared_input_output_embedding
												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							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        __A       (       self	:				Dict						):





												'''simple docstring'''





												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}"""						)
												SCREAMING_SNAKE_CASE							:    Any							=							self.rope_scaling.get('''type'''    ,		lowercase_						)
												SCREAMING_SNAKE_CASE							:    Tuple							=							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}"""						)






import time
import warnings
from abc import ABC
from copy import deepcopy
from typing import Optional

import torch

from ..utils import add_start_docstrings, logging


UpperCamelCase  							=						logging.get_logger(__name__)


UpperCamelCase  							=						R'''
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        scores (`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`):
            Prediction scores of a language modeling head. These can be scores for each vocabulary token before SoftMax
            or scores for each vocabulary token after SoftMax.
        kwargs (`Dict[str, Any]`, *optional*):
            Additional stopping criteria specific kwargs.

    Return:
        `bool`. `False` indicates we should continue, `True` indicates we should stop.

'''



class   snake_case_       (		__A       ):






   @add_start_docstrings(lowercase_  )
   def __call__(      self				:     Optional[Any]	,						lowercase_				:     torch.LongTensor	,						lowercase_				:     torch.FloatTensor	,						**lowercase_				:     List[str]  )					->						bool:
       raise NotImplementedError("StoppingCriteria needs to be subclassed"  )



class   snake_case_       (		__A       ):






   def __init__(      self				:     Dict	,						lowercase_				:     int	,						lowercase_				:     Optional[int] = None  )					->						List[str]:
       lowercase__ :   str    					=				max_length
       lowercase__ :   Optional[int]    					=				max_position_embeddings







   @add_start_docstrings(lowercase_  )
   def __call__(      self				:     Tuple	,						lowercase_				:     torch.LongTensor	,						lowercase_				:     torch.FloatTensor	,						**lowercase_				:     Union[str, Any]  )					->						bool:
       lowercase__ :   str    					=				input_ids.shape[-1]
       lowercase__ :   Any    					=				cur_len >= self.max_length
       if self.max_position_embeddings is not None and not is_done and cur_len >= self.max_position_embeddings:
           logger.warning_once(
               "This is a friendly reminder - the current text generation call will exceed the model's predefined "
               F'''maximum length ({self.max_position_embeddings}). Depending on the model, you may observe '''
               "exceptions, performance degradation, or nothing at all."  )
       return is_done



class   snake_case_       (		__A       ):






   def __init__(      self				:     Tuple	,						lowercase_				:     int	,						lowercase_				:     int  )					->						List[str]:
       warnings.warn(
           "The class `MaxNewTokensCriteria` is deprecated. "
           F'''Please use `MaxLengthCriteria(max_length={start_length + max_new_tokens})` '''
           "with `max_length = start_length + max_new_tokens` instead."	,						lowercase_	,						)
       lowercase__ :   Optional[int]    					=				start_length
       lowercase__ :   str    					=				max_new_tokens
       lowercase__ :   Tuple    					=				start_length + max_new_tokens







   @add_start_docstrings(lowercase_  )
   def __call__(      self				:     List[Any]	,						lowercase_				:     torch.LongTensor	,						lowercase_				:     torch.FloatTensor	,						**lowercase_				:     Dict  )					->						bool:
       return input_ids.shape[-1] >= self.max_length



class   snake_case_       (		__A       ):






   def __init__(      self				:     Tuple	,						lowercase_				:     float	,						lowercase_				:     Optional[float] = None  )					->						Dict:
       lowercase__ :   List[str]    					=				max_time
       lowercase__ :   Tuple    					=				time.time() if initial_timestamp is None else initial_timestamp







   @add_start_docstrings(lowercase_  )
   def __call__(      self				:     int	,						lowercase_				:     torch.LongTensor	,						lowercase_				:     torch.FloatTensor	,						**lowercase_				:     Union[str, Any]  )					->						bool:
       return time.time() - self.initial_timestamp > self.max_time



class   snake_case_       (		__A       ):






   @add_start_docstrings(lowercase_  )
   def __call__(      self				:     str	,						lowercase_				:     torch.LongTensor	,						lowercase_				:     torch.FloatTensor	,						**lowercase_				:     List[str]  )					->						bool:
       return any(criteria(lowercase_	,						lowercase_  ) for criteria in self  )







   @property
   def       __UpperCamelCase     (      self				:     Optional[Any]  )					->						Optional[int]:
       for stopping_criterium in self:
           if isinstance(lowercase_	,						lowercase_  ):
               return stopping_criterium.max_length
           elif isinstance(lowercase_	,						lowercase_  ):
               return stopping_criterium.max_length
       return None



def 			lowercase_				(			_lowerCamelCase							:       StoppingCriteriaList		,	_lowerCamelCase							:       int):
    lowercase__ :   Optional[int]    					=				stopping_criteria.max_length
    lowercase__ :   str    					=				deepcopy(_lowerCamelCase)
    if stopping_max_length is not None and stopping_max_length != max_length:
        warnings.warn("You set different `max_length` for stopping criteria and `max_length` parameter"		,	_lowerCamelCase)
    elif stopping_max_length is None:
        new_stopping_criteria.append(MaxLengthCriteria(max_length=_lowerCamelCase))
    return new_stopping_criteria



