





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 _A       (   __magic_name__  , __magic_name__	):
   lowercase__			       =  torch.load(__magic_name__  , map_location="cpu"	)

   lowercase__			       =  chkpt["model"]

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

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

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

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

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

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

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


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













from __future__ import annotations


def _A       (   __magic_name__  , __magic_name__	):
   lowercase__			       =  []
   create_all_state(1  , __magic_name__  , __magic_name__  , []  , __magic_name__	)
   return result


def _A       (   __magic_name__  , __magic_name__  , __magic_name__  , __magic_name__  , __magic_name__  , ):
   if level == 0:
      total_list.append(current_list[:]	)
      return

   for i in range(__magic_name__  , total_number - level + 2	):
      current_list.append(__magic_name__	)
      create_all_state(i + 1  , __magic_name__  , level - 1  , __magic_name__  , __magic_name__	)
      current_list.pop()


def _A       (   __magic_name__	):
   for i in total_list:
      print(*__magic_name__	)


if __name__ == "__main__":
  _snake_case           =			4
  _snake_case           =			2
  _snake_case           =			generate_all_combinations(n, k)
  print_all_state(total_list)






