
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

from tqdm import auto as tqdm_lib


SCREAMING_SNAKE_CASE__				=							threading.Lock()
SCREAMING_SNAKE_CASE__				=							None

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

SCREAMING_SNAKE_CASE__				=							logging.WARNING

SCREAMING_SNAKE_CASE__				=							True




def 				__SCREAMING_SNAKE_CASE  (						)	->		int:
				__lowercase								=   os.getenv('DIFFUSERS_VERBOSITY'       ,				SCREAMING_SNAKE_CASE     )
				if env_level_str:
								if env_level_str in log_levels:
												return log_levels[env_level_str]
								else:
												logging.getLogger().warning(
												    F"""Unknown option DIFFUSERS_VERBOSITY={env_level_str}, """
												    F"""has to be one of: { ", ".join(log_levels.keys()     ) }"""     )
				return _default_log_level




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




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




def 				__SCREAMING_SNAKE_CASE  (						)	->		None:
				global _default_handler

				with _lock:
								if _default_handler:
												# This library has already configured the library root logger.
												return
								__lowercase								=   logging.StreamHandler()  # Set sys.stderr as stream.
								__lowercase								=   sys.stderr.flush

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




def 				__SCREAMING_SNAKE_CASE  (						)	->		None:
				global _default_handler

				with _lock:
								if not _default_handler:
												return

								__lowercase								=   _get_library_root_logger()
								library_root_logger.removeHandler(_default_handler     )
								library_root_logger.setLevel(logging.NOTSET     )
								__lowercase								=   None




def 				__SCREAMING_SNAKE_CASE  (						)	->		Dict:
				return log_levels




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: Optional[str] = None     )	->		logging.Logger:

				if name is None:
								__lowercase								=   _get_library_name()

				_configure_library_root_logger()
				return logging.getLogger(SCREAMING_SNAKE_CASE     )




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




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: int     )	->		None:
				_configure_library_root_logger()
				_get_library_root_logger().setLevel(SCREAMING_SNAKE_CASE     )




def 				__SCREAMING_SNAKE_CASE  (						)	->		List[Any]:
				return set_verbosity(SCREAMING_SNAKE_CASE     )




def 				__SCREAMING_SNAKE_CASE  (						)	->		List[Any]:
				return set_verbosity(SCREAMING_SNAKE_CASE     )




def 				__SCREAMING_SNAKE_CASE  (						)	->		List[str]:
				return set_verbosity(SCREAMING_SNAKE_CASE     )




def 				__SCREAMING_SNAKE_CASE  (						)	->		List[Any]:
				return set_verbosity(SCREAMING_SNAKE_CASE     )




def 				__SCREAMING_SNAKE_CASE  (						)	->		None:
				_configure_library_root_logger()

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




def 				__SCREAMING_SNAKE_CASE  (						)	->		None:
				_configure_library_root_logger()

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




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: logging.Handler     )	->		None:
				_configure_library_root_logger()

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




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: 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(SCREAMING_SNAKE_CASE     )




def 				__SCREAMING_SNAKE_CASE  (						)	->		None:
				_configure_library_root_logger()
				__lowercase								=   False




def 				__SCREAMING_SNAKE_CASE  (						)	->		None:
				_configure_library_root_logger()
				__lowercase								=   True




def 				__SCREAMING_SNAKE_CASE  (						)	->		None:
				__lowercase								=   _get_library_root_logger().handlers

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




def 				__SCREAMING_SNAKE_CASE  (						)	->		None:
				__lowercase								=   _get_library_root_logger().handlers

				for handler in handlers:
								handler.setFormatter(SCREAMING_SNAKE_CASE     )




def 				__SCREAMING_SNAKE_CASE  (						self			: Any       ,				*SCREAMING_SNAKE_CASE			: Tuple       ,				**SCREAMING_SNAKE_CASE			: int     )	->		int:
				__lowercase								=   os.getenv('DIFFUSERS_NO_ADVISORY_WARNINGS'       ,				SCREAMING_SNAKE_CASE     )
				if no_advisory_warnings:
								return
				self.warning(*SCREAMING_SNAKE_CASE       ,				**SCREAMING_SNAKE_CASE     )


