




'''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      UpperCamelCase_(	snake_case							:       Optional[int]							,				snake_case							:       Dict     ):

							'''simple docstring'''






							snake_case_						=      torch.load(snake_case							,				map_location="cpu"     )

							snake_case_						=      chkpt["model"]

							# We have the base model one level deeper than the original XLM repository
							snake_case_						=      {}
							for k, v in state_dict.items():
														if "pred_layer" in k:
																					snake_case_						=      v
														else:
																					snake_case_						=      v

							snake_case_						=      chkpt["params"]
							snake_case_						=      {n: v for n, v in config.items() if not isinstance(snake_case							,				(torch.FloatTensor, numpy.ndarray)     )}

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

							# Save pytorch-model
							snake_case_						=      pytorch_dump_folder_path + "/" + WEIGHTS_NAME
							snake_case_						=      pytorch_dump_folder_path + "/" + CONFIG_NAME
							snake_case_						=      pytorch_dump_folder_path + "/" + VOCAB_FILES_NAMES["vocab_file"]

							print(f'Save PyTorch model to {pytorch_weights_dump_path}'     )
							torch.save(snake_case							,				snake_case     )

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

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


if __name__ == "__main__":
		_SCREAMING_SNAKE_CASE							:   Optional[Any]      		= 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."
		)
		_SCREAMING_SNAKE_CASE							:   Optional[int]      		= parser.parse_args()
		convert_xlm_checkpoint_to_pytorch(args.xlm_checkpoint_path, args.pytorch_dump_folder_path)








def 				__lowerCamelCase						( UpperCAmelCase_						:		int ,  UpperCAmelCase_						:		int						):




      """simple docstring"""





      while b:
            a							,				a						:Optional[Any] 							=       b, a % b
      return a
def 				__lowerCamelCase						( UpperCAmelCase_						:		int ,  UpperCAmelCase_						:		int						):




      """simple docstring"""





      return a if b == 0 else euclidean_gcd_recursive(UpperCAmelCase_ ,  a % b						)
def 				__lowerCamelCase						( ):




      """simple docstring"""





      print(F'''euclidean_gcd(3, 5) = {euclidean_gcd(3 ,  5						)}'''						)
      print(F'''euclidean_gcd(5, 3) = {euclidean_gcd(5 ,  3						)}'''						)
      print(F'''euclidean_gcd(1, 3) = {euclidean_gcd(1 ,  3						)}'''						)
      print(F'''euclidean_gcd(3, 6) = {euclidean_gcd(3 ,  6						)}'''						)
      print(F'''euclidean_gcd(6, 3) = {euclidean_gcd(6 ,  3						)}'''						)

      print(F'''euclidean_gcd_recursive(3, 5) = {euclidean_gcd_recursive(3 ,  5						)}'''						)
      print(F'''euclidean_gcd_recursive(5, 3) = {euclidean_gcd_recursive(5 ,  3						)}'''						)
      print(F'''euclidean_gcd_recursive(1, 3) = {euclidean_gcd_recursive(1 ,  3						)}'''						)
      print(F'''euclidean_gcd_recursive(3, 6) = {euclidean_gcd_recursive(3 ,  6						)}'''						)
      print(F'''euclidean_gcd_recursive(6, 3) = {euclidean_gcd_recursive(6 ,  3						)}'''						)


if __name__ == "__main__":
     main()





