'''simple docstring'''

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


_A			:      int					      =				logging.get_logger(__name__)

_A			:      List[str]					      =				{
    '''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 				_lowercase     (				UpperCAmelCase__			):


 '''simple docstring'''






 _SCREAMING_SNAKE_CASE     :       Dict      	=					"""speech_to_text"""
 _SCREAMING_SNAKE_CASE     :       Optional[int]      	=					["""past_key_values"""]
 _SCREAMING_SNAKE_CASE     :       str      	=					{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}
 def __init__(      self   :	Dict      ,       SCREAMING_SNAKE_CASE__   :	List[str]=1_00_00      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]=12      ,       SCREAMING_SNAKE_CASE__   :	str=20_48      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=4      ,       SCREAMING_SNAKE_CASE__   :	List[Any]=6      ,       SCREAMING_SNAKE_CASE__   :	List[Any]=20_48      ,       SCREAMING_SNAKE_CASE__   :	Tuple=4      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=0.0      ,       SCREAMING_SNAKE_CASE__   :	Any=0.0      ,       SCREAMING_SNAKE_CASE__   :	List[str]=True      ,       SCREAMING_SNAKE_CASE__   :	int=True      ,       SCREAMING_SNAKE_CASE__   :	int="relu"      ,       SCREAMING_SNAKE_CASE__   :	str=2_56      ,       SCREAMING_SNAKE_CASE__   :	Tuple=0.1      ,       SCREAMING_SNAKE_CASE__   :	Any=0.0      ,       SCREAMING_SNAKE_CASE__   :	str=0.0      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=0.0_2      ,       SCREAMING_SNAKE_CASE__   :	Any=2      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=True      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]=1      ,       SCREAMING_SNAKE_CASE__   :	Optional[int]=0      ,       SCREAMING_SNAKE_CASE__   :	int=2      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=60_00      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=10_24      ,       SCREAMING_SNAKE_CASE__   :	List[Any]=2      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=(5, 5)      ,       SCREAMING_SNAKE_CASE__   :	Any=10_24      ,       SCREAMING_SNAKE_CASE__   :	int=80      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=1      ,       **SCREAMING_SNAKE_CASE__   :	str      ,       )  ->    Optional[Any]:
  __lowerCAmelCase											=						vocab_size
  __lowerCAmelCase											=						d_model
  __lowerCAmelCase											=						encoder_ffn_dim
  __lowerCAmelCase											=						encoder_layers
  __lowerCAmelCase											=						encoder_attention_heads
  __lowerCAmelCase											=						decoder_ffn_dim
  __lowerCAmelCase											=						decoder_layers
  __lowerCAmelCase											=						decoder_attention_heads
  __lowerCAmelCase											=						dropout
  __lowerCAmelCase											=						attention_dropout
  __lowerCAmelCase											=						activation_dropout
  __lowerCAmelCase											=						activation_function
  __lowerCAmelCase											=						init_std
  __lowerCAmelCase											=						encoder_layerdrop
  __lowerCAmelCase											=						decoder_layerdrop
  __lowerCAmelCase											=						use_cache
  __lowerCAmelCase											=						encoder_layers
  __lowerCAmelCase											=						scale_embedding  # scale factor will be sqrt(d_model) if True
  __lowerCAmelCase											=						max_source_positions
  __lowerCAmelCase											=						max_target_positions
  __lowerCAmelCase											=						num_conv_layers
  __lowerCAmelCase											=						list(SCREAMING_SNAKE_CASE__							)
  __lowerCAmelCase											=						conv_channels
  __lowerCAmelCase											=						input_feat_per_channel
  __lowerCAmelCase											=						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)