SCREAMING_SNAKE_CASE__				=							warning_advice
class       A__  :





							def __init__(					self    :  Optional[int]	,					*_UpperCAmelCase    :  Optional[int]	,					**_UpperCAmelCase    :  str							)		->						Tuple:  # pylint: disable=unused-argument



											"""simple docstring"""


											__lowercase								=   args[0] if args else None





							def __iter__(					self    :  Any							)		->						Optional[int]:



											"""simple docstring"""


											return iter(self._iterator							)





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



											"""simple docstring"""


											def empty_fn(*_UpperCAmelCase    :  Optional[int]	,					**_UpperCAmelCase    :  Dict							):  # pylint: disable=unused-argument
															return

											return empty_fn





							def __enter__(					self    :  List[Any]							)		->						Tuple:



											"""simple docstring"""


											return self





							def __exit__(					self    :  Optional[int]	,					_UpperCAmelCase    :  str	,					_UpperCAmelCase    :  str	,					_UpperCAmelCase    :  Dict							)		->						Optional[int]:



											"""simple docstring"""


											return






class       A__  :





							def __call__(					self    :  Optional[Any]	,					*_UpperCAmelCase    :  Any	,					**_UpperCAmelCase    :  str							)		->						List[str]:



											"""simple docstring"""


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





							def      a__					(					self    :  Any	,					*_UpperCAmelCase    :  Union[str, Any]	,					**_UpperCAmelCase    :  Any							)		->						List[str]:



											"""simple docstring"""


											__lowercase								=   None
											if _tqdm_active:
															return tqdm_lib.tqdm.set_lock(*_UpperCAmelCase	,					**_UpperCAmelCase							)





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



											"""simple docstring"""


											if _tqdm_active:
															return tqdm_lib.tqdm.get_lock()






SCREAMING_SNAKE_CASE__				=							_tqdm_cls()




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




def 				__SCREAMING_SNAKE_CASE  (						)	->		Union[str, Any]:
				global _tqdm_active
				__lowercase								=   True




def 				__SCREAMING_SNAKE_CASE  (						)	->		str:
				global _tqdm_active
				__lowercase								=   False







from ctypes import c_float, sizeof
from enum import Enum
from typing import TYPE_CHECKING, Optional, Union


if TYPE_CHECKING:
							from .. import AutoFeatureExtractor, AutoProcessor, AutoTokenizer  # tests_ignore
class       A__  (		lowerCAmelCase__							):
							lowerCAmelCase__						:		Any            =				c_float





							@property
							def      a__					(					self    :  List[str]							)		->						int:



											"""simple docstring"""


											return sizeof(self.value							)






def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: int       ,				SCREAMING_SNAKE_CASE			: int       ,				SCREAMING_SNAKE_CASE			: int = 0     )	->		int:
				# < 0 is possible if using a dynamic axis
				if dimension <= 0:
								__lowercase								=   fixed_dimension

				dimension -= num_token_to_add
				return dimension




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: int       ,				SCREAMING_SNAKE_CASE			: ParameterFormat     )	->		int:
				return num_parameters * dtype.size




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: str     )	->		Optional[Union["AutoTokenizer", "AutoFeatureExtractor", "AutoProcessor"]]:
				from .. import AutoFeatureExtractor, AutoProcessor, AutoTokenizer  # tests_ignore

				try:
								return AutoProcessor.from_pretrained(SCREAMING_SNAKE_CASE     )
				except (ValueError, OSError, KeyError):
								__lowercase						,   __lowercase								=   None, None
								try:
												__lowercase								=   AutoTokenizer.from_pretrained(SCREAMING_SNAKE_CASE     )
								except (OSError, KeyError):
												pass
								try:
												__lowercase								=   AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE     )
								except (OSError, KeyError):
												pass

								if tokenizer is not None and feature_extractor is not None:
												raise ValueError(
												    F"""Couldn't auto-detect preprocessor for {model_name}. Found both a tokenizer and a feature extractor."""     )
								elif tokenizer is None and feature_extractor is None:
												return None
								elif tokenizer is not None:
												return tokenizer
								else:
												return feature_extractor





