




"""simple docstring"""


from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_       							=    logging.get_logger(__name__)

a_       							=    {
    "facebook/s2t-small-librispeech-asr": (
        "https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json"
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}
class snake_case      (  __lowerCAmelCase):
		__UpperCamelCase           =			'''speech_to_text'''
		__UpperCamelCase           =			['''past_key_values''']
		__UpperCamelCase           =			{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}







		def __init__(					self      :       Tuple    ,   a__      :       Union[str, Any]=1_00_00    ,   a__      :       Tuple=12    ,   a__      :       Tuple=20_48    ,   a__      :       List[str]=4    ,   a__      :       List[Any]=6    ,   a__      :       List[str]=20_48    ,   a__      :       List[str]=4    ,   a__      :       Dict=0.0    ,   a__      :       Any=0.0    ,   a__      :       List[Any]=True    ,   a__      :       Any=True    ,   a__      :       List[Any]="relu"    ,   a__      :       Dict=2_56    ,   a__      :       int=0.1    ,   a__      :       Dict=0.0    ,   a__      :       Any=0.0    ,   a__      :       Dict=0.0_2    ,   a__      :       int=2    ,   a__      :       Union[str, Any]=True    ,   a__      :       int=1    ,   a__      :       Union[str, Any]=0    ,   a__      :       str=2    ,   a__      :       Optional[int]=60_00    ,   a__      :       List[Any]=10_24    ,   a__      :       str=2    ,   a__      :       Optional[int]=(5, 5)    ,   a__      :       str=10_24    ,   a__      :       Optional[int]=80    ,   a__      :       str=1    ,   **a__      :       List[str]    ,   )       ->						Tuple:





						'''simple docstring'''







						_A					  =			vocab_size
						_A					  =			d_model
						_A					  =			encoder_ffn_dim
						_A					  =			encoder_layers
						_A					  =			encoder_attention_heads
						_A					  =			decoder_ffn_dim
						_A					  =			decoder_layers
						_A					  =			decoder_attention_heads
						_A					  =			dropout
						_A					  =			attention_dropout
						_A					  =			activation_dropout
						_A					  =			activation_function
						_A					  =			init_std
						_A					  =			encoder_layerdrop
						_A					  =			decoder_layerdrop
						_A					  =			use_cache
						_A					  =			encoder_layers
						_A					  =			scale_embedding  # scale factor will be sqrt(d_model) if True
						_A					  =			max_source_positions
						_A					  =			max_target_positions
						_A					  =			num_conv_layers
						_A					  =			list(lowerCAmelCase_		)
						_A					  =			conv_channels
						_A					  =			input_feat_per_channel
						_A					  =			input_channels

						if len(self.conv_kernel_sizes		) != self.num_conv_layers:
										raise ValueError(
										    "Configuration for convolutional module is incorrect. "
										    "It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` "
										    F"""but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes		)}`, """
										    F"""`config.num_conv_layers = {self.num_conv_layers}`."""		)

						super().__init__(
						    pad_token_id=lowerCAmelCase_    ,   bos_token_id=lowerCAmelCase_    ,   eos_token_id=lowerCAmelCase_    ,   is_encoder_decoder=lowerCAmelCase_    ,   decoder_start_token_id=lowerCAmelCase_    ,   **lowerCAmelCase_    ,   )



"""simple docstring"""


import argparse

import torch
from torch import nn

from transformers import MBartConfig, MBartForConditionalGeneration






def      a__ (				__lowercase   )	->	Optional[int]:
				_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(__lowercase     ,			__lowercase   )






def      a__ (				__lowercase   )	->	List[Any]:
				_A  ,		_A					  =			emb.weight.shape
				_A					  =			nn.Linear(__lowercase     ,			__lowercase     ,			bias=__lowercase   )
				_A					  =			emb.weight.data
				return lin_layer






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

				_A					  =			MBartConfig.from_pretrained(__lowercase     ,			vocab_size=__lowercase   )
				if mbart_aa and finetuned:
								_A					  =			"relu"

				_A					  =			state_dict["decoder.embed_tokens.weight"]
				_A					  =			MBartForConditionalGeneration(__lowercase   )
				model.model.load_state_dict(__lowercase   )

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

				return model


if __name__ == "__main__":
		a_       							=    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")
		a_       							=    parser.parse_args()
		a_       							=    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)