




'''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 			_a  (	UpperCAmelCase__ ):
       __a				:     Dict   				=					"""speech_to_text"""
       __a				:     Optional[int]   				=					["""past_key_values"""]
       __a				:     str   				=					{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}
       def __init__(	self						:	Dict   ,				lowercase						:	List[str]=10_000   ,				lowercase						:	Optional[Any]=12   ,				lowercase						:	str=2_048   ,				lowercase						:	Union[str, Any]=4   ,				lowercase						:	List[Any]=6   ,				lowercase						:	List[Any]=2_048   ,				lowercase						:	Tuple=4   ,				lowercase						:	Union[str, Any]=0.0   ,				lowercase						:	Any=0.0   ,				lowercase						:	List[str]=True   ,				lowercase						:	int=True   ,				lowercase						:	int="relu"   ,				lowercase						:	str=256   ,				lowercase						:	Tuple=0.1   ,				lowercase						:	Any=0.0   ,				lowercase						:	str=0.0   ,				lowercase						:	Union[str, Any]=0.02   ,				lowercase						:	Any=2   ,				lowercase						:	Union[str, Any]=True   ,				lowercase						:	Optional[Any]=1   ,				lowercase						:	Optional[int]=0   ,				lowercase						:	int=2   ,				lowercase						:	Union[str, Any]=6_000   ,				lowercase						:	Union[str, Any]=1_024   ,				lowercase						:	List[Any]=2   ,				lowercase						:	Union[str, Any]=(5, 5)   ,				lowercase						:	Any=1_024   ,				lowercase						:	int=80   ,				lowercase						:	Union[str, Any]=1   ,				**lowercase						:	str   ,				):



           '''simple docstring'''

           UpperCAmelCase			       =		vocab_size
           UpperCAmelCase			       =		d_model
           UpperCAmelCase			       =		encoder_ffn_dim
           UpperCAmelCase			       =		encoder_layers
           UpperCAmelCase			       =		encoder_attention_heads
           UpperCAmelCase			       =		decoder_ffn_dim
           UpperCAmelCase			       =		decoder_layers
           UpperCAmelCase			       =		decoder_attention_heads
           UpperCAmelCase			       =		dropout
           UpperCAmelCase			       =		attention_dropout
           UpperCAmelCase			       =		activation_dropout
           UpperCAmelCase			       =		activation_function
           UpperCAmelCase			       =		init_std
           UpperCAmelCase			       =		encoder_layerdrop
           UpperCAmelCase			       =		decoder_layerdrop
           UpperCAmelCase			       =		use_cache
           UpperCAmelCase			       =		encoder_layers
           UpperCAmelCase			       =		scale_embedding  # scale factor will be sqrt(d_model) if True
           UpperCAmelCase			       =		max_source_positions
           UpperCAmelCase			       =		max_target_positions
           UpperCAmelCase			       =		num_conv_layers
           UpperCAmelCase			       =		list(SCREAMING_SNAKE_CASE__				)
           UpperCAmelCase			       =		conv_channels
           UpperCAmelCase			       =		input_feat_per_channel
           UpperCAmelCase			       =		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=SCREAMING_SNAKE_CASE__   ,				bos_token_id=SCREAMING_SNAKE_CASE__   ,				eos_token_id=SCREAMING_SNAKE_CASE__   ,				is_encoder_decoder=SCREAMING_SNAKE_CASE__   ,				decoder_start_token_id=SCREAMING_SNAKE_CASE__   ,				**SCREAMING_SNAKE_CASE__   ,				)





'''simple docstring'''

import argparse

import torch
from torch import nn

from transformers import MaMaaaConfig, MaMaaaForConditionalGeneration







def      UpperCamelCase_						(					snake_case_       :       Any      )					->     Optional[Any]:






 '''simple docstring'''

 __lowerCAmelCase											=						[
     """encoder.version""",
     """decoder.version""",
     """model.encoder.version""",
     """model.decoder.version""",
     """decoder.output_projection.weight""",
     """_float_tensor""",
     """encoder.embed_positions._float_tensor""",
     """decoder.embed_positions._float_tensor""",
 ]
 for k in ignore_keys:
  state_dict.pop(snake_case_						,		snake_case_      )







def      UpperCamelCase_						(					snake_case_       :       Optional[Any]      )					->     List[Any]:






 '''simple docstring'''

 __lowerCAmelCase							,       __lowerCAmelCase											=						emb.weight.shape
 __lowerCAmelCase											=						nn.Linear(snake_case_						,		snake_case_						,		bias=snake_case_      )
 __lowerCAmelCase											=						emb.weight.data
 return lin_layer







def      UpperCamelCase_						(					snake_case_       :       Any      )					->     Any:






 '''simple docstring'''

 __lowerCAmelCase											=						torch.load(snake_case_						,		map_location="""cpu"""      )
 __lowerCAmelCase											=						mam_aaa["""args"""] or mam_aaa["""cfg"""]["""model"""]
 __lowerCAmelCase											=						mam_aaa["""model"""]
 remove_ignore_keys_(snake_case_      )
 __lowerCAmelCase											=						state_dict["""encoder.embed_tokens.weight"""].shape[0]

 __lowerCAmelCase											=						MaMaaaConfig(
     vocab_size=snake_case_						,		max_position_embeddings=10_24						,		encoder_layers=args.encoder_layers						,		decoder_layers=args.decoder_layers						,		encoder_attention_heads=args.encoder_attention_heads						,		decoder_attention_heads=args.decoder_attention_heads						,		encoder_ffn_dim=args.encoder_ffn_embed_dim						,		decoder_ffn_dim=args.decoder_ffn_embed_dim						,		d_model=args.encoder_embed_dim						,		encoder_layerdrop=args.encoder_layerdrop						,		decoder_layerdrop=args.decoder_layerdrop						,		dropout=args.dropout						,		attention_dropout=args.attention_dropout						,		activation_dropout=args.activation_dropout						,		activation_function="""relu"""						,		)

 __lowerCAmelCase											=						state_dict["""decoder.embed_tokens.weight"""]
 __lowerCAmelCase											=						MaMaaaForConditionalGeneration(snake_case_      )
 model.model.load_state_dict(snake_case_						,		strict=snake_case_      )
 __lowerCAmelCase											=						make_linear_from_emb(model.model.shared      )

 return model


if __name__ == "__main__":
 _A			:      Union[str, Any]					      =				argparse.ArgumentParser()
 # Required parameters
 parser.add_argument('''fairseq_path''', type=str, help='''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.''')
 _A			:      str					      =				parser.parse_args()
 _A			:      Optional[int]					      =				convert_fairseq_mamaaa_checkpoint_from_disk(args.fairseq_pathß)
 model.save_pretrained(args.pytorch_dump_folder_path)






