






from typing import List, Optional, Union

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


snake_case     					=		logging.get_logger(__name__)

snake_case     					=		{
    """huggingface/informer-tourism-monthly""": (
        """https://huggingface.co/huggingface/informer-tourism-monthly/resolve/main/config.json"""
    ),
    # See all Informer models at https://huggingface.co/models?filter=informer
}


class 			SCREAMING_SNAKE_CASE      (      lowerCAmelCase       ):
     '''simple docstring'''


     UpperCamelCase_				:		Tuple								=						'''informer'''
     UpperCamelCase_				:		Tuple								=						{
         '''hidden_size''': '''d_model''',
         '''num_attention_heads''': '''encoder_attention_heads''',
         '''num_hidden_layers''': '''encoder_layers''',
     }


     def __init__(					self							:						Any       ,			UpperCAmelCase_							:						Optional[int] = None       ,			UpperCAmelCase_							:						Optional[int] = None       ,			UpperCAmelCase_							:						str = "student_t"       ,			UpperCAmelCase_							:						str = "nll"       ,			UpperCAmelCase_							:						int = 1       ,			UpperCAmelCase_							:						List[int] = None       ,			UpperCAmelCase_							:						Optional[Union[str, bool]] = "mean"       ,			UpperCAmelCase_							:						int = 0       ,			UpperCAmelCase_							:						int = 0       ,			UpperCAmelCase_							:						int = 0       ,			UpperCAmelCase_							:						int = 0       ,			UpperCAmelCase_							:						Optional[List[int]] = None       ,			UpperCAmelCase_							:						Optional[List[int]] = None       ,			UpperCAmelCase_							:						int = 64       ,			UpperCAmelCase_							:						int = 32       ,			UpperCAmelCase_							:						int = 32       ,			UpperCAmelCase_							:						int = 2       ,			UpperCAmelCase_							:						int = 2       ,			UpperCAmelCase_							:						int = 2       ,			UpperCAmelCase_							:						int = 2       ,			UpperCAmelCase_							:						bool = True       ,			UpperCAmelCase_							:						str = "gelu"       ,			UpperCAmelCase_							:						float = 0.05       ,			UpperCAmelCase_							:						float = 0.1       ,			UpperCAmelCase_							:						float = 0.1       ,			UpperCAmelCase_							:						float = 0.1       ,			UpperCAmelCase_							:						float = 0.1       ,			UpperCAmelCase_							:						int = 100       ,			UpperCAmelCase_							:						float = 0.02       ,			UpperCAmelCase_							:						Optional[int]=True       ,			UpperCAmelCase_							:						str = "prob"       ,			UpperCAmelCase_							:						int = 5       ,			UpperCAmelCase_							:						bool = True       ,			**UpperCAmelCase_							:						Tuple       ,			):
       # time series specific configuration
       SCREAMING_SNAKE_CASE							:   str						    =     prediction_length
       SCREAMING_SNAKE_CASE							:   List[str]						    =     context_length or prediction_length
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     distribution_output
       SCREAMING_SNAKE_CASE							:   Tuple						    =     loss
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     input_size
       SCREAMING_SNAKE_CASE							:   Any						    =     num_time_features
       SCREAMING_SNAKE_CASE							:   List[str]						    =     lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     scaling
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     num_dynamic_real_features
       SCREAMING_SNAKE_CASE							:   Dict						    =     num_static_real_features
       SCREAMING_SNAKE_CASE							:   Dict						    =     num_static_categorical_features

       # set cardinality
       if cardinality and num_static_categorical_features > 0:
         if len(UpperCAmelCase_   ) != num_static_categorical_features:
           raise ValueError(
               "The cardinality should be a list of the same length as `num_static_categorical_features`"   )
         SCREAMING_SNAKE_CASE							:   Any						    =     cardinality
       else:
         SCREAMING_SNAKE_CASE							:   Optional[int]						    =     [0]

       # set embedding_dimension
       if embedding_dimension and num_static_categorical_features > 0:
         if len(UpperCAmelCase_   ) != num_static_categorical_features:
           raise ValueError(
               "The embedding dimension should be a list of the same length as `num_static_categorical_features`"   )
         SCREAMING_SNAKE_CASE							:   Tuple						    =     embedding_dimension
       else:
         SCREAMING_SNAKE_CASE							:   List[str]						    =     [min(50       ,			(cat + 1) // 2   ) for cat in self.cardinality]

       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     num_parallel_samples

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

       SCREAMING_SNAKE_CASE							:   List[str]						    =     dropout
       SCREAMING_SNAKE_CASE							:   Optional[int]						    =     attention_dropout
       SCREAMING_SNAKE_CASE							:   Dict						    =     activation_dropout
       SCREAMING_SNAKE_CASE							:   List[str]						    =     encoder_layerdrop
       SCREAMING_SNAKE_CASE							:   Tuple						    =     decoder_layerdrop

       SCREAMING_SNAKE_CASE							:   str						    =     activation_function
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     init_std

       SCREAMING_SNAKE_CASE							:   Any						    =     use_cache

       # Informer
       SCREAMING_SNAKE_CASE							:   Dict						    =     attention_type
       SCREAMING_SNAKE_CASE							:   Dict						    =     sampling_factor
       SCREAMING_SNAKE_CASE							:   Any						    =     distil

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






     @property
     def 					_A							(					self							:						Any   ):
       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 importlib
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
import transformers.models.auto
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.bert.configuration_bert import BertConfig
from transformers.models.roberta.configuration_roberta import RobertaConfig
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / '''utils'''))

