
'''simple docstring'''
import importlib
import os
import platform
from pathlib import Path

from packaging import version

from .utils.logging import get_logger


A__ :		Union[str, Any]					=get_logger(__name__)

# Datasets
A__ :		Optional[int]					='https://s3.amazonaws.com/datasets.huggingface.co/datasets/datasets'
A__ :		Any					='https://cdn-datasets.huggingface.co/datasets/datasets'
A__ :		Union[str, Any]					='https://raw.githubusercontent.com/huggingface/datasets/{revision}/datasets/{path}/{name}'

# Metrics
A__ :		Any					='https://s3.amazonaws.com/datasets.huggingface.co/datasets/metrics'
A__ :		Optional[int]					='https://cdn-datasets.huggingface.co/datasets/metric'
A__ :		str					='https://raw.githubusercontent.com/huggingface/datasets/{revision}/metrics/{path}/{name}'

# Hub
A__ :		int					=os.environ.get('HF_ENDPOINT', 'https://huggingface.co')
A__ :		Optional[Any]					=HF_ENDPOINT + '/datasets/{repo_id}/resolve/{revision}/{path}'
A__ :		str					='main'

A__ :		List[Any]					=version.parse(platform.python_version())

if PY_VERSION < version.parse('3.8'):
     import importlib_metadata
else:
     import importlib.metadata as importlib_metadata

# General environment variables accepted values for booleans
A__ :		Optional[int]					={'1', 'ON', 'YES', 'TRUE'}
A__ :		Tuple					=ENV_VARS_TRUE_VALUES.union({'AUTO'})


# Imports
A__ :		Optional[int]					=version.parse(importlib_metadata.version('dill'))
A__ :		Optional[Any]					=version.parse(importlib_metadata.version('pandas'))
A__ :		Optional[int]					=version.parse(importlib_metadata.version('pyarrow'))

A__ :		Tuple					=os.environ.get('USE_TF', 'AUTO').upper()
A__ :		List[Any]					=os.environ.get('USE_TORCH', 'AUTO').upper()
A__ :		str					=os.environ.get('USE_JAX', 'AUTO').upper()

A__ :		Dict					='N/A'
A__ :		int					=False

if USE_TORCH in ENV_VARS_TRUE_AND_AUTO_VALUES and USE_TF not in ENV_VARS_TRUE_VALUES:
     A__ :		str					=importlib.util.find_spec('torch') is not None
     if TORCH_AVAILABLE:
          try:
               A__ :		Tuple					=version.parse(importlib_metadata.version('torch'))
               logger.info(F"PyTorch version {TORCH_VERSION} available.")
          except importlib_metadata.PackageNotFoundError:
               pass
else:
     logger.info('Disabling PyTorch because USE_TF is set')

A__ :		List[str]					='N/A'
A__ :		Tuple					=False

if USE_TF in ENV_VARS_TRUE_AND_AUTO_VALUES and USE_TORCH not in ENV_VARS_TRUE_VALUES:
     A__ :		Optional[Any]					=importlib.util.find_spec('tensorflow') is not None
     if TF_AVAILABLE:
          # For the metadata, we have to look for both tensorflow and tensorflow-cpu
          for package in [
              "tensorflow",
              "tensorflow-cpu",
              "tensorflow-gpu",
              "tf-nightly",
              "tf-nightly-cpu",
              "tf-nightly-gpu",
              "intel-tensorflow",
              "tensorflow-rocm",
              "tensorflow-macos",
          ]:
               try:
                    A__ :		Optional[Any]					=version.parse(importlib_metadata.version(package))
               except importlib_metadata.PackageNotFoundError:
                    continue
               else:
                    break
          else:
               A__ :		Optional[int]					=False
     if TF_AVAILABLE:
          if TF_VERSION.major < 2:
               logger.info(F"TensorFlow found but with version {TF_VERSION}. `datasets` requires version 2 minimum.")
               A__ :		Union[str, Any]					=False
          else:
               logger.info(F"TensorFlow version {TF_VERSION} available.")
else:
     logger.info('Disabling Tensorflow because USE_TORCH is set')


