


# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import importlib.metadata
import json
import os
from dataclasses import dataclass
from typing import Any, Dict, Union

from packaging import version

from ..utils import is_torch_available, logging


if is_torch_available():
    import torch


__snake_case   							=						logging.get_logger(__name__)



@dataclass
class 	__lowerCamelCase			:







       def __init__(			self: Dict,A_: Dict=False,A_: int=False,A_: Optional[int]=6.0,A_: Tuple=None,A_: Any=False,A_: Union[str, Any]=False,A_: Tuple=None,A_: Union[str, Any]="fp4",A_: Optional[int]=False,**A_: str,):






            '''simple docstring'''




            __UpperCamelCase =			load_in_abit
            __UpperCamelCase =			load_in_abit
            __UpperCamelCase =			llm_inta_threshold
            __UpperCamelCase =			llm_inta_skip_modules
            __UpperCamelCase =			llm_inta_enable_fpaa_cpu_offload
            __UpperCamelCase =			llm_inta_has_fpaa_weight
            __UpperCamelCase =			bnb_abit_quant_type
            __UpperCamelCase =			bnb_abit_use_double_quant

            if bnb_abit_compute_dtype is None:
                 __UpperCamelCase =			torch.floataa
            elif isinstance(A_,A_					):
                 __UpperCamelCase =			getattr(A_,A_					)
            elif isinstance(A_,torch.dtype					):
                 __UpperCamelCase =			bnb_abit_compute_dtype
            else:
                 raise ValueError('bnb_4bit_compute_dtype must be a string or a torch.dtype'					)

            self.post_init()







       def 		snake_case_	(			self: List[str]					):






            '''simple docstring'''




            if not isinstance(self.llm_inta_threshold,A_					):
                 raise ValueError('llm_int8_threshold must be a float'					)

            if self.llm_inta_skip_modules is not None and not isinstance(self.llm_inta_skip_modules,A_					):
                 raise ValueError('llm_int8_skip_modules must be a list of strings'					)
            if not isinstance(self.llm_inta_enable_fpaa_cpu_offload,A_					):
                 raise ValueError('llm_int8_enable_fp32_cpu_offload must be a boolean'					)

            if not isinstance(self.llm_inta_has_fpaa_weight,A_					):
                 raise ValueError('llm_int8_has_fp16_weight must be a boolean'					)

            if self.bnb_abit_compute_dtype is not None and not isinstance(self.bnb_abit_compute_dtype,torch.dtype					):
                 raise ValueError('bnb_4bit_compute_dtype must be torch.dtype'					)

            if not isinstance(self.bnb_abit_quant_type,A_					):
                 raise ValueError('bnb_4bit_quant_type must be a string'					)

            if not isinstance(self.bnb_abit_use_double_quant,A_					):
                 raise ValueError('bnb_4bit_use_double_quant must be a boolean'					)

            if self.load_in_abit and not version.parse(importlib.metadata.version('bitsandbytes'					)					) >= version.parse(
                '0.39.0'					):
                 raise ValueError(
                     '4 bit quantization requires bitsandbytes>=0.39.0 - please upgrade your bitsandbytes version'					)







       def 		snake_case_	(			self: Dict					):






            '''simple docstring'''




            return self.load_in_abit or self.load_in_abit







       def 		snake_case_	(			self: int					):






            '''simple docstring'''




            if self.load_in_abit:
                 return "llm_int8"
            elif self.load_in_abit and self.bnb_abit_quant_type == "fp4":
                 return "fp4"
            elif self.load_in_abit and self.bnb_abit_quant_type == "nf4":
                 return "nf4"
            else:
                 return None







       @classmethod
       def 		snake_case_	(			cls: str,A_: Optional[Any],A_: Optional[int],**A_: Optional[Any]					):






            '''simple docstring'''




            __UpperCamelCase =			cls(**A_					)

            __UpperCamelCase =			[]
            for key, value in kwargs.items():
                 if hasattr(A_,A_					):
                      setattr(A_,A_,A_					)
                      to_remove.append(A_					)
            for key in to_remove:
                 kwargs.pop(A_,A_					)

            if return_unused_kwargs:
                 return config, kwargs
            else:
                 return config







       def 		snake_case_	(			self: Dict,A_: Union[str, os.PathLike]					):






            '''simple docstring'''




            with open(A_,'w',encoding='utf-8'					) as writer:
                 __UpperCamelCase =			self.to_dict()
                 __UpperCamelCase =			json.dumps(A_,indent=2,sort_keys=A_					) + '\n'

                 writer.write(A_					)







       def 		snake_case_	(			self: str					):






            '''simple docstring'''




            __UpperCamelCase =			copy.deepcopy(self.__dict__					)
            __UpperCamelCase =			str(output['bnb_4bit_compute_dtype']					).split('.'					)[1]

            return output







       def __repr__(			self: Dict					):






            '''simple docstring'''




            return F'''{self.__class__.__name__} {self.to_json_string()}'''







       def 		snake_case_	(			self: Optional[Any],A_: bool = True					):






            '''simple docstring'''




            if use_diff is True:
                 __UpperCamelCase =			self.to_diff_dict()
            else:
                 __UpperCamelCase =			self.to_dict()
            return json.dumps(A_,indent=2,sort_keys=A_					) + "\n"







       def 		snake_case_	(			self: Union[str, Any]					):






            '''simple docstring'''




            __UpperCamelCase =			self.to_dict()

            # get the default config dict
            __UpperCamelCase =			BitsAndBytesConfig().to_dict()

            __UpperCamelCase =			{}

            # only serialize values that differ from the default config
            for key, value in config_dict.items():
                 if value != default_config_dict[key]:
                      __UpperCamelCase =			value

            return serializable_config_dict








