




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


lowerCamelCase    :		Optional[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       _SCREAMING_SNAKE_CASE      (							lowercase     :	str     ,							lowercase     :	str     ,							lowercase     :	Any     ,							lowercase     :	Dict=None					):


      '''simple docstring'''



      lowerCamelCase_							=   XLNetConfig.from_json_file(snake_case_					)

      lowerCamelCase_							=   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}"""					)
            lowerCamelCase_							=   finetuning_task
            lowerCamelCase_							=   GLUE_TASKS_NUM_LABELS[finetuning_task]
            lowerCamelCase_							=   XLNetForSequenceClassification(snake_case_					)
      elif "squad" in finetuning_task:
            lowerCamelCase_							=   finetuning_task
            lowerCamelCase_							=   XLNetForQuestionAnswering(snake_case_					)
      else:
            lowerCamelCase_							=   XLNetLMHeadModel(snake_case_					)

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

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


if __name__ == "__main__":
 lowerCamelCase    :		Tuple			   =       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",
 )
 lowerCamelCase    :		Any			   =       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
 )









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


lowerCamelCase    :		Optional[Any]			   =       logging.get_logger(__name__)

lowerCamelCase    :		Tuple			   =       {
    "transfo-xl-wt103": "https://huggingface.co/transfo-xl-wt103/resolve/main/config.json",
}







class   A(						UpperCamelCase       ):



 '''simple docstring'''


 UpperCamelCase						       =						'''transfo-xl'''
 UpperCamelCase						       =						['''mems''']
 UpperCamelCase						       =						{
     '''n_token''': '''vocab_size''',
     '''hidden_size''': '''d_model''',
     '''num_attention_heads''': '''n_head''',
     '''num_hidden_layers''': '''n_layer''',
 }

 def __init__(    self :  Any						,							A_ :  Optional[Any]=267735						,							A_ :  Optional[Any]=[20000, 40000, 200000]						,							A_ :  Union[str, Any]=1024						,							A_ :  Optional[Any]=1024						,							A_ :  Optional[int]=16						,							A_ :  Any=64						,							A_ :  List[Any]=4096						,							A_ :  str=4						,							A_ :  int=False						,							A_ :  List[Any]=18						,							A_ :  Optional[int]=1600						,							A_ :  Union[str, Any]=1000						,							A_ :  Optional[Any]=True						,							A_ :  Optional[int]=True						,							A_ :  List[str]=0						,							A_ :  int=-1						,							A_ :  List[Any]=True						,							A_ :  List[Any]=0.1						,							A_ :  str=0.0						,							A_ :  Dict=True						,							A_ :  Dict="normal"						,							A_ :  Dict=0.01						,							A_ :  Optional[Any]=0.01						,							A_ :  Any=0.02						,							A_ :  int=1E-5						,							A_ :  List[str]=0						,							**A_ :  Optional[Any]						,							)       ->     Optional[int]:

       """simple docstring"""






       lowerCamelCase_							=   vocab_size
       lowerCamelCase_							=   []
       self.cutoffs.extend(A_  )
       if proj_share_all_but_first:
             lowerCamelCase_							=   [False] + [True] * len(self.cutoffs  )
       else:
             lowerCamelCase_							=   [False] + [False] * len(self.cutoffs  )
       lowerCamelCase_							=   d_model
       lowerCamelCase_							=   d_embed
       lowerCamelCase_							=   d_head
       lowerCamelCase_							=   d_inner
       lowerCamelCase_							=   div_val
       lowerCamelCase_							=   pre_lnorm
       lowerCamelCase_							=   n_layer
       lowerCamelCase_							=   n_head
       lowerCamelCase_							=   mem_len
       lowerCamelCase_							=   same_length
       lowerCamelCase_							=   attn_type
       lowerCamelCase_							=   clamp_len
       lowerCamelCase_							=   sample_softmax
       lowerCamelCase_							=   adaptive
       lowerCamelCase_							=   dropout
       lowerCamelCase_							=   dropatt
       lowerCamelCase_							=   untie_r
       lowerCamelCase_							=   init
       lowerCamelCase_							=   init_range
       lowerCamelCase_							=   proj_init_std
       lowerCamelCase_							=   init_std
       lowerCamelCase_							=   layer_norm_epsilon
       super().__init__(eos_token_id=A_						,							**A_  )

 @property
 def     a__			(    self :  Tuple  )       ->     Any:

       """simple docstring"""






       logger.info(f"""The model {self.model_type} is one of the few models that has no sequence length limit."""  )
       return -1





 @max_position_embeddings.setter
 def     a__			(    self :  Dict						,							A_ :  Optional[int]  )       ->     List[Any]:

       """simple docstring"""






       raise NotImplementedError(
           f"""The model {self.model_type} is one of the few models that has no sequence length limit."""  )