A__ :		str					='N/A'
A__ :		Dict					=False

if USE_JAX in ENV_VARS_TRUE_AND_AUTO_VALUES:
     A__ :		Union[str, Any]					=importlib.util.find_spec('jax') is not None and importlib.util.find_spec('jaxlib') is not None
     if JAX_AVAILABLE:
          try:
               A__ :		Optional[int]					=version.parse(importlib_metadata.version('jax'))
               logger.info(F"JAX version {JAX_VERSION} available.")
          except importlib_metadata.PackageNotFoundError:
               pass
else:
     logger.info('Disabling JAX because USE_JAX is set to False')


A__ :		Optional[Any]					=os.environ.get('USE_BEAM', 'AUTO').upper()
A__ :		Optional[Any]					='N/A'
A__ :		Optional[Any]					=False
if USE_BEAM in ENV_VARS_TRUE_AND_AUTO_VALUES:
     try:
          A__ :		List[Any]					=version.parse(importlib_metadata.version('apache_beam'))
          A__ :		str					=True
          logger.info(F"Apache Beam version {BEAM_VERSION} available.")
     except importlib_metadata.PackageNotFoundError:
          pass
else:
     logger.info('Disabling Apache Beam because USE_BEAM is set to False')


# Optional tools for data loading
A__ :		int					=importlib.util.find_spec('sqlalchemy') is not None

# Optional tools for feature decoding
A__ :		Optional[Any]					=importlib.util.find_spec('PIL') is not None
A__ :		Optional[Any]					=importlib.util.find_spec('soundfile') is not None and version.parse(
    importlib.import_module('soundfile').__libsndfile_version__
) >= version.parse('1.0.31')
A__ :		Union[str, Any]					=importlib.util.find_spec('soundfile') is not None and version.parse(
    importlib.import_module('soundfile').__libsndfile_version__
) >= version.parse('1.1.0')

# Optional compression tools
A__ :		Tuple					=importlib.util.find_spec('rarfile') is not None
A__ :		List[Any]					=importlib.util.find_spec('zstandard') is not None
A__ :		Dict					=importlib.util.find_spec('lz4') is not None
A__ :		Optional[int]					=importlib.util.find_spec('py7zr') is not None


# Cache location
A__ :		Optional[int]					='~/.cache'
A__ :		int					=os.getenv('XDG_CACHE_HOME', DEFAULT_XDG_CACHE_HOME)
A__ :		Any					=os.path.join(XDG_CACHE_HOME, 'huggingface')
A__ :		Optional[int]					=os.path.expanduser(os.getenv('HF_HOME', DEFAULT_HF_CACHE_HOME))

A__ :		Optional[Any]					=os.path.join(HF_CACHE_HOME, 'datasets')
A__ :		List[Any]					=Path(os.getenv('HF_DATASETS_CACHE', DEFAULT_HF_DATASETS_CACHE))

A__ :		Any					=os.path.join(HF_CACHE_HOME, 'metrics')
A__ :		str					=Path(os.getenv('HF_METRICS_CACHE', DEFAULT_HF_METRICS_CACHE))

A__ :		List[str]					=os.path.join(HF_CACHE_HOME, 'modules')
A__ :		Tuple					=Path(os.getenv('HF_MODULES_CACHE', DEFAULT_HF_MODULES_CACHE))

A__ :		Any					='downloads'
A__ :		Optional[int]					=os.path.join(HF_DATASETS_CACHE, DOWNLOADED_DATASETS_DIR)
A__ :		Union[str, Any]					=Path(os.getenv('HF_DATASETS_DOWNLOADED_DATASETS_PATH', DEFAULT_DOWNLOADED_DATASETS_PATH))

A__ :		Any					='extracted'
A__ :		List[Any]					=os.path.join(DEFAULT_DOWNLOADED_DATASETS_PATH, EXTRACTED_DATASETS_DIR)
A__ :		List[str]					=Path(os.getenv('HF_DATASETS_EXTRACTED_DATASETS_PATH', DEFAULT_EXTRACTED_DATASETS_PATH))

