





import datasets


lowercase_          =		"""\
@InProceedings{conneau2018xnli,
  author = \"Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin\",
  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",
  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing\",
  year = \"2018\",
  publisher = \"Association for Computational Linguistics\",
  location = \"Brussels, Belgium\",
}
"""

lowercase_          =		"""\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""

lowercase_          =		"""
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    'accuracy': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric(\"xnli\")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}
"""




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)    ->       List[str]:
  return (preds == labels).mean()


@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION      ,     _KWARGS_DESCRIPTION				)
class     SCREAMING_SNAKE_CASE       (datasets.Metric				):


   def 	SCREAMING_SNAKE_CASE_							(   self      :    int	)->       Union[str, Any]:





     """simple docstring"""







     return datasets.MetricInfo(
         description=_DESCRIPTION      ,					citation=_CITATION      ,					inputs_description=_KWARGS_DESCRIPTION      ,					features=datasets.Features(
             {
                 'predictions': datasets.Value('int64' if self.config_name != 'sts-b' else 'float32'	),
                 'references': datasets.Value('int64' if self.config_name != 'sts-b' else 'float32'	),
             }	)      ,					codebase_urls=[]      ,					reference_urls=[]      ,					format='numpy'      ,					)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    int      ,					a      :    Tuple      ,					a      :    List[str]	)->       List[str]:





     """simple docstring"""







     return {"accuracy": simple_accuracy(a      ,					a	)}









import argparse

import torch
from torch import nn

from transformers import MBartConfig, MBartForConditionalGeneration




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		)    ->       Union[str, Any]:
  lowercase__           =  [
      'encoder.version',
      'decoder.version',
      'model.encoder.version',
      'model.decoder.version',
      '_float_tensor',
      'decoder.output_projection.weight',
  ]
  for k in ignore_keys:
    state_dict.pop(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		)    ->       Dict:
  lowercase__      ,   lowercase__           =  emb.weight.shape
  lowercase__           =  nn.Linear(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						bias=_SCREAMING_SNAKE_CASE		)
  lowercase__           =  emb.weight.data
  return lin_layer




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE="facebook/mbart-large-en-ro"		,						_SCREAMING_SNAKE_CASE=False		,						_SCREAMING_SNAKE_CASE=False		)    ->       str:
  lowercase__           =  torch.load(_SCREAMING_SNAKE_CASE		,						map_location='cpu'		)['model']
  remove_ignore_keys_(_SCREAMING_SNAKE_CASE		)
  lowercase__           =  state_dict['encoder.embed_tokens.weight'].shape[0]

  lowercase__           =  MBartConfig.from_pretrained(_SCREAMING_SNAKE_CASE		,						vocab_size=_SCREAMING_SNAKE_CASE		)
  if mbart_aa and finetuned:
    lowercase__           =  'relu'

  lowercase__           =  state_dict['decoder.embed_tokens.weight']
  lowercase__           =  MBartForConditionalGeneration(_SCREAMING_SNAKE_CASE		)
  model.model.load_state_dict(_SCREAMING_SNAKE_CASE		)

  if finetuned:
    lowercase__           =  make_linear_from_emb(model.model.shared		)

  return model


if __name__ == "__main__":
      lowercase_          =		argparse.ArgumentParser()
      # Required parameters
      parser.add_argument(
          """fairseq_path""", type=str, help="""bart.large, bart.large.cnn or a path to a 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="""facebook/mbart-large-cc25""",
          type=str,
          help="""Which huggingface architecture to use: mbart-large""",
      )
      parser.add_argument("""--mbart_50""", action="""store_true""", help="""whether the model is mMART-50 checkpoint""")
      parser.add_argument("""--finetuned""", action="""store_true""", help="""whether the model is a fine-tuned checkpoint""")
      lowercase_          =		parser.parse_args()
      lowercase_          =		convert_fairseq_mbart_checkpoint_from_disk(
          args.fairseq_path, hf_config_path=args.hf_config, finetuned=args.finetuned, mbart_aa=args.mbart_aa
      )
      model.save_pretrained(args.pytorch_dump_folder_path)


