






'''simple docstring'''


from typing import List, Optional

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


lowercase_      :				int   					=    logging.get_logger(__name__)

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




class      __UpperCamelCase       (_UpperCAmelCase			):
	__A			  =					'''autoformer'''
	__A			  =					{
	    '''hidden_size''': '''d_model''',
	    '''num_attention_heads''': '''encoder_attention_heads''',
	    '''num_hidden_layers''': '''encoder_layers''',
	}







	def __init__(    self ,				_lowerCAmelCase = None ,				_lowerCAmelCase = None ,				_lowerCAmelCase = "student_t" ,				_lowerCAmelCase = "nll" ,				_lowerCAmelCase = 1 ,				_lowerCAmelCase = [1, 2, 3, 4, 5, 6, 7] ,				_lowerCAmelCase = True ,				_lowerCAmelCase = 0 ,				_lowerCAmelCase = 0 ,				_lowerCAmelCase = 0 ,				_lowerCAmelCase = 0 ,				_lowerCAmelCase = None ,				_lowerCAmelCase = None ,				_lowerCAmelCase = 64 ,				_lowerCAmelCase = 2 ,				_lowerCAmelCase = 2 ,				_lowerCAmelCase = 2 ,				_lowerCAmelCase = 2 ,				_lowerCAmelCase = 32 ,				_lowerCAmelCase = 32 ,				_lowerCAmelCase = "gelu" ,				_lowerCAmelCase = 0.1 ,				_lowerCAmelCase = 0.1 ,				_lowerCAmelCase = 0.1 ,				_lowerCAmelCase = 0.1 ,				_lowerCAmelCase = 0.1 ,				_lowerCAmelCase = 100 ,				_lowerCAmelCase = 0.02 ,				_lowerCAmelCase = True ,				_lowerCAmelCase=True ,				_lowerCAmelCase = 10 ,				_lowerCAmelCase = 25 ,				_lowerCAmelCase = 3 ,				**_lowerCAmelCase ,				)    ->    str:
							'''simple docstring'''






							lowercase        =							prediction_length
							lowercase        =							context_length if context_length is not None else prediction_length
							lowercase        =							distribution_output
							lowercase        =							loss
							lowercase        =							input_size
							lowercase        =							num_time_features
							lowercase        =							lags_sequence
							lowercase        =							scaling
							lowercase        =							num_dynamic_real_features
							lowercase        =							num_static_real_features
							lowercase        =							num_static_categorical_features
							if cardinality is not None and num_static_categorical_features > 0:
													if len(_lowerCAmelCase						) != num_static_categorical_features:
																			raise ValueError(
																			    """The cardinality should be a list of the same length as `num_static_categorical_features`"""						)
													lowercase        =							cardinality
							else:
													lowercase        =							[0]
							if embedding_dimension is not None and num_static_categorical_features > 0:
													if len(_lowerCAmelCase						) != num_static_categorical_features:
																			raise ValueError(
																			    """The embedding dimension should be a list of the same length as `num_static_categorical_features`"""						)
													lowercase        =							embedding_dimension
							else:
													lowercase        =							[min(50 ,				(cat + 1) // 2						) for cat in self.cardinality]
							lowercase        =							num_parallel_samples

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

							lowercase        =							dropout
							lowercase        =							attention_dropout
							lowercase        =							activation_dropout
							lowercase        =							encoder_layerdrop
							lowercase        =							decoder_layerdrop

							lowercase        =							activation_function
							lowercase        =							init_std

							lowercase        =							use_cache

							# Autoformer
							lowercase        =							label_length
							lowercase        =							moving_average
							lowercase        =							autocorrelation_factor

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







	@property
	def   _a   (    self						)    ->    Dict:
							'''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
							)







'''simple docstring'''


import json
import logging
import os
import socket

import git
import numpy as np
import torch


logging.basicConfig(
    format='''%(asctime)s - %(levelname)s - %(name)s - PID: %(process)d -  %(message)s''',
    datefmt='''%m/%d/%Y %H:%M:%S''',
    level=logging.INFO,
)
lowercase_      :				Tuple   					=    logging.getLogger(__name__)







def      SCREAMING_SNAKE_CASE				(				lowercase_    :      str						):
						lowercase        =							git.Repo(search_parent_directories=lowercase_						)
						lowercase        =							{
						    """repo_id""": str(lowercase_						),
						    """repo_sha""": str(repo.head.object.hexsha						),
						    """repo_branch""": str(repo.active_branch						),
						}

						with open(os.path.join(lowercase_ ,  """git_log.json"""						) ,  """w"""						) as f:
												json.dump(lowercase_ ,  lowercase_ ,  indent=4						)







def      SCREAMING_SNAKE_CASE				(				lowercase_    :      str						):
						if params.n_gpu <= 0:
												lowercase        =							0
												lowercase        =							-1
												lowercase        =							True
												lowercase        =							False
												return

						assert torch.cuda.is_available()

						logger.info("""Initializing GPUs"""						)
						if params.n_gpu > 1:
												assert params.local_rank != -1

												lowercase        =							int(os.environ["""WORLD_SIZE"""]						)
												lowercase        =							int(os.environ["""N_GPU_NODE"""]						)
												lowercase        =							int(os.environ["""RANK"""]						)

												# number of nodes / node ID
												lowercase        =							params.world_size // params.n_gpu_per_node
												lowercase        =							params.global_rank // params.n_gpu_per_node
												lowercase        =							True

												assert params.n_nodes == int(os.environ["""N_NODES"""]						)
												assert params.node_id == int(os.environ["""NODE_RANK"""]						)

						# local job (single GPU)
						else:
												assert params.local_rank == -1

												lowercase        =							1
												lowercase        =							0
												lowercase        =							0
												lowercase        =							0
												lowercase        =							1
												lowercase        =							1
												lowercase        =							False

						# sanity checks
						assert params.n_nodes >= 1
						assert 0 <= params.node_id < params.n_nodes
						assert 0 <= params.local_rank <= params.global_rank < params.world_size
						assert params.world_size == params.n_nodes * params.n_gpu_per_node

						# define whether this is the master process / if we are in multi-node distributed mode
						lowercase        =							params.node_id == 0 and params.local_rank == 0
						lowercase        =							params.n_nodes > 1

						# summary
						lowercase        =							F"""--- Global rank: {params.global_rank} - """
						logger.info(PREFIX + """Number of nodes: %i""" % params.n_nodes						)
						logger.info(PREFIX + """Node ID        : %i""" % params.node_id						)
						logger.info(PREFIX + """Local rank     : %i""" % params.local_rank						)
						logger.info(PREFIX + """World size     : %i""" % params.world_size						)
						logger.info(PREFIX + """GPUs per node  : %i""" % params.n_gpu_per_node						)
						logger.info(PREFIX + """Master         : %s""" % str(params.is_master						)						)
						logger.info(PREFIX + """Multi-node     : %s""" % str(params.multi_node						)						)
						logger.info(PREFIX + """Multi-GPU      : %s""" % str(params.multi_gpu						)						)
						logger.info(PREFIX + """Hostname       : %s""" % socket.gethostname()						)

						# set GPU device
						torch.cuda.set_device(params.local_rank						)

						# initialize multi-GPU
						if params.multi_gpu:
												logger.info("""Initializing PyTorch distributed"""						)
												torch.distributed.init_process_group(
												    init_method="""env://""" ,  backend="""nccl""" ,  )







def      SCREAMING_SNAKE_CASE				(				lowercase_    :      Optional[Any]						):
						np.random.seed(args.seed						)
						torch.manual_seed(args.seed						)
						if args.n_gpu > 0:
												torch.cuda.manual_seed_all(args.seed						)


