
'''simple docstring'''





import csv
import os

import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.csv import CsvDatasetReader, CsvDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases
def 	snake_case_							(				_a  :				Any			,       _a  :				str      ):
      assert isinstance(_a			,       _a      )
      assert dataset.num_rows == 4
      assert dataset.num_columns == 3
      assert dataset.column_names == ["col_1", "col_2", "col_3"]
      for feature, expected_dtype in expected_features.items():
            assert dataset.features[feature].dtype == expected_dtype
@pytest.mark.parametrize("keep_in_memory"			,       [False, True]      )
def 	snake_case_							(				_a  :				List[str]			,       _a  :				List[Any]			,       _a  :				str      ):
      snake_case_    							=				tmp_path / "cache"
      snake_case_    							=				{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
            snake_case_    							=				CsvDatasetReader(_a			,       cache_dir=_a			,       keep_in_memory=_a      ).read()
      _check_csv_dataset(_a			,       _a      )
@pytest.mark.parametrize(
    "features"			,       [
        None,
        {"col_1": "string", "col_2": "int64", "col_3": "float64"},
        {"col_1": "string", "col_2": "string", "col_3": "string"},
        {"col_1": "int32", "col_2": "int32", "col_3": "int32"},
        {"col_1": "float32", "col_2": "float32", "col_3": "float32"},
    ]			,       )
def 	snake_case_							(				_a  :				Any			,       _a  :				int			,       _a  :				Optional[int]      ):
      snake_case_    							=				tmp_path / "cache"
      # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
      snake_case_    							=				{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      snake_case_    							=				features.copy() if features else default_expected_features
      snake_case_    							=				(
          Features({feature: Value(_a      ) for feature, dtype in features.items()}      ) if features is not None else None
      )
      snake_case_    							=				CsvDatasetReader(_a			,       features=_a			,       cache_dir=_a      ).read()
      _check_csv_dataset(_a			,       _a      )
@pytest.mark.parametrize("split"			,       [None, NamedSplit("train"      ), "train", "test"]      )
def 	snake_case_							(				_a  :				Optional[Any]			,       _a  :				Dict			,       _a  :				Tuple      ):
      snake_case_    							=				tmp_path / "cache"
      snake_case_    							=				{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      snake_case_    							=				CsvDatasetReader(_a			,       cache_dir=_a			,       split=_a      ).read()
      _check_csv_dataset(_a			,       _a      )
      assert dataset.split == split if split else "train"
@pytest.mark.parametrize("path_type"			,       [str, list]      )
def 	snake_case_							(				_a  :				int			,       _a  :				Optional[int]			,       _a  :				Dict      ):
      if issubclass(_a			,       _a      ):
            snake_case_    							=				csv_path
      elif issubclass(_a			,       _a      ):
            snake_case_    							=				[csv_path]
      snake_case_    							=				tmp_path / "cache"
      snake_case_    							=				{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      snake_case_    							=				CsvDatasetReader(_a			,       cache_dir=_a      ).read()
      _check_csv_dataset(_a			,       _a      )
def 	snake_case_							(				_a  :				Tuple			,       _a  :				str			,       _a  :				List[str]=("train",)      ):
      assert isinstance(_a			,       _a      )
      for split in splits:
            snake_case_    							=				dataset_dict[split]
            assert dataset.num_rows == 4
            assert dataset.num_columns == 3
            assert dataset.column_names == ["col_1", "col_2", "col_3"]
            for feature, expected_dtype in expected_features.items():
                  assert dataset.features[feature].dtype == expected_dtype
@pytest.mark.parametrize("keep_in_memory"			,       [False, True]      )
def 	snake_case_							(				_a  :				Any			,       _a  :				int			,       _a  :				Union[str, Any]      ):
      snake_case_    							=				tmp_path / "cache"
      snake_case_    							=				{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
            snake_case_    							=				CsvDatasetReader({"train": csv_path}			,       cache_dir=_a			,       keep_in_memory=_a      ).read()
      _check_csv_datasetdict(_a			,       _a      )
@pytest.mark.parametrize(
    "features"			,       [
        None,
        {"col_1": "string", "col_2": "int64", "col_3": "float64"},
        {"col_1": "string", "col_2": "string", "col_3": "string"},
        {"col_1": "int32", "col_2": "int32", "col_3": "int32"},
        {"col_1": "float32", "col_2": "float32", "col_3": "float32"},
    ]			,       )
def 	snake_case_							(				_a  :				Optional[int]			,       _a  :				Optional[int]			,       _a  :				List[str]      ):
      snake_case_    							=				tmp_path / "cache"
      # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
      snake_case_    							=				{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      snake_case_    							=				features.copy() if features else default_expected_features
      snake_case_    							=				(
          Features({feature: Value(_a      ) for feature, dtype in features.items()}      ) if features is not None else None
      )
      snake_case_    							=				CsvDatasetReader({"train": csv_path}			,       features=_a			,       cache_dir=_a      ).read()
      _check_csv_datasetdict(_a			,       _a      )
@pytest.mark.parametrize("split"			,       [None, NamedSplit("train"      ), "train", "test"]      )
def 	snake_case_							(				_a  :				str			,       _a  :				List[str]			,       _a  :				List[Any]      ):
      if split:
            snake_case_    							=				{split: csv_path}
      else:
            snake_case_    							=				{"train": csv_path, "test": csv_path}
      snake_case_    							=				tmp_path / "cache"
      snake_case_    							=				{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      snake_case_    							=				CsvDatasetReader(_a			,       cache_dir=_a      ).read()
      _check_csv_datasetdict(_a			,       _a			,       splits=list(path.keys()      )      )
      assert all(dataset[split].split == split for split in path.keys()      )
def 	snake_case_							(				_a  :				List[Any]      ):
      with open(_a			,       encoding="utf-8"      ) as csvfile:
            yield from csv.reader(_a      )
def 	snake_case_							(				_a  :				Optional[Any]			,       _a  :				int      ):
      snake_case_    							=				tmp_path / "cache"
      snake_case_    							=				os.path.join(_a			,       "tmp.csv"      )
      snake_case_    							=				CsvDatasetReader({"train": csv_path}			,       cache_dir=_a      ).read()
      CsvDatasetWriter(dataset["train"]			,       _a			,       num_proc=1      ).write()

      snake_case_    							=				iter_csv_file(_a      )
      snake_case_    							=				iter_csv_file(_a      )

      for rowa, rowa in zip(_a			,       _a      ):
            assert rowa == rowa
def 	snake_case_							(				_a  :				str			,       _a  :				Dict      ):
      snake_case_    							=				tmp_path / "cache"
      snake_case_    							=				os.path.join(_a			,       "tmp.csv"      )
      snake_case_    							=				CsvDatasetReader({"train": csv_path}			,       cache_dir=_a      ).read()
      CsvDatasetWriter(dataset["train"]			,       _a			,       num_proc=2      ).write()

      snake_case_    							=				iter_csv_file(_a      )
      snake_case_    							=				iter_csv_file(_a      )

      for rowa, rowa in zip(_a			,       _a      ):
            assert rowa == rowa




def 	snake_case_							(				_a  :				Any			,       _a  :				Any      ):
      snake_case_    							=				tmp_path / "cache"
      snake_case_    							=				os.path.join(_a			,       "tmp.csv"      )
      snake_case_    							=				CsvDatasetReader({"train": csv_path}			,       cache_dir=_a      ).read()
      with pytest.raises(_a      ):
            CsvDatasetWriter(dataset["train"]			,       _a			,       num_proc=0      )



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


_A							=       logging.get_logger(__name__)

_A							=       {
    '''facebook/opt-125m''': '''https://huggingface.co/facebook/opt-125m/blob/main/config.json''',
    '''facebook/opt-350m''': '''https://huggingface.co/facebook/opt-350m/blob/main/config.json''',
    '''facebook/opt-1.3b''': '''https://huggingface.co/facebook/opt-1.3b/blob/main/config.json''',
    '''facebook/opt-2.7b''': '''https://huggingface.co/facebook/opt-2.7b/blob/main/config.json''',
    '''facebook/opt-6.7b''': '''https://huggingface.co/facebook/opt-6.7b/blob/main/config.json''',
    '''facebook/opt-13b''': '''https://huggingface.co/facebook/opt-13b/blob/main/config.json''',
}

class 		lowercase_							(							__SCREAMING_SNAKE_CASE					):
 A__    :					Dict    =     """opt"""
 A__    :					int    =     ["""past_key_values"""]

 def __init__(   self  ,						__UpperCamelCase=5_0_2_7_2  ,						__UpperCamelCase=7_6_8  ,						__UpperCamelCase=1_2  ,						__UpperCamelCase=3_0_7_2  ,						__UpperCamelCase=2_0_4_8  ,						__UpperCamelCase=True  ,						__UpperCamelCase=False  ,						__UpperCamelCase=None  ,						__UpperCamelCase=0.1  ,						__UpperCamelCase=0.0  ,						__UpperCamelCase=1_2  ,						__UpperCamelCase="relu"  ,						__UpperCamelCase=0.0  ,						__UpperCamelCase=0.02  ,						__UpperCamelCase=True  ,						__UpperCamelCase=1  ,						__UpperCamelCase=2  ,						__UpperCamelCase=2  ,						__UpperCamelCase=True  ,						__UpperCamelCase=True  ,						**__UpperCamelCase  ,						):




        """simple docstring"""


        super().__init__(
            pad_token_id=__UpperCamelCase  ,						bos_token_id=__UpperCamelCase  ,						eos_token_id=__UpperCamelCase  ,						**__UpperCamelCase  ,						)
        UpperCamelCase_											=							vocab_size
        UpperCamelCase_											=							max_position_embeddings
        UpperCamelCase_											=							num_attention_heads
        UpperCamelCase_											=							word_embed_proj_dim if word_embed_proj_dim is not None else hidden_size
        UpperCamelCase_											=							ffn_dim
        UpperCamelCase_											=							hidden_size
        UpperCamelCase_											=							num_hidden_layers
        UpperCamelCase_											=							dropout
        UpperCamelCase_											=							attention_dropout
        UpperCamelCase_											=							activation_function
        UpperCamelCase_											=							init_std
        UpperCamelCase_											=							layerdrop
        UpperCamelCase_											=							use_cache
        UpperCamelCase_											=							do_layer_norm_before
        # We keep these variables at `True` for backward compatibility.
        UpperCamelCase_											=							enable_bias
        UpperCamelCase_											=							layer_norm_elementwise_affine

        # Note that the only purpose of `_remove_final_layer_norm` is to keep backward compatibility
        # with checkpoints that have been fine-tuned before transformers v4.20.1
        # see https://github.com/facebookresearch/metaseq/pull/164
        UpperCamelCase_											=							_remove_final_layer_norm



