'''simple docstring'''






import argparse

import torch
from torch import nn

from transformers import MBartConfig, MBartForConditionalGeneration





def  _SCREAMING_SNAKE_CASE		(      __snake_case							:			str				):
     _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(__snake_case   ,		__snake_case				)





def  _SCREAMING_SNAKE_CASE		(      __snake_case							:			str				):
     _A		,       _A    		=  emb.weight.shape
     _A    		=  nn.Linear(__snake_case   ,		__snake_case   ,		bias=__snake_case				)
     _A    		=  emb.weight.data
     return lin_layer





def  _SCREAMING_SNAKE_CASE		(      __snake_case							:			Any   ,		__snake_case							:			List[Any]="facebook/mbart-large-en-ro"   ,		__snake_case							:			Tuple=False   ,		__snake_case							:			Dict=False				):
     _A    		=  torch.load(__snake_case   ,		map_location='cpu'				)['model']
     remove_ignore_keys_(__snake_case				)
     _A    		=  state_dict['encoder.embed_tokens.weight'].shape[0]

     _A    		=  MBartConfig.from_pretrained(__snake_case   ,		vocab_size=__snake_case				)
     if mbart_aa and finetuned:
          _A    		=  'relu'

     _A    		=  state_dict['decoder.embed_tokens.weight']
     _A    		=  MBartForConditionalGeneration(__snake_case				)
     model.model.load_state_dict(__snake_case				)

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

     return model


if __name__ == "__main__":
   _UpperCAmelCase    :     Optional[Any]         =       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''')
   _UpperCAmelCase    :     Optional[Any]         =       parser.parse_args()
   _UpperCAmelCase    :     Optional[int]         =       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)




'''simple docstring'''






import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline





@pytest.mark.integration
def  _SCREAMING_SNAKE_CASE		(      ):
     with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT				):
          with pytest.raises(__snake_case				):
               requests.request('GET'   ,		'https://huggingface.co'				)
          with pytest.raises(requests.exceptions.ConnectTimeout				):
               requests.request('GET'   ,		'https://huggingface.co'   ,		timeout=1.0				)





@pytest.mark.integration
def  _SCREAMING_SNAKE_CASE		(      ):
     with offline(OfflineSimulationMode.CONNECTION_FAILS				):
          with pytest.raises(requests.exceptions.ConnectionError				):
               requests.request('GET'   ,		'https://huggingface.co'				)





def  _SCREAMING_SNAKE_CASE		(      ):
     with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1				):
          with pytest.raises(__snake_case				):
               http_head('https://huggingface.co'				)



