
import os
import sys
import unittest


UpperCAmelCase_   :				int						      = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, 'utils'))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
UpperCAmelCase_   :				Tuple						      = os.path.join(git_repo_path, 'src', 'transformers')

UpperCAmelCase_   :				Union[str, Any]						      = '\n{0} = None\n'

UpperCAmelCase_   :				Optional[int]						      = '\nclass {0}(metaclass=DummyObject):\n    _backends = {1}\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, {1})\n'


UpperCAmelCase_   :				Dict						      = '\ndef {0}(*args, **kwargs):\n    requires_backends({0}, {1})\n'
class 				SCREAMING_SNAKE_CASE__						(       unittest.TestCase    ):
      def  SCREAMING_SNAKE_CASE							( self       : Optional[Any]  )	->    List[str]:
             a_      :	Dict							=						find_backend('    _import_structure["models.albert"].append("AlbertTokenizerFast")'  )
             self.assertIsNone(SCREAMING_SNAKE_CASE__  )

             a_      :	Optional[int]							=						find_backend('    if not is_tokenizers_available():'  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							'tokenizers'  )

             a_      :	Dict							=						find_backend('    if not is_tensorflow_text_available():'  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							'tensorflow_text'  )

             a_      :	Tuple							=						find_backend('    if not (is_sentencepiece_available() and is_tokenizers_available()):'  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							'sentencepiece_and_tokenizers'  )

             a_      :	Any							=						find_backend(
                 '    if not (is_sentencepiece_available() and is_tensorflow_text_available()):'  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							'sentencepiece_and_tensorflow_text'  )

             a_      :	Optional[int]							=						find_backend(
                 '    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):'  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							'sentencepiece_and_tokenizers_and_vision'  )
      def  SCREAMING_SNAKE_CASE							( self       : int  )	->    Dict:
             a_      :	int							=						read_init()
             # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
             self.assertIn('torch'  ,							SCREAMING_SNAKE_CASE__  )
             self.assertIn('tensorflow_text'  ,							SCREAMING_SNAKE_CASE__  )
             self.assertIn('sentencepiece_and_tokenizers'  ,							SCREAMING_SNAKE_CASE__  )

             # Likewise, we can't assert on the exact content of a key
             self.assertIn('BertModel'  ,							objects['torch']  )
             self.assertIn('TFBertModel'  ,							objects['tf']  )
             self.assertIn('FlaxBertModel'  ,							objects['flax']  )
             self.assertIn('BertModel'  ,							objects['torch']  )
             self.assertIn('TFBertTokenizer'  ,							objects['tensorflow_text']  )
             self.assertIn('convert_slow_tokenizer'  ,							objects['sentencepiece_and_tokenizers']  )
      def  SCREAMING_SNAKE_CASE							( self       : Optional[int]  )	->    Optional[Any]:
             a_      :	Union[str, Any]							=						create_dummy_object('CONSTANT'  ,							'\'torch\''  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							'\nCONSTANT = None\n'  )

             a_      :	List[Any]							=						create_dummy_object('function'  ,							'\'torch\''  )
             self.assertEqual(
                 SCREAMING_SNAKE_CASE__  ,							'\ndef function(*args, **kwargs):\n    requires_backends(function, \'torch\')\n'  )

             a_      :	Optional[Any]							=						'\nclass FakeClass(metaclass=DummyObject):\n    _backends = \'torch\'\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, \'torch\')\n'
             a_      :	Optional[Any]							=						create_dummy_object('FakeClass'  ,							'\'torch\''  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							SCREAMING_SNAKE_CASE__  )

      def  SCREAMING_SNAKE_CASE							( self       : str  )	->    List[Any]:
             a_      :	Any							=						'# This file is autogenerated by the command `make fix-copies`, do not edit.\nfrom ..utils import DummyObject, requires_backends\n\n\nCONSTANT = None\n\n\ndef function(*args, **kwargs):\n    requires_backends(function, ["torch"])\n\n\nclass FakeClass(metaclass=DummyObject):\n    _backends = ["torch"]\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, ["torch"])\n'
             a_      :	int							=						create_dummy_files({'torch': ['CONSTANT', 'function', 'FakeClass']}  )
             self.assertEqual(dummy_files['torch']  ,							SCREAMING_SNAKE_CASE__  )






from typing import List, Optional

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


UpperCAmelCase_   :				Dict						      = logging.get_logger(__name__)

