





"""simple docstring"""





from typing import Optional

from .. import Features, NamedSplit
from ..packaged_modules.text.text import Text
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader

class 		lowercase					(					_UpperCAmelCase					):





      def __init__(       self      ,						lowercase      ,						lowercase = None      ,						lowercase = None      ,						lowercase = None      ,						lowercase = False      ,						lowercase = False      ,						lowercase = None      ,						**lowercase      ,						)		->     int:
            super().__init__(
                lowercase      ,						split=lowercase      ,						features=lowercase      ,						cache_dir=lowercase      ,						keep_in_memory=lowercase      ,						streaming=lowercase      ,						num_proc=lowercase      ,						**lowercase      ,						)
            lowerCAmelCase  						=       path_or_paths if isinstance(lowercase      ,						lowercase ) else {self.split: path_or_paths}
            lowerCAmelCase  						=       Text(
                cache_dir=lowercase      ,						data_files=lowercase      ,						features=lowercase      ,						**lowercase      ,						)





      def     _snake_case			(       self )		->     Tuple:
            # Build iterable dataset
            if self.streaming:
                  lowerCAmelCase  						=       self.builder.as_streaming_dataset(split=self.split )
            # Build regular (map-style) dataset
            else:
                  lowerCAmelCase  						=       None
                  lowerCAmelCase  						=       None
                  lowerCAmelCase  						=       None
                  lowerCAmelCase  						=       None

                  self.builder.download_and_prepare(
                      download_config=lowercase      ,						download_mode=lowercase      ,						verification_mode=lowercase      ,						base_path=lowercase      ,						num_proc=self.num_proc      ,						)
                  lowerCAmelCase  						=       self.builder.as_dataset(
                      split=self.split      ,						verification_mode=lowercase      ,						in_memory=self.keep_in_memory )
            return dataset










'''simple docstring'''



import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_huggingface_suite,
    require_multi_gpu,
    require_single_gpu,
)
from accelerate.utils import patch_environment





@require_huggingface_suite
class 							__UpperCamelCase				(		unittest.TestCase					):




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       List[Any]					    =  inspect.getfile(accelerate.test_utils							)
						__a			:       List[str]					    =  os.path.sep.join(
						    mod_file.split(os.path.sep							)[:-1] + ['scripts', 'external_deps', 'test_metrics.py']							)

						from accelerate.test_utils.scripts.external_deps import test_metrics  # noqa: F401

						__a			:       Union[str, Any]					    =  test_metrics




	@require_cpu
	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						debug_launcher(self.test_metrics.main						,				num_processes=1							)




	@require_cpu
	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						debug_launcher(self.test_metrics.main							)




	@require_single_gpu
	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						self.test_metrics.main()





	@require_multi_gpu
	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						print(f"""Found {torch.cuda.device_count()} devices."""							)
						__a			:       List[Any]					    =  ['torchrun', f"""--nproc_per_node={torch.cuda.device_count()}""", self.test_file_path]
						with patch_environment(omp_num_threads=1							):
											execute_subprocess_async(__a						,				env=os.environ.copy()							)



