



'''simple docstring'''





from typing import List, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__a  			=						logging.get_logger(__name__)

__a  			=						{
    "huggingface/time-series-transformer-tourism-monthly": (
        "https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json"
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}







class        UpperCAmelCase_			(			_a      ):
    """simple docstring"""







    lowercase   =						"time_series_transformer"
    lowercase   =						{
        "hidden_size": "d_model",
        "num_attention_heads": "encoder_attention_heads",
        "num_hidden_layers": "encoder_layers",
    }




    def __init__(       self   :	List[Any]					,	snake_case_   :	Optional[int] = None					,	snake_case_   :	Optional[int] = None					,	snake_case_   :	str = "student_t"					,	snake_case_   :	str = "nll"					,	snake_case_   :	int = 1					,	snake_case_   :	List[int] = [1, 2, 3, 4, 5, 6, 7]					,	snake_case_   :	Optional[Union[str, bool]] = "mean"					,	snake_case_   :	int = 0					,	snake_case_   :	int = 0					,	snake_case_   :	int = 0					,	snake_case_   :	int = 0					,	snake_case_   :	Optional[List[int]] = None					,	snake_case_   :	Optional[List[int]] = None					,	snake_case_   :	int = 32					,	snake_case_   :	int = 32					,	snake_case_   :	int = 2					,	snake_case_   :	int = 2					,	snake_case_   :	int = 2					,	snake_case_   :	int = 2					,	snake_case_   :	bool = True					,	snake_case_   :	str = "gelu"					,	snake_case_   :	int = 64					,	snake_case_   :	float = 0.1					,	snake_case_   :	float = 0.1					,	snake_case_   :	float = 0.1					,	snake_case_   :	float = 0.1					,	snake_case_   :	float = 0.1					,	snake_case_   :	int = 100					,	snake_case_   :	float = 0.02					,	snake_case_   :	int=True					,	**snake_case_   :	List[Any]					,	):
          # time series specific configuration
          snake_case__    :       Tuple       		= prediction_length
          snake_case__    :       List[Any]       		= context_length or prediction_length
          snake_case__    :       List[str]       		= distribution_output
          snake_case__    :       int       		= loss
          snake_case__    :       Optional[int]       		= input_size
          snake_case__    :       List[Any]       		= num_time_features
          snake_case__    :       List[str]       		= lags_sequence
          snake_case__    :       List[str]       		= scaling
          snake_case__    :       Any       		= num_dynamic_real_features
          snake_case__    :       Optional[Any]       		= num_static_real_features
          snake_case__    :       Any       		= num_static_categorical_features
          if cardinality and num_static_categorical_features > 0:
                if len(snake_case_		) != num_static_categorical_features:
                      raise ValueError(
                          """The cardinality should be a list of the same length as `num_static_categorical_features`"""		)
                snake_case__    :       int       		= cardinality
          else:
                snake_case__    :       int       		= [0]
          if embedding_dimension and num_static_categorical_features > 0:
                if len(snake_case_		) != num_static_categorical_features:
                      raise ValueError(
                          """The embedding dimension should be a list of the same length as `num_static_categorical_features`"""		)
                snake_case__    :       Union[str, Any]       		= embedding_dimension
          else:
                snake_case__    :       Optional[int]       		= [min(50					,	(cat + 1) // 2		) for cat in self.cardinality]
          snake_case__    :       Optional[int]       		= num_parallel_samples

          # Transformer architecture configuration
          snake_case__    :       Optional[int]       		= input_size * len(snake_case_		) + self._number_of_features
          snake_case__    :       Optional[int]       		= d_model
          snake_case__    :       Union[str, Any]       		= encoder_attention_heads
          snake_case__    :       List[str]       		= decoder_attention_heads
          snake_case__    :       Dict       		= encoder_ffn_dim
          snake_case__    :       Tuple       		= decoder_ffn_dim
          snake_case__    :       List[str]       		= encoder_layers
          snake_case__    :       List[Any]       		= decoder_layers

          snake_case__    :       Optional[Any]       		= dropout
          snake_case__    :       Optional[Any]       		= attention_dropout
          snake_case__    :       List[Any]       		= activation_dropout
          snake_case__    :       Optional[Any]       		= encoder_layerdrop
          snake_case__    :       Optional[int]       		= decoder_layerdrop

          snake_case__    :       int       		= activation_function
          snake_case__    :       int       		= init_std

          snake_case__    :       List[str]       		= use_cache

          super().__init__(is_encoder_decoder=snake_case_					,	**snake_case_		)




    @property
    def lowerCamelCase			(       self   :	Tuple		):
          return (
              sum(self.embedding_dimension		)
              + self.num_dynamic_real_features
              + self.num_time_features
              + self.num_static_real_features
              + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
          )





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







    def lowerCamelCase			(       self   :	Optional[int]		):
          snake_case__    :       int       		= logging.get_logger()

          # the current default level is logging.WARNING
          snake_case__    :       str       		= 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(snake_case_		)




    def lowerCamelCase			(       self   :	Union[str, Any]		):
          snake_case__    :       List[Any]       		= logging.get_verbosity()

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

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

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




    @mockenv(TRANSFORMERS_VERBOSITY="""error"""		)
    def lowerCamelCase			(       self   :	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
          snake_case__    :       Union[str, Any]       		= logging.get_logger("""transformers.models.bart.tokenization_bart"""		)

          snake_case__    :       int       		= os.getenv("""TRANSFORMERS_VERBOSITY"""					,	snake_case_		)
          snake_case__    :       List[Any]       		= logging.log_levels[env_level_str]

          snake_case__    :       str       		= logging.get_verbosity()
          self.assertEqual(
              snake_case_					,	snake_case_					,	f"TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}"					,	)

          # restore to the original level
          snake_case__    :       List[Any]       		= """"""
          transformers.utils.logging._reset_library_root_logger()




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

          snake_case__    :       Optional[int]       		= logging.get_logger("""transformers.models.bart.tokenization_bart"""		)
          snake_case__    :       Tuple       		= """Testing 1, 2, 3"""

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

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





def 		__snake_case(							)						->					List[str]:
      disable_progress_bar()
      assert are_progress_bars_disabled()

      enable_progress_bar()
      assert not are_progress_bars_disabled()
