






lowerCAmelCase_           = {
    'Pillow': 'Pillow<10.0.0',
    'accelerate': 'accelerate>=0.20.3',
    'av': 'av==9.2.0',
    'beautifulsoup4': 'beautifulsoup4',
    'black': 'black~=23.1',
    'codecarbon': 'codecarbon==1.2.0',
    'cookiecutter': 'cookiecutter==1.7.3',
    'dataclasses': 'dataclasses',
    'datasets': 'datasets!=2.5.0',
    'decord': 'decord==0.6.0',
    'deepspeed': 'deepspeed>=0.9.3',
    'diffusers': 'diffusers',
    'dill': 'dill<0.3.5',
    'evaluate': 'evaluate>=0.2.0',
    'fairscale': 'fairscale>0.3',
    'faiss-cpu': 'faiss-cpu',
    'fastapi': 'fastapi',
    'filelock': 'filelock',
    'flax': 'flax>=0.4.1,<=0.7.0',
    'ftfy': 'ftfy',
    'fugashi': 'fugashi>=1.0',
    'GitPython': 'GitPython<3.1.19',
    'hf-doc-builder': 'hf-doc-builder>=0.3.0',
    'huggingface-hub': 'huggingface-hub>=0.14.1,<1.0',
    'importlib_metadata': 'importlib_metadata',
    'ipadic': 'ipadic>=1.0.0,<2.0',
    'isort': 'isort>=5.5.4',
    'jax': 'jax>=0.2.8,!=0.3.2,<=0.4.13',
    'jaxlib': 'jaxlib>=0.1.65,<=0.4.13',
    'jieba': 'jieba',
    'kenlm': 'kenlm',
    'keras-nlp': 'keras-nlp>=0.3.1',
    'librosa': 'librosa',
    'nltk': 'nltk',
    'natten': 'natten>=0.14.6',
    'numpy': 'numpy>=1.17',
    'onnxconverter-common': 'onnxconverter-common',
    'onnxruntime-tools': 'onnxruntime-tools>=1.4.2',
    'onnxruntime': 'onnxruntime>=1.4.0',
    'opencv-python': 'opencv-python',
    'optuna': 'optuna',
    'optax': 'optax>=0.0.8,<=0.1.4',
    'packaging': 'packaging>=20.0',
    'parameterized': 'parameterized',
    'phonemizer': 'phonemizer',
    'protobuf': 'protobuf',
    'psutil': 'psutil',
    'pyyaml': 'pyyaml>=5.1',
    'pydantic': 'pydantic<2',
    'pytest': 'pytest>=7.2.0',
    'pytest-timeout': 'pytest-timeout',
    'pytest-xdist': 'pytest-xdist',
    'python': 'python>=3.8.0',
    'ray[tune]': 'ray[tune]',
    'regex': 'regex!=2019.12.17',
    'requests': 'requests',
    'rhoknp': 'rhoknp>=1.1.0,<1.3.1',
    'rjieba': 'rjieba',
    'rouge-score': 'rouge-score!=0.0.7,!=0.0.8,!=0.1,!=0.1.1',
    'ruff': 'ruff>=0.0.241,<=0.0.259',
    'sacrebleu': 'sacrebleu>=1.4.12,<2.0.0',
    'sacremoses': 'sacremoses',
    'safetensors': 'safetensors>=0.3.1',
    'sagemaker': 'sagemaker>=2.31.0',
    'scikit-learn': 'scikit-learn',
    'sentencepiece': 'sentencepiece>=0.1.91,!=0.1.92',
    'sigopt': 'sigopt',
    'starlette': 'starlette',
    'sudachipy': 'sudachipy>=0.6.6',
    'sudachidict_core': 'sudachidict_core>=20220729',
    'tensorflow-cpu': 'tensorflow-cpu>=2.6,<2.14',
    'tensorflow': 'tensorflow>=2.6,<2.14',
    'tensorflow-text': 'tensorflow-text<2.14',
    'tf2onnx': 'tf2onnx',
    'timeout-decorator': 'timeout-decorator',
    'timm': 'timm',
    'tokenizers': 'tokenizers>=0.11.1,!=0.11.3,<0.14',
    'torch': 'torch>=1.9,!=1.12.0',
    'torchaudio': 'torchaudio',
    'torchvision': 'torchvision',
    'pyctcdecode': 'pyctcdecode>=0.4.0',
    'tqdm': 'tqdm>=4.27',
    'unidic': 'unidic>=1.0.2',
    'unidic_lite': 'unidic_lite>=1.0.7',
    'urllib3': 'urllib3<2.0.0',
    'uvicorn': 'uvicorn',
}













