






import argparse

import torch
from torch import nn

from transformers import MaMaaaConfig, MaMaaaForConditionalGeneration






def    __magic_name__    (	SCREAMING_SNAKE_CASE				)     ->    int:
							_lowercase							:   Any 							=   [
							    '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(A__     ,     A__				)






def    __magic_name__    (	SCREAMING_SNAKE_CASE				)     ->    Optional[int]:
							_lowercase							:   List[Any] 							=   emb.weight.shape
							_lowercase							:   List[Any] 							=   nn.Linear(A__     ,     A__     ,     bias=A__				)
							_lowercase							:   Dict 							=   emb.weight.data
							return lin_layer






def    __magic_name__    (	SCREAMING_SNAKE_CASE				)     ->    Tuple:
							_lowercase							:   List[Any] 							=   torch.load(A__     ,     map_location='cpu'				)
							_lowercase							:   Tuple 							=   mam_aaa['args'] or mam_aaa['cfg']['model']
							_lowercase							:   Any 							=   mam_aaa['model']
							remove_ignore_keys_(A__				)
							_lowercase							:   List[str] 							=   state_dict['encoder.embed_tokens.weight'].shape[0]

							_lowercase							:   Dict 							=   MaMaaaConfig(
							    vocab_size=A__     ,     max_position_embeddings=1_024     ,     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'     ,     )

							_lowercase							:   int 							=   state_dict['decoder.embed_tokens.weight']
							_lowercase							:   Union[str, Any] 							=   MaMaaaForConditionalGeneration(A__				)
							model.model.load_state_dict(A__     ,     strict=A__				)
							_lowercase							:   int 							=   make_linear_from_emb(model.model.shared				)

							return model


if __name__ == "__main__":
							UpperCamelCase								=		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.")
							UpperCamelCase								=		parser.parse_args()
							UpperCamelCase								=		convert_fairseq_mamaaa_checkpoint_from_disk(args.fairseq_pathß)
							model.save_pretrained(args.pytorch_dump_folder_path)








from ...processing_utils import ProcessorMixin







class 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							_UpperCAmelCase      =						"""WhisperFeatureExtractor"""
							_UpperCAmelCase      =						"""WhisperTokenizer"""






							def __init__(      self			,						lowerCAmelCase__			,						lowerCAmelCase__       ):





										"""simple docstring"""




										super().__init__(lowerCAmelCase__			,						lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					self.feature_extractor
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					False






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__=None			,						lowerCAmelCase__=None			,						lowerCAmelCase__=True       ):





										"""simple docstring"""




										return self.tokenizer.get_decoder_prompt_ids(task=lowerCAmelCase__			,						language=lowerCAmelCase__			,						no_timestamps=lowerCAmelCase__       )






							def __call__(      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										if self._in_target_context_manager:
													return self.current_processor(*lowerCAmelCase__			,						**lowerCAmelCase__       )

										SCREAMING_SNAKE_CASE_		:     Tuple					=					kwargs.pop('audio'			,						lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     str					=					kwargs.pop('sampling_rate'			,						lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					kwargs.pop('text'			,						lowerCAmelCase__       )
										if len(lowerCAmelCase__       ) > 0:
													SCREAMING_SNAKE_CASE_		:     List[Any]					=					args[0]
													SCREAMING_SNAKE_CASE_		:     List[Any]					=					args[1:]

										if audio is None and text is None:
													raise ValueError('You need to specify either an `audio` or `text` input to process.'       )

										if audio is not None:
													SCREAMING_SNAKE_CASE_		:     List[Any]					=					self.feature_extractor(lowerCAmelCase__			,						*lowerCAmelCase__			,						sampling_rate=lowerCAmelCase__			,						**lowerCAmelCase__       )
										if text is not None:
													SCREAMING_SNAKE_CASE_		:     Optional[int]					=					self.tokenizer(lowerCAmelCase__			,						**lowerCAmelCase__       )

										if text is None:
													return inputs

										elif audio is None:
													return encodings
										else:
													SCREAMING_SNAKE_CASE_		:     Optional[int]					=					encodings['input_ids']
													return inputs






							def 					UpperCamelCase__     (      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										return self.tokenizer.batch_decode(*lowerCAmelCase__			,						**lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										return self.tokenizer.decode(*lowerCAmelCase__			,						**lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__="np"       ):





										"""simple docstring"""




										return self.tokenizer.get_prompt_ids(lowerCAmelCase__			,						return_tensors=lowerCAmelCase__       )





