


'''simple docstring'''



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


_lowercase     :     Dict        =	logging.get_logger(__name__)






@dataclass
class 			UpperCamelCase__:




				def __init__(						self     :					Optional[Any] ,       lowerCAmelCase     :					Any=False ,       lowerCAmelCase     :					str=False ,       lowerCAmelCase     :					int=6.0 ,       lowerCAmelCase     :					int=None ,       lowerCAmelCase     :					Any=False ,       lowerCAmelCase     :					int=False ,       lowerCAmelCase     :					List[Any]=None ,       lowerCAmelCase     :					List[str]="fp4" ,       lowerCAmelCase     :					Tuple=False ,       **lowerCAmelCase     :					Any ,       )->	Union[str, Any]:

										"""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(UpperCamelCase__ ,       UpperCamelCase__ ):
																UpperCAmelCase								=      getattr(UpperCamelCase__ ,       UpperCamelCase__ )
										elif isinstance(UpperCamelCase__ ,       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 	a__(						self     :					Dict )->	Union[str, Any]:

										"""simple docstring"""




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

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

										if not isinstance(self.bnb_abit_use_double_quant ,       UpperCamelCase__ ):
																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 	a__(						self     :					Dict )->	Dict:

										"""simple docstring"""




										return self.load_in_abit or self.load_in_abit




				def 	a__(						self     :					Optional[Any] )->	Dict:

										"""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 	a__(						cls     :					Any ,       lowerCAmelCase     :					Union[str, Any] ,       lowerCAmelCase     :					Union[str, Any] ,       **lowerCAmelCase     :					Any )->	Optional[int]:

										"""simple docstring"""




										UpperCAmelCase								=      cls(**UpperCamelCase__ )

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

										if return_unused_kwargs:
																return config, kwargs
										else:
																return config




				def 	a__(						self     :					int ,       lowerCAmelCase     :					str )->	Tuple:

										"""simple docstring"""




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

																writer.write(UpperCamelCase__ )




				def 	a__(						self     :					List[str] )->	Dict[str, Any]:

										"""simple docstring"""




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

										return output




				def __repr__(						self     :					Optional[int] )->	int:

										"""simple docstring"""




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




				def 	a__(						self     :					Dict ,       lowerCAmelCase     :					List[Any] = True )->	str:

										"""simple docstring"""




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





				def 	a__(						self     :					Tuple )->	Dict[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








'''simple docstring'''







from ...configuration_utils import PretrainedConfig


class        A__   (   _snake_case      ):
    lowercase						       =		"bert-generation"



    def __init__(       self		,					UpperCamelCase__=50358		,					UpperCamelCase__=1024		,					UpperCamelCase__=24		,					UpperCamelCase__=16		,					UpperCamelCase__=4096		,					UpperCamelCase__="gelu"		,					UpperCamelCase__=0.1		,					UpperCamelCase__=0.1		,					UpperCamelCase__=512		,					UpperCamelCase__=0.02		,					UpperCamelCase__=1e-1_2		,					UpperCamelCase__=0		,					UpperCamelCase__=2		,					UpperCamelCase__=1		,					UpperCamelCase__="absolute"		,					UpperCamelCase__=True		,					**UpperCamelCase__		,					)    ->   Any:





           '''simple docstring'''
           super().__init__(pad_token_id=UpperCamelCase__		,					bos_token_id=UpperCamelCase__		,					eos_token_id=UpperCamelCase__		,					**UpperCamelCase__							)

           A_						       =   vocab_size
           A_						       =   hidden_size
           A_						       =   num_hidden_layers
           A_						       =   num_attention_heads
           A_						       =   hidden_act
           A_						       =   intermediate_size
           A_						       =   hidden_dropout_prob
           A_						       =   attention_probs_dropout_prob
           A_						       =   max_position_embeddings
           A_						       =   initializer_range
           A_						       =   layer_norm_eps
           A_						       =   position_embedding_type
           A_						       =   use_cache
