



from typing import List, Optional, Union

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


_snake_case		=  logging.get_logger(__name__)

_snake_case		=  {
    "huggingface/time-series-transformer-tourism-monthly": (
        "https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json"
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}



class   UpperCAmelCase_    (       a):
							lowerCamelCase__   			=		'time_series_transformer'
							lowerCamelCase__   			=		{
							    'hidden_size': 'd_model',
							    'num_attention_heads': 'encoder_attention_heads',
							    'num_hidden_layers': 'encoder_layers',
							}







							def __init__(   self,			__a = None,			__a = None,			__a = "student_t",			__a = "nll",			__a = 1,			__a = [1, 2, 3, 4, 5, 6, 7],			__a = "mean",			__a = 0,			__a = 0,			__a = 0,			__a = 0,			__a = None,			__a = None,			__a = 32,			__a = 32,			__a = 2,			__a = 2,			__a = 2,			__a = 2,			__a = True,			__a = "gelu",			__a = 64,			__a = 0.1,			__a = 0.1,			__a = 0.1,			__a = 0.1,			__a = 0.1,			__a = 100,			__a = 0.02,			__a=True,			**__a,			):

														'''simple docstring'''

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

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

														_lowerCAmelCase     :							List[str]    =    dropout
														_lowerCAmelCase     :							List[Any]    =    attention_dropout
														_lowerCAmelCase     :							Optional[Any]    =    activation_dropout
														_lowerCAmelCase     :							Optional[int]    =    encoder_layerdrop
														_lowerCAmelCase     :							Tuple    =    decoder_layerdrop

														_lowerCAmelCase     :							Optional[int]    =    activation_function
														_lowerCAmelCase     :							List[str]    =    init_std

														_lowerCAmelCase     :							Union[str, Any]    =    use_cache

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







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







import argparse
import os

import torch

from transformers import (
    XLNetConfig,
    XLNetForQuestionAnswering,
    XLNetForSequenceClassification,
    XLNetLMHeadModel,
    load_tf_weights_in_xlnet,
)
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


UpperCAmelCase	:	int		     =       {
    """cola""": 2,
    """mnli""": 3,
    """mrpc""": 2,
    """sst-2""": 2,
    """sts-b""": 1,
    """qqp""": 2,
    """qnli""": 2,
    """rte""": 2,
    """wnli""": 2,
}


logging.set_verbosity_info()
def      _A       (		SCREAMING_SNAKE_CASE     :   List[Any]       ,       SCREAMING_SNAKE_CASE     :   Dict       ,       SCREAMING_SNAKE_CASE     :   Dict       ,       SCREAMING_SNAKE_CASE     :   Union[str, Any]=None						):





  """simple docstring"""



  a__	:					Optional[int]										=XLNetConfig.from_json_file(SCREAMING_SNAKE_CASE						)

  a__	:					Dict										=finetuning_task.lower() if finetuning_task is not None else ""
  if finetuning_task in GLUE_TASKS_NUM_LABELS:
    print(f'''Building PyTorch XLNetForSequenceClassification model from configuration: {config}'''						)
    a__	:					List[str]										=finetuning_task
    a__	:					Tuple										=GLUE_TASKS_NUM_LABELS[finetuning_task]
    a__	:					List[Any]										=XLNetForSequenceClassification(SCREAMING_SNAKE_CASE						)
  elif "squad" in finetuning_task:
    a__	:					Optional[int]										=finetuning_task
    a__	:					Dict										=XLNetForQuestionAnswering(SCREAMING_SNAKE_CASE						)
  else:
    a__	:					List[Any]										=XLNetLMHeadModel(SCREAMING_SNAKE_CASE						)

  # Load weights from tf checkpoint
  load_tf_weights_in_xlnet(SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE						)

  # Save pytorch-model
  a__	:					Dict										=os.path.join(SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE						)
  a__	:					Dict										=os.path.join(SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE						)
  print(f'''Save PyTorch model to {os.path.abspath(SCREAMING_SNAKE_CASE						)}'''						)
  torch.save(model.state_dict()       ,       SCREAMING_SNAKE_CASE						)
  print(f'''Save configuration file to {os.path.abspath(SCREAMING_SNAKE_CASE						)}'''						)
  with open(SCREAMING_SNAKE_CASE       ,       "w"       ,       encoding="utf-8"						) as f:
    f.write(config.to_json_string()						)


if __name__ == "__main__":
     UpperCAmelCase	:	List[str]		     =       argparse.ArgumentParser()
     # Required parameters
     parser.add_argument(
         """--tf_checkpoint_path""", default=None, type=str, required=True, help="""Path to the TensorFlow checkpoint path."""
     )
     parser.add_argument(
         """--xlnet_config_file""",
         default=None,
         type=str,
         required=True,
         help=(
             """The config json file corresponding to the pre-trained XLNet model. \n"""
             """This specifies the model architecture."""
         ),
     )
     parser.add_argument(
         """--pytorch_dump_folder_path""",
         default=None,
         type=str,
         required=True,
         help="""Path to the folder to store the PyTorch model or dataset/vocab.""",
     )
     parser.add_argument(
         """--finetuning_task""",
         default=None,
         type=str,
         help="""Name of a task on which the XLNet TensorFlow model was fine-tuned""",
     )
     UpperCAmelCase	:	int		     =       parser.parse_args()
     print(args)

     convert_xlnet_checkpoint_to_pytorch(
         args.tf_checkpoint_path, args.xlnet_config_file, args.pytorch_dump_folder_path, args.finetuning_task
     )






