

"""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  UpperCAmelCase__	():
  """simple docstring"""

  _snake_case							:		Dict								=  os.getenv("""TRANSFORMERS_VERBOSITY"""		,       lowerCAmelCase__   )
  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  UpperCAmelCase__	():
  """simple docstring"""

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


def  UpperCAmelCase__	():
  """simple docstring"""

  return logging.getLogger(_get_library_name()   )


def  UpperCAmelCase__	():
  """simple docstring"""

  global _default_handler

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

    # Apply our default configuration to the library root logger.
    _snake_case							:		Union[str, Any]								=  _get_library_root_logger()
    library_root_logger.addHandler(_default_handler   )
    library_root_logger.setLevel(_get_default_logging_level()   )
    _snake_case							:		Union[str, Any]								=  False


def  UpperCAmelCase__	():
  """simple docstring"""

  global _default_handler

  with _lock:
    if not _default_handler:
      return

    _snake_case							:		Optional[Any]								=  _get_library_root_logger()
    library_root_logger.removeHandler(_default_handler   )
    library_root_logger.setLevel(logging.NOTSET   )
    _snake_case							:		str								=  None


def  UpperCAmelCase__	():
  """simple docstring"""

  return log_levels


def  UpperCAmelCase__	(snake_case__							: Optional[str] = None   ):
  """simple docstring"""

  if name is None:
    _snake_case							:		str								=  _get_library_name()

  _configure_library_root_logger()
  return logging.getLogger(lowerCAmelCase__   )


def  UpperCAmelCase__	():
  """simple docstring"""

  _configure_library_root_logger()
  return _get_library_root_logger().getEffectiveLevel()


def  UpperCAmelCase__	(snake_case__							: int   ):
  """simple docstring"""

  _configure_library_root_logger()
  _get_library_root_logger().setLevel(lowerCAmelCase__   )


def  UpperCAmelCase__	():
  """simple docstring"""

  return set_verbosity(lowerCAmelCase__   )


def  UpperCAmelCase__	():
  """simple docstring"""

  return set_verbosity(lowerCAmelCase__   )


def  UpperCAmelCase__	():
  """simple docstring"""

  return set_verbosity(lowerCAmelCase__   )


def  UpperCAmelCase__	():
  """simple docstring"""

  return set_verbosity(lowerCAmelCase__   )


def  UpperCAmelCase__	():
  """simple docstring"""

  _configure_library_root_logger()

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


def  UpperCAmelCase__	():
  """simple docstring"""

  _configure_library_root_logger()

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


def  UpperCAmelCase__	(snake_case__							: logging.Handler   ):
  """simple docstring"""

  _configure_library_root_logger()

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


def  UpperCAmelCase__	(snake_case__							: logging.Handler   ):
  """simple docstring"""

  _configure_library_root_logger()

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


def  UpperCAmelCase__	():
  """simple docstring"""

  _configure_library_root_logger()
  _snake_case							:		Tuple								=  False


def  UpperCAmelCase__	():
  """simple docstring"""

  _configure_library_root_logger()
  _snake_case							:		Dict								=  True


def  UpperCAmelCase__	():
  """simple docstring"""

  _snake_case							:		Optional[Any]								=  _get_library_root_logger().handlers

  for handler in handlers:
    _snake_case							:		Optional[int]								=  logging.Formatter("""[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"""   )
    handler.setFormatter(lowerCAmelCase__   )


def  UpperCAmelCase__	():
  """simple docstring"""

  _snake_case							:		Tuple								=  _get_library_root_logger().handlers

  for handler in handlers:
    handler.setFormatter(lowerCAmelCase__   )


def  UpperCAmelCase__	(self							: List[Any]		,       *snake_case__							: List[str]		,       **snake_case__							: Optional[int]   ):
  """simple docstring"""

  _snake_case							:		Union[str, Any]								=  os.getenv("""TRANSFORMERS_NO_ADVISORY_WARNINGS"""		,       lowerCAmelCase__   )
  if no_advisory_warnings:
    return
  self.warning(*lowerCAmelCase__		,       **lowerCAmelCase__   )


A_      =    warning_advice


@functools.lru_cache(lowerCAmelCase__   )
def  UpperCAmelCase__	(self							: Any		,       *snake_case__							: Optional[Any]		,       **snake_case__							: Any   ):
  """simple docstring"""

  self.warning(*lowerCAmelCase__		,       **lowerCAmelCase__   )


A_      =    warning_once






class  lowercase:







 '''simple docstring'''





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




   '''simple docstring'''



   _snake_case							:		Optional[int]								=  args[0] if args else None


 def __iter__(    self:		Dict		):




   '''simple docstring'''



   return iter(self._iterator		)


 def __getattr__(    self:		List[str],				a_:		List[Any]		):




   '''simple docstring'''



   def empty_fn(*a_:		Tuple,				**a_:		Union[str, Any]		):  # pylint: disable=unused-argument
     return

   return empty_fn


 def __enter__(    self:		Union[str, Any]		):




   '''simple docstring'''



   return self


 def __exit__(    self:		Tuple,				a_:		List[Any],				a_:		List[str],				a_:		List[str]		):




   '''simple docstring'''



   return







class  lowercase:







 '''simple docstring'''





 def __call__(    self:		List[Any],				*a_:		List[str],				**a_:		List[Any]		):




   '''simple docstring'''



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


 def 			UpperCamelCase_       (    self:		str,				*a_:		Any,				**a_:		List[Any]		):




   '''simple docstring'''



   _snake_case							:		str								=  None
   if _tqdm_active:
     return tqdm_lib.tqdm.set_lock(*snake_case_,				**snake_case_		)


 def 			UpperCamelCase_       (    self:		str		):




   '''simple docstring'''



   if _tqdm_active:
     return tqdm_lib.tqdm.get_lock()







A_      =    _tqdm_cls()


def  UpperCAmelCase__	():
  """simple docstring"""

  global _tqdm_active
  return bool(_tqdm_active   )


def  UpperCAmelCase__	():
  """simple docstring"""

  global _tqdm_active
  _snake_case							:		str								=  True
  hf_hub_utils.enable_progress_bars()






def  UpperCAmelCase__	():
  """simple docstring"""

  global _tqdm_active
  _snake_case							:		Optional[int]								=  False
  hf_hub_utils.disable_progress_bars()








"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


A_      =    logging.get_logger(__name__)

A_      =    {
    '''microsoft/swin-tiny-patch4-window7-224''': (
        '''https://huggingface.co/microsoft/swin-tiny-patch4-window7-224/resolve/main/config.json'''
    ),
    # See all Swin models at https://huggingface.co/models?filter=swin
}






class  lowercase(					__a	,      __a			):







 '''simple docstring'''





 lowercase__			 = "swin"

 lowercase__			 = {
     "num_attention_heads": "num_heads",
     "num_hidden_layers": "num_layers",
 }


 def __init__(    self:		Any,				a_:		List[str]=224,				a_:		List[Any]=4,				a_:		List[Any]=3,				a_:		Dict=96,				a_:		List[str]=[2, 2, 6, 2],				a_:		int=[3, 6, 12, 24],				a_:		int=7,				a_:		str=4.0,				a_:		Optional[Any]=True,				a_:		Dict=0.0,				a_:		List[Any]=0.0,				a_:		List[str]=0.1,				a_:		Union[str, Any]="gelu",				a_:		Dict=False,				a_:		Union[str, Any]=0.02,				a_:		Optional[int]=1E-5,				a_:		Optional[int]=32,				a_:		Tuple=None,				a_:		Union[str, Any]=None,				**a_:		Any,				):




   '''simple docstring'''



   super().__init__(**a_		)

   _snake_case							:		Any								=  image_size
   _snake_case							:		List[Any]								=  patch_size
   _snake_case							:		Tuple								=  num_channels
   _snake_case							:		str								=  embed_dim
   _snake_case							:		Union[str, Any]								=  depths
   _snake_case							:		int								=  len(a_		)
   _snake_case							:		Union[str, Any]								=  num_heads
   _snake_case							:		List[str]								=  window_size
   _snake_case							:		str								=  mlp_ratio
   _snake_case							:		Union[str, Any]								=  qkv_bias
   _snake_case							:		Dict								=  hidden_dropout_prob
   _snake_case							:		str								=  attention_probs_dropout_prob
   _snake_case							:		Union[str, Any]								=  drop_path_rate
   _snake_case							:		Optional[int]								=  hidden_act
   _snake_case							:		str								=  use_absolute_embeddings
   _snake_case							:		Tuple								=  layer_norm_eps
   _snake_case							:		List[Any]								=  initializer_range
   _snake_case							:		Optional[Any]								=  encoder_stride
   # we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
   # this indicates the channel dimension after the last stage of the model
   _snake_case							:		Any								=  int(embed_dim * 2 ** (len(a_		) - 1)		)
   _snake_case							:		Any								=  ["""stem"""] + [f"stage{idx}" for idx in range(1,				len(a_		) + 1		)]
   _snake_case		, _snake_case							:		List[str]								=  get_aligned_output_features_output_indices(
       out_features=a_,				out_indices=a_,				stage_names=self.stage_names		)







class  lowercase(					__a			):







 '''simple docstring'''





 lowercase__			 = version.parse("1.11"			)


 @property
 def 			UpperCamelCase_       (    self:		Any		):




   '''simple docstring'''



   return OrderedDict(
       [
           ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
       ]		)


 @property
 def 			UpperCamelCase_       (    self:		List[str]		):




   '''simple docstring'''



   return 1E-4


