





"""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 		__lowercase					(       )       ->List[Any]:



    '''simple docstring'''







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







def 		__lowercase					(       )       ->str:



    '''simple docstring'''







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







def 		__lowercase					(       )       ->logging.Logger:



    '''simple docstring'''







    return logging.getLogger(_get_library_name()						)







def 		__lowercase					(       )       ->None:



    '''simple docstring'''







    global _default_handler

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

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







def 		__lowercase					(       )       ->None:



    '''simple docstring'''







    global _default_handler

    with _lock:
        if not _default_handler:
            return

        __A   :						Union[str, Any]									=					_get_library_root_logger()
        library_root_logger.removeHandler(_default_handler						)
        library_root_logger.setLevel(logging.NOTSET						)
        __A   :						Tuple									=					None







def 		__lowercase					(       )       ->Tuple:



    '''simple docstring'''







    return log_levels







def 		__lowercase					(       snake_case_  :  Optional[str] = None						)       ->logging.Logger:



    '''simple docstring'''







    if name is None:
        __A   :						Union[str, Any]									=					_get_library_name()

    _configure_library_root_logger()
    return logging.getLogger(snake_case_						)







def 		__lowercase					(       )       ->int:



    '''simple docstring'''







    _configure_library_root_logger()
    return _get_library_root_logger().getEffectiveLevel()







def 		__lowercase					(       snake_case_  :  int						)       ->None:



    '''simple docstring'''







    _configure_library_root_logger()
    _get_library_root_logger().setLevel(snake_case_						)







def 		__lowercase					(       )       ->List[Any]:



    '''simple docstring'''







    return set_verbosity(snake_case_						)







def 		__lowercase					(       )       ->str:



    '''simple docstring'''







    return set_verbosity(snake_case_						)







def 		__lowercase					(       )       ->Optional[Any]:



    '''simple docstring'''







    return set_verbosity(snake_case_						)







def 		__lowercase					(       )       ->Tuple:



    '''simple docstring'''







    return set_verbosity(snake_case_						)







def 		__lowercase					(       )       ->None:



    '''simple docstring'''







    _configure_library_root_logger()

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







def 		__lowercase					(       )       ->None:



    '''simple docstring'''







    _configure_library_root_logger()

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







def 		__lowercase					(       snake_case_  :  logging.Handler						)       ->None:



    '''simple docstring'''







    _configure_library_root_logger()

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







def 		__lowercase					(       snake_case_  :  logging.Handler						)       ->None:



    '''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(snake_case_						)







def 		__lowercase					(       )       ->None:



    '''simple docstring'''







    _configure_library_root_logger()
    __A   :						Optional[Any]									=					False







def 		__lowercase					(       )       ->None:



    '''simple docstring'''







    _configure_library_root_logger()
    __A   :						Union[str, Any]									=					True







def 		__lowercase					(       )       ->None:



    '''simple docstring'''







    __A   :						List[Any]									=					_get_library_root_logger().handlers

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







def 		__lowercase					(       )       ->None:



    '''simple docstring'''







    __A   :						Optional[int]									=					_get_library_root_logger().handlers

    for handler in handlers:
        handler.setFormatter(snake_case_						)







def 		__lowercase					(       self  :  int    ,*snake_case_  :  str    ,**snake_case_  :  List[Any]						)       ->List[Any]:



    '''simple docstring'''







    __A   :						int									=					os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS'''    ,snake_case_						)
    if no_advisory_warnings:
        return
    self.warning(*snake_case_    ,**snake_case_						)


a_			=      warning_advice







@functools.lru_cache(snake_case_						)
def 		__lowercase					(       self  :  Any    ,*snake_case_  :  Union[str, Any]    ,**snake_case_  :  List[Any]						)       ->Union[str, Any]:



    '''simple docstring'''







    self.warning(*snake_case_    ,**snake_case_						)


a_			=      warning_once






class 		__snake_case :





 """simple docstring"""


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



     '''simple docstring'''




     __A   :						Optional[int]									=					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 		__snake_case :





 """simple docstring"""


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



     '''simple docstring'''




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

 def  UpperCamelCase__(   self ,						*__lowerCamelCase ,						**__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						List[str]									=					None
     if _tqdm_active:
         return tqdm_lib.tqdm.set_lock(*__lowerCamelCase ,						**__lowerCamelCase  )







 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     if _tqdm_active:
         return tqdm_lib.tqdm.get_lock()






a_			=      _tqdm_cls()







def 		__lowercase					(       )       ->bool:



    '''simple docstring'''







    global _tqdm_active
    return bool(_tqdm_active						)







def 		__lowercase					(       )       ->Union[str, Any]:



    '''simple docstring'''







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







def 		__lowercase					(       )       ->str:



    '''simple docstring'''







    global _tqdm_active
    __A   :						List[str]									=					False
    hf_hub_utils.disable_progress_bars()











"""simple docstring"""



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


a_			=      logging.get_logger(__name__)

a_			=      {
    """shi-labs/dinat-mini-in1k-224""": """https://huggingface.co/shi-labs/dinat-mini-in1k-224/resolve/main/config.json""",
    # See all Dinat models at https://huggingface.co/models?filter=dinat
}






class 		__snake_case (		SCREAMING_SNAKE_CASE__							,							SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 _lowerCamelCase				=					"""dinat"""

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

 def __init__(   self ,						__lowerCamelCase=4 ,						__lowerCamelCase=3 ,						__lowerCamelCase=64 ,						__lowerCamelCase=[3, 4, 6, 5] ,						__lowerCamelCase=[2, 4, 8, 16] ,						__lowerCamelCase=7 ,						__lowerCamelCase=[[1, 8, 1], [1, 4, 1, 4], [1, 2, 1, 2, 1, 2], [1, 1, 1, 1, 1]] ,						__lowerCamelCase=3.0 ,						__lowerCamelCase=True ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=0.1 ,						__lowerCamelCase="gelu" ,						__lowerCamelCase=0.0_2 ,						__lowerCamelCase=1e-5 ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=None ,						__lowerCamelCase=None ,						**__lowerCamelCase ,						):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase  )

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




