

'''simple docstring'''




import unittest

from transformers import MraConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_torch_available():
				import torch

				from transformers import (
				    MraForMaskedLM,
				    MraForMultipleChoice,
				    MraForQuestionAnswering,
				    MraForSequenceClassification,
				    MraForTokenClassification,
				    MraModel,
				)
				from transformers.models.mra.modeling_mra import MRA_PRETRAINED_MODEL_ARCHIVE_LIST

class     UpperCAmelCase_ :



	"""simple docstring"""





	def __init__(    self				,			lowerCamelCase				,			lowerCamelCase=2				,			lowerCamelCase=8				,			lowerCamelCase=True				,			lowerCamelCase=True				,			lowerCamelCase=True				,			lowerCamelCase=True				,			lowerCamelCase=99				,			lowerCamelCase=16				,			lowerCamelCase=5				,			lowerCamelCase=2				,			lowerCamelCase=36				,			lowerCamelCase="gelu"				,			lowerCamelCase=0.0				,			lowerCamelCase=0.0				,			lowerCamelCase=5_12				,			lowerCamelCase=16				,			lowerCamelCase=2				,			lowerCamelCase=0.02				,			lowerCamelCase=3				,			lowerCamelCase=4				,			lowerCamelCase=None				,			)							->     Tuple:




				'''simple docstring'''






				UpperCamelCase				:	Optional[int]    						=					parent
				UpperCamelCase				:	Optional[Any]    						=					batch_size
				UpperCamelCase				:	str    						=					seq_length
				UpperCamelCase				:	List[Any]    						=					is_training
				UpperCamelCase				:	Optional[int]    						=					use_input_mask
				UpperCamelCase				:	Optional[int]    						=					use_token_type_ids
				UpperCamelCase				:	Dict    						=					use_labels
				UpperCamelCase				:	Union[str, Any]    						=					vocab_size
				UpperCamelCase				:	Any    						=					hidden_size
				UpperCamelCase				:	Tuple    						=					num_hidden_layers
				UpperCamelCase				:	Optional[int]    						=					num_attention_heads
				UpperCamelCase				:	Union[str, Any]    						=					intermediate_size
				UpperCamelCase				:	Dict    						=					hidden_act
				UpperCamelCase				:	List[Any]    						=					hidden_dropout_prob
				UpperCamelCase				:	List[Any]    						=					attention_probs_dropout_prob
				UpperCamelCase				:	Union[str, Any]    						=					max_position_embeddings
				UpperCamelCase				:	List[Any]    						=					type_vocab_size
				UpperCamelCase				:	Any    						=					type_sequence_label_size
				UpperCamelCase				:	Tuple    						=					initializer_range
				UpperCamelCase				:	int    						=					num_labels
				UpperCamelCase				:	Optional[int]    						=					num_choices
				UpperCamelCase				:	Dict    						=					scope

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Dict:




				'''simple docstring'''






				UpperCamelCase				:	str    						=					ids_tensor([self.batch_size, self.seq_length]				,			self.vocab_size   )

				UpperCamelCase				:	List[Any]    						=					None
				if self.use_input_mask:
							UpperCamelCase				:	Union[str, Any]    						=					random_attention_mask([self.batch_size, self.seq_length]   )

				UpperCamelCase				:	str    						=					None
				if self.use_token_type_ids:
							UpperCamelCase				:	Optional[Any]    						=					ids_tensor([self.batch_size, self.seq_length]				,			self.type_vocab_size   )

				UpperCamelCase				:	Dict    						=					None
				UpperCamelCase				:	Tuple    						=					None
				UpperCamelCase				:	str    						=					None
				if self.use_labels:
							UpperCamelCase				:	Any    						=					ids_tensor([self.batch_size]				,			self.type_sequence_label_size   )
							UpperCamelCase				:	List[Any]    						=					ids_tensor([self.batch_size, self.seq_length]				,			self.num_labels   )
							UpperCamelCase				:	Tuple    						=					ids_tensor([self.batch_size]				,			self.num_choices   )

				UpperCamelCase				:	Optional[int]    						=					self.get_config()

				return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Tuple:




				'''simple docstring'''






				return MraConfig(
				    vocab_size=self.vocab_size				,			hidden_size=self.hidden_size				,			num_hidden_layers=self.num_hidden_layers				,			num_attention_heads=self.num_attention_heads				,			intermediate_size=self.intermediate_size				,			hidden_act=self.hidden_act				,			hidden_dropout_prob=self.hidden_dropout_prob				,			attention_probs_dropout_prob=self.attention_probs_dropout_prob				,			max_position_embeddings=self.max_position_embeddings				,			type_vocab_size=self.type_vocab_size				,			is_decoder=lowerCAmelCase__				,			initializer_range=self.initializer_range				,			)

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Union[str, Any]:




				'''simple docstring'''






				UpperCamelCase				:	Optional[int]    						=					self.get_config()
				UpperCamelCase				:	Optional[int]    						=					3_00
				return config

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     List[Any]:




				'''simple docstring'''






				(
				    (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   	
				)				:	int    						=					self.prepare_config_and_inputs()

				UpperCamelCase				:	Any    						=					True
				UpperCamelCase				:	Optional[int]    						=					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]   )
				UpperCamelCase				:	Optional[int]    						=					ids_tensor([self.batch_size, self.seq_length]				,			vocab_size=2   )

				return (
				    config,
				    input_ids,
				    token_type_ids,
				    input_mask,
				    sequence_labels,
				    token_labels,
				    choice_labels,
				    encoder_hidden_states,
				    encoder_attention_mask,
				)

	def 	SCREAMING_SNAKE_CASE__							(    self				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase   )							->     List[Any]:




				'''simple docstring'''






				UpperCamelCase				:	Dict    						=					MraModel(config=lowerCAmelCase__   )
				model.to(lowerCAmelCase__   )
				model.eval()
				UpperCamelCase				:	Optional[Any]    						=					model(lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__   )
				UpperCamelCase				:	Optional[int]    						=					model(lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__   )
				UpperCamelCase				:	Any    						=					model(lowerCAmelCase__   )
				self.parent.assertEqual(result.last_hidden_state.shape				,			(self.batch_size, self.seq_length, self.hidden_size)   )

	def 	SCREAMING_SNAKE_CASE__							(    self				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			)							->     List[Any]:




				'''simple docstring'''






				UpperCamelCase				:	Optional[int]    						=					True
				UpperCamelCase				:	Any    						=					MraModel(lowerCAmelCase__   )
				model.to(lowerCAmelCase__   )
				model.eval()
				UpperCamelCase				:	Optional[int]    						=					model(
				    lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__				,			encoder_hidden_states=lowerCAmelCase__				,			encoder_attention_mask=lowerCAmelCase__				,			)
				UpperCamelCase				:	str    						=					model(
				    lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__				,			encoder_hidden_states=lowerCAmelCase__				,			)
				UpperCamelCase				:	Any    						=					model(lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__   )
				self.parent.assertEqual(result.last_hidden_state.shape				,			(self.batch_size, self.seq_length, self.hidden_size)   )

	def 	SCREAMING_SNAKE_CASE__							(    self				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase   )							->     List[Any]:




				'''simple docstring'''






				UpperCamelCase				:	List[Any]    						=					MraForMaskedLM(config=lowerCAmelCase__   )
				model.to(lowerCAmelCase__   )
				model.eval()
				UpperCamelCase				:	Any    						=					model(lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__				,			labels=lowerCAmelCase__   )
				self.parent.assertEqual(result.logits.shape				,			(self.batch_size, self.seq_length, self.vocab_size)   )

	def 	SCREAMING_SNAKE_CASE__							(    self				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase   )							->     List[str]:




				'''simple docstring'''






				UpperCamelCase				:	Optional[Any]    						=					MraForQuestionAnswering(config=lowerCAmelCase__   )
				model.to(lowerCAmelCase__   )
				model.eval()
				UpperCamelCase				:	List[str]    						=					model(
				    lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__				,			start_positions=lowerCAmelCase__				,			end_positions=lowerCAmelCase__				,			)
				self.parent.assertEqual(result.start_logits.shape				,			(self.batch_size, self.seq_length)   )
				self.parent.assertEqual(result.end_logits.shape				,			(self.batch_size, self.seq_length)   )

	def 	SCREAMING_SNAKE_CASE__							(    self				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase   )							->     List[Any]:




				'''simple docstring'''






				UpperCamelCase				:	int    						=					self.num_labels
				UpperCamelCase				:	Any    						=					MraForSequenceClassification(lowerCAmelCase__   )
				model.to(lowerCAmelCase__   )
				model.eval()
				UpperCamelCase				:	Dict    						=					model(lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__				,			labels=lowerCAmelCase__   )
				self.parent.assertEqual(result.logits.shape				,			(self.batch_size, self.num_labels)   )

	def 	SCREAMING_SNAKE_CASE__							(    self				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase   )							->     Tuple:




				'''simple docstring'''






				UpperCamelCase				:	Optional[int]    						=					self.num_labels
				UpperCamelCase				:	List[Any]    						=					MraForTokenClassification(config=lowerCAmelCase__   )
				model.to(lowerCAmelCase__   )
				model.eval()
				UpperCamelCase				:	List[Any]    						=					model(lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__				,			labels=lowerCAmelCase__   )
				self.parent.assertEqual(result.logits.shape				,			(self.batch_size, self.seq_length, self.num_labels)   )

	def 	SCREAMING_SNAKE_CASE__							(    self				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase   )							->     Any:




				'''simple docstring'''






				UpperCamelCase				:	List[Any]    						=					self.num_choices
				UpperCamelCase				:	Any    						=					MraForMultipleChoice(config=lowerCAmelCase__   )
				model.to(lowerCAmelCase__   )
				model.eval()
				UpperCamelCase				:	str    						=					input_ids.unsqueeze(1   ).expand(-1				,			self.num_choices				,			-1   ).contiguous()
				UpperCamelCase				:	Dict    						=					token_type_ids.unsqueeze(1   ).expand(-1				,			self.num_choices				,			-1   ).contiguous()
				UpperCamelCase				:	Optional[Any]    						=					input_mask.unsqueeze(1   ).expand(-1				,			self.num_choices				,			-1   ).contiguous()
				UpperCamelCase				:	List[str]    						=					model(
				    lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__				,			labels=lowerCAmelCase__				,			)
				self.parent.assertEqual(result.logits.shape				,			(self.batch_size, self.num_choices)   )



	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     List[Any]:




				'''simple docstring'''






				UpperCamelCase				:	str    						=					self.prepare_config_and_inputs()
				(
				    (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   (
				    UpperCamelCase	
				)						,   	
				)				:	int    						=					config_and_inputs
				UpperCamelCase				:	List[Any]    						=					{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
				return config, inputs_dict

@require_torch
class     UpperCAmelCase_ (	__a				,	unittest.TestCase    ):



	"""simple docstring"""





	__SCREAMING_SNAKE_CASE					=       (
	    (
	        MraModel,
	        MraForMaskedLM,
	        MraForMultipleChoice,
	        MraForQuestionAnswering,
	        MraForSequenceClassification,
	        MraForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	__SCREAMING_SNAKE_CASE					=       False
	__SCREAMING_SNAKE_CASE					=       False
	__SCREAMING_SNAKE_CASE					=       False
	__SCREAMING_SNAKE_CASE					=       False

	__SCREAMING_SNAKE_CASE					=       ()

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     List[Any]:




				'''simple docstring'''






				UpperCamelCase				:	Any    						=					MraModelTester(self   )
				UpperCamelCase				:	int    						=					ConfigTester(self				,			config_class=lowerCAmelCase__				,			hidden_size=37   )

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     str:




				'''simple docstring'''






				self.config_tester.run_common_tests()

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Tuple:




				'''simple docstring'''






				UpperCamelCase				:	Optional[Any]    						=					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*lowerCAmelCase__   )

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Any:




				'''simple docstring'''






				UpperCamelCase				:	Optional[Any]    						=					self.model_tester.prepare_config_and_inputs()
				for type in ["absolute", "relative_key", "relative_key_query"]:
							UpperCamelCase				:	List[Any]    						=					type
							self.model_tester.create_and_check_model(*lowerCAmelCase__   )

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




				'''simple docstring'''






				UpperCamelCase				:	Optional[Any]    						=					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase__   )

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Union[str, Any]:




				'''simple docstring'''






				UpperCamelCase				:	List[Any]    						=					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase__   )

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     str:




				'''simple docstring'''






				UpperCamelCase				:	Union[str, Any]    						=					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__   )

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Any:




				'''simple docstring'''






				UpperCamelCase				:	List[Any]    						=					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__   )

	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     str:




				'''simple docstring'''






				UpperCamelCase				:	Union[str, Any]    						=					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__   )

	@slow
	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     int:




				'''simple docstring'''






				for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCamelCase				:	Union[str, Any]    						=					MraModel.from_pretrained(lowerCAmelCase__   )
							self.assertIsNotNone(lowerCAmelCase__   )



	@unittest.skip(reason="MRA does not output attentions"   )
	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Union[str, Any]:




				'''simple docstring'''






				return

