





"""simple docstring"""






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

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


A 			=  threading.Lock()
A 			=  None

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

A 			=  logging.WARNING

A 			=  True

def     __A      (			)		->		Union[str, Any]:
				__a :						List[str]			       =  os.getenv('''TRANSFORMERS_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 TRANSFORMERS_VERBOSITY={env_level_str}, """
												    F"""has to be one of: { ", ".join(log_levels.keys()) }""")
				return _default_log_level

def     __A      (			)		->		str:
				return __name__.split('''.''')[0]

def     __A      (			)		->		logging.Logger:
				return logging.getLogger(_get_library_name())

def     __A      (			)		->		None:
				global _default_handler

				with _lock:
								if _default_handler:
												# This library has already configured the library root logger.
												return
								__a :						int			       =  logging.StreamHandler()  # Set sys.stderr as stream.
								__a :						Optional[Any]			       =  sys.stderr.flush

								# Apply our default configuration to the library root logger.
								__a :						int			       =  _get_library_root_logger()
								library_root_logger.addHandler(_default_handler)
								library_root_logger.setLevel(_get_default_logging_level())
								__a :						str			       =  False

def     __A      (			)		->		None:
				global _default_handler

				with _lock:
								if not _default_handler:
												return

								__a :						List[str]			       =  _get_library_root_logger()
								library_root_logger.removeHandler(_default_handler)
								library_root_logger.setLevel(logging.NOTSET)
								__a :						int			       =  None

def     __A      (			)		->		Optional[Any]:
				return log_levels

def     __A      (			a_						:Optional[str] = None)		->		logging.Logger:

				if name is None:
								__a :						Dict			       =  _get_library_name()

				_configure_library_root_logger()
				return logging.getLogger(a_)

def     __A      (			)		->		int:
				_configure_library_root_logger()
				return _get_library_root_logger().getEffectiveLevel()

def     __A      (			a_						:int)		->		None:
				_configure_library_root_logger()
				_get_library_root_logger().setLevel(a_)

def     __A      (			)		->		int:
				return set_verbosity(a_)

def     __A      (			)		->		List[Any]:
				return set_verbosity(a_)

def     __A      (			)		->		Optional[int]:
				return set_verbosity(a_)

def     __A      (			)		->		int:
				return set_verbosity(a_)

def     __A      (			)		->		None:
				_configure_library_root_logger()

				assert _default_handler is not None
				_get_library_root_logger().removeHandler(_default_handler)

def     __A      (			)		->		None:
				_configure_library_root_logger()

				assert _default_handler is not None
				_get_library_root_logger().addHandler(_default_handler)

def     __A      (			a_						:logging.Handler)		->		None:
				_configure_library_root_logger()

				assert handler is not None
				_get_library_root_logger().addHandler(a_)

def     __A      (			a_						:logging.Handler)		->		None:
				_configure_library_root_logger()

				assert handler is not None and handler not in _get_library_root_logger().handlers
				_get_library_root_logger().removeHandler(a_)

def     __A      (			)		->		None:
				_configure_library_root_logger()
				__a :						Dict			       =  False

def     __A      (			)		->		None:
				_configure_library_root_logger()
				__a :						Optional[Any]			       =  True

def     __A      (			)		->		None:
				__a :						Any			       =  _get_library_root_logger().handlers

				for handler in handlers:
								__a :						str			       =  logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s''')
								handler.setFormatter(a_)

def     __A      (			)		->		None:
				__a :						List[str]			       =  _get_library_root_logger().handlers

				for handler in handlers:
								handler.setFormatter(a_)