from test_module.custom_configuration import CustomConfig  # noqa E402


snake_case   					=				get_tests_dir('''fixtures/dummy-config.json''')



class     UpperCAmelCase    (	unittest.TestCase  ):



   def    __UpperCAmelCase    (       self    :	Any				):



     """simple docstring"""
     _snake_case   	=      0



   def    __UpperCAmelCase    (       self    :	Optional[Any]				):



     """simple docstring"""
     self.assertIsNotNone(transformers.models.auto.__spec__				)
     self.assertIsNotNone(importlib.util.find_spec('''transformers.models.auto'''				)				)



   def    __UpperCAmelCase    (       self    :	List[str]				):



     """simple docstring"""
     _snake_case   	=      AutoConfig.from_pretrained('''bert-base-uncased'''				)
     self.assertIsInstance(__lowerCamelCase							,       __lowerCamelCase				)



   def    __UpperCAmelCase    (       self    :	Union[str, Any]				):



     """simple docstring"""
     _snake_case   	=      AutoConfig.from_pretrained(__lowerCamelCase				)
     self.assertIsInstance(__lowerCamelCase							,       __lowerCamelCase				)



   def    __UpperCAmelCase    (       self    :	int				):



     """simple docstring"""
     _snake_case   	=      AutoConfig.from_pretrained(__lowerCamelCase				)
     self.assertIsInstance(__lowerCamelCase							,       __lowerCamelCase				)



   def    __UpperCAmelCase    (       self    :	Union[str, Any]				):



     """simple docstring"""
     _snake_case   	=      AutoConfig.for_model('''roberta'''				)
     self.assertIsInstance(__lowerCamelCase							,       __lowerCamelCase				)



   def    __UpperCAmelCase    (       self    :	Dict				):



     """simple docstring"""
     with tempfile.TemporaryDirectory() as tmp_dir:
       # This model name contains bert and roberta, but roberta ends up being picked.
       _snake_case   	=      os.path.join(__lowerCamelCase							,       '''fake-roberta'''				)
       os.makedirs(__lowerCamelCase							,       exist_ok=__lowerCamelCase				)
       with open(os.path.join(__lowerCamelCase							,       '''config.json'''				)							,       '''w'''				) as f:
         f.write(json.dumps({}				)				)
       _snake_case   	=      AutoConfig.from_pretrained(__lowerCamelCase				)
       self.assertEqual(type(__lowerCamelCase				)							,       __lowerCamelCase				)



   def    __UpperCAmelCase    (       self    :	Optional[Any]				):



     """simple docstring"""
     try:
       AutoConfig.register('''custom'''							,       __lowerCamelCase				)
       # Wrong model type will raise an error
       with self.assertRaises(__lowerCamelCase				):
         AutoConfig.register('''model'''							,       __lowerCamelCase				)
       # Trying to register something existing in the Transformers library will raise an error
       with self.assertRaises(__lowerCamelCase				):
         AutoConfig.register('''bert'''							,       __lowerCamelCase				)

       # Now that the config is registered, it can be used as any other config with the auto-API
       _snake_case   	=      CustomConfig()
       with tempfile.TemporaryDirectory() as tmp_dir:
         config.save_pretrained(__lowerCamelCase				)
         _snake_case   	=      AutoConfig.from_pretrained(__lowerCamelCase				)
         self.assertIsInstance(__lowerCamelCase							,       __lowerCamelCase				)

     finally:
       if "custom" in CONFIG_MAPPING._extra_content:
         del CONFIG_MAPPING._extra_content["custom"]



   def    __UpperCAmelCase    (       self    :	Optional[int]				):



     """simple docstring"""
     with self.assertRaisesRegex(
         __lowerCamelCase							,       '''bert-base is not a local folder and is not a valid model identifier'''				):
       _snake_case   	=      AutoConfig.from_pretrained('''bert-base'''				)



   def    __UpperCAmelCase    (       self    :	Dict				):



     """simple docstring"""
     with self.assertRaisesRegex(
         __lowerCamelCase							,       R'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''				):
       _snake_case   	=      AutoConfig.from_pretrained(__lowerCamelCase							,       revision='''aaaaaa'''				)



   def    __UpperCAmelCase    (       self    :	Dict				):



     """simple docstring"""
     with self.assertRaisesRegex(
         __lowerCamelCase							,       '''hf-internal-testing/no-config-test-repo does not appear to have a file named config.json.'''							,       ):
       _snake_case   	=      AutoConfig.from_pretrained('''hf-internal-testing/no-config-test-repo'''				)



   def    __UpperCAmelCase    (       self    :	str				):



     """simple docstring"""
     # If remote code is not set, we will time out when asking whether to load the model.
     with self.assertRaises(__lowerCamelCase				):
       _snake_case   	=      AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''				)
     # If remote code is disabled, we can't load this config.
     with self.assertRaises(__lowerCamelCase				):
       _snake_case   	=      AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''							,       trust_remote_code=__lowerCamelCase				)

     _snake_case   	=      AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''							,       trust_remote_code=__lowerCamelCase				)
     self.assertEqual(config.__class__.__name__							,       '''NewModelConfig'''				)

     # Test config can be reloaded.
     with tempfile.TemporaryDirectory() as tmp_dir:
       config.save_pretrained(__lowerCamelCase				)
       _snake_case   	=      AutoConfig.from_pretrained(__lowerCamelCase							,       trust_remote_code=__lowerCamelCase				)
     self.assertEqual(reloaded_config.__class__.__name__							,       '''NewModelConfig'''				)





   def    __UpperCAmelCase    (       self    :	Union[str, Any]				):



     """simple docstring"""



     class     UpperCAmelCase    (	__SCREAMING_SNAKE_CASE  ):
        A__		:	List[Any]           =  '''new-model'''

     try:
       AutoConfig.register('''new-model'''							,       __lowerCamelCase				)
       # If remote code is not set, the default is to use local
       _snake_case   	=      AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''				)
       self.assertEqual(config.__class__.__name__							,       '''NewModelConfigLocal'''				)

       # If remote code is disabled, we load the local one.
       _snake_case   	=      AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''							,       trust_remote_code=__lowerCamelCase				)
       self.assertEqual(config.__class__.__name__							,       '''NewModelConfigLocal'''				)

       # If remote is enabled, we load from the Hub
       _snake_case   	=      AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''							,       trust_remote_code=__lowerCamelCase				)
       self.assertEqual(config.__class__.__name__							,       '''NewModelConfig'''				)

     finally:
       if "new-model" in CONFIG_MAPPING._extra_content:
         del CONFIG_MAPPING._extra_content["new-model"]





