
'''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


snake_case_ :  Optional[int]     =					threading.Lock()
snake_case_ :  Optional[logging.Handler]     =					None

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

snake_case_ :  List[str]     =					logging.WARNING

snake_case_ :  List[str]     =					True



def  __snake_case     (    ):
   UpperCamelCase       =  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  __snake_case     (    ):
   return __name__.split('''.''')[0]



def  __snake_case     (    ):
   return logging.getLogger(_get_library_name())



def  __snake_case     (    ):
   global _default_handler

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

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



def  __snake_case     (    ):
   global _default_handler

   with _lock:
      if not _default_handler:
         return

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



def  __snake_case     (    ):
   return log_levels



def  __snake_case     (    _UpperCAmelCase					:       List[Any] = None):

   if name is None:
      UpperCamelCase       =  _get_library_name()

   _configure_library_root_logger()
   return logging.getLogger(_lowerCAmelCase)



def  __snake_case     (    ):
   _configure_library_root_logger()
   return _get_library_root_logger().getEffectiveLevel()



def  __snake_case     (    _UpperCAmelCase					:       List[str]):
   _configure_library_root_logger()
   _get_library_root_logger().setLevel(_lowerCAmelCase)



def  __snake_case     (    ):
   return set_verbosity(_lowerCAmelCase)



def  __snake_case     (    ):
   return set_verbosity(_lowerCAmelCase)



def  __snake_case     (    ):
   return set_verbosity(_lowerCAmelCase)



def  __snake_case     (    ):
   return set_verbosity(_lowerCAmelCase)



def  __snake_case     (    ):
   _configure_library_root_logger()

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



def  __snake_case     (    ):
   _configure_library_root_logger()

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



def  __snake_case     (    _UpperCAmelCase					:       Any):
   _configure_library_root_logger()

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



def  __snake_case     (    _UpperCAmelCase					:       Dict):
   _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  __snake_case     (    ):
   _configure_library_root_logger()
   UpperCamelCase       =  False



def  __snake_case     (    ):
   _configure_library_root_logger()
   UpperCamelCase       =  True



def  __snake_case     (    ):
   UpperCamelCase       =  _get_library_root_logger().handlers

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



def  __snake_case     (    ):
   UpperCamelCase       =  _get_library_root_logger().handlers

   for handler in handlers:
      handler.setFormatter(_lowerCAmelCase)



def  __snake_case     (    self					:       str,      *_UpperCAmelCase					:       Any,      **_UpperCAmelCase					:       int):
   UpperCamelCase       =  os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS''',      _lowerCAmelCase)
   if no_advisory_warnings:
      return
   self.warning(*_lowerCAmelCase,      **_lowerCAmelCase)


snake_case_ :  Tuple     =					warning_advice



@functools.lru_cache(_lowerCAmelCase)
def  __snake_case     (    self					:       List[str],      *_UpperCAmelCase					:       Optional[int],      **_UpperCAmelCase					:       List[str]):
   self.warning(*_lowerCAmelCase,      **_lowerCAmelCase)


snake_case_ :  str     =					warning_once


class 						lowercase__	:






   '''simple docstring'''







   def __init__(			self ,   *lowerCamelCase__ ,   **lowerCamelCase__   ):  # pylint: disable=unused-argument

      '''simple docstring'''







      UpperCamelCase       =  args[0] if args else None







   def __iter__(			self   ):

      '''simple docstring'''







      return iter(self._iterator   )







   def __getattr__(			self ,   lowerCamelCase__   ):

      '''simple docstring'''







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

      return empty_fn







   def __enter__(			self   ):

      '''simple docstring'''







      return self







   def __exit__(			self ,   lowerCamelCase__ ,   lowerCamelCase__ ,   lowerCamelCase__   ):

      '''simple docstring'''







      return




class 						lowercase__	:






   '''simple docstring'''







   def __call__(			self ,   *lowerCamelCase__ ,   **lowerCamelCase__   ):

      '''simple docstring'''







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







   def       UpperCAmelCase				(			self ,   *lowerCamelCase__ ,   **lowerCamelCase__   ):

      '''simple docstring'''







      UpperCamelCase       =  None
      if _tqdm_active:
         return tqdm_lib.tqdm.set_lock(*A_ ,   **A_   )







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      if _tqdm_active:
         return tqdm_lib.tqdm.get_lock()




snake_case_ :  Union[str, Any]     =					_tqdm_cls()



def  __snake_case     (    ):
   global _tqdm_active
   return bool(_tqdm_active)



def  __snake_case     (    ):
   global _tqdm_active
   UpperCamelCase       =  True
   hf_hub_utils.enable_progress_bars()



def  __snake_case     (    ):
   global _tqdm_active
   UpperCamelCase       =  False
   hf_hub_utils.disable_progress_bars()







'''simple docstring'''


from __future__ import annotations



def  __snake_case     (    _UpperCAmelCase					:       list[int]):
   UpperCamelCase       =  len(_UpperCAmelCase) // 2

   # choose the middle 3 elements
   UpperCamelCase       =  lst[m - 1 : m + 2]

   # if middle element is peak
   if three[1] > three[0] and three[1] > three[2]:
      return three[1]

   # if increasing, recurse on right
   elif three[0] < three[2]:
      if len(lst[:m]) == 2:
         m -= 1
      return peak(lst[m:])

   # decreasing
   else:
      if len(lst[:m]) == 2:
         m += 1
      return peak(lst[:m])


if __name__ == "__main__":
   import doctest

   doctest.testmod()





