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


lowerCAmelCase__     						=			logging.get_logger(__name__)
@dataclass
class     a_			:






    '''simple docstring'''






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







           '''simple docstring'''



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

           if bnb_abit_compute_dtype is None:
                  lowerCAmelCase__					     = torch.floataa
           elif isinstance(lowerCAmelCase__      ,   lowerCAmelCase__):
                  lowerCAmelCase__					     = getattr(lowerCAmelCase__      ,   lowerCAmelCase__)
           elif isinstance(lowerCAmelCase__      ,   torch.dtype):
                  lowerCAmelCase__					     = 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 :  Optional[Any]):







           '''simple docstring'''



           if not isinstance(self.llm_inta_threshold      ,   lowerCAmelCase__):
                  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      ,   lowerCAmelCase__):
                  raise ValueError('llm_int8_skip_modules must be a list of strings')
           if not isinstance(self.llm_inta_enable_fpaa_cpu_offload      ,   lowerCAmelCase__):
                  raise ValueError('llm_int8_enable_fp32_cpu_offload must be a boolean')

           if not isinstance(self.llm_inta_has_fpaa_weight      ,   lowerCAmelCase__):
                  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      ,   lowerCAmelCase__):
                  raise ValueError('bnb_4bit_quant_type must be a string')

           if not isinstance(self.bnb_abit_use_double_quant      ,   lowerCAmelCase__):
                  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 :  Tuple):







           '''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 :  int      ,   lowercase__ :  Dict      ,   lowercase__ :  str      ,   **lowercase__ :  Optional[Any]):







           '''simple docstring'''



           lowerCAmelCase__					     = cls(**lowerCAmelCase__)

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

           if return_unused_kwargs:
                  return config, kwargs
           else:
                  return config




    def 		__snake_case						(      self :  int      ,   lowercase__ :  str):







           '''simple docstring'''



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

                  writer.write(lowerCAmelCase__)




    def 		__snake_case						(      self :  List[str]):







           '''simple docstring'''



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

           return output




    def __repr__(      self :  Optional[Any]):







           '''simple docstring'''



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




    def 		__snake_case						(      self :  Dict      ,   lowercase__ :  Any = True):







           '''simple docstring'''



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




    def 		__snake_case						(      self :  str):







           '''simple docstring'''



           lowerCAmelCase__					     = self.to_dict()

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

           lowerCAmelCase__					     = {}

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

           return serializable_config_dict

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


lowerCAmelCase__     						=			{
    'configuration_transfo_xl': ['TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TransfoXLConfig'],
    'tokenization_transfo_xl': ['TransfoXLCorpus', 'TransfoXLTokenizer'],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__     						=			[
        'TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
        'AdaptiveEmbedding',
        'TransfoXLForSequenceClassification',
        'TransfoXLLMHeadModel',
        'TransfoXLModel',
        'TransfoXLPreTrainedModel',
        'load_tf_weights_in_transfo_xl',
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__     						=			[
        'TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
        'TFAdaptiveEmbedding',
        'TFTransfoXLForSequenceClassification',
        'TFTransfoXLLMHeadModel',
        'TFTransfoXLMainLayer',
        'TFTransfoXLModel',
        'TFTransfoXLPreTrainedModel',
    ]


if TYPE_CHECKING:
    from .configuration_transfo_xl import TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP, TransfoXLConfig
    from .tokenization_transfo_xl import TransfoXLCorpus, TransfoXLTokenizer

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_transfo_xl import (
            TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
            AdaptiveEmbedding,
            TransfoXLForSequenceClassification,
            TransfoXLLMHeadModel,
            TransfoXLModel,
            TransfoXLPreTrainedModel,
            load_tf_weights_in_transfo_xl,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_transfo_xl import (
            TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
            TFAdaptiveEmbedding,
            TFTransfoXLForSequenceClassification,
            TFTransfoXLLMHeadModel,
            TFTransfoXLMainLayer,
            TFTransfoXLModel,
            TFTransfoXLPreTrainedModel,
        )

else:
    import sys

    lowerCAmelCase__     						=			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