def     __A      (			self						:Optional[Any]   ,       *a_						:str   ,       **a_						:Optional[int])		->		int:
				__a :						Any			       =  os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS'''   ,       a_)
				if no_advisory_warnings:
								return
				self.warning(*a_   ,       **a_)


A 			=  warning_advice

@functools.lru_cache(a_)
def     __A      (			self						:Optional[Any]   ,       *a_						:int   ,       **a_						:List[Any])		->		List[str]:
				self.warning(*a_   ,       **a_)


A 			=  warning_once




class 				__lowercase			:







					'''simple docstring'''




					def __init__(						self	,			*_UpperCAmelCase	,			**_UpperCAmelCase     ):  # pylint: disable=unused-argument
									__a :						List[Any]			       =  args[0] if args else None







					def __iter__(						self     ):
									return iter(self._iterator     )







					def __getattr__(						self	,			_UpperCAmelCase     ):

									def empty_fn(*_UpperCAmelCase	,			**_UpperCAmelCase     ):  # pylint: disable=unused-argument
													return

									return empty_fn







					def __enter__(						self     ):
									return self







					def __exit__(						self	,			_UpperCAmelCase	,			_UpperCAmelCase	,			_UpperCAmelCase     ):
									return






class 				__lowercase			:







					'''simple docstring'''




					def __call__(						self	,			*_UpperCAmelCase	,			**_UpperCAmelCase     ):
									if _tqdm_active:
													return tqdm_lib.tqdm(*_UpperCAmelCase	,			**_UpperCAmelCase     )
									else:
													return EmptyTqdm(*_UpperCAmelCase	,			**_UpperCAmelCase     )







					def  _lowerCamelCase		(						self	,			*_UpperCAmelCase	,			**_UpperCAmelCase     ):
									__a :						Any			       =  None
									if _tqdm_active:
													return tqdm_lib.tqdm.set_lock(*_UpperCAmelCase	,			**_UpperCAmelCase     )







					def  _lowerCamelCase		(						self     ):
									if _tqdm_active:
													return tqdm_lib.tqdm.get_lock()






A 			=  _tqdm_cls()

def     __A      (			)		->		bool:
				global _tqdm_active
				return bool(_tqdm_active)

def     __A      (			)		->		str:
				global _tqdm_active
				__a :						str			       =  True
				hf_hub_utils.enable_progress_bars()






def     __A      (			)		->		int:
				global _tqdm_active
				__a :						int			       =  False
				hf_hub_utils.disable_progress_bars()










"""simple docstring"""






import copy
import re




class 				__lowercase			:







					'''simple docstring'''




					__lowerCAmelCase  =  '''hp'''
					__lowerCAmelCase  =  {}
					__lowerCAmelCase  =  None







					@classmethod
					def  _lowerCamelCase		(						cls	,			_UpperCAmelCase	,			_UpperCAmelCase     ):
									__a :						Optional[int]			       =  prefix
									__a :						List[str]			       =  defaults
									cls.build_naming_info()







					@staticmethod
					def  _lowerCamelCase		(						_UpperCAmelCase	,			_UpperCAmelCase     ):
									if len(_UpperCAmelCase     ) == 0:
													return ""
									__a :						Optional[int]			       =  None
									if any(char.isdigit() for char in word     ):
													raise Exception(f"""Parameters should not contain numbers: '{word}' contains a number"""     )
									if word in info["short_word"]:
													return info["short_word"][word]
									for prefix_len in range(1	,			len(_UpperCAmelCase     ) + 1     ):
													__a :						str			       =  word[:prefix_len]
													if prefix in info["reverse_short_word"]:
																	continue
													else:
																	__a :						Tuple			       =  prefix
																	break

									if short_word is None:
													# Paranoid fallback
													def int_to_alphabetic(_UpperCAmelCase     ):
																	__a :						List[str]			       =  ''''''
																	while integer != 0:
																					__a :						Union[str, Any]			       =  chr(ord('''A'''     ) + integer % 10     ) + s
																					integer //= 10
																	return s

													__a :						Optional[int]			       =  0
													while True:
																	__a :						List[str]			       =  word + '''#''' + int_to_alphabetic(_UpperCAmelCase     )
																	if sword in info["reverse_short_word"]:
																					continue
																	else:
																					__a :						Optional[Any]			       =  sword
																					break

									__a :						List[str]			       =  short_word
									__a :						Dict			       =  word
									return short_word







					@staticmethod
					def  _lowerCamelCase		(						_UpperCAmelCase	,			_UpperCAmelCase     ):
									__a :						str			       =  param_name.split('''_'''     )

									__a :						str			       =  [TrialShortNamer.shortname_for_word(_UpperCAmelCase	,			_UpperCAmelCase     ) for word in words]

									# We try to create a separatorless short name, but if there is a collision we have to fallback
									# to a separated short name
									__a :						Dict			       =  ['''''', '''_''']

									for separator in separators:
													__a :						Union[str, Any]			       =  separator.join(_UpperCAmelCase     )
													if shortname not in info["reverse_short_param"]:
																	__a :						List[str]			       =  shortname
																	__a :						Union[str, Any]			       =  param_name
																	return shortname

									return param_name







					@staticmethod
					def  _lowerCamelCase		(						_UpperCAmelCase	,			_UpperCAmelCase     ):
									__a :						int			       =  TrialShortNamer.shortname_for_key(_UpperCAmelCase	,			_UpperCAmelCase     )
									__a :						Optional[Any]			       =  short_name
									__a :						Optional[Any]			       =  param_name







					@classmethod
					def  _lowerCamelCase		(						cls     ):
									if cls.NAMING_INFO is not None:
													return

									__a :						Optional[Any]			       =  {
									    '''short_word''': {},
									    '''reverse_short_word''': {},
									    '''short_param''': {},
									    '''reverse_short_param''': {},
									}

									__a :						List[str]			       =  list(cls.DEFAULTS.keys()     )

									for k in field_keys:
													cls.add_new_param_name(_UpperCAmelCase	,			_UpperCAmelCase     )

									__a :						Optional[Any]			       =  info







					@classmethod
					def  _lowerCamelCase		(						cls	,			_UpperCAmelCase     ):
									cls.build_naming_info()
									assert cls.PREFIX is not None
									__a :						str			       =  [copy.copy(cls.PREFIX     )]

									for k, v in params.items():
													if k not in cls.DEFAULTS:
																	raise Exception(f"""You should provide a default value for the param name {k} with value {v}"""     )
													if v == cls.DEFAULTS[k]:
																	# The default value is not added to the name
																	continue

													__a :						Union[str, Any]			       =  cls.NAMING_INFO['''short_param'''][k]

													if isinstance(_UpperCAmelCase	,			_UpperCAmelCase     ):
																	__a :						str			       =  1 if v else 0

													__a :						Tuple			       =  '''''' if isinstance(_UpperCAmelCase	,			(int, float)     ) else '''-'''
													__a :						Dict			       =  f"""{key}{sep}{v}"""
													name.append(_UpperCAmelCase     )

									return "_".join(_UpperCAmelCase     )







					@classmethod
					def  _lowerCamelCase		(						cls	,			_UpperCAmelCase     ):
									__a :						List[Any]			       =  repr[len(cls.PREFIX     ) + 1 :]
									if repr == "":
													__a :						Tuple			       =  []
									else:
													__a :						str			       =  repr.split('''_'''     )

									__a :						Optional[Any]			       =  {}

									for value in values:
													if "-" in value:
																	__a       ,						__a :						List[Any]			       =  value.split('''-'''     )
													else:
																	__a :						int			       =  re.sub('''[0-9.]'''	,			''''''	,			_UpperCAmelCase     )
																	__a :						Union[str, Any]			       =  float(re.sub('''[^0-9.]'''	,			''''''	,			_UpperCAmelCase     )     )

													__a :						Dict			       =  cls.NAMING_INFO['''reverse_short_param'''][p_k]

													__a :						Union[str, Any]			       =  p_v

									for k in cls.DEFAULTS:
													if k not in parameters:
																	__a :						Optional[int]			       =  cls.DEFAULTS[k]

									return parameters