






from typing import List, Optional, Union

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


SCREAMING_SNAKE_CASE__				     =			logging.get_logger(__name__)

SCREAMING_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 			_UpperCamelCase(       __lowerCamelCase		):
		__SCREAMING_SNAKE_CASE  :       List[Any]							=							'''informer'''
		__SCREAMING_SNAKE_CASE  :       List[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] = None    ,       SCREAMING_SNAKE_CASE__		:    Optional[Union[str, bool]] = "mean"    ,       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 = 3_2    ,       SCREAMING_SNAKE_CASE__		:    int = 3_2    ,       SCREAMING_SNAKE_CASE__		:    int = 2    ,       SCREAMING_SNAKE_CASE__		:    int = 2    ,       SCREAMING_SNAKE_CASE__		:    int = 2    ,       SCREAMING_SNAKE_CASE__		:    int = 2    ,       SCREAMING_SNAKE_CASE__		:    bool = True    ,       SCREAMING_SNAKE_CASE__		:    str = "gelu"    ,       SCREAMING_SNAKE_CASE__		:    float = 0.05    ,       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__		:    Union[str, Any]=True    ,       SCREAMING_SNAKE_CASE__		:    str = "prob"    ,       SCREAMING_SNAKE_CASE__		:    int = 5    ,       SCREAMING_SNAKE_CASE__		:    bool = True    ,       **SCREAMING_SNAKE_CASE__		:    Tuple    ,       ):



					'''simple docstring'''



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

					# set cardinality
					if cardinality 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						:  Optional[Any]									=     cardinality
					else:
								__a						:  Optional[int]									=     [0]

					# set embedding_dimension
					if embedding_dimension 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						:  int									=     embedding_dimension
					else:
								__a						:  List[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						:  Optional[int]									=     d_model
					__a						:  Union[str, Any]									=     encoder_attention_heads
					__a						:  int									=     decoder_attention_heads
					__a						:  Any									=     encoder_ffn_dim
					__a						:  Union[str, Any]									=     decoder_ffn_dim
					__a						:  List[Any]									=     encoder_layers
					__a						:  Optional[int]									=     decoder_layers

					__a						:  int									=     dropout
					__a						:  Optional[Any]									=     attention_dropout
					__a						:  Dict									=     activation_dropout
					__a						:  Union[str, Any]									=     encoder_layerdrop
					__a						:  Optional[int]									=     decoder_layerdrop

					__a						:  List[str]									=     activation_function
					__a						:  str									=     init_std

					__a						:  Optional[int]									=     use_cache

					# Informer
					__a						:  Union[str, Any]									=     attention_type
					__a						:  str									=     sampling_factor
					__a						:  Dict									=     distil

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



		@property
		def    __lowerCAmelCase  (					self		:    Any    ):



					'''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
					)













import argparse

import torch
from torch import nn

from transformers import MaMaaaConfig, MaMaaaForConditionalGeneration

def   __lowercase       (			snake_case			):







				"""simple docstring"""






				__magic_name__		:Optional[Any]   =   [
				    '''encoder.version''',
				    '''decoder.version''',
				    '''model.encoder.version''',
				    '''model.decoder.version''',
				    '''decoder.output_projection.weight''',
				    '''_float_tensor''',
				    '''encoder.embed_positions._float_tensor''',
				    '''decoder.embed_positions._float_tensor''',
				]
				for k in ignore_keys:
								state_dict.pop(snake_case,	snake_case			)

def   __lowercase       (			snake_case			):







				"""simple docstring"""






				__magic_name__  ,					__magic_name__		:Tuple   =   emb.weight.shape
				__magic_name__		:int   =   nn.Linear(snake_case,	snake_case,	bias=snake_case			)
				__magic_name__		:str   =   emb.weight.data
				return lin_layer

def   __lowercase       (			snake_case			):







				"""simple docstring"""






				__magic_name__		:int   =   torch.load(snake_case,	map_location='''cpu'''			)
				__magic_name__		:Optional[Any]   =   mam_aaa['''args'''] or mam_aaa['''cfg''']['''model''']
				__magic_name__		:List[Any]   =   mam_aaa['''model''']
				remove_ignore_keys_(snake_case			)
				__magic_name__		:Tuple   =   state_dict['''encoder.embed_tokens.weight'''].shape[0]

				__magic_name__		:List[str]   =   MaMaaaConfig(
				    vocab_size=snake_case,	max_position_embeddings=1_0_2_4,	encoder_layers=args.encoder_layers,	decoder_layers=args.decoder_layers,	encoder_attention_heads=args.encoder_attention_heads,	decoder_attention_heads=args.decoder_attention_heads,	encoder_ffn_dim=args.encoder_ffn_embed_dim,	decoder_ffn_dim=args.decoder_ffn_embed_dim,	d_model=args.encoder_embed_dim,	encoder_layerdrop=args.encoder_layerdrop,	decoder_layerdrop=args.decoder_layerdrop,	dropout=args.dropout,	attention_dropout=args.attention_dropout,	activation_dropout=args.activation_dropout,	activation_function='''relu''',	)

				__magic_name__		:int   =   state_dict['''decoder.embed_tokens.weight''']
				__magic_name__		:List[str]   =   MaMaaaForConditionalGeneration(snake_case			)
				model.model.load_state_dict(snake_case,	strict=snake_case			)
				__magic_name__		:List[str]   =   make_linear_from_emb(model.model.shared			)

				return model


if __name__ == "__main__":
					SCREAMING_SNAKE_CASE__   :      Optional[Any]				=		argparse.ArgumentParser()
					# Required parameters
					parser.add_argument("""fairseq_path""", type=str, help="""path to a model.pt on local filesystem.""")
					parser.add_argument("""pytorch_dump_folder_path""", default=None, type=str, help="""Path to the output PyTorch model.""")
					SCREAMING_SNAKE_CASE__   :      int				=		parser.parse_args()
					SCREAMING_SNAKE_CASE__   :      Any				=		convert_fairseq_mamaaa_checkpoint_from_disk(args.fairseq_pathß)
					model.save_pretrained(args.pytorch_dump_folder_path)






