


"""simple docstring"""






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


_lowerCAmelCase							:    List[str]					   =	logging.get_logger(__name__)

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




class 							A_      (       _a ):
  lowerCAmelCase__      			=	'open-llama'


  def __init__(			self:						List[Any]							,__lowerCAmelCase:						int=100_000							,__lowerCAmelCase:						Optional[int]=4_096							,__lowerCAmelCase:						Optional[int]=11_008							,__lowerCAmelCase:						Tuple=32							,__lowerCAmelCase:						Union[str, Any]=32							,__lowerCAmelCase:						int="silu"							,__lowerCAmelCase:						Dict=2_048							,__lowerCAmelCase:						Dict=0.02							,__lowerCAmelCase:						Any=1e-6							,__lowerCAmelCase:						Optional[Any]=True							,__lowerCAmelCase:						Optional[Any]=0							,__lowerCAmelCase:						List[Any]=1							,__lowerCAmelCase:						Optional[Any]=2							,__lowerCAmelCase:						int=False							,__lowerCAmelCase:						Optional[Any]=True							,__lowerCAmelCase:						Any=0.1							,__lowerCAmelCase:						Optional[int]=0.1							,__lowerCAmelCase:						str=True							,__lowerCAmelCase:						Any=True							,__lowerCAmelCase:						Dict=None							,**__lowerCAmelCase:						Union[str, Any]							,):







     '''simple docstring'''







     _lowerCamelCase   :				str							=     vocab_size
     _lowerCamelCase   :				Optional[int]							=     max_position_embeddings
     _lowerCamelCase   :				Any							=     hidden_size
     _lowerCamelCase   :				List[str]							=     intermediate_size
     _lowerCamelCase   :				List[Any]							=     num_hidden_layers
     _lowerCamelCase   :				List[Any]							=     num_attention_heads
     _lowerCamelCase   :				Tuple							=     hidden_act
     _lowerCamelCase   :				List[Any]							=     initializer_range
     _lowerCamelCase   :				Any							=     rms_norm_eps
     _lowerCamelCase   :				Optional[Any]							=     use_cache
     _lowerCamelCase   :				str							=     kwargs.pop(
         "use_memorry_efficient_attention"							,__lowerCAmelCase    )
     _lowerCamelCase   :				Optional[Any]							=     hidden_dropout_prob
     _lowerCamelCase   :				List[str]							=     attention_dropout_prob
     _lowerCamelCase   :				Optional[int]							=     use_stable_embedding
     _lowerCamelCase   :				List[Any]							=     shared_input_output_embedding
     _lowerCamelCase   :				Tuple							=     rope_scaling
     self._rope_scaling_validation()

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






  def 							_lowercase					(			self:						List[str]    ):







     '''simple docstring'''







     if self.rope_scaling is None:
        return

     if not isinstance(self.rope_scaling							,__lowerCAmelCase    ) 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   :				Optional[Any]							=     self.rope_scaling.get("type"							,__lowerCAmelCase    )
     _lowerCamelCase   :				int							=     self.rope_scaling.get("factor"							,__lowerCAmelCase    )
     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(__lowerCAmelCase							,__lowerCAmelCase    ) 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'''


import math
import time

from transformers import Trainer, is_torch_tpu_available
from transformers.trainer_utils import PredictionOutput, speed_metrics


if is_torch_tpu_available(check_device=False):
      import torch_xla.core.xla_model as xm
      import torch_xla.debug.metrics as met







class 							__magic_name__	(       lowerCAmelCase ):

     """simple docstring"""






     def __init__(   self			,     *lowerCamelCase			,     lowerCamelCase=None			,     lowerCamelCase=None			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(*lowerCamelCase			,     **lowerCamelCase		)
          __A	:       Tuple      =							eval_examples
          __A	:       List[str]      =							post_process_function


     def lowerCAmelCase__  (   self			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase = "eval"		):


          '''simple docstring'''





          __A	:       Any      =							self.eval_dataset if eval_dataset is None else eval_dataset
          __A	:       Dict      =							self.get_eval_dataloader(lowerCamelCase		)
          __A	:       str      =							self.eval_examples if eval_examples is None else eval_examples

          # Temporarily disable metric computation, we will do it in the loop here.
          __A	:       Any      =							self.compute_metrics
          __A	:       Optional[int]      =							None
          __A	:       Tuple      =							self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
          __A	:       Dict      =							time.time()
          try:
               __A	:       List[str]      =							eval_loop(
                   lowerCamelCase			,     description="Evaluation"			,     prediction_loss_only=True if compute_metrics is None else None			,     ignore_keys=lowerCamelCase			,     metric_key_prefix=lowerCamelCase			,     )
          finally:
               __A	:       List[str]      =							compute_metrics
          __A	:       List[Any]      =							self.args.eval_batch_size * self.args.world_size
          if f"{metric_key_prefix}_jit_compilation_time" in output.metrics:
               start_time += output.metrics[f"{metric_key_prefix}_jit_compilation_time"]
          output.metrics.update(
              speed_metrics(
                  lowerCamelCase			,     lowerCamelCase			,     num_samples=output.num_samples			,     num_steps=math.ceil(output.num_samples / total_batch_size		)			,     )		)
          if self.post_process_function is not None and self.compute_metrics is not None and self.args.should_save:
               # Only the main node write the results by default
               __A	:       List[Any]      =							self.post_process_function(lowerCamelCase			,     lowerCamelCase			,     output.predictions		)
               __A	:       List[str]      =							self.compute_metrics(lowerCamelCase		)

               # Prefix all keys with metric_key_prefix + '_'
               for key in list(metrics.keys()		):
                    if not key.startswith(f"{metric_key_prefix}_"		):
                         __A	:       Union[str, Any]      =							metrics.pop(lowerCamelCase		)
               metrics.update(output.metrics		)
          else:
               __A	:       Any      =							output.metrics

          if self.args.should_log:
               # Only the main node log the results by default
               self.log(lowerCamelCase		)

          if self.args.tpu_metrics_debug or self.args.debug:
               # tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)
               xm.master_print(met.metrics_report()		)

          __A	:       str      =							self.callback_handler.on_evaluate(self.args			,     self.state			,     self.control			,     lowerCamelCase		)
          return metrics


     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase=None			,     lowerCamelCase = "test"		):


          '''simple docstring'''





          __A	:       Tuple      =							self.get_test_dataloader(lowerCamelCase		)

          # Temporarily disable metric computation, we will do it in the loop here.
          __A	:       Union[str, Any]      =							self.compute_metrics
          __A	:       Union[str, Any]      =							None
          __A	:       Optional[Any]      =							self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
          __A	:       Tuple      =							time.time()
          try:
               __A	:       List[str]      =							eval_loop(
                   lowerCamelCase			,     description="Prediction"			,     prediction_loss_only=True if compute_metrics is None else None			,     ignore_keys=lowerCamelCase			,     metric_key_prefix=lowerCamelCase			,     )
          finally:
               __A	:       int      =							compute_metrics
          __A	:       List[Any]      =							self.args.eval_batch_size * self.args.world_size
          if f"{metric_key_prefix}_jit_compilation_time" in output.metrics:
               start_time += output.metrics[f"{metric_key_prefix}_jit_compilation_time"]
          output.metrics.update(
              speed_metrics(
                  lowerCamelCase			,     lowerCamelCase			,     num_samples=output.num_samples			,     num_steps=math.ceil(output.num_samples / total_batch_size		)			,     )		)

          if self.post_process_function is None or self.compute_metrics is None:
               return output

          __A	:       Dict      =							self.post_process_function(lowerCamelCase			,     lowerCamelCase			,     output.predictions			,     "predict"		)
          __A	:       Tuple      =							self.compute_metrics(lowerCamelCase		)

          # Prefix all keys with metric_key_prefix + '_'
          for key in list(metrics.keys()		):
               if not key.startswith(f"{metric_key_prefix}_"		):
                    __A	:       Any      =							metrics.pop(lowerCamelCase		)
          metrics.update(output.metrics		)
          return PredictionOutput(predictions=predictions.predictions			,     label_ids=predictions.label_ids			,     metrics=lowerCamelCase		)