UpperCAmelCase_   :				int						      = {
    'huggingface/autoformer-tourism-monthly': 'https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json',
}
class 				SCREAMING_SNAKE_CASE__						(       lowercase__    ):
      snake_case__       :  Union[str, Any]       =		'''autoformer'''
      snake_case__       :  Any       =		{
          '''hidden_size''': '''d_model''',
          '''num_attention_heads''': '''encoder_attention_heads''',
          '''num_hidden_layers''': '''encoder_layers''',
      }
      def __init__( self       : Optional[int]  ,							SCREAMING_SNAKE_CASE__       : Optional[int] = None  ,							SCREAMING_SNAKE_CASE__       : Optional[int] = None  ,							SCREAMING_SNAKE_CASE__       : str = "student_t"  ,							SCREAMING_SNAKE_CASE__       : str = "nll"  ,							SCREAMING_SNAKE_CASE__       : int = 1  ,							SCREAMING_SNAKE_CASE__       : List[int] = [1, 2, 3, 4, 5, 6, 7]  ,							SCREAMING_SNAKE_CASE__       : bool = True  ,							SCREAMING_SNAKE_CASE__       : int = 0  ,							SCREAMING_SNAKE_CASE__       : int = 0  ,							SCREAMING_SNAKE_CASE__       : int = 0  ,							SCREAMING_SNAKE_CASE__       : int = 0  ,							SCREAMING_SNAKE_CASE__       : Optional[List[int]] = None  ,							SCREAMING_SNAKE_CASE__       : Optional[List[int]] = None  ,							SCREAMING_SNAKE_CASE__       : int = 6_4  ,							SCREAMING_SNAKE_CASE__       : int = 2  ,							SCREAMING_SNAKE_CASE__       : int = 2  ,							SCREAMING_SNAKE_CASE__       : int = 2  ,							SCREAMING_SNAKE_CASE__       : int = 2  ,							SCREAMING_SNAKE_CASE__       : int = 3_2  ,							SCREAMING_SNAKE_CASE__       : int = 3_2  ,							SCREAMING_SNAKE_CASE__       : str = "gelu"  ,							SCREAMING_SNAKE_CASE__       : float = 0.1  ,							SCREAMING_SNAKE_CASE__       : float = 0.1  ,							SCREAMING_SNAKE_CASE__       : float = 0.1  ,							SCREAMING_SNAKE_CASE__       : float = 0.1  ,							SCREAMING_SNAKE_CASE__       : float = 0.1  ,							SCREAMING_SNAKE_CASE__       : int = 1_0_0  ,							SCREAMING_SNAKE_CASE__       : float = 0.02  ,							SCREAMING_SNAKE_CASE__       : bool = True  ,							SCREAMING_SNAKE_CASE__       : List[str]=True  ,							SCREAMING_SNAKE_CASE__       : int = 1_0  ,							SCREAMING_SNAKE_CASE__       : int = 2_5  ,							SCREAMING_SNAKE_CASE__       : int = 3  ,							**SCREAMING_SNAKE_CASE__       : int  ,							)	->    Union[str, Any]:
             # time series specific configuration
             a_      :	Optional[int]							=						prediction_length
             a_      :	Tuple							=						context_length if context_length is not None else prediction_length
             a_      :	Tuple							=						distribution_output
             a_      :	int							=						loss
             a_      :	Tuple							=						input_size
             a_      :	int							=						num_time_features
             a_      :	Dict							=						lags_sequence
             a_      :	List[str]							=						scaling
             a_      :	Tuple							=						num_dynamic_real_features
             a_      :	Dict							=						num_static_real_features
             a_      :	Dict							=						num_static_categorical_features
             if cardinality is not None and num_static_categorical_features > 0:
                    if len(SCREAMING_SNAKE_CASE__  ) != num_static_categorical_features:
                           raise ValueError(
                               'The cardinality should be a list of the same length as `num_static_categorical_features`'  )
                    a_      :	Any							=						cardinality
             else:
                    a_      :	Tuple							=						[0]
             if embedding_dimension is not None and num_static_categorical_features > 0:
                    if len(SCREAMING_SNAKE_CASE__  ) != num_static_categorical_features:
                           raise ValueError(
                               'The embedding dimension should be a list of the same length as `num_static_categorical_features`'  )
                    a_      :	Tuple							=						embedding_dimension
             else:
                    a_      :	Optional[Any]							=						[min(5_0  ,							(cat + 1) // 2  ) for cat in self.cardinality]
             a_      :	Optional[Any]							=						num_parallel_samples

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

             a_      :	List[Any]							=						dropout
             a_      :	Tuple							=						attention_dropout
             a_      :	Union[str, Any]							=						activation_dropout
             a_      :	List[Any]							=						encoder_layerdrop
             a_      :	List[str]							=						decoder_layerdrop

             a_      :	Optional[Any]							=						activation_function
             a_      :	Union[str, Any]							=						init_std

             a_      :	List[str]							=						use_cache

             # Autoformer
             a_      :	Tuple							=						label_length
             a_      :	List[Any]							=						moving_average
             a_      :	Optional[Any]							=						autocorrelation_factor

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

      @property
      def  SCREAMING_SNAKE_CASE							( self       : List[Any]  )	->    int:
             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
             )


