

from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_torch_available, is_torch_tpu_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_torch_available():
			import torch

if is_torch_tpu_available(check_device=False):
			import torch_xla.core.xla_model as xm


a__				=		logging.get_logger(__name__)

@dataclass
class 				UpperCAmelCase_		(			UpperCAmelCase__   ):
							"""simple docstring"""







							UpperCAmelCase__       :						Optional[int]	    =    [
							    """no_inference""",
							    """no_cuda""",
							    """no_tpu""",
							    """no_speed""",
							    """no_memory""",
							    """no_env_print""",
							    """no_multi_process""",
							]


							def __init__(			self       ,							**_a       )    ->    Any:

												for deprecated_arg in self.deprecated_args:
																	if deprecated_arg in kwargs:
																						_a	:    Dict         =		deprecated_arg[3:]
																						setattr(self       ,							snake_case_       ,							not kwargs.pop(snake_case_       )       )
																						logger.warning(
																						    F"""{deprecated_arg} is depreciated. Please use --no_{positive_arg} or"""
																						    F""" {positive_arg}={kwargs[positive_arg]}"""       )

												_a	:    Optional[int]         =		kwargs.pop('''torchscript'''       ,							self.torchscript       )
												_a	:    List[Any]         =		kwargs.pop('''torch_xla_tpu_print_metrics'''       ,							self.torch_xla_tpu_print_metrics       )
												_a	:    Optional[int]         =		kwargs.pop('''fp16_opt_level'''       ,							self.fpaa_opt_level       )
												super().__init__(**snake_case_       )

							UpperCAmelCase__       :						bool	    =    field(default=UpperCAmelCase__				,       metadata={"help": "Trace the models using torchscript"}   )
							UpperCAmelCase__       :						bool	    =    field(default=UpperCAmelCase__				,       metadata={"help": "Print Xla/PyTorch tpu metrics"}   )
							UpperCAmelCase__       :						str	    =    field(
							    default="O1"				,       metadata={
							        "help": (
							            "For fp16: Apex AMP optimization level selected in ['O0', 'O1', 'O2', and 'O3']. "
							            "See details at https://nvidia.github.io/apex/amp.html"
							        )
							    }				,       )


							@cached_property
							def 				__lowercase				(			self       )    ->    Optional[int]:
												requires_backends(self       ,							['''torch''']       )
												logger.info('''PyTorch: setting up devices'''       )
												if not self.cuda:
																	_a	:    Optional[Any]         =		torch.device('''cpu'''       )
																	_a	:    Optional[int]         =		0
												elif is_torch_tpu_available():
																	_a	:    int         =		xm.xla_device()
																	_a	:    Union[str, Any]         =		0
												else:
																	_a	:    Dict         =		torch.device('''cuda''' if torch.cuda.is_available() else '''cpu'''       )
																	_a	:    Optional[Any]         =		torch.cuda.device_count()
												return device, n_gpu


							@property
							def 				__lowercase				(			self       )    ->    Dict:
												return is_torch_tpu_available() and self.tpu


							@property
							def 				__lowercase				(			self       )    ->    Dict:
												requires_backends(self       ,							['''torch''']       )
												# TODO(PVP): currently only single GPU is supported
												return torch.cuda.current_device()


							@property
							def 				__lowercase				(			self       )    ->    int:
												requires_backends(self       ,							['''torch''']       )
												return self._setup_devices[0]


							@property
							def 				__lowercase				(			self       )    ->    int:
												requires_backends(self       ,							['''torch''']       )
												return self._setup_devices[1]




							@property
							def 				__lowercase				(			self       )    ->    List[Any]:
												return self.n_gpu > 0










"""simple docstring"""




from typing import List, Optional, Union

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


lowerCamelCase_     :						Union[str, Any]						=					logging.get_logger(__name__)

lowerCamelCase_     :						Optional[Any]						=					{
    '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  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''
      lowercase_      : Tuple	    =   """informer"""
      lowercase_      : str	    =   {
          """hidden_size""": """d_model""",
          """num_attention_heads""": """encoder_attention_heads""",
          """num_hidden_layers""": """encoder_layers""",
      }

      def __init__(     self					,      snake_case_ = None					,      snake_case_ = None					,      snake_case_ = "student_t"					,      snake_case_ = "nll"					,      snake_case_ = 1					,      snake_case_ = None					,      snake_case_ = "mean"					,      snake_case_ = 0					,      snake_case_ = 0					,      snake_case_ = 0					,      snake_case_ = 0					,      snake_case_ = None					,      snake_case_ = None					,      snake_case_ = 6_4					,      snake_case_ = 3_2					,      snake_case_ = 3_2					,      snake_case_ = 2					,      snake_case_ = 2					,      snake_case_ = 2					,      snake_case_ = 2					,      snake_case_ = True					,      snake_case_ = "gelu"					,      snake_case_ = 0.05					,      snake_case_ = 0.1					,      snake_case_ = 0.1					,      snake_case_ = 0.1					,      snake_case_ = 0.1					,      snake_case_ = 1_0_0					,      snake_case_ = 0.02					,      snake_case_=True					,      snake_case_ = "prob"					,      snake_case_ = 5					,      snake_case_ = True					,      **snake_case_					,      ):

        """simple docstring"""

        A_  :       str										=  prediction_length
        A_  :       List[Any]										=  context_length or prediction_length
        A_  :       str										=  distribution_output
        A_  :       Dict										=  loss
        A_  :       Any										=  input_size
        A_  :       Union[str, Any]										=  num_time_features
        A_  :       Optional[Any]										=  lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
        A_  :       List[Any]										=  scaling
        A_  :       Tuple										=  num_dynamic_real_features
        A_  :       Any										=  num_static_real_features
        A_  :       str										=  num_static_categorical_features

        # set cardinality
        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`'  )
          A_  :       Optional[int]										=  cardinality
        else:
          A_  :       Optional[Any]										=  [0]

        # set embedding_dimension
        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`'  )
          A_  :       Any										=  embedding_dimension
        else:
          A_  :       Optional[Any]										=  [min(5_0					,      (cat + 1) // 2  ) for cat in self.cardinality]

        A_  :       int										=  num_parallel_samples

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

        A_  :       List[Any]										=  dropout
        A_  :       str										=  attention_dropout
        A_  :       Tuple										=  activation_dropout
        A_  :       List[str]										=  encoder_layerdrop
        A_  :       List[str]										=  decoder_layerdrop

        A_  :       str										=  activation_function
        A_  :       Optional[int]										=  init_std

        A_  :       List[Any]										=  use_cache

        # Informer
        A_  :       Tuple										=  attention_type
        A_  :       List[Any]										=  sampling_factor
        A_  :       Optional[int]										=  distil

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

      @property
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        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
        )