import json
import os
from pathlib import Path

import pytest

from datasets.download.download_config import DownloadConfig
from datasets.download.download_manager import DownloadManager
from datasets.utils.file_utils import hash_url_to_filename


lowerCAmelCase__	   =						'http://www.mocksite.com/file1.txt'
lowerCAmelCase__	   =						'"text": ["foo", "foo"]'
lowerCAmelCase__	   =						'6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8'
class 					snake_case	:

   """simple docstring"""







   __lowerCAmelCase   						=      200
   __lowerCAmelCase   						=      {'Content-Length': '100'}
   __lowerCAmelCase   						=      {}





   def 				snake_case__							(    self					,	**lowerCAmelCase_	):
     return [bytes(lowerCAmelCase_					,	"utf-8"	)]







def      __lowercase				(      *_UpperCAmelCase			, **_UpperCAmelCase			)      ->     Union[str, Any]:






  '''simple docstring'''

  return MockResponse()



@pytest.mark.parametrize("urls_type"			, [str, list, dict]			)
def      __lowercase				(      _UpperCAmelCase			, _UpperCAmelCase			, _UpperCAmelCase			)      ->     List[str]:






  '''simple docstring'''

  import requests

  monkeypatch.setattr(_lowercase			, "request"			, _lowercase			)

  __lowercase					=		URL
  if issubclass(_lowercase			, _lowercase			):
    __lowercase					=		url
  elif issubclass(_lowercase			, _lowercase			):
    __lowercase					=		[url]
  elif issubclass(_lowercase			, _lowercase			):
    __lowercase					=		{"train": url}
  __lowercase					=		"dummy"
  __lowercase					=		"downloads"
  __lowercase					=		tmp_path
  __lowercase					=		DownloadConfig(
      cache_dir=os.path.join(_lowercase			, _lowercase			)			, use_etag=_lowercase			, )
  __lowercase					=		DownloadManager(dataset_name=_lowercase			, download_config=_lowercase			)
  __lowercase					=		dl_manager.download(_lowercase			)
  __lowercase					=		urls
  for downloaded_paths in [downloaded_paths]:
    if isinstance(_lowercase			, _lowercase			):
      __lowercase					=		[downloaded_paths]
      __lowercase					=		[urls]
    elif isinstance(_lowercase			, _lowercase			):
      assert "train" in downloaded_paths.keys()
      __lowercase					=		downloaded_paths.values()
      __lowercase					=		urls.values()
    assert downloaded_paths
    for downloaded_path, input_url in zip(_lowercase			, _lowercase			):
      assert downloaded_path == dl_manager.downloaded_paths[input_url]
      __lowercase					=		Path(_lowercase			)
      __lowercase					=		downloaded_path.parts
      assert parts[-1] == HASH
      assert parts[-2] == cache_subdir
      assert downloaded_path.exists()
      __lowercase					=		downloaded_path.read_text()
      assert content == CONTENT
      __lowercase					=		downloaded_path.with_suffix(".json"			)
      assert metadata_downloaded_path.exists()
      __lowercase					=		json.loads(metadata_downloaded_path.read_text()			)
      assert metadata_content == {"url": URL, "etag": None}



@pytest.mark.parametrize("paths_type"			, [str, list, dict]			)
def      __lowercase				(      _UpperCAmelCase			, _UpperCAmelCase			, _UpperCAmelCase			)      ->     Dict:






  '''simple docstring'''

  __lowercase					=		str(_lowercase			)
  if issubclass(_lowercase			, _lowercase			):
    __lowercase					=		filename
  elif issubclass(_lowercase			, _lowercase			):
    __lowercase					=		[filename]
  elif issubclass(_lowercase			, _lowercase			):
    __lowercase					=		{"train": filename}
  __lowercase					=		"dummy"
  __lowercase					=		xz_file.parent
  __lowercase					=		"extracted"
  __lowercase					=		DownloadConfig(
      cache_dir=_lowercase			, use_etag=_lowercase			, )
  __lowercase					=		DownloadManager(dataset_name=_lowercase			, download_config=_lowercase			)
  __lowercase					=		dl_manager.extract(_lowercase			)
  __lowercase					=		paths
  for extracted_paths in [extracted_paths]:
    if isinstance(_lowercase			, _lowercase			):
      __lowercase					=		[extracted_paths]
      __lowercase					=		[paths]
    elif isinstance(_lowercase			, _lowercase			):
      assert "train" in extracted_paths.keys()
      __lowercase					=		extracted_paths.values()
      __lowercase					=		paths.values()
    assert extracted_paths
    for extracted_path, input_path in zip(_lowercase			, _lowercase			):
      assert extracted_path == dl_manager.extracted_paths[input_path]
      __lowercase					=		Path(_lowercase			)
      __lowercase					=		extracted_path.parts
      assert parts[-1] == hash_url_to_filename(_lowercase			, etag=_lowercase			)
      assert parts[-2] == extracted_subdir
      assert extracted_path.exists()
      __lowercase					=		extracted_path.read_text()
      __lowercase					=		text_file.read_text()
      assert extracted_file_content == expected_file_content



