


'''simple docstring'''





import os
import unittest

from huggingface_hub.utils import are_progress_bars_disabled

import transformers.models.bart.tokenization_bart
from transformers import logging
from transformers.testing_utils import CaptureLogger, mockenv, mockenv_context
from transformers.utils.logging import disable_progress_bar, enable_progress_bar




class 				UpperCAmelCase			(			unittest.TestCase						):


 def        __SCREAMING_SNAKE_CASE					(      self							:	Union[str, Any] ):
    UpperCAmelCase__	:str      =      logging.get_logger()

    # the current default level is logging.WARNING
    UpperCAmelCase__	:Tuple      =      logging.get_verbosity()

    logging.set_verbosity_error()
    self.assertEqual(logger.getEffectiveLevel()			,       logging.get_verbosity() )

    logging.set_verbosity_warning()
    self.assertEqual(logger.getEffectiveLevel()			,       logging.get_verbosity() )

    logging.set_verbosity_info()
    self.assertEqual(logger.getEffectiveLevel()			,       logging.get_verbosity() )

    logging.set_verbosity_debug()
    self.assertEqual(logger.getEffectiveLevel()			,       logging.get_verbosity() )

    # restore to the original level
    logging.set_verbosity(__lowerCamelCase )


 def        __SCREAMING_SNAKE_CASE					(      self							:	Union[str, Any] ):
    UpperCAmelCase__	:int      =      logging.get_verbosity()

    UpperCAmelCase__	:Tuple      =      logging.get_logger('''transformers.models.bart.tokenization_bart''' )
    UpperCAmelCase__	:List[Any]      =      '''Testing 1, 2, 3'''

    # should be able to log warnings (if default settings weren't overridden by `pytest --log-level-all`)
    if level_origin <= logging.WARNING:
       with CaptureLogger(__lowerCamelCase ) as cl:
          logger.warning(__lowerCamelCase )
       self.assertEqual(cl.out			,       msg + '''\n''' )

    # this is setting the level for all of `transformers.*` loggers
    logging.set_verbosity_error()

    # should not be able to log warnings
    with CaptureLogger(__lowerCamelCase ) as cl:
       logger.warning(__lowerCamelCase )
    self.assertEqual(cl.out			,       '''''' )

    # should be able to log warnings again
    logging.set_verbosity_warning()
    with CaptureLogger(__lowerCamelCase ) as cl:
       logger.warning(__lowerCamelCase )
    self.assertEqual(cl.out			,       msg + '''\n''' )

    # restore to the original level
    logging.set_verbosity(__lowerCamelCase )


 @mockenv(TRANSFORMERS_VERBOSITY='''error''' )
 def        __SCREAMING_SNAKE_CASE					(      self							:	Union[str, Any] ):
    # reset for the env var to take effect, next time some logger call is made
    transformers.utils.logging._reset_library_root_logger()
    # this action activates the env var
    UpperCAmelCase__	:List[Any]      =      logging.get_logger('''transformers.models.bart.tokenization_bart''' )

    UpperCAmelCase__	:Optional[int]      =      os.getenv('''TRANSFORMERS_VERBOSITY'''			,       __lowerCamelCase )
    UpperCAmelCase__	:List[Any]      =      logging.log_levels[env_level_str]

    UpperCAmelCase__	:List[str]      =      logging.get_verbosity()
    self.assertEqual(
        __lowerCamelCase			,       __lowerCamelCase			,       f'''TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}'''			,       )

    # restore to the original level
    UpperCAmelCase__	:Tuple      =      ''''''
    transformers.utils.logging._reset_library_root_logger()


 @mockenv(TRANSFORMERS_VERBOSITY='''super-error''' )
 def        __SCREAMING_SNAKE_CASE					(      self							:	List[str] ):
    # reset for the env var to take effect, next time some logger call is made
    transformers.utils.logging._reset_library_root_logger()
    UpperCAmelCase__	:Tuple      =      logging.logging.getLogger()
    with CaptureLogger(__lowerCamelCase ) as cl:
       # this action activates the env var
       logging.get_logger('''transformers.models.bart.tokenization_bart''' )
    self.assertIn('''Unknown option TRANSFORMERS_VERBOSITY=super-error'''			,       cl.out )

    # no need to restore as nothing was changed





 def        __SCREAMING_SNAKE_CASE					(      self							:	str ):
    # testing `logger.warning_advice()`
    transformers.utils.logging._reset_library_root_logger()

    UpperCAmelCase__	:Any      =      logging.get_logger('''transformers.models.bart.tokenization_bart''' )
    UpperCAmelCase__	:str      =      '''Testing 1, 2, 3'''

    with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS='''1''' ):
       # nothing should be logged as env var disables this method
       with CaptureLogger(__lowerCamelCase ) as cl:
          logger.warning_advice(__lowerCamelCase )
       self.assertEqual(cl.out			,       '''''' )

    with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS='''''' ):
       # should log normally as TRANSFORMERS_NO_ADVISORY_WARNINGS is unset
       with CaptureLogger(__lowerCamelCase ) as cl:
          logger.warning_advice(__lowerCamelCase )
       self.assertEqual(cl.out			,       msg + '''\n''' )