import argparse

import torch
from torch import nn

from transformers import SpeechaTextConfig, SpeechaTextForConditionalGeneration







def      snake_case		(							UpperCAmelCase	:       List[Any]   ):
				A	 =      [
				    '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(UpperCAmelCase,						UpperCAmelCase   )







def      snake_case		(							UpperCAmelCase	:       Union[str, Any]   ):
				A	 =      list(s_dict.keys()   )
				for key in keys:
								if "transformer_layers" in key:
												A	 =      s_dict.pop(UpperCAmelCase   )
								elif "subsample" in key:
												A	 =      s_dict.pop(UpperCAmelCase   )







def      snake_case		(							UpperCAmelCase	:       Union[str, Any]   ):
				A ,		A	 =      emb.weight.shape
				A	 =      nn.Linear(UpperCAmelCase,						UpperCAmelCase,						bias=UpperCAmelCase   )
				A	 =      emb.weight.data
				return lin_layer







def      snake_case		(							UpperCAmelCase	:       str,						UpperCAmelCase	:       str   ):
				A	 =      torch.load(UpperCAmelCase,						map_location='cpu'   )
				A	 =      mam_aaa['args']
				A	 =      mam_aaa['model']
				A	 =      state_dict['decoder.output_projection.weight']

				remove_ignore_keys_(UpperCAmelCase   )
				rename_keys(UpperCAmelCase   )

				A	 =      state_dict['decoder.embed_tokens.weight'].shape[0]

				A	 =      args.share_decoder_input_output_embed

				A	 =      [int(UpperCAmelCase   ) for i in args.conv_kernel_sizes.split(','   )]
				A	 =      SpeechaTextConfig(
				    vocab_size=UpperCAmelCase,						max_source_positions=args.max_source_positions,						max_target_positions=args.max_target_positions,						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,						dropout=args.dropout,						attention_dropout=args.attention_dropout,						activation_dropout=args.activation_dropout,						activation_function='relu',						num_conv_layers=len(UpperCAmelCase   ),						conv_channels=args.conv_channels,						conv_kernel_sizes=UpperCAmelCase,						input_feat_per_channel=args.input_feat_per_channel,						input_channels=args.input_channels,						tie_word_embeddings=UpperCAmelCase,						num_beams=5,						max_length=2_00,						use_cache=UpperCAmelCase,						decoder_start_token_id=2,						early_stopping=UpperCAmelCase,						)

				A	 =      SpeechaTextForConditionalGeneration(UpperCAmelCase   )
				A ,		A	 =      model.model.load_state_dict(UpperCAmelCase,						strict=UpperCAmelCase   )
				if len(UpperCAmelCase   ) > 0 and not set(UpperCAmelCase   ) <= {
				    "encoder.embed_positions.weights",
				    "decoder.embed_positions.weights",
				}:
								raise ValueError(
								    'Only `encoder.embed_positions.weights` and `decoder.embed_positions.weights`  are allowed to be missing,'
								    f' but all the following weights are missing {missing}'   )

				if tie_embeds:
								A	 =      make_linear_from_emb(model.model.decoder.embed_tokens   )
				else:
								A	 =      lm_head_weights

				model.save_pretrained(UpperCAmelCase   )


if __name__ == "__main__":
					lowerCAmelCase_           = argparse.ArgumentParser()
					# Required parameters
					parser.add_argument('--fairseq_path', type=str, help='Path to the fairseq model (.pt) file.')
					parser.add_argument('--pytorch_dump_folder_path', default=None, type=str, help='Path to the output PyTorch model.')
					lowerCAmelCase_           = parser.parse_args()
					convert_fairseq_sat_checkpoint_to_tfms(args.fairseq_path, args.pytorch_dump_folder_path)





