


"""simple docstring"""







import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.text import TextDatasetReader

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases
def 					a__			(				SCREAMING_SNAKE_CASE    :    Optional[Any]				,      SCREAMING_SNAKE_CASE    :    List[Any]				):


  '''simple docstring'''







  assert isinstance(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				)
  assert dataset.num_rows == 4
  assert dataset.num_columns == 1
  assert dataset.column_names == ["text"]
  for feature, expected_dtype in expected_features.items():
    assert dataset.features[feature].dtype == expected_dtype
@pytest.mark.parametrize("keep_in_memory"				,      [False, True]				)
def 					a__			(				SCREAMING_SNAKE_CASE    :    List[Any]				,      SCREAMING_SNAKE_CASE    :    int				,      SCREAMING_SNAKE_CASE    :    List[str]				):


  '''simple docstring'''







  lowerCAmelCase     :     Union[str, Any]								=							tmp_path / "cache"
  lowerCAmelCase     :     Tuple								=							{"text": "string"}
  with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
    lowerCAmelCase     :     Union[str, Any]								=							TextDatasetReader(SCREAMING_SNAKE_CASE				,      cache_dir=SCREAMING_SNAKE_CASE				,      keep_in_memory=SCREAMING_SNAKE_CASE				).read()
  _check_text_dataset(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				)
@pytest.mark.parametrize(
    "features"				,      [
        None,
        {"text": "string"},
        {"text": "int32"},
        {"text": "float32"},
    ]				,      )
def 					a__			(				SCREAMING_SNAKE_CASE    :    Optional[Any]				,      SCREAMING_SNAKE_CASE    :    int				,      SCREAMING_SNAKE_CASE    :    Optional[int]				):


  '''simple docstring'''







  lowerCAmelCase     :     Union[str, Any]								=							tmp_path / "cache"
  lowerCAmelCase     :     Any								=							{"text": "string"}
  lowerCAmelCase     :     Union[str, Any]								=							features.copy() if features else default_expected_features
  lowerCAmelCase     :     Union[str, Any]								=							(
      Features({feature: Value(SCREAMING_SNAKE_CASE				) for feature, dtype in features.items()}				) if features is not None else None
  )
  lowerCAmelCase     :     str								=							TextDatasetReader(SCREAMING_SNAKE_CASE				,      features=SCREAMING_SNAKE_CASE				,      cache_dir=SCREAMING_SNAKE_CASE				).read()
  _check_text_dataset(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				)
@pytest.mark.parametrize("split"				,      [None, NamedSplit("train"				), "train", "test"]				)
def 					a__			(				SCREAMING_SNAKE_CASE    :    List[str]				,      SCREAMING_SNAKE_CASE    :    Any				,      SCREAMING_SNAKE_CASE    :    Optional[int]				):


  '''simple docstring'''







  lowerCAmelCase     :     Union[str, Any]								=							tmp_path / "cache"
  lowerCAmelCase     :     Tuple								=							{"text": "string"}
  lowerCAmelCase     :     Union[str, Any]								=							TextDatasetReader(SCREAMING_SNAKE_CASE				,      cache_dir=SCREAMING_SNAKE_CASE				,      split=SCREAMING_SNAKE_CASE				).read()
  _check_text_dataset(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				)
  assert dataset.split == split if split else "train"
@pytest.mark.parametrize("path_type"				,      [str, list]				)
def 					a__			(				SCREAMING_SNAKE_CASE    :    Optional[Any]				,      SCREAMING_SNAKE_CASE    :    List[Any]				,      SCREAMING_SNAKE_CASE    :    Dict				):


  '''simple docstring'''







  if issubclass(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				):
    lowerCAmelCase     :     int								=							text_path
  elif issubclass(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				):
    lowerCAmelCase     :     Tuple								=							[text_path]
  lowerCAmelCase     :     List[Any]								=							tmp_path / "cache"
  lowerCAmelCase     :     int								=							{"text": "string"}
  lowerCAmelCase     :     List[Any]								=							TextDatasetReader(SCREAMING_SNAKE_CASE				,      cache_dir=SCREAMING_SNAKE_CASE				).read()
  _check_text_dataset(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				)
def 					a__			(				SCREAMING_SNAKE_CASE    :    Any				,      SCREAMING_SNAKE_CASE    :    Any				,      SCREAMING_SNAKE_CASE    :    List[Any]=("train",)				):


  '''simple docstring'''







  assert isinstance(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				)
  for split in splits:
    lowerCAmelCase     :     List[str]								=							dataset_dict[split]
    assert dataset.num_rows == 4
    assert dataset.num_columns == 1
    assert dataset.column_names == ["text"]
    for feature, expected_dtype in expected_features.items():
      assert dataset.features[feature].dtype == expected_dtype
