


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


_lowerCAmelCase:						int   				=       logging.get_logger(__name__)




@dataclass
class       lowercase_					(lowercase__   ):
				snake_case	    =[
				    'no_inference',
				    'no_cuda',
				    'no_tpu',
				    'no_speed',
				    'no_memory',
				    'no_env_print',
				    'no_multi_process',
				]





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

											a__      =kwargs.pop('torchscript'       ,  self.torchscript)
											a__      =kwargs.pop('torch_xla_tpu_print_metrics'       ,  self.torch_xla_tpu_print_metrics)
											a__      =kwargs.pop('fp16_opt_level'       ,  self.fpaa_opt_level)
											super().__init__(**lowercase_)

				snake_case	    =field(default=lowercase__      ,					metadata={'help': 'Trace the models using torchscript'}   )
				snake_case	    =field(default=lowercase__      ,					metadata={'help': 'Print Xla/PyTorch tpu metrics'}   )
				snake_case	    =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 						__UpperCamelCase    (				self)  -> Tuple["torch.device", int]:
											requires_backends(self       ,  ['torch'])
											logger.info('PyTorch: setting up devices')
											if not self.cuda:
																		a__      =torch.device('cpu')
																		a__      =0
											elif is_torch_tpu_available():
																		a__      =xm.xla_device()
																		a__      =0
											else:
																		a__      =torch.device('cuda' if torch.cuda.is_available() else 'cpu')
																		a__      =torch.cuda.device_count()
											return device, n_gpu





				@property
				def 						__UpperCamelCase    (				self)  -> List[Any]:
											return is_torch_tpu_available() and self.tpu





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





				@property
				def 						__UpperCamelCase    (				self)  -> "torch.device":
											requires_backends(self       ,  ['torch'])
											return self._setup_devices[0]





				@property
				def 						__UpperCamelCase    (				self)  -> List[str]:
											requires_backends(self       ,  ['torch'])
											return self._setup_devices[1]





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





from typing import List, Optional

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


_lowerCAmelCase:						List[Any]   				=       logging.get_logger(__name__)

_lowerCAmelCase:						Any   				=       {
    'huggingface/autoformer-tourism-monthly': 'https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json',
}




class       lowercase_					(lowercase__   ):
				snake_case	    ='autoformer'
				snake_case	    ={
				    'hidden_size': 'd_model',
				    'num_attention_heads': 'encoder_attention_heads',
				    'num_hidden_layers': 'encoder_layers',
				}





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

											# Transformer architecture configuration
											a__      =input_size * len(self.lags_sequence) + self._number_of_features
											a__      =d_model
											a__      =encoder_attention_heads
											a__      =decoder_attention_heads
											a__      =encoder_ffn_dim
											a__      =decoder_ffn_dim
											a__      =encoder_layers
											a__      =decoder_layers

											a__      =dropout
											a__      =attention_dropout
											a__      =activation_dropout
											a__      =encoder_layerdrop
											a__      =decoder_layerdrop

											a__      =activation_function
											a__      =init_std

											a__      =use_cache

											# Autoformer
											a__      =label_length
											a__      =moving_average
											a__      =autocorrelation_factor

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





				@property
				def 						__UpperCamelCase    (				self)  -> 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
											)

