
'''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       _lowerCAmelCase   (   unittest.TestCase				):







							'''simple docstring'''

							def 	lowercase							(self  )					->       Union[str, Any]:
														_snake_case       =  logging.get_logger()

														# the current default level is logging.WARNING
														_snake_case       =  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(UpperCAmelCase  )

							def 	lowercase							(self  )					->       Optional[Any]:
														_snake_case       =  logging.get_verbosity()

														_snake_case       =  logging.get_logger("""transformers.models.bart.tokenization_bart"""  )
														_snake_case       =  """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(UpperCAmelCase  ) as cl:
																												logger.warning(UpperCAmelCase  )
																					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(UpperCAmelCase  ) as cl:
																					logger.warning(UpperCAmelCase  )
														self.assertEqual(cl.out  ,  """"""  )

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

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

							@mockenv(TRANSFORMERS_VERBOSITY="""error"""  )
							def 	lowercase							(self  )					->       Dict:
														# 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
														_snake_case       =  logging.get_logger("""transformers.models.bart.tokenization_bart"""  )

														_snake_case       =  os.getenv("""TRANSFORMERS_VERBOSITY"""  ,  UpperCAmelCase  )
														_snake_case       =  logging.log_levels[env_level_str]

														_snake_case       =  logging.get_verbosity()
														self.assertEqual(
														    UpperCAmelCase  ,  UpperCAmelCase  ,  f"""TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}"""  ,  )

														# restore to the original level
														_snake_case       =  """"""
														transformers.utils.logging._reset_library_root_logger()

							@mockenv(TRANSFORMERS_VERBOSITY="""super-error"""  )
							def 	lowercase							(self  )					->       List[Any]:
														# reset for the env var to take effect, next time some logger call is made
														transformers.utils.logging._reset_library_root_logger()
														_snake_case       =  logging.logging.getLogger()
														with CaptureLogger(UpperCAmelCase  ) 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 	lowercase							(self  )					->       Optional[int]:
														# testing `logger.warning_advice()`
														transformers.utils.logging._reset_library_root_logger()

														_snake_case       =  logging.get_logger("""transformers.models.bart.tokenization_bart"""  )
														_snake_case       =  """Testing 1, 2, 3"""

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

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






def  __SCREAMING_SNAKE_CASE				(  ):
							disable_progress_bar()
							assert are_progress_bars_disabled()

							enable_progress_bar()
							assert not are_progress_bars_disabled()




'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__lowerCAmelCase												=	logging.get_logger(__name__)

__lowerCAmelCase												=	{
    'shi-labs/nat-mini-in1k-224': 'https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json',
    # See all Nat models at https://huggingface.co/models?filter=nat
}


class       _lowerCAmelCase   (   __snake_case					,							__snake_case				):







							'''simple docstring'''

							lowerCAmelCase_ 						=						"nat"

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

							def __init__(self  ,  UpperCAmelCase=4  ,  UpperCAmelCase=3  ,  UpperCAmelCase=64  ,  UpperCAmelCase=[3, 4, 6, 5]  ,  UpperCAmelCase=[2, 4, 8, 16]  ,  UpperCAmelCase=7  ,  UpperCAmelCase=3.0  ,  UpperCAmelCase=True  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=0.1  ,  UpperCAmelCase="gelu"  ,  UpperCAmelCase=0.02  ,  UpperCAmelCase=1e-5  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=None  ,  UpperCAmelCase=None  ,  **UpperCAmelCase  ,  )					->       str:
														super().__init__(**UpperCAmelCase  )

														_snake_case       =  patch_size
														_snake_case       =  num_channels
														_snake_case       =  embed_dim
														_snake_case       =  depths
														_snake_case       =  len(UpperCAmelCase  )
														_snake_case       =  num_heads
														_snake_case       =  kernel_size
														_snake_case       =  mlp_ratio
														_snake_case       =  qkv_bias
														_snake_case       =  hidden_dropout_prob
														_snake_case       =  attention_probs_dropout_prob
														_snake_case       =  drop_path_rate
														_snake_case       =  hidden_act
														_snake_case       =  layer_norm_eps
														_snake_case       =  initializer_range
														# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
														# this indicates the channel dimension after the last stage of the model
														_snake_case       =  int(embed_dim * 2 ** (len(UpperCAmelCase  ) - 1)  )
														_snake_case       =  layer_scale_init_value
														_snake_case       =  ["""stem"""] + [f"""stage{idx}""" for idx in range(1  ,  len(UpperCAmelCase  ) + 1  )]
														_snake_case,							_snake_case       =  get_aligned_output_features_output_indices(
														    out_features=UpperCAmelCase  ,  out_indices=UpperCAmelCase  ,  stage_names=self.stage_names  )