





import argparse

import torch
from torch import nn

from transformers import PLBartConfig, PLBartForConditionalGeneration, PLBartForSequenceClassification
def 				__UpperCamelCase  (		snake_case     )  ->						int:


   '''simple docstring'''







   __A				 =       [
       """encoder.version""",
       """decoder.version""",
       """model.encoder.version""",
       """model.decoder.version""",
       """_float_tensor""",
       """decoder.output_projection.weight""",
   ]
   for k in ignore_keys:
      state_dict.pop(_lowerCamelCase    ,	_lowerCamelCase     )
def 				__UpperCamelCase  (		snake_case     )  ->						Any:


   '''simple docstring'''







   __A				 =       emb.weight.shape
   __A				 =       nn.Linear(_lowerCamelCase    ,	_lowerCamelCase    ,	bias=_lowerCamelCase     )
   __A				 =       emb.weight.data
   return lin_layer
def 				__UpperCamelCase  (		snake_case    ,	snake_case="uclanlp/plbart-base"    ,	snake_case=False    ,	snake_case=False     )  ->						Union[str, Any]:


   '''simple docstring'''







   __A				 =       torch.load(_lowerCamelCase    ,	map_location='''cpu'''     )["""model"""]
   remove_ignore_keys_(_lowerCamelCase     )
   __A				 =       state_dict["""encoder.embed_tokens.weight"""].shape[0]

   __A				 =       PLBartConfig.from_pretrained(_lowerCamelCase    ,	vocab_size=_lowerCamelCase     )

   __A				 =       state_dict["""decoder.embed_tokens.weight"""]
   if not classification:
      __A				 =       PLBartForConditionalGeneration(_lowerCamelCase     )
      model.model.load_state_dict(_lowerCamelCase     )
      if finetuned:
         __A				 =       make_linear_from_emb(model.model.shared     )

   else:
      __A				 =       {}
      for key, value in state_dict.copy().items():
         if key.startswith('''classification_heads.sentence_classification_head'''     ):
            __A				 =       value
            state_dict.pop(_lowerCamelCase     )
      __A				 =       PLBartForSequenceClassification(_lowerCamelCase     )
      model.model.load_state_dict(_lowerCamelCase     )
      model.classification_head.load_state_dict(_lowerCamelCase     )

   return model


if __name__ == "__main__":
    _UpperCamelCase   :							Union[str, Any]     =	argparse.ArgumentParser()
    # Required parameters
    parser.add_argument("""fairseq_path""", type=str, help="""model.pt on local filesystem.""")
    parser.add_argument("""pytorch_dump_folder_path""", default=None, type=str, help="""Path to the output PyTorch model.""")
    parser.add_argument(
        """--hf_config""",
        default="""uclanlp/plbart-base""",
        type=str,
        help="""Which huggingface architecture to use: plbart-base""",
    )
    parser.add_argument("""--finetuned""", action="""store_true""", help="""whether the model is a fine-tuned checkpoint""")
    parser.add_argument(
        """--classification""", action="""store_true""", help="""whether the model is a classification checkpoint"""
    )
    _UpperCamelCase   :							List[Any]     =	parser.parse_args()
    _UpperCamelCase   :							List[Any]     =	convert_fairseq_plbart_checkpoint_from_disk(
        args.fairseq_path,
        hf_config_path=args.hf_config,
        finetuned=args.finetuned,
        classification=args.classification,
    )
    model.save_pretrained(args.pytorch_dump_folder_path)








from __future__ import annotations

import sys
def 				__UpperCamelCase  (		snake_case    ,	snake_case     )  ->						tuple[int, int]:


   '''simple docstring'''







   if abs(snake_case     ) == 1:
      return a, 0
   elif abs(snake_case     ) == 1:
      return 0, b

   __A ,						__A				 =       a, b
   __A ,						__A				 =       1, 0
   __A ,						__A				 =       0, 1

   while remainder != 0:
      __A				 =       old_remainder // remainder
      __A ,						__A				 =       remainder, old_remainder - quotient * remainder
      __A ,						__A				 =       coeff_a, old_coeff_a - quotient * coeff_a
      __A ,						__A				 =       coeff_b, old_coeff_b - quotient * coeff_b

   # sign correction for negative numbers
   if a < 0:
      __A				 =       -old_coeff_a
   if b < 0:
      __A				 =       -old_coeff_b

   return old_coeff_a, old_coeff_b
def 				__UpperCamelCase  (		)  ->						Tuple:


   '''simple docstring'''







   if len(sys.argv     ) < 3:
      print('''2 integer arguments required'''     )
      return 1
   __A				 =       int(sys.argv[1]     )
   __A				 =       int(sys.argv[2]     )
   print(extended_euclidean_algorithm(snake_case    ,	snake_case     )     )
   return 0


if __name__ == "__main__":
    raise SystemExit(main())