@pytest.mark.parametrize("keep_in_memory"				,      [False, True]				)
def 					a__			(				SCREAMING_SNAKE_CASE    :    Tuple				,      SCREAMING_SNAKE_CASE    :    List[str]				,      SCREAMING_SNAKE_CASE    :    Union[str, Any]				):


  '''simple docstring'''







  lowerCAmelCase     :     Optional[Any]								=							tmp_path / "cache"
  lowerCAmelCase     :     str								=							{"text": "string"}
  with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
    lowerCAmelCase     :     Optional[int]								=							TextDatasetReader({"train": text_path}				,      cache_dir=SCREAMING_SNAKE_CASE				,      keep_in_memory=SCREAMING_SNAKE_CASE				).read()
  _check_text_datasetdict(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				)
@pytest.mark.parametrize(
    "features"				,      [
        None,
        {"text": "string"},
        {"text": "int32"},
        {"text": "float32"},
    ]				,      )
def 					a__			(				SCREAMING_SNAKE_CASE    :    List[str]				,      SCREAMING_SNAKE_CASE    :    List[Any]				,      SCREAMING_SNAKE_CASE    :    Optional[Any]				):


  '''simple docstring'''







  lowerCAmelCase     :     Any								=							tmp_path / "cache"
  # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
  lowerCAmelCase     :     Optional[Any]								=							{"text": "string"}
  lowerCAmelCase     :     Union[str, Any]								=							features.copy() if features else default_expected_features
  lowerCAmelCase     :     int								=							(
      Features({feature: Value(SCREAMING_SNAKE_CASE				) for feature, dtype in features.items()}				) if features is not None else None
  )
  lowerCAmelCase     :     List[Any]								=							TextDatasetReader({"train": text_path}				,      features=SCREAMING_SNAKE_CASE				,      cache_dir=SCREAMING_SNAKE_CASE				).read()
  _check_text_datasetdict(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				)





@pytest.mark.parametrize("split"				,      [None, NamedSplit("train"				), "train", "test"]				)
def 					a__			(				SCREAMING_SNAKE_CASE    :    List[Any]				,      SCREAMING_SNAKE_CASE    :    Optional[int]				,      SCREAMING_SNAKE_CASE    :    Tuple				):


  '''simple docstring'''







  if split:
    lowerCAmelCase     :     Dict								=							{split: text_path}
  else:
    lowerCAmelCase     :     List[str]								=							"train"
    lowerCAmelCase     :     int								=							{"train": text_path, "test": text_path}
  lowerCAmelCase     :     List[Any]								=							tmp_path / "cache"
  lowerCAmelCase     :     Optional[Any]								=							{"text": "string"}
  lowerCAmelCase     :     List[Any]								=							TextDatasetReader(SCREAMING_SNAKE_CASE				,      cache_dir=SCREAMING_SNAKE_CASE				).read()
  _check_text_datasetdict(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				,      splits=list(path.keys()				)				)
  assert all(dataset[split].split == split for split in path.keys()				)









"""simple docstring"""







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


lowerCAmelCase__      				=   logging.get_logger(__name__)

lowerCAmelCase__      				=   {}


class       SCREAMING_SNAKE_CASE__				(		lowercase				):
       """simple docstring"""


       a  :				str   ="llama"
       a  :				List[str]   =["past_key_values"]

       def __init__(						self		,     snake_case__=32_000		,     snake_case__=4_096		,     snake_case__=11_008		,     snake_case__=32		,     snake_case__=32		,     snake_case__=None		,     snake_case__="silu"		,     snake_case__=2_048		,     snake_case__=0.02		,     snake_case__=1e-6		,     snake_case__=True		,     snake_case__=0		,     snake_case__=1		,     snake_case__=2		,     snake_case__=1		,     snake_case__=False		,     snake_case__=None		,     **snake_case__		,     ):






         """simple docstring"""





         lowerCAmelCase     :     Optional[Any]								=							vocab_size
         lowerCAmelCase     :     str								=							max_position_embeddings
         lowerCAmelCase     :     str								=							hidden_size
         lowerCAmelCase     :     Optional[int]								=							intermediate_size
         lowerCAmelCase     :     Any								=							num_hidden_layers
         lowerCAmelCase     :     List[str]								=							num_attention_heads

         # for backward compatibility
         if num_key_value_heads is None:
           lowerCAmelCase     :     Tuple								=							num_attention_heads

         lowerCAmelCase     :     Dict								=							num_key_value_heads
         lowerCAmelCase     :     Optional[Any]								=							hidden_act
         lowerCAmelCase     :     Optional[Any]								=							initializer_range
         lowerCAmelCase     :     Any								=							rms_norm_eps
         lowerCAmelCase     :     List[Any]								=							pretraining_tp
         lowerCAmelCase     :     int								=							use_cache
         lowerCAmelCase     :     List[str]								=							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						):






         """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}"""						)
         lowerCAmelCase     :     Optional[Any]								=							self.rope_scaling.get("type"		,     snake_case__						)
         lowerCAmelCase     :     int								=							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}"""						)





