


from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
       import tensorflow as tf

       from transformers import (
           TFConvBertForMaskedLM,
           TFConvBertForMultipleChoice,
           TFConvBertForQuestionAnswering,
           TFConvBertForSequenceClassification,
           TFConvBertForTokenClassification,
           TFConvBertModel,
       )





class  lowerCAmelCase__:






    '''simple docstring'''





    def __init__(	self				:   Union[str, Any]       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   List[Any]=13       ,   __snake_case				:   List[Any]=7       ,   __snake_case				:   Union[str, Any]=True       ,   __snake_case				:   str=True       ,   __snake_case				:   Dict=True       ,   __snake_case				:   Any=True       ,   __snake_case				:   Tuple=99       ,   __snake_case				:   str=32       ,   __snake_case				:   int=2       ,   __snake_case				:   Union[str, Any]=4       ,   __snake_case				:   List[Any]=37       ,   __snake_case				:   Optional[int]="gelu"       ,   __snake_case				:   int=0.1       ,   __snake_case				:   List[Any]=0.1       ,   __snake_case				:   List[Any]=512       ,   __snake_case				:   int=16       ,   __snake_case				:   Optional[int]=2       ,   __snake_case				:   Dict=0.02       ,   __snake_case				:   Optional[Any]=3       ,   __snake_case				:   List[str]=4       ,   __snake_case				:   int=None       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      Tuple						=   parent
       UpperCAmelCase_							:      Tuple						=   13
       UpperCAmelCase_							:      int						=   7
       UpperCAmelCase_							:      str						=   True
       UpperCAmelCase_							:      Tuple						=   True
       UpperCAmelCase_							:      Any						=   True
       UpperCAmelCase_							:      Union[str, Any]						=   True
       UpperCAmelCase_							:      Optional[int]						=   99
       UpperCAmelCase_							:      List[str]						=   384
       UpperCAmelCase_							:      Union[str, Any]						=   2
       UpperCAmelCase_							:      Tuple						=   4
       UpperCAmelCase_							:      List[Any]						=   37
       UpperCAmelCase_							:      List[str]						=   '''gelu'''
       UpperCAmelCase_							:      Optional[int]						=   0.1
       UpperCAmelCase_							:      List[Any]						=   0.1
       UpperCAmelCase_							:      str						=   512
       UpperCAmelCase_							:      List[str]						=   16
       UpperCAmelCase_							:      str						=   2
       UpperCAmelCase_							:      List[str]						=   0.02
       UpperCAmelCase_							:      Optional[int]						=   3
       UpperCAmelCase_							:      int						=   4
       UpperCAmelCase_							:      Union[str, Any]						=   128
       UpperCAmelCase_							:      Union[str, Any]						=   2
       UpperCAmelCase_							:      Any						=   9
       UpperCAmelCase_							:      Tuple						=   1
       UpperCAmelCase_							:      Union[str, Any]						=   None





    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[Any]						=   ids_tensor([self.batch_size, self.seq_length]       ,   self.vocab_size	)

       UpperCAmelCase_							:      List[str]						=   None
       if self.use_input_mask:
          UpperCAmelCase_							:      Dict						=   random_attention_mask([self.batch_size, self.seq_length]	)

       UpperCAmelCase_							:      List[str]						=   None
       if self.use_token_type_ids:
          UpperCAmelCase_							:      List[str]						=   ids_tensor([self.batch_size, self.seq_length]       ,   self.type_vocab_size	)

       UpperCAmelCase_							:      Tuple						=   None
       UpperCAmelCase_							:      Optional[Any]						=   None
       UpperCAmelCase_							:      Optional[int]						=   None
       if self.use_labels:
          UpperCAmelCase_							:      Dict						=   ids_tensor([self.batch_size]       ,   self.type_sequence_label_size	)
          UpperCAmelCase_							:      int						=   ids_tensor([self.batch_size, self.seq_length]       ,   self.num_labels	)
          UpperCAmelCase_							:      Optional[int]						=   ids_tensor([self.batch_size]       ,   self.num_choices	)

       UpperCAmelCase_							:      Union[str, Any]						=   ConvBertConfig(
           vocab_size=self.vocab_size       ,   hidden_size=self.hidden_size       ,   num_hidden_layers=self.num_hidden_layers       ,   num_attention_heads=self.num_attention_heads       ,   intermediate_size=self.intermediate_size       ,   hidden_act=self.hidden_act       ,   hidden_dropout_prob=self.hidden_dropout_prob       ,   attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,   max_position_embeddings=self.max_position_embeddings       ,   type_vocab_size=self.type_vocab_size       ,   initializer_range=self.initializer_range       ,   return_dict=__snake_case       ,   )

       return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels





    def 					_lowerCamelCase (	self				:   int       ,   __snake_case				:   Optional[Any]       ,   __snake_case				:   Dict       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   List[str]       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   Any	):





       '''simple docstring'''
       UpperCAmelCase_							:      int						=   TFConvBertModel(config=__snake_case	)
       UpperCAmelCase_							:      Tuple						=   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

       UpperCAmelCase_							:      Tuple						=   [input_ids, input_mask]
       UpperCAmelCase_							:      List[str]						=   model(__snake_case	)

       UpperCAmelCase_							:      str						=   model(__snake_case	)

       self.parent.assertEqual(result.last_hidden_state.shape       ,   (self.batch_size, self.seq_length, self.hidden_size)	)





    def 					_lowerCamelCase (	self				:   Any       ,   __snake_case				:   List[str]       ,   __snake_case				:   str       ,   __snake_case				:   str       ,   __snake_case				:   Any       ,   __snake_case				:   Optional[Any]       ,   __snake_case				:   str       ,   __snake_case				:   Union[str, Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   TFConvBertForMaskedLM(config=__snake_case	)
       UpperCAmelCase_							:      str						=   {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }
       UpperCAmelCase_							:      str						=   model(__snake_case	)
       self.parent.assertEqual(result.logits.shape       ,   (self.batch_size, self.seq_length, self.vocab_size)	)





    def 					_lowerCamelCase (	self				:   Any       ,   __snake_case				:   Dict       ,   __snake_case				:   List[Any]       ,   __snake_case				:   Optional[Any]       ,   __snake_case				:   Dict       ,   __snake_case				:   int       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   Any	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   self.num_labels
       UpperCAmelCase_							:      Tuple						=   TFConvBertForSequenceClassification(config=__snake_case	)
       UpperCAmelCase_							:      List[str]						=   {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }

       UpperCAmelCase_							:      Any						=   model(__snake_case	)
       self.parent.assertEqual(result.logits.shape       ,   (self.batch_size, self.num_labels)	)





    def 					_lowerCamelCase (	self				:   int       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   Union[str, Any]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   Tuple       ,   __snake_case				:   List[str]       ,   __snake_case				:   Dict       ,   __snake_case				:   Tuple	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[str]						=   self.num_choices
       UpperCAmelCase_							:      int						=   TFConvBertForMultipleChoice(config=__snake_case	)
       UpperCAmelCase_							:      Any						=   tf.tile(tf.expand_dims(__snake_case       ,   1	)       ,   (1, self.num_choices, 1)	)
       UpperCAmelCase_							:      Tuple						=   tf.tile(tf.expand_dims(__snake_case       ,   1	)       ,   (1, self.num_choices, 1)	)
       UpperCAmelCase_							:      List[str]						=   tf.tile(tf.expand_dims(__snake_case       ,   1	)       ,   (1, self.num_choices, 1)	)
       UpperCAmelCase_							:      str						=   {
           '''input_ids''': multiple_choice_inputs_ids,
           '''attention_mask''': multiple_choice_input_mask,
           '''token_type_ids''': multiple_choice_token_type_ids,
       }
       UpperCAmelCase_							:      Tuple						=   model(__snake_case	)
       self.parent.assertEqual(result.logits.shape       ,   (self.batch_size, self.num_choices)	)





    def 					_lowerCamelCase (	self				:   List[Any]       ,   __snake_case				:   str       ,   __snake_case				:   Dict       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   Optional[Any]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   Tuple       ,   __snake_case				:   Dict	):





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   self.num_labels
       UpperCAmelCase_							:      Any						=   TFConvBertForTokenClassification(config=__snake_case	)
       UpperCAmelCase_							:      Union[str, Any]						=   {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }
       UpperCAmelCase_							:      Any						=   model(__snake_case	)
       self.parent.assertEqual(result.logits.shape       ,   (self.batch_size, self.seq_length, self.num_labels)	)





    def 					_lowerCamelCase (	self				:   List[str]       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   Dict       ,   __snake_case				:   Tuple       ,   __snake_case				:   Union[str, Any]       ,   __snake_case				:   Dict       ,   __snake_case				:   Optional[Any]       ,   __snake_case				:   Dict	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[str]						=   TFConvBertForQuestionAnswering(config=__snake_case	)
       UpperCAmelCase_							:      Dict						=   {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }

       UpperCAmelCase_							:      Optional[Any]						=   model(__snake_case	)
       self.parent.assertEqual(result.start_logits.shape       ,   (self.batch_size, self.seq_length)	)
       self.parent.assertEqual(result.end_logits.shape       ,   (self.batch_size, self.seq_length)	)





    def 					_lowerCamelCase (	self				:   int	):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   self.prepare_config_and_inputs()
       (
           (
           UpperCAmelCase_
       )		,      (
           UpperCAmelCase_
       )		,      (
           UpperCAmelCase_
       )		,      (
           UpperCAmelCase_
       )		,      (
           UpperCAmelCase_
       )		,      (
           UpperCAmelCase_
       )		,      (
           UpperCAmelCase_
       )		,      
       )							:      List[Any]						=   config_and_inputs
       UpperCAmelCase_							:      List[Any]						=   {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict





@require_tf
class  lowerCAmelCase__(    snake_case__    ,    snake_case__    ,    unittest.TestCase						):






    '''simple docstring'''





    A_  :     Union[str, Any]			= (
        (
            TFConvBertModel,
            TFConvBertForMaskedLM,
            TFConvBertForQuestionAnswering,
            TFConvBertForSequenceClassification,
            TFConvBertForTokenClassification,
            TFConvBertForMultipleChoice,
        )
        if is_tf_available()
        else ()
    )
    A_  :     List[str]			= (
        {
            'feature-extraction': TFConvBertModel,
            'fill-mask': TFConvBertForMaskedLM,
            'question-answering': TFConvBertForQuestionAnswering,
            'text-classification': TFConvBertForSequenceClassification,
            'token-classification': TFConvBertForTokenClassification,
            'zero-shot': TFConvBertForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    A_  :     Any			= False
    A_  :     Optional[int]			= False
    A_  :     Dict			= False





    def 					_lowerCamelCase (	self				:   Tuple	):





       '''simple docstring'''
       UpperCAmelCase_							:      Tuple						=   TFConvBertModelTester(self	)
       UpperCAmelCase_							:      Tuple						=   ConfigTester(self       ,   config_class=__snake_case       ,   hidden_size=37	)





    def 					_lowerCamelCase (	self				:   Dict	):





       '''simple docstring'''
       self.config_tester.run_common_tests()





    def 					_lowerCamelCase (	self				:   str	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__snake_case	)





    def 					_lowerCamelCase (	self				:   Dict	):





       '''simple docstring'''
       UpperCAmelCase_							:      str						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*__snake_case	)





    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*__snake_case	)





    def 					_lowerCamelCase (	self				:   Any	):





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*__snake_case	)





    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[str]						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*__snake_case	)





    def 					_lowerCamelCase (	self				:   Optional[Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*__snake_case	)





    @slow
    def 					_lowerCamelCase (	self				:   Union[str, Any]	):





       '''simple docstring'''
       UpperCAmelCase_		,      UpperCAmelCase_							:      Optional[int]						=   self.model_tester.prepare_config_and_inputs_for_common()
       UpperCAmelCase_							:      Dict						=   True
       UpperCAmelCase_							:      Any						=   True

       if hasattr(__snake_case       ,   '''use_cache'''	):
          UpperCAmelCase_							:      str						=   True

       UpperCAmelCase_							:      Optional[int]						=   getattr(self.model_tester       ,   '''encoder_seq_length'''       ,   self.model_tester.seq_length	)
       UpperCAmelCase_							:      str						=   getattr(self.model_tester       ,   '''key_length'''       ,   __snake_case	)

       for model_class in self.all_model_classes:
          UpperCAmelCase_							:      List[Any]						=   self._prepare_for_class(__snake_case       ,   __snake_case	)
          UpperCAmelCase_							:      Optional[int]						=   model_class(__snake_case	)
          UpperCAmelCase_							:      List[Any]						=   len(model(__snake_case	)	)

          with tempfile.TemporaryDirectory() as tmpdirname:
             model.save_pretrained(__snake_case       ,   saved_model=__snake_case	)
             UpperCAmelCase_							:      Any						=   os.path.join(__snake_case       ,   '''saved_model'''       ,   '''1'''	)
             UpperCAmelCase_							:      Optional[int]						=   tf.keras.models.load_model(__snake_case	)
             UpperCAmelCase_							:      List[Any]						=   model(__snake_case	)

             if self.is_encoder_decoder:
                UpperCAmelCase_							:      Union[str, Any]						=   outputs['''encoder_hidden_states''']
                UpperCAmelCase_							:      List[str]						=   outputs['''encoder_attentions''']
             else:
                UpperCAmelCase_							:      Union[str, Any]						=   outputs['''hidden_states''']
                UpperCAmelCase_							:      Union[str, Any]						=   outputs['''attentions''']

             self.assertEqual(len(__snake_case	)       ,   __snake_case	)

             UpperCAmelCase_							:      Union[str, Any]						=   getattr(
                 self.model_tester       ,   '''expected_num_hidden_layers'''       ,   self.model_tester.num_hidden_layers + 1	)

             self.assertEqual(len(__snake_case	)       ,   __snake_case	)
             self.assertListEqual(
                 list(output_hidden_states[0].shape[-2:]	)       ,   [self.model_tester.seq_length, self.model_tester.hidden_size]       ,   )

             self.assertEqual(len(__snake_case	)       ,   self.model_tester.num_hidden_layers	)
             self.assertListEqual(
                 list(output_attentions[0].shape[-3:]	)       ,   [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]       ,   )





    @slow
    def 					_lowerCamelCase (	self				:   Any	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''	)
       self.assertIsNotNone(__snake_case	)





    def 					_lowerCamelCase (	self				:   Optional[Any]	):





       '''simple docstring'''
       UpperCAmelCase_		,      UpperCAmelCase_							:      str						=   self.model_tester.prepare_config_and_inputs_for_common()
       UpperCAmelCase_							:      List[str]						=   True
       UpperCAmelCase_							:      Optional[Any]						=   getattr(self.model_tester       ,   '''decoder_seq_length'''       ,   self.model_tester.seq_length	)
       UpperCAmelCase_							:      List[str]						=   getattr(self.model_tester       ,   '''encoder_seq_length'''       ,   self.model_tester.seq_length	)
       UpperCAmelCase_							:      Optional[Any]						=   getattr(self.model_tester       ,   '''key_length'''       ,   __snake_case	)
       UpperCAmelCase_							:      Optional[Any]						=   getattr(self.model_tester       ,   '''key_length'''       ,   __snake_case	)

       def check_decoder_attentions_output(__snake_case				:   Tuple	):
          UpperCAmelCase_							:      Any						=   len(__snake_case	)
          self.assertEqual(out_len % 2       ,   0	)
          UpperCAmelCase_							:      Union[str, Any]						=   outputs.decoder_attentions
          self.assertEqual(len(__snake_case	)       ,   self.model_tester.num_hidden_layers	)
          self.assertListEqual(
              list(decoder_attentions[0].shape[-3:]	)       ,   [self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]       ,   )

       def check_encoder_attentions_output(__snake_case				:   int	):
          UpperCAmelCase_							:      Tuple						=   [
              t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
          ]
          self.assertEqual(len(__snake_case	)       ,   self.model_tester.num_hidden_layers	)
          self.assertListEqual(
              list(attentions[0].shape[-3:]	)       ,   [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]       ,   )

       for model_class in self.all_model_classes:
          UpperCAmelCase_							:      Dict						=   True
          UpperCAmelCase_							:      Tuple						=   False
          UpperCAmelCase_							:      Optional[Any]						=   model_class(__snake_case	)
          UpperCAmelCase_							:      List[str]						=   model(self._prepare_for_class(__snake_case       ,   __snake_case	)	)
          UpperCAmelCase_							:      Optional[int]						=   len(__snake_case	)
          self.assertEqual(config.output_hidden_states       ,   __snake_case	)
          check_encoder_attentions_output(__snake_case	)

          if self.is_encoder_decoder:
             UpperCAmelCase_							:      List[Any]						=   model_class(__snake_case	)
             UpperCAmelCase_							:      Optional[int]						=   model(self._prepare_for_class(__snake_case       ,   __snake_case	)	)
             self.assertEqual(config.output_hidden_states       ,   __snake_case	)
             check_decoder_attentions_output(__snake_case	)

          # Check that output attentions can also be changed via the config
          del inputs_dict["output_attentions"]
          UpperCAmelCase_							:      Any						=   True
          UpperCAmelCase_							:      List[str]						=   model_class(__snake_case	)
          UpperCAmelCase_							:      Optional[int]						=   model(self._prepare_for_class(__snake_case       ,   __snake_case	)	)
          self.assertEqual(config.output_hidden_states       ,   __snake_case	)
          check_encoder_attentions_output(__snake_case	)

          # Check attention is always last and order is fine
          UpperCAmelCase_							:      List[Any]						=   True
          UpperCAmelCase_							:      Optional[int]						=   True
          UpperCAmelCase_							:      List[Any]						=   model_class(__snake_case	)
          UpperCAmelCase_							:      List[str]						=   model(self._prepare_for_class(__snake_case       ,   __snake_case	)	)

          self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)       ,   len(__snake_case	)	)
          self.assertEqual(model.config.output_hidden_states       ,   __snake_case	)
          check_encoder_attentions_output(__snake_case	)





@require_tf
class  lowerCAmelCase__(    unittest.TestCase						):






    '''simple docstring'''





    @slow
    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Dict						=   TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''	)
       UpperCAmelCase_							:      str						=   tf.constant([[0, 1, 2, 3, 4, 5]]	)
       UpperCAmelCase_							:      Union[str, Any]						=   model(__snake_case	)[0]

       UpperCAmelCase_							:      Union[str, Any]						=   [1, 6, 768]
       self.assertEqual(output.shape       ,   __snake_case	)

       UpperCAmelCase_							:      Any						=   tf.constant(
           [
               [
                   [-0.03_475_493, -0.4_686_034, -0.30_638_832],
                   [0.22_637_248, -0.26_988_646, -0.7_423_424],
                   [0.10_324_868, -0.45_013_508, -0.58_280_784],
               ]
           ]	)
       tf.debugging.assert_near(output[:, :3, :3]       ,   __snake_case       ,   atol=1E-4	)



import argparse
import json

import numpy
import torch

from transformers.models.xlm.tokenization_xlm import VOCAB_FILES_NAMES
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()
def      snake_case_						( __lowercase			,       __lowercase       ):
   # Load checkpoint
   UpperCAmelCase_							:      Tuple						=   torch.load(__lowercase			,       map_location='''cpu'''       )

   UpperCAmelCase_							:      Optional[int]						=   chkpt['''model''']

   # We have the base model one level deeper than the original XLM repository
   UpperCAmelCase_							:      str						=   {}
   for k, v in state_dict.items():
      if "pred_layer" in k:
         UpperCAmelCase_							:      Tuple						=   v
      else:
         UpperCAmelCase_							:      Union[str, Any]						=   v

   UpperCAmelCase_							:      int						=   chkpt['''params''']
   UpperCAmelCase_							:      Union[str, Any]						=   {n: v for n, v in config.items() if not isinstance(__lowercase			,       (torch.FloatTensor, numpy.ndarray)       )}

   UpperCAmelCase_							:      int						=   chkpt['''dico_word2id''']
   UpperCAmelCase_							:      List[Any]						=   {s + '''</w>''' if s.find('''@@'''       ) == -1 and i > 1_3 else s.replace('''@@'''			,       ''''''       ): i for s, i in vocab.items()}

   # Save pytorch-model
   UpperCAmelCase_							:      Tuple						=   pytorch_dump_folder_path + '''/''' + WEIGHTS_NAME
   UpperCAmelCase_							:      Tuple						=   pytorch_dump_folder_path + '''/''' + CONFIG_NAME
   UpperCAmelCase_							:      Dict						=   pytorch_dump_folder_path + '''/''' + VOCAB_FILES_NAMES['''vocab_file''']

   print(F'''Save PyTorch model to {pytorch_weights_dump_path}'''       )
   torch.save(__lowercase			,       __lowercase       )

   print(F'''Save configuration file to {pytorch_config_dump_path}'''       )
   with open(__lowercase			,       '''w'''			,       encoding='''utf-8'''       ) as f:
      f.write(json.dumps(__lowercase			,       indent=2       ) + '''\n'''       )

   print(F'''Save vocab file to {pytorch_config_dump_path}'''       )
   with open(__lowercase			,       '''w'''			,       encoding='''utf-8'''       ) as f:
      f.write(json.dumps(__lowercase			,       indent=2       ) + '''\n'''       )


if __name__ == "__main__":
       __UpperCamelCase				:  str      					=							argparse.ArgumentParser()
       # Required parameters
       parser.add_argument(
           '--xlm_checkpoint_path', default=None, type=str, required=True, help='Path the official PyTorch dump.'
       )
       parser.add_argument(
           '--pytorch_dump_folder_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
       )
       __UpperCamelCase				:  Dict      					=							parser.parse_args()
       convert_xlm_checkpoint_to_pytorch(args.xlm_checkpoint_path, args.pytorch_dump_folder_path)