@require_torch
class     UpperCAmelCase_ (	unittest.TestCase    ):



	"""simple docstring"""





	@slow
	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Dict:




				'''simple docstring'''






				UpperCamelCase				:	Optional[Any]    						=					MraModel.from_pretrained("uw-madison/mra-base-512-4"   )
				UpperCamelCase				:	List[Any]    						=					torch.arange(2_56   ).unsqueeze(0   )

				with torch.no_grad():
							UpperCamelCase				:	Optional[int]    						=					model(lowerCAmelCase__   )[0]

				UpperCamelCase				:	Optional[Any]    						=					torch.Size((1, 2_56, 7_68)   )
				self.assertEqual(output.shape				,			lowerCAmelCase__   )

				UpperCamelCase				:	Union[str, Any]    						=					torch.tensor(
				    [[[-0.0140, 0.0830, -0.0381], [0.1546, 0.1402, 0.0220], [0.1162, 0.0851, 0.0165]]]   )

				self.assertTrue(torch.allclose(output[:, :3, :3]				,			lowerCAmelCase__				,			atol=1e-4   )   )

	@slow
	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     List[str]:




				'''simple docstring'''






				UpperCamelCase				:	Optional[int]    						=					MraForMaskedLM.from_pretrained("uw-madison/mra-base-512-4"   )
				UpperCamelCase				:	List[str]    						=					torch.arange(2_56   ).unsqueeze(0   )

				with torch.no_grad():
							UpperCamelCase				:	Dict    						=					model(lowerCAmelCase__   )[0]

				UpperCamelCase				:	Any    						=					5_02_65

				UpperCamelCase				:	str    						=					torch.Size((1, 2_56, vocab_size)   )
				self.assertEqual(output.shape				,			lowerCAmelCase__   )

				UpperCamelCase				:	List[Any]    						=					torch.tensor(
				    [[[9.2595, -3.6038, 11.8819], [9.3869, -3.2693, 11.0956], [11.8524, -3.4938, 13.1210]]]   )

				self.assertTrue(torch.allclose(output[:, :3, :3]				,			lowerCAmelCase__				,			atol=1e-4   )   )



	@slow
	def 	SCREAMING_SNAKE_CASE__							(    self   )							->     Optional[Any]:




				'''simple docstring'''






				UpperCamelCase				:	Any    						=					MraForMaskedLM.from_pretrained("uw-madison/mra-base-4096-8-d3"   )
				UpperCamelCase				:	List[str]    						=					torch.arange(40_96   ).unsqueeze(0   )

				with torch.no_grad():
							UpperCamelCase				:	Any    						=					model(lowerCAmelCase__   )[0]

				UpperCamelCase				:	Dict    						=					5_02_65

				UpperCamelCase				:	int    						=					torch.Size((1, 40_96, vocab_size)   )
				self.assertEqual(output.shape				,			lowerCAmelCase__   )

				UpperCamelCase				:	List[Any]    						=					torch.tensor(
				    [[[5.4789, -2.3564, 7.5064], [7.9067, -1.3369, 9.9668], [9.0712, -1.8106, 7.0380]]]   )

				self.assertTrue(torch.allclose(output[:, :3, :3]				,			lowerCAmelCase__				,			atol=1e-4   )   )