def      __lowercase				(      _UpperCAmelCase			, _UpperCAmelCase			)      ->     Union[str, Any]:






  '''simple docstring'''

  assert path.endswith(".jsonl"			)
  for num_items, line in enumerate(_lowercase			, start=1			):
    __lowercase					=		json.loads(line.decode("utf-8"			)			)
    assert item.keys() == {"col_1", "col_2", "col_3"}
  assert num_items == 4



@pytest.mark.parametrize("archive_jsonl"			, ["tar_jsonl_path", "zip_jsonl_path"]			)
def      __lowercase				(      _UpperCAmelCase			, _UpperCAmelCase			)      ->     Dict:






  '''simple docstring'''

  __lowercase					=		request.getfixturevalue(_lowercase			)
  __lowercase					=		DownloadManager()
  for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(_lowercase			)			, start=1			):
    _test_jsonl(_lowercase			, _lowercase			)
  assert num_jsonl == 2



@pytest.mark.parametrize("archive_nested_jsonl"			, ["tar_nested_jsonl_path", "zip_nested_jsonl_path"]			)
def      __lowercase				(      _UpperCAmelCase			, _UpperCAmelCase			)      ->     str:






  '''simple docstring'''

  __lowercase					=		request.getfixturevalue(_lowercase			)
  __lowercase					=		DownloadManager()
  for num_tar, (path, file) in enumerate(dl_manager.iter_archive(_lowercase			)			, start=1			):
    for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(_lowercase			)			, start=1			):
      _test_jsonl(_lowercase			, _lowercase			)
  assert num_tar == 1
  assert num_jsonl == 2




def      __lowercase				(      _UpperCAmelCase			)      ->     List[Any]:






  '''simple docstring'''

  __lowercase					=		DownloadManager()
  for num_file, file in enumerate(dl_manager.iter_files(_lowercase			)			, start=1			):
    assert os.path.basename(_lowercase			) == ("test.txt" if num_file == 1 else "train.txt")
  assert num_file == 2





"""simple docstring"""



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


lowercase_							=							logging.get_logger(__name__)

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







class    __a						( __snake_case							):
				lowerCamelCase     :       Union[str, Any]			       ='open-llama'







				def __init__( self      ,	UpperCAmelCase=10_0000      ,	UpperCAmelCase=4096      ,	UpperCAmelCase=1_1008      ,	UpperCAmelCase=32      ,	UpperCAmelCase=32      ,	UpperCAmelCase="silu"      ,	UpperCAmelCase=2048      ,	UpperCAmelCase=0.0_2      ,	UpperCAmelCase=1E-6      ,	UpperCAmelCase=True      ,	UpperCAmelCase=0      ,	UpperCAmelCase=1      ,	UpperCAmelCase=2      ,	UpperCAmelCase=False      ,	UpperCAmelCase=True      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=True      ,	UpperCAmelCase=True      ,	UpperCAmelCase=None      ,	**UpperCAmelCase      ,	):

					'''simple docstring'''






					lowerCAmelCase_      							=			vocab_size
					lowerCAmelCase_      							=			max_position_embeddings
					lowerCAmelCase_      							=			hidden_size
					lowerCAmelCase_      							=			intermediate_size
					lowerCAmelCase_      							=			num_hidden_layers
					lowerCAmelCase_      							=			num_attention_heads
					lowerCAmelCase_      							=			hidden_act
					lowerCAmelCase_      							=			initializer_range
					lowerCAmelCase_      							=			rms_norm_eps
					lowerCAmelCase_      							=			use_cache
					lowerCAmelCase_      							=			kwargs.pop(
					    '''use_memorry_efficient_attention'''      ,	UpperCAmelCase   )
					lowerCAmelCase_      							=			hidden_dropout_prob
					lowerCAmelCase_      							=			attention_dropout_prob
					lowerCAmelCase_      							=			use_stable_embedding
					lowerCAmelCase_      							=			shared_input_output_embedding
					lowerCAmelCase_      							=			rope_scaling
					self._rope_scaling_validation()

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







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					if self.rope_scaling is None:
						return

					if not isinstance(self.rope_scaling      ,	UpperCAmelCase   ) 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_      							=			self.rope_scaling.get('''type'''      ,	UpperCAmelCase   )
					lowerCAmelCase_      							=			self.rope_scaling.get('''factor'''      ,	UpperCAmelCase   )
					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(UpperCAmelCase      ,	UpperCAmelCase   ) or rope_scaling_factor <= 1.0:
						raise ValueError(F"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""   )