



"""simple docstring"""






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_  (				A_ :		int,    A_ :		List[str]						):


       '''simple docstring'''





       _lowerCamelCase						:    str         =			torch.load(A_,    map_location='''cpu'''						)

       _lowerCamelCase						:    Optional[Any]         =			chkpt['''model''']

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

       _lowerCamelCase						:    Dict         =			chkpt['''params''']
       _lowerCamelCase						:    Dict         =			{n: v for n, v in config.items() if not isinstance(A_,    (torch.FloatTensor, numpy.ndarray)						)}

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

       # Save pytorch-model
       _lowerCamelCase						:    str         =			pytorch_dump_folder_path + '''/''' + WEIGHTS_NAME
       _lowerCamelCase						:    str         =			pytorch_dump_folder_path + '''/''' + CONFIG_NAME
       _lowerCamelCase						:    Any         =			pytorch_dump_folder_path + '''/''' + VOCAB_FILES_NAMES['''vocab_file''']

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

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

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


if __name__ == "__main__":
   lowerCAmelCase__      =    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.'''
   )
   lowerCAmelCase__      =    parser.parse_args()
   convert_xlm_checkpoint_to_pytorch(args.xlm_checkpoint_path, args.pytorch_dump_folder_path)







"""simple docstring"""






def 	snake_case_  (				A_ :		float						):


       '''simple docstring'''





       if edge <= 0 or not isinstance(A_,    A_						):
              raise ValueError('''Length must be a positive.'''						)
       return 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2)






def 	snake_case_  (				A_ :		float						):


       '''simple docstring'''





       if edge <= 0 or not isinstance(A_,    A_						):
              raise ValueError('''Length must be a positive.'''						)
       return ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3)


if __name__ == "__main__":
   import doctest

   doctest.testmod()