# Download count for the website
A__ :		Any					=(
    os.environ.get('HF_UPDATE_DOWNLOAD_COUNTS', 'AUTO').upper() in ENV_VARS_TRUE_AND_AUTO_VALUES
)

# Batch size constants. For more info, see:
# https://github.com/apache/arrow/blob/master/docs/source/cpp/arrays.rst#size-limitations-and-recommendations)
A__ :		List[str]					=1_000

# Size of the preloaded record batch in `Dataset.__iter__`
A__ :		Optional[Any]					=10

# Pickling tables works only for small tables (<4GiB)
# For big tables, we write them on disk instead
A__ :		Optional[Any]					=4 << 30

# Max shard size in bytes (e.g. to shard parquet datasets in push_to_hub or download_and_prepare)
A__ :		List[Any]					='500MB'

# Parquet configuration
A__ :		Tuple					=100
A__ :		Optional[Any]					=100
A__ :		Optional[Any]					=100

# Offline mode
A__ :		Union[str, Any]					=os.environ.get('HF_DATASETS_OFFLINE', 'AUTO').upper() in ENV_VARS_TRUE_VALUES

# In-memory
A__ :		Union[str, Any]					=0  # Disabled
A__ :		Dict					=float(os.environ.get('HF_DATASETS_IN_MEMORY_MAX_SIZE', DEFAULT_IN_MEMORY_MAX_SIZE))

# File names
A__ :		List[str]					='dataset.arrow'
A__ :		Dict					='indices.arrow'
A__ :		List[Any]					='state.json'
A__ :		List[str]					='dataset_info.json'
A__ :		Optional[int]					='dataset_infos.json'
A__ :		List[str]					='LICENSE'
A__ :		Union[str, Any]					='metric_info.json'
A__ :		Dict					='dataset_dict.json'

A__ :		Any					='datasets_modules'

A__ :		Optional[Any]					=255

# Streaming
A__ :		List[str]					=20
A__ :		Optional[Any]					=5

# Datasets without script
A__ :		Tuple					=200
A__ :		str					=10
A__ :		Optional[Any]					=200

# Progress bars
A__ :		List[str]					=0.0_5  # 20 progress updates per sec






"""simple docstring"""






