




import timeit

import numpy as np

import datasets
from datasets.arrow_writer import ArrowWriter
from datasets.features.features import _ArrayXD


def    A						(__A   :    List[str]       )   ->      Tuple:







     """simple docstring"""


     def wrapper(*__A   :    Any   ,				**__A   :    Union[str, Any]       ):
          UpperCAmelCase_          =							timeit.default_timer()
          UpperCAmelCase_          =							func(*__A   ,				**__A       )
          UpperCAmelCase_          =							timeit.default_timer() - starttime
          return delta

     UpperCAmelCase_          =							func.__name__

     return wrapper


def    A						(__A   :    dict   ,				__A   :    str=100   ,				__A   :    Dict=None       )   ->      str:







     """simple docstring"""


     UpperCAmelCase_          =							[]
     UpperCAmelCase_          =							seq_shapes or {}
     for i in range(__A       ):
          UpperCAmelCase_          =							{}
          for col_id, (k, v) in enumerate(features.items()       ):
               if isinstance(__A   ,				_ArrayXD       ):
                    UpperCAmelCase_          =							np.random.rand(*v.shape       ).astype(v.dtype       )
               elif isinstance(__A   ,				datasets.Value       ):
                    if v.dtype == "string":
                         UpperCAmelCase_          =							'''The small grey turtle was surprisingly fast when challenged.'''
                    else:
                         UpperCAmelCase_          =							np.random.randint(10   ,				size=1       ).astype(v.dtype       ).item()
               elif isinstance(__A   ,				datasets.Sequence       ):
                    while isinstance(__A   ,				datasets.Sequence       ):
                         UpperCAmelCase_          =							v.feature
                    UpperCAmelCase_          =							seq_shapes[k]
                    UpperCAmelCase_          =							np.random.rand(*__A       ).astype(v.dtype       )
               UpperCAmelCase_          =							data

          dummy_data.append((i, example)       )

     return dummy_data


def    A						(__A   :    Optional[Any]   ,				__A   :    List[Any]   ,				__A   :    Dict=100   ,				__A   :    str=None       )   ->      Optional[Any]:







     """simple docstring"""


     UpperCAmelCase_          =							generate_examples(__A   ,				num_examples=__A   ,				seq_shapes=__A       )

     with ArrowWriter(features=__A   ,				path=__A       ) as writer:
          for key, record in dummy_data:
               UpperCAmelCase_          =							features.encode_example(__A       )
               writer.write(__A       )

          UpperCAmelCase_     ,       UpperCAmelCase_          =							writer.finalize()

     if not num_final_examples == num_examples:
          raise ValueError(
              F"""Error writing the dataset, wrote {num_final_examples} examples but should have written {num_examples}."""       )

     UpperCAmelCase_          =							datasets.Dataset.from_file(filename=__A   ,				info=datasets.DatasetInfo(features=__A       )       )

     return dataset












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


snake_case_ : int    		=       logging.get_logger(__name__)

snake_case_ : str    		=       {}







class __snake_case			(			a		):
   UpperCAmelCase__  :    str          =  '''llama'''
   UpperCAmelCase__  :    Dict          =  ['''past_key_values''']







   def __init__(      self		:						str					,						_snake_case		:						List[str]=32000					,						_snake_case		:						int=4096					,						_snake_case		:						List[str]=11008					,						_snake_case		:						Optional[int]=32					,						_snake_case		:						List[Any]=32					,						_snake_case		:						Tuple=None					,						_snake_case		:						int="silu"					,						_snake_case		:						List[Any]=2048					,						_snake_case		:						List[str]=0.0_2					,						_snake_case		:						Any=1e-6					,						_snake_case		:						List[str]=True					,						_snake_case		:						Optional[Any]=0					,						_snake_case		:						Dict=1					,						_snake_case		:						List[Any]=2					,						_snake_case		:						str=1					,						_snake_case		:						Union[str, Any]=False					,						_snake_case		:						str=None					,						**_snake_case		:						List[Any]					,						):

        """simple docstring"""


        UpperCAmelCase_          =							vocab_size
        UpperCAmelCase_          =							max_position_embeddings
        UpperCAmelCase_          =							hidden_size
        UpperCAmelCase_          =							intermediate_size
        UpperCAmelCase_          =							num_hidden_layers
        UpperCAmelCase_          =							num_attention_heads

        # for backward compatibility
        if num_key_value_heads is None:
             UpperCAmelCase_          =							num_attention_heads

        UpperCAmelCase_          =							num_key_value_heads
        UpperCAmelCase_          =							hidden_act
        UpperCAmelCase_          =							initializer_range
        UpperCAmelCase_          =							rms_norm_eps
        UpperCAmelCase_          =							pretraining_tp
        UpperCAmelCase_          =							use_cache
        UpperCAmelCase_          =							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 lowerCamelCase						(      self		:						Optional[int]):

        """simple docstring"""


        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}""")
        UpperCAmelCase_          =							self.rope_scaling.get('''type'''					,						_snake_case)
        UpperCAmelCase_          =							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}""")






