






'''simple docstring'''
import argparse

import torch
from torch import nn

from transformers import SpeechaTextConfig, SpeechaTextForConditionalGeneration





def 	_a(					UpperCamelCase__			:  Tuple							):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__       :			str													=[
          '''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 	_a(					UpperCamelCase__			:  Tuple							):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__       :			Optional[int]													=list(s_dict.keys()							)
      for key in keys:
            if "transformer_layers" in key:
                  SCREAMING_SNAKE_CASE__       :			Any													=s_dict.pop(UpperCamelCase__							)
            elif "subsample" in key:
                  SCREAMING_SNAKE_CASE__       :			Dict													=s_dict.pop(UpperCamelCase__							)





def 	_a(					UpperCamelCase__			:  str							):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			List[str]													=emb.weight.shape
      SCREAMING_SNAKE_CASE__       :			Optional[int]													=nn.Linear(UpperCamelCase__,		UpperCamelCase__,		bias=UpperCamelCase__							)
      SCREAMING_SNAKE_CASE__       :			Dict													=emb.weight.data
      return lin_layer





def 	_a(					UpperCamelCase__			:  Any,		UpperCamelCase__			:  Dict							):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__       :			List[str]													=torch.load(UpperCamelCase__,		map_location='''cpu'''							)
      SCREAMING_SNAKE_CASE__       :			Any													=mam_aaa['''args''']
      SCREAMING_SNAKE_CASE__       :			int													=mam_aaa['''model''']
      SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=state_dict['''decoder.output_projection.weight''']

      remove_ignore_keys_(UpperCamelCase__							)
      rename_keys(UpperCamelCase__							)

      SCREAMING_SNAKE_CASE__       :			Tuple													=state_dict['''decoder.embed_tokens.weight'''].shape[0]

      SCREAMING_SNAKE_CASE__       :			Any													=args.share_decoder_input_output_embed

      SCREAMING_SNAKE_CASE__       :			str													=[int(UpperCamelCase__							) for i in args.conv_kernel_sizes.split(''','''							)]
      SCREAMING_SNAKE_CASE__       :			List[str]													=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_0_0,		use_cache=UpperCamelCase__,		decoder_start_token_id=2,		early_stopping=UpperCamelCase__,		)

      SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=SpeechaTextForConditionalGeneration(UpperCamelCase__							)
      SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			List[str]													=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:
            SCREAMING_SNAKE_CASE__       :			List[str]													=make_linear_from_emb(model.model.decoder.embed_tokens							)
      else:
            SCREAMING_SNAKE_CASE__       :			int													=lm_head_weights

      model.save_pretrained(UpperCamelCase__							)


if __name__ == "__main__":
  a_					=	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.')
  a_					=	parser.parse_args()
  convert_fairseq_sat_checkpoint_to_tfms(args.fairseq_path, args.pytorch_dump_folder_path)







'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


a_					=	{
    'configuration_lxmert': ['LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LxmertConfig'],
    'tokenization_lxmert': ['LxmertTokenizer'],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					=	['LxmertTokenizerFast']

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					=	[
      'LxmertEncoder',
      'LxmertForPreTraining',
      'LxmertForQuestionAnswering',
      'LxmertModel',
      'LxmertPreTrainedModel',
      'LxmertVisualFeatureEncoder',
      'LxmertXLayer',
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					=	[
      'TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST',
      'TFLxmertForPreTraining',
      'TFLxmertMainLayer',
      'TFLxmertModel',
      'TFLxmertPreTrainedModel',
      'TFLxmertVisualFeatureEncoder',
  ]


if TYPE_CHECKING:
  from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
  from .tokenization_lxmert import LxmertTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_lxmert_fast import LxmertTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_lxmert import (
        LxmertEncoder,
        LxmertForPreTraining,
        LxmertForQuestionAnswering,
        LxmertModel,
        LxmertPreTrainedModel,
        LxmertVisualFeatureEncoder,
        LxmertXLayer,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_lxmert import (
        TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFLxmertForPreTraining,
        TFLxmertMainLayer,
        TFLxmertModel,
        TFLxmertPreTrainedModel,
        TFLxmertVisualFeatureEncoder,
    )

else:
  import sys

  a_					=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)