




from typing import List, Optional, Union

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


_snake_case   :   List[str]     							=	logging.get_logger(__name__)

_snake_case   :   Tuple     							=	{
    '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     A					(	_a					):
							lowercase_           =       'informer'
							lowercase_           =       {
							    'hidden_size': 'd_model',
							    'num_attention_heads': 'encoder_attention_heads',
							    'num_hidden_layers': 'encoder_layers',
							}







							def __init__(						self :						Union[str, Any]							,    lowerCAmelCase_ :						Optional[int] = None							,    lowerCAmelCase_ :						Optional[int] = None							,    lowerCAmelCase_ :						str = "student_t"							,    lowerCAmelCase_ :						str = "nll"							,    lowerCAmelCase_ :						int = 1							,    lowerCAmelCase_ :						List[int] = None							,    lowerCAmelCase_ :						Optional[Union[str, bool]] = "mean"							,    lowerCAmelCase_ :						int = 0							,    lowerCAmelCase_ :						int = 0							,    lowerCAmelCase_ :						int = 0							,    lowerCAmelCase_ :						int = 0							,    lowerCAmelCase_ :						Optional[List[int]] = None							,    lowerCAmelCase_ :						Optional[List[int]] = None							,    lowerCAmelCase_ :						int = 64							,    lowerCAmelCase_ :						int = 32							,    lowerCAmelCase_ :						int = 32							,    lowerCAmelCase_ :						int = 2							,    lowerCAmelCase_ :						int = 2							,    lowerCAmelCase_ :						int = 2							,    lowerCAmelCase_ :						int = 2							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						str = "gelu"							,    lowerCAmelCase_ :						float = 0.0_5							,    lowerCAmelCase_ :						float = 0.1							,    lowerCAmelCase_ :						float = 0.1							,    lowerCAmelCase_ :						float = 0.1							,    lowerCAmelCase_ :						float = 0.1							,    lowerCAmelCase_ :						int = 1_00							,    lowerCAmelCase_ :						float = 0.0_2							,    lowerCAmelCase_ :						int=True							,    lowerCAmelCase_ :						str = "prob"							,    lowerCAmelCase_ :						int = 5							,    lowerCAmelCase_ :						bool = True							,    **lowerCAmelCase_ :						Tuple							,    )    ->							Optional[int]:


														"""simple docstring"""


														_a			  =       prediction_length
														_a			  =       context_length or prediction_length
														_a			  =       distribution_output
														_a			  =       loss
														_a			  =       input_size
														_a			  =       num_time_features
														_a			  =       lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
														_a			  =       scaling
														_a			  =       num_dynamic_real_features
														_a			  =       num_static_real_features
														_a			  =       num_static_categorical_features

														# set cardinality
														if cardinality 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`'''      )
																					_a			  =       cardinality
														else:
																					_a			  =       [0]

														# set embedding_dimension
														if embedding_dimension 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`'''      )
																					_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

														# Informer
														_a			  =       attention_type
														_a			  =       sampling_factor
														_a			  =       distil

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







							@property
							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							int:


														"""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 argparse
import os

import numpy as np
import tensorflow as tf
import torch

from transformers import BertModel
def 	snake_case_					(UpperCamelCase :						BertModel				,		UpperCamelCase :						str				,		UpperCamelCase :						str   ):





							'''simple docstring'''


							_a			  =       ('''dense.weight''', '''attention.self.query''', '''attention.self.key''', '''attention.self.value''')

							_a			  =       (
							    ('''layer.''', '''layer_'''),
							    ('''word_embeddings.weight''', '''word_embeddings'''),
							    ('''position_embeddings.weight''', '''position_embeddings'''),
							    ('''token_type_embeddings.weight''', '''token_type_embeddings'''),
							    ('''.''', '''/'''),
							    ('''LayerNorm/weight''', '''LayerNorm/gamma'''),
							    ('''LayerNorm/bias''', '''LayerNorm/beta'''),
							    ('''weight''', '''kernel'''),
							)

							if not os.path.isdir(UpperCamelCase   ):
														os.makedirs(UpperCamelCase   )

							_a			  =       model.state_dict()

							def to_tf_var_name(UpperCamelCase :						str   ):
														for patt, repl in iter(UpperCamelCase   ):
																					_a			  =       name.replace(UpperCamelCase				,		UpperCamelCase   )
														return f'bert/{name}'

							def create_tf_var(UpperCamelCase :						np.ndarray				,		UpperCamelCase :						str				,		UpperCamelCase :						tf.Session   ):
														_a			  =       tf.dtypes.as_dtype(tensor.dtype   )
														_a			  =       tf.get_variable(dtype=UpperCamelCase				,		shape=tensor.shape				,		name=UpperCamelCase				,		initializer=tf.zeros_initializer()   )
														session.run(tf.variables_initializer([tf_var]   )   )
														session.run(UpperCamelCase   )
														return tf_var

							tf.reset_default_graph()
							with tf.Session() as session:
														for var_name in state_dict:
																					_a			  =       to_tf_var_name(UpperCamelCase   )
																					_a			  =       state_dict[var_name].numpy()
																					if any(x in var_name for x in tensors_to_transpose   ):
																												_a			  =       torch_tensor.T
																					_a			  =       create_tf_var(tensor=UpperCamelCase				,		name=UpperCamelCase				,		session=UpperCamelCase   )
																					tf.keras.backend.set_value(UpperCamelCase				,		UpperCamelCase   )
																					_a			  =       session.run(UpperCamelCase   )
																					print(f'Successfully created {tf_name}: {np.allclose(UpperCamelCase				,		UpperCamelCase   )}'   )

														_a			  =       tf.train.Saver(tf.trainable_variables()   )
														saver.save(UpperCamelCase				,		os.path.join(UpperCamelCase				,		model_name.replace('''-'''				,		'''_'''   ) + '''.ckpt'''   )   )
def 	snake_case_					(UpperCamelCase :						Tuple=None   ):





							'''simple docstring'''


							_a			  =       argparse.ArgumentParser()
							parser.add_argument('''--model_name'''				,		type=UpperCamelCase				,		required=UpperCamelCase				,		help='''model name e.g. bert-base-uncased'''   )
							parser.add_argument(
							    '''--cache_dir'''				,		type=UpperCamelCase				,		default=UpperCamelCase				,		required=UpperCamelCase				,		help='''Directory containing pytorch model'''   )
							parser.add_argument('''--pytorch_model_path'''				,		type=UpperCamelCase				,		required=UpperCamelCase				,		help='''/path/to/<pytorch-model-name>.bin'''   )
							parser.add_argument('''--tf_cache_dir'''				,		type=UpperCamelCase				,		required=UpperCamelCase				,		help='''Directory in which to save tensorflow model'''   )
							_a			  =       parser.parse_args(UpperCamelCase   )

							_a			  =       BertModel.from_pretrained(
							    pretrained_model_name_or_path=args.model_name				,		state_dict=torch.load(args.pytorch_model_path   )				,		cache_dir=args.cache_dir				,		)

							convert_pytorch_checkpoint_to_tf(model=UpperCamelCase				,		ckpt_dir=args.tf_cache_dir				,		model_name=args.model_name   )


if __name__ == "__main__":
				main()

