






# 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


_UpperCAmelCase			:		str   				=    logging.get_logger(__name__)
@dataclass
class  lowerCAmelCase_       :




							def __init__(   self     :   str ,							SCREAMING_SNAKE_CASE_     :   List[str]=False ,							SCREAMING_SNAKE_CASE_     :   str=False ,							SCREAMING_SNAKE_CASE_     :   Optional[int]=6.0 ,							SCREAMING_SNAKE_CASE_     :   List[str]=None ,							SCREAMING_SNAKE_CASE_     :   List[str]=False ,							SCREAMING_SNAKE_CASE_     :   Dict=False ,							SCREAMING_SNAKE_CASE_     :   int=None ,							SCREAMING_SNAKE_CASE_     :   Any="fp4" ,							SCREAMING_SNAKE_CASE_     :   Dict=False ,							**SCREAMING_SNAKE_CASE_     :   List[Any] ,							):
											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(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	):
															lowerCAmelCase__      			=						getattr(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)
											elif isinstance(SCREAMING_SNAKE_CASE_ ,							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     :   str	):
											if not isinstance(self.llm_inta_threshold ,							SCREAMING_SNAKE_CASE_	):
															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 ,							SCREAMING_SNAKE_CASE_	):
															raise ValueError('''llm_int8_skip_modules must be a list of strings'''	)
											if not isinstance(self.llm_inta_enable_fpaa_cpu_offload ,							SCREAMING_SNAKE_CASE_	):
															raise ValueError('''llm_int8_enable_fp32_cpu_offload must be a boolean'''	)

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

											if not isinstance(self.bnb_abit_use_double_quant ,							SCREAMING_SNAKE_CASE_	):
															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     :   Tuple	):
											return self.load_in_abit or self.load_in_abit




							def 						__snake_case					(   self     :   int	):
											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     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   List[Any] ,							**SCREAMING_SNAKE_CASE_     :   Any	):
											lowerCAmelCase__      			=						cls(**SCREAMING_SNAKE_CASE_	)

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

											if return_unused_kwargs:
															return config, kwargs
											else:
															return config




							def 						__snake_case					(   self     :   int ,							SCREAMING_SNAKE_CASE_     :   Union[str, os.PathLike]	):
											with open(SCREAMING_SNAKE_CASE_ ,							'''w''' ,							encoding='''utf-8'''	) as writer:
															lowerCAmelCase__      			=						self.to_dict()
															lowerCAmelCase__      			=						json.dumps(SCREAMING_SNAKE_CASE_ ,							indent=2 ,							sort_keys=SCREAMING_SNAKE_CASE_	) + '''\n'''

															writer.write(SCREAMING_SNAKE_CASE_	)




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

											return output




							def __repr__(   self     :   Optional[int]	):
											return f'{self.__class__.__name__} {self.to_json_string()}'




							def 						__snake_case					(   self     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   bool = True	):
											if use_diff is True:
															lowerCAmelCase__      			=						self.to_diff_dict()
											else:
															lowerCAmelCase__      			=						self.to_dict()
											return json.dumps(SCREAMING_SNAKE_CASE_ ,							indent=2 ,							sort_keys=SCREAMING_SNAKE_CASE_	) + "\n"




							def 						__snake_case					(   self     :   str	):
											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_torch_available


_UpperCAmelCase			:		int   				=    {
    "configuration_git": ["GIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "GitConfig", "GitVisionConfig"],
    "processing_git": ["GitProcessor"],
}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_UpperCAmelCase			:		Dict   				=    [
			    "GIT_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "GitForCausalLM",
			    "GitModel",
			    "GitPreTrainedModel",
			    "GitVisionModel",
			]

if TYPE_CHECKING:
			from .configuration_git import GIT_PRETRAINED_CONFIG_ARCHIVE_MAP, GitConfig, GitVisionConfig
			from .processing_git import GitProcessor

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_git import (
						    GIT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    GitForCausalLM,
						    GitModel,
						    GitPreTrainedModel,
						    GitVisionModel,
						)

else:
			import sys

			_UpperCAmelCase			:		Optional[int]   				=    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