from manim import *
class 	_lowerCAmelCase    (      __snake_case       ):

							def 					_lowerCAmelCase  ( self       :    Dict    )   ->    Tuple:

									"""simple docstring"""
									lowercase										=							Rectangle(height=0.5 ,		width=0.5    )
									lowercase										=							Rectangle(height=0.46 ,		width=0.46    ).set_stroke(width=0    )
									lowercase										=							Rectangle(height=0.25 ,		width=0.25    )

									lowercase										=							[mem.copy() for i in range(6    )]
									lowercase										=							[mem.copy() for i in range(6    )]
									lowercase										=							VGroup(*a    ).arrange(a ,		buff=0    )
									lowercase										=							VGroup(*a    ).arrange(a ,		buff=0    )
									lowercase										=							VGroup(a ,		a    ).arrange(a ,		buff=0    )
									lowercase										=							Text('''CPU''' ,		font_size=24    )
									lowercase										=							Group(a ,		a    ).arrange(a ,		buff=0.5 ,		aligned_edge=a    )
									cpu.move_to([-2.5, -0.5, 0]    )
									self.add(a    )

									lowercase										=							[mem.copy() for i in range(4    )]
									lowercase										=							VGroup(*a    ).arrange(a ,		buff=0    )
									lowercase										=							Text('''GPU''' ,		font_size=24    )
									lowercase										=							Group(a ,		a    ).arrange(a ,		buff=0.5 ,		aligned_edge=a    )
									gpu.move_to([-1, -1, 0]    )
									self.add(a    )

									lowercase										=							[mem.copy() for i in range(6    )]
									lowercase										=							VGroup(*a    ).arrange(a ,		buff=0    )

									lowercase										=							Text('''Model''' ,		font_size=24    )
									lowercase										=							Group(a ,		a    ).arrange(a ,		buff=0.5 ,		aligned_edge=a    )
									model.move_to([3, -1.0, 0]    )
									self.add(a    )

									lowercase										=							[]
									lowercase										=							[]

									for i, rect in enumerate(a    ):
											rect.set_stroke(a    )

											lowercase										=							Rectangle(height=0.46 / 4 ,		width=0.46 / 3    ).set_stroke(width=0.0    ).set_fill(a ,		opacity=0.7    )

											if i == 0:
													cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT    ) ,		buff=0.02 ,		direction=a    )
													cpu_target.set_x(cpu_target.get_x() + 0.1    )
											elif i == 3:
													cpu_target.next_to(model_cpu_arr[0] ,		direction=a ,		buff=0.0    )
											else:
													cpu_target.next_to(model_cpu_arr[i - 1] ,		direction=a ,		buff=0.0    )
											self.add(a    )
											model_cpu_arr.append(a    )

									self.add(*a ,		*a    )

									lowercase										=							[meta_mem.copy() for i in range(6    )]
									lowercase										=							[meta_mem.copy() for i in range(6    )]
									lowercase										=							VGroup(*a    ).arrange(a ,		buff=0    )
									lowercase										=							VGroup(*a    ).arrange(a ,		buff=0    )
									lowercase										=							VGroup(a ,		a    ).arrange(a ,		buff=0    )
									lowercase										=							Text('''Disk''' ,		font_size=24    )
									lowercase										=							Group(a ,		a    ).arrange(a ,		buff=0.5 ,		aligned_edge=a    )
									disk.move_to([-4.0, -1.25, 0]    )
									self.add(a ,		a    )

									lowercase										=							[]

									for i in range(6    ):
											lowercase										=							fill.copy().set_fill(a ,		opacity=0.8    )
											target.move_to(disk_left_col_base[i]    ).scale(0.5    )
											cpu_disk_arr.append(a    )

									self.add(*a    )

									lowercase										=							Square(side_length=2.2    )
									key.move_to([-5, 2, 0]    )

									lowercase										=							MarkupText(
									    f"""<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model""" ,		font_size=18 ,		)

									key_text.move_to([-5, 2.4, 0]    )

									self.add(a ,		a    )

									lowercase										=							MarkupText(
									    f"""<span fgcolor='{BLUE}'>●</span> Checkpoint""" ,		font_size=18 ,		)

									blue_text.next_to(a ,		DOWN * 2.4 ,		aligned_edge=key_text.get_left()    )
									self.add(a    )

									lowercase										=							MarkupText(f"""The offloaded weights are all sent to the CPU.""" ,		font_size=24    )
									step_a.move_to([2, 2, 0]    )

									self.play(Write(a ,		run_time=3    )    )

									for i in range(6    ):
											lowercase										=							cpu_disk_arr[i]
											lowercase										=							rect.copy().set_fill(a ,		opacity=0.8    ).scale(2.0    )
											cpa.generate_target()
											cpa.target.move_to(model_base[i]    )

											if i == 0:
													rect.set_fill(a ,		opacity=0.8    )
													rect.generate_target()
													rect.target.move_to(cpu_left_col_base[0]    ).scale(2.0    )

													self.remove(
													    *a ,		*a ,		)

											else:
													rect.generate_target()
													rect.target.move_to(cpu_left_col_base[i]    ).scale(2.0    )
											self.play(MoveToTarget(a    ) ,		MoveToTarget(a    ) ,		model_base[i].animate.set_stroke(a    )    )
									self.play(FadeOut(a    )    )

									lowercase										=							MarkupText(
									    f"""Finally, hooks are added to each weight in the model\nto transfer the weights from CPU to GPU\n\t\tand back when needed.""" ,		font_size=24 ,		)
									step_a.move_to([2, 2, 0]    )

									self.play(Write(a ,		run_time=3    )    )

									lowercase										=							[]
									lowercase										=							[]
									for i in range(6    ):
											lowercase										=							Arrow(start=a ,		end=a ,		color=a ,		buff=0.5    )
											a.next_to(model_base[i].get_left() ,		a ,		buff=0.2    )
											arrows.append(a    )
											animations.append(Write(a    )    )
									self.play(*a    )
									self.wait()