

'''simple docstring'''


import copy
import json
import os
import tempfile

from transformers import is_torch_available

from .test_configuration_utils import config_common_kwargs
class    _SCREAMING_SNAKE_CASE							(		__lowerCAmelCase	):


			'''simple docstring'''





			def __init__(   self							:						Union[str, Any] ,      lowercase							:						Optional[int] ,      lowercase							:						Optional[Any]=None ,      lowercase							:						int=True ,      lowercase							:						str=None ,      **lowercase							:						List[Any]			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = parent
									UpperCamelCase__         = config_class
									UpperCamelCase__         = has_text_modality
									UpperCamelCase__         = kwargs
									UpperCamelCase__         = common_properties






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

									'''simple docstring'''







									UpperCamelCase__         = self.config_class(**self.inputs_dict			)
									UpperCamelCase__         = (
									    ['''hidden_size''', '''num_attention_heads''', '''num_hidden_layers''']
									    if self.common_properties is None
									    else self.common_properties
									)

									# Add common fields for text models
									if self.has_text_modality:
															common_properties.extend(["""vocab_size"""]			)

									# Test that config has the common properties as getters
									for prop in common_properties:
															self.parent.assertTrue(hasattr(lowerCamelCase__ ,      lowerCamelCase__			) ,      msg=f"`{prop}` does not exist"			)

									# Test that config has the common properties as setter
									for idx, name in enumerate(lowerCamelCase__			):
															try:
																					setattr(lowerCamelCase__ ,      lowerCamelCase__ ,      lowerCamelCase__			)
																					self.parent.assertEqual(
																					    getattr(lowerCamelCase__ ,      lowerCamelCase__			) ,      lowerCamelCase__ ,      msg=f"`{name} value {idx} expected, but was {getattr(lowerCamelCase__ ,      lowerCamelCase__			)}"			)
															except NotImplementedError:
																					# Some models might not be able to implement setters for common_properties
																					# In that case, a NotImplementedError is raised
																					pass

																					# Test if config class can be called with Config(prop_name=..)
									for idx, name in enumerate(lowerCamelCase__			):
															try:
																					UpperCamelCase__         = self.config_class(**{name: idx}			)
																					self.parent.assertEqual(
																					    getattr(lowerCamelCase__ ,      lowerCamelCase__			) ,      lowerCamelCase__ ,      msg=f"`{name} value {idx} expected, but was {getattr(lowerCamelCase__ ,      lowerCamelCase__			)}"			)
															except NotImplementedError:
																					# Some models might not be able to implement setters for common_properties
																					# In that case, a NotImplementedError is raised
																					pass






			def 				A      (   self							:						Optional[int]			)							->    Dict:

									'''simple docstring'''







									UpperCamelCase__         = self.config_class(**self.inputs_dict			)
									UpperCamelCase__         = json.loads(config.to_json_string()			)
									for key, value in self.inputs_dict.items():
															self.parent.assertEqual(obj[key] ,      lowerCamelCase__			)






			def 				A      (   self							:						Optional[int]			)							->    Dict:

									'''simple docstring'''







									UpperCamelCase__         = self.config_class(**self.inputs_dict			)

									with tempfile.TemporaryDirectory() as tmpdirname:
															UpperCamelCase__         = os.path.join(lowerCamelCase__ ,      """config.json"""			)
															config_first.to_json_file(lowerCamelCase__			)
															UpperCamelCase__         = self.config_class.from_json_file(lowerCamelCase__			)

									self.parent.assertEqual(config_second.to_dict() ,      config_first.to_dict()			)






			def 				A      (   self							:						Any			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.config_class(**self.inputs_dict			)

									with tempfile.TemporaryDirectory() as tmpdirname:
															config_first.save_pretrained(lowerCamelCase__			)
															UpperCamelCase__         = self.config_class.from_pretrained(lowerCamelCase__			)

									self.parent.assertEqual(config_second.to_dict() ,      config_first.to_dict()			)






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

									'''simple docstring'''







									UpperCamelCase__         = self.config_class(**self.inputs_dict			)

									UpperCamelCase__         = '''test'''
									with tempfile.TemporaryDirectory() as tmpdirname:
															UpperCamelCase__         = os.path.join(lowerCamelCase__ ,      lowerCamelCase__			)
															config_first.save_pretrained(lowerCamelCase__			)
															UpperCamelCase__         = self.config_class.from_pretrained(lowerCamelCase__ ,      subfolder=lowerCamelCase__			)

									self.parent.assertEqual(config_second.to_dict() ,      config_first.to_dict()			)






			def 				A      (   self							:						str			)							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = self.config_class(**self.inputs_dict ,      num_labels=5			)
									self.parent.assertEqual(len(config.idalabel			) ,      5			)
									self.parent.assertEqual(len(config.labelaid			) ,      5			)

									UpperCamelCase__         = 3
									self.parent.assertEqual(len(config.idalabel			) ,      3			)
									self.parent.assertEqual(len(config.labelaid			) ,      3			)






			def 				A      (   self							:						str			)							->    Any:

									'''simple docstring'''







									if self.config_class.is_composition:
															return
									UpperCamelCase__         = self.config_class()
									self.parent.assertIsNotNone(lowerCamelCase__			)






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

									'''simple docstring'''







									UpperCamelCase__         = copy.deepcopy(lowerCamelCase__			)
									UpperCamelCase__         = self.config_class(**lowerCamelCase__			)
									UpperCamelCase__         = []
									for key, value in config_common_kwargs.items():
															if key == "torch_dtype":
																					if not is_torch_available():
																											continue
																					else:
																											import torch

																											if config.torch_dtype != torch.floataa:
																																	wrong_values.append(("""torch_dtype""", config.torch_dtype, torch.floataa)			)
															elif getattr(lowerCamelCase__ ,      lowerCamelCase__			) != value:
																					wrong_values.append((key, getattr(lowerCamelCase__ ,      lowerCamelCase__			), value)			)

									if len(lowerCamelCase__			) > 0:
															UpperCamelCase__         = '''\n'''.join([f"- {v[0]}: got {v[1]} instead of {v[2]}" for v in wrong_values]			)
															raise ValueError(f"The following keys were not properly set in the config:\n{errors}"			)







			def 				A      (   self							:						Any			)							->    Any:

									'''simple docstring'''







									self.create_and_test_config_common_properties()
									self.create_and_test_config_to_json_string()
									self.create_and_test_config_to_json_file()
									self.create_and_test_config_from_and_save_pretrained()
									self.create_and_test_config_from_and_save_pretrained_subfolder()
									self.create_and_test_config_with_num_labels()
									self.check_config_can_be_init_without_params()
									self.check_config_arguments_init()








'''simple docstring'''


import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


lowerCamelCase_				: Any    	=							{
    '''debug''': logging.DEBUG,
    '''info''': logging.INFO,
    '''warning''': logging.WARNING,
    '''error''': logging.ERROR,
    '''critical''': logging.CRITICAL,
}

lowerCamelCase_				: Optional[int]    	=							logging.WARNING







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = os.getenv("""DATASETS_VERBOSITY"""						,      _A					)
						if env_level_str:
												if env_level_str in log_levels:
																		return log_levels[env_level_str]
												else:
																		logging.getLogger().warning(
																		    f"Unknown option DATASETS_VERBOSITY={env_level_str}, "
																		    f"has to be one of: { ', '.join(log_levels.keys()					) }"					)
						return _default_log_level







def 	__magic_name__( ):
						'''simple docstring'''





						return __name__.split("""."""					)[0]







def 	__magic_name__( ):
						'''simple docstring'''





						return logging.getLogger(_get_library_name()					)







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = _get_library_root_logger()
						library_root_logger.setLevel(_get_default_logging_level()					)







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = _get_library_root_logger()
						library_root_logger.setLevel(logging.NOTSET					)







def 	__magic_name__( _A = None					):
						'''simple docstring'''





						if name is None:
												UpperCamelCase__         = _get_library_name()
						return logging.getLogger(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return _get_library_root_logger().getEffectiveLevel()







def 	__magic_name__( _A					):
						'''simple docstring'''





						_get_library_root_logger().setLevel(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return set_verbosity(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return set_verbosity(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return set_verbosity(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return set_verbosity(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = False







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()
class    _SCREAMING_SNAKE_CASE							:


			'''simple docstring'''





			def __init__(   self							:						int ,      *lowercase							:						Any ,      **lowercase							:						int			)							->    List[Any]:  # pylint: disable=unused-argument

									'''simple docstring'''







									UpperCamelCase__         = args[0] if args else None






			def __iter__(   self							:						str			)							->    List[str]:

									'''simple docstring'''







									return iter(self._iterator			)






			def __getattr__(   self							:						Optional[int] ,      lowercase							:						Tuple			)							->    int:

									'''simple docstring'''







									def empty_fn(*lowercase							:						List[Any] ,      **lowercase							:						Dict			):  # pylint: disable=unused-argument
															return

									return empty_fn






			def __enter__(   self							:						Dict			)							->    Tuple:

									'''simple docstring'''







									return self







			def __exit__(   self							:						Tuple ,      lowercase							:						Optional[Any] ,      lowercase							:						Any ,      lowercase							:						int			)							->    Any:

									'''simple docstring'''







									return
lowerCamelCase_				: str    	=							True
class    _SCREAMING_SNAKE_CASE							:


			'''simple docstring'''





			def __call__(   self							:						List[Any] ,      *lowercase							:						str ,      lowercase							:						Optional[int]=False ,      **lowercase							:						Optional[int]			)							->    Optional[int]:

									'''simple docstring'''







									if _tqdm_active and not disable:
															return tqdm_lib.tqdm(*lowercase ,      **lowercase			)
									else:
															return EmptyTqdm(*lowercase ,      **lowercase			)






			def 				A      (   self							:						Optional[Any] ,      *lowercase							:						Tuple ,      **lowercase							:						Any			)							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = None
									if _tqdm_active:
															return tqdm_lib.tqdm.set_lock(*lowercase ,      **lowercase			)







			def 				A      (   self							:						Optional[Any]			)							->    Optional[Any]:

									'''simple docstring'''







									if _tqdm_active:
															return tqdm_lib.tqdm.get_lock()
lowerCamelCase_				: int    	=							_tqdm_cls()







def 	__magic_name__( ):
						'''simple docstring'''





						global _tqdm_active
						return bool(_tqdm_active					)







def 	__magic_name__( ):
						'''simple docstring'''





						global _tqdm_active
						UpperCamelCase__         = True







def 	__magic_name__( ):
						'''simple docstring'''





						global _tqdm_active
						UpperCamelCase__         = False