# 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      :							Optional[Any]     	=    logging.get_logger(__name__)





@dataclass
class   UpperCamelCase_      :







						'''simple docstring'''



						def __init__(			self							:str		,    lowerCAmelCase__							:Any=False		,    lowerCAmelCase__							:Tuple=False		,    lowerCAmelCase__							:List[str]=6.0		,    lowerCAmelCase__							:int=None		,    lowerCAmelCase__							:Optional[Any]=False		,    lowerCAmelCase__							:List[Any]=False		,    lowerCAmelCase__							:int=None		,    lowerCAmelCase__							:Tuple="fp4"		,    lowerCAmelCase__							:Union[str, Any]=False		,    **lowerCAmelCase__							:Optional[Any]		,    )  ->Any:
										lowercase         =      load_in_abit
										lowercase         =      load_in_abit
										lowercase         =      llm_inta_threshold
										lowercase         =      llm_inta_skip_modules
										lowercase         =      llm_inta_enable_fpaa_cpu_offload
										lowercase         =      llm_inta_has_fpaa_weight
										lowercase         =      bnb_abit_quant_type
										lowercase         =      bnb_abit_use_double_quant

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

										self.post_init()





						def        SCREAMING_SNAKE_CASE(			self							:Any     )  ->str:
										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        SCREAMING_SNAKE_CASE(			self							:List[str]     )  ->Tuple:
										return self.load_in_abit or self.load_in_abit





						def        SCREAMING_SNAKE_CASE(			self							:List[str]     )  ->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        SCREAMING_SNAKE_CASE(			cls							:Union[str, Any]		,    lowerCAmelCase__							:List[Any]		,    lowerCAmelCase__							:Union[str, Any]		,    **lowerCAmelCase__							:Any     )  ->Optional[Any]:
										lowercase         =      cls(**lowerCAmelCase__     )

										lowercase         =      []
										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        SCREAMING_SNAKE_CASE(			self							:Dict		,    lowerCAmelCase__							:Union[str, os.PathLike]     )  ->Optional[int]:
										with open(lowerCAmelCase__		,    "w"		,    encoding="utf-8"     ) as writer:
														lowercase         =      self.to_dict()
														lowercase         =      json.dumps(lowerCAmelCase__		,    indent=2		,    sort_keys=lowerCAmelCase__     ) + "\n"

														writer.write(lowerCAmelCase__     )





						def        SCREAMING_SNAKE_CASE(			self							:Any     )  ->Dict[str, Any]:
										lowercase         =      copy.deepcopy(self.__dict__     )
										lowercase         =      str(output["bnb_4bit_compute_dtype"]     ).split("."     )[1]

										return output





						def __repr__(			self							:int     )  ->Optional[Any]:
										return F'''{self.__class__.__name__} {self.to_json_string()}'''





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





						def        SCREAMING_SNAKE_CASE(			self							:int     )  ->Dict[str, Any]:
										lowercase         =      self.to_dict()

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

										lowercase         =      {}

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

										return serializable_config_dict