def        a__     (					):
   disable_progress_bar()
   assert are_progress_bars_disabled()

   enable_progress_bar()
   assert not are_progress_bars_disabled()







'''simple docstring'''





import warnings
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


__lowerCamelCase												=						logging.get_logger(__name__)

__lowerCamelCase												=						{
    '''nvidia/segformer-b0-finetuned-ade-512-512''': (
        '''https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json'''
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					"segformer"


 def __init__(      self							:	Dict			,       __lowerCamelCase							:	Dict=3			,       __lowerCamelCase							:	List[str]=4			,       __lowerCamelCase							:	List[Any]=[2, 2, 2, 2]			,       __lowerCamelCase							:	List[str]=[8, 4, 2, 1]			,       __lowerCamelCase							:	Optional[Any]=[3_2, 6_4, 1_6_0, 2_5_6]			,       __lowerCamelCase							:	Tuple=[7, 3, 3, 3]			,       __lowerCamelCase							:	Tuple=[4, 2, 2, 2]			,       __lowerCamelCase							:	Any=[1, 2, 5, 8]			,       __lowerCamelCase							:	Optional[Any]=[4, 4, 4, 4]			,       __lowerCamelCase							:	Union[str, Any]="gelu"			,       __lowerCamelCase							:	Dict=0.0			,       __lowerCamelCase							:	Union[str, Any]=0.0			,       __lowerCamelCase							:	Tuple=0.1			,       __lowerCamelCase							:	Optional[Any]=0.02			,       __lowerCamelCase							:	Optional[int]=0.1			,       __lowerCamelCase							:	str=1e-6			,       __lowerCamelCase							:	List[Any]=2_5_6			,       __lowerCamelCase							:	int=2_5_5			,       **__lowerCamelCase							:	str			,       ):
    super().__init__(**__lowerCamelCase )

    if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
       warnings.warn(
           '''Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be'''
           ''' removed, as the behaviour will default to that of reshape_last_stage = True.'''			,       __lowerCamelCase			,       )

    UpperCAmelCase__	:Dict      =      num_channels
    UpperCAmelCase__	:List[Any]      =      num_encoder_blocks
    UpperCAmelCase__	:List[str]      =      depths
    UpperCAmelCase__	:str      =      sr_ratios
    UpperCAmelCase__	:Optional[Any]      =      hidden_sizes
    UpperCAmelCase__	:List[str]      =      patch_sizes
    UpperCAmelCase__	:List[str]      =      strides
    UpperCAmelCase__	:List[str]      =      mlp_ratios
    UpperCAmelCase__	:Dict      =      num_attention_heads
    UpperCAmelCase__	:Tuple      =      hidden_act
    UpperCAmelCase__	:List[str]      =      hidden_dropout_prob
    UpperCAmelCase__	:List[Any]      =      attention_probs_dropout_prob
    UpperCAmelCase__	:int      =      classifier_dropout_prob
    UpperCAmelCase__	:str      =      initializer_range
    UpperCAmelCase__	:List[str]      =      drop_path_rate
    UpperCAmelCase__	:Dict      =      layer_norm_eps
    UpperCAmelCase__	:List[str]      =      decoder_hidden_size
    UpperCAmelCase__	:Optional[int]      =      kwargs.get('''reshape_last_stage'''			,       __lowerCamelCase )
    UpperCAmelCase__	:str      =      semantic_loss_ignore_index




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					version.parse("1.11"						)


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[Any] ):
    return OrderedDict(
        [
            ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
        ] )


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[int] ):
    return 1e-4





 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	List[str] ):
    return 1_2