# Lint as: python3
# pylint: enable=line-too-long
# pylint: disable=g-import-not-at-top,g-bad-import-order,wrong-import-position

__a							     =					'2.13.1'

import platform

import pyarrow
from packaging import version


if version.parse(platform.python_version()) < version.parse('3.7'):
     raise ImportWarning(
         'To use `datasets`, Python>=3.7 is required, and the current version of Python doesn\'t match this condition.'
     )

if version.parse(pyarrow.__version__).major < 8:
     raise ImportWarning(
         'To use `datasets`, the module `pyarrow>=8.0.0` is required, and the current version of `pyarrow` doesn\'t match this condition.\n'
         'If you are running this in a Google Colab, you should probably just restart the runtime to use the right version of `pyarrow`.'
     )

del platform
del pyarrow
del version

from .arrow_dataset import Dataset
from .arrow_reader import ReadInstruction
from .builder import ArrowBasedBuilder, BeamBasedBuilder, BuilderConfig, DatasetBuilder, GeneratorBasedBuilder
from .combine import concatenate_datasets, interleave_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .download import *
from .features import *
from .fingerprint import disable_caching, enable_caching, is_caching_enabled, set_caching_enabled
from .info import DatasetInfo, MetricInfo
from .inspect import (
    get_dataset_config_info,
    get_dataset_config_names,
    get_dataset_infos,
    get_dataset_split_names,
    inspect_dataset,
    inspect_metric,
    list_datasets,
    list_metrics,
)
from .iterable_dataset import IterableDataset
from .load import load_dataset, load_dataset_builder, load_from_disk, load_metric
from .metric import Metric
from .splits import (
    NamedSplit,
    NamedSplitAll,
    Split,
    SplitBase,
    SplitDict,
    SplitGenerator,
    SplitInfo,
    SubSplitInfo,
    percent,
)
from .tasks import *
from .utils import *
from .utils import logging


# deprecated modules
from datasets import arrow_dataset as _arrow_dataset  # isort:skip
from datasets import utils as _utils  # isort:skip
from datasets.utils import download_manager as _deprecated_download_manager  # isort:skip

__a							     =					concatenate_datasets
__a							     =					DownloadConfig
__a							     =					DownloadManager
__a							     =					DownloadMode
__a							     =					DownloadConfig
__a							     =					DownloadMode
__a							     =					DownloadManager

del _arrow_dataset, _utils, _deprecated_download_manager