


from __future__ import annotations

import copy
import inspect
import unittest

import numpy as np

from transformers import is_tf_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers import (
	    TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
	    TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
	    TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
	    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
	    TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
	    LayoutLMvaConfig,
	    TFLayoutLMvaForQuestionAnswering,
	    TFLayoutLMvaForSequenceClassification,
	    TFLayoutLMvaForTokenClassification,
	    TFLayoutLMvaModel,
	)

if is_vision_available():
	from PIL import Image

	from transformers import LayoutLMvaImageProcessor





class       A    :


							def __init__(self      ,				lowerCAmelCase      ,				lowerCAmelCase=2      ,				lowerCAmelCase=3      ,				lowerCAmelCase=4      ,				lowerCAmelCase=2      ,				lowerCAmelCase=7      ,				lowerCAmelCase=True      ,				lowerCAmelCase=True      ,				lowerCAmelCase=True      ,				lowerCAmelCase=True      ,				lowerCAmelCase=9_9      ,				lowerCAmelCase=3_6      ,				lowerCAmelCase=2      ,				lowerCAmelCase=4      ,				lowerCAmelCase=3_7      ,				lowerCAmelCase="gelu"      ,				lowerCAmelCase=0.1      ,				lowerCAmelCase=0.1      ,				lowerCAmelCase=5_1_2      ,				lowerCAmelCase=1_6      ,				lowerCAmelCase=2      ,				lowerCAmelCase=0.02      ,				lowerCAmelCase=6      ,				lowerCAmelCase=6      ,				lowerCAmelCase=3      ,				lowerCAmelCase=4      ,				lowerCAmelCase=None      ,				lowerCAmelCase=1_0_0_0      ,				):
									__lowercase=			parent
									__lowercase=			batch_size
									__lowercase=			num_channels
									__lowercase=			image_size
									__lowercase=			patch_size
									__lowercase=			is_training
									__lowercase=			use_input_mask
									__lowercase=			use_token_type_ids
									__lowercase=			use_labels
									__lowercase=			vocab_size
									__lowercase=			hidden_size
									__lowercase=			num_hidden_layers
									__lowercase=			num_attention_heads
									__lowercase=			intermediate_size
									__lowercase=			hidden_act
									__lowercase=			hidden_dropout_prob
									__lowercase=			attention_probs_dropout_prob
									__lowercase=			max_position_embeddings
									__lowercase=			type_vocab_size
									__lowercase=			type_sequence_label_size
									__lowercase=			initializer_range
									__lowercase=			coordinate_size
									__lowercase=			shape_size
									__lowercase=			num_labels
									__lowercase=			num_choices
									__lowercase=			scope
									__lowercase=			range_bbox

									# LayoutLMv3's sequence length equals the number of text tokens + number of patches + 1 (we add 1 for the CLS token)
									__lowercase=			text_seq_length
									__lowercase=			(image_size // patch_size) ** 2 + 1
									__lowercase=			self.text_seq_length + self.image_seq_length


							def 			_A       (self					):
									__lowercase=			ids_tensor([self.batch_size, self.text_seq_length]      ,				self.vocab_size					)

									__lowercase=			ids_tensor([self.batch_size, self.text_seq_length, 4]      ,				self.range_bbox					)
									__lowercase=			bbox.numpy()
									# Ensure that bbox is legal
									for i in range(bbox.shape[0]					):
											for j in range(bbox.shape[1]					):
													if bbox[i, j, 3] < bbox[i, j, 1]:
															__lowercase=			bbox[i, j, 3]
															__lowercase=			bbox[i, j, 1]
															__lowercase=			tmp_coordinate
													if bbox[i, j, 2] < bbox[i, j, 0]:
															__lowercase=			bbox[i, j, 2]
															__lowercase=			bbox[i, j, 0]
															__lowercase=			tmp_coordinate
									__lowercase=			tf.constant(__UpperCamelCase					)

									__lowercase=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

									__lowercase=			None
									if self.use_input_mask:
											__lowercase=			random_attention_mask([self.batch_size, self.text_seq_length]					)

									__lowercase=			None
									if self.use_token_type_ids:
											__lowercase=			ids_tensor([self.batch_size, self.text_seq_length]      ,				self.type_vocab_size					)

									__lowercase=			None
									__lowercase=			None
									if self.use_labels:
											__lowercase=			ids_tensor([self.batch_size]      ,				self.type_sequence_label_size					)
											__lowercase=			ids_tensor([self.batch_size, self.text_seq_length]      ,				self.num_labels					)

									__lowercase=			LayoutLMvaConfig(
									    vocab_size=self.vocab_size      ,				hidden_size=self.hidden_size      ,				num_hidden_layers=self.num_hidden_layers      ,				num_attention_heads=self.num_attention_heads      ,				intermediate_size=self.intermediate_size      ,				hidden_act=self.hidden_act      ,				hidden_dropout_prob=self.hidden_dropout_prob      ,				attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,				max_position_embeddings=self.max_position_embeddings      ,				type_vocab_size=self.type_vocab_size      ,				initializer_range=self.initializer_range      ,				coordinate_size=self.coordinate_size      ,				shape_size=self.shape_size      ,				input_size=self.image_size      ,				patch_size=self.patch_size      ,				)

									return config, input_ids, bbox, pixel_values, token_type_ids, input_mask, sequence_labels, token_labels


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			TFLayoutLMvaModel(config=__UpperCamelCase					)

									# text + image
									__lowercase=			model(__UpperCamelCase      ,				pixel_values=__UpperCamelCase      ,				training=__UpperCamelCase					)
									__lowercase=			model(
									    __UpperCamelCase      ,				bbox=__UpperCamelCase      ,				pixel_values=__UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				training=__UpperCamelCase      ,				)
									__lowercase=			model(__UpperCamelCase      ,				bbox=__UpperCamelCase      ,				pixel_values=__UpperCamelCase      ,				training=__UpperCamelCase					)

									self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, self.seq_length, self.hidden_size)					)

									# text only
									__lowercase=			model(__UpperCamelCase      ,				training=__UpperCamelCase					)
									self.parent.assertEqual(
									    result.last_hidden_state.shape      ,				(self.batch_size, self.text_seq_length, self.hidden_size)					)

									# image only
									__lowercase=			model({'pixel_values': pixel_values}      ,				training=__UpperCamelCase					)
									self.parent.assertEqual(
									    result.last_hidden_state.shape      ,				(self.batch_size, self.image_seq_length, self.hidden_size)					)


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			self.num_labels
									__lowercase=			TFLayoutLMvaForSequenceClassification(config=__UpperCamelCase					)
									__lowercase=			model(
									    __UpperCamelCase      ,				bbox=__UpperCamelCase      ,				pixel_values=__UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				labels=__UpperCamelCase      ,				training=__UpperCamelCase      ,				)
									self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_labels)					)


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			self.num_labels
									__lowercase=			TFLayoutLMvaForTokenClassification(config=__UpperCamelCase					)
									__lowercase=			model(
									    __UpperCamelCase      ,				bbox=__UpperCamelCase      ,				pixel_values=__UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				labels=__UpperCamelCase      ,				training=__UpperCamelCase      ,				)
									self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.text_seq_length, self.num_labels)					)


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			2
									__lowercase=			TFLayoutLMvaForQuestionAnswering(config=__UpperCamelCase					)
									__lowercase=			model(
									    __UpperCamelCase      ,				bbox=__UpperCamelCase      ,				pixel_values=__UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				start_positions=__UpperCamelCase      ,				end_positions=__UpperCamelCase      ,				training=__UpperCamelCase      ,				)
									self.parent.assertEqual(result.start_logits.shape      ,				(self.batch_size, self.seq_length)					)
									self.parent.assertEqual(result.end_logits.shape      ,				(self.batch_size, self.seq_length)					)







							def 			_A       (self					):
									__lowercase=			self.prepare_config_and_inputs()
									((__lowercase),							(__lowercase),							(__lowercase),							(__lowercase),							(__lowercase),							(__lowercase),							(__lowercase),							(__lowercase))=			config_and_inputs
									__lowercase=			{
									    'input_ids': input_ids,
									    'bbox': bbox,
									    'pixel_values': pixel_values,
									    'token_type_ids': token_type_ids,
									    'attention_mask': input_mask,
									}
									return config, inputs_dict





@require_tf
class       A    (   lowercase_					,				lowercase_					,				unittest.TestCase ):
							UpperCamelCase_   :							Any       =(
							    (
							        TFLayoutLMvaModel,
							        TFLayoutLMvaForQuestionAnswering,
							        TFLayoutLMvaForSequenceClassification,
							        TFLayoutLMvaForTokenClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							UpperCamelCase_   :							int       =(
							    {'''document-question-answering''': TFLayoutLMvaForQuestionAnswering, '''feature-extraction''': TFLayoutLMvaModel}
							    if is_tf_available()
							    else {}
							)

							UpperCamelCase_   :							Dict       =False
							UpperCamelCase_   :							Optional[Any]       =False
							UpperCamelCase_   :							Dict       =False


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									return True


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase=False					):
									__lowercase=			copy.deepcopy(__UpperCamelCase					)

									if model_class in get_values(__UpperCamelCase					):
											__lowercase=			{
											    k: tf.tile(tf.expand_dims(__UpperCamelCase      ,				1					)      ,				(1, self.model_tester.num_choices) + (1,) * (v.ndim - 1)					)
											    if isinstance(__UpperCamelCase      ,				tf.Tensor					) and v.ndim > 0
											    else v
											    for k, v in inputs_dict.items()
											}

									if return_labels:
											if model_class in get_values(__UpperCamelCase					):
													__lowercase=			tf.ones(self.model_tester.batch_size      ,				dtype=tf.intaa					)
											elif model_class in get_values(__UpperCamelCase					):
													__lowercase=			tf.zeros(self.model_tester.batch_size      ,				dtype=tf.intaa					)
													__lowercase=			tf.zeros(self.model_tester.batch_size      ,				dtype=tf.intaa					)
											elif model_class in get_values(__UpperCamelCase					):
													__lowercase=			tf.zeros(self.model_tester.batch_size      ,				dtype=tf.intaa					)
											elif model_class in get_values(__UpperCamelCase					):
													__lowercase=			tf.zeros(
													    (self.model_tester.batch_size, self.model_tester.text_seq_length)      ,				dtype=tf.intaa					)

									return inputs_dict


							def 			_A       (self					):
									__lowercase=			TFLayoutLMvaModelTester(self					)
									__lowercase=			ConfigTester(self      ,				config_class=__UpperCamelCase      ,				hidden_size=3_7					)


							def 			_A       (self					):
									self.config_tester.run_common_tests()


							def 			_A       (self					):
									__lowercase,							__lowercase=			self.model_tester.prepare_config_and_inputs_for_common()
									for model_class in self.all_model_classes:
											__lowercase=			model_class(__UpperCamelCase					)
											if getattr(__UpperCamelCase      ,				'hf_compute_loss'      ,				__UpperCamelCase					):
													# The number of elements in the loss should be the same as the number of elements in the label
													__lowercase=			self._prepare_for_class(inputs_dict.copy()      ,				__UpperCamelCase      ,				return_labels=__UpperCamelCase					)
													__lowercase=			prepared_for_class[
													    sorted(prepared_for_class.keys() - inputs_dict.keys()      ,				reverse=__UpperCamelCase					)[0]
													]
													__lowercase=			added_label.shape.as_list()[:1]

													# Test that model correctly compute the loss with kwargs
													__lowercase=			self._prepare_for_class(inputs_dict.copy()      ,				__UpperCamelCase      ,				return_labels=__UpperCamelCase					)
													__lowercase=			prepared_for_class.pop('input_ids'					)

													__lowercase=			model(__UpperCamelCase      ,				**__UpperCamelCase					)[0]
													self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]					)

													# Test that model correctly compute the loss when we mask some positions
													__lowercase=			self._prepare_for_class(inputs_dict.copy()      ,				__UpperCamelCase      ,				return_labels=__UpperCamelCase					)
													__lowercase=			prepared_for_class.pop('input_ids'					)
													if "labels" in prepared_for_class:
															__lowercase=			prepared_for_class['labels'].numpy()
															if len(labels.shape					) > 1 and labels.shape[1] != 1:
																	__lowercase=			-1_0_0
																	__lowercase=			tf.convert_to_tensor(__UpperCamelCase					)
																	__lowercase=			model(__UpperCamelCase      ,				**__UpperCamelCase					)[0]
																	self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]					)
																	self.assertTrue(not np.any(np.isnan(loss.numpy()					)					)					)

                # Test that model correctly compute the loss with a dict
													__lowercase=			self._prepare_for_class(inputs_dict.copy()      ,				__UpperCamelCase      ,				return_labels=__UpperCamelCase					)
													__lowercase=			model(__UpperCamelCase					)[0]
													self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]					)

													# Test that model correctly compute the loss with a tuple
													__lowercase=			self._prepare_for_class(inputs_dict.copy()      ,				__UpperCamelCase      ,				return_labels=__UpperCamelCase					)

													# Get keys that were added with the _prepare_for_class function
													__lowercase=			prepared_for_class.keys() - inputs_dict.keys()
													__lowercase=			inspect.signature(model.call					).parameters
													__lowercase=			list(signature.keys()					)

													# Create a dictionary holding the location of the tensors in the tuple
													__lowercase=			{0: 'input_ids'}
													for label_key in label_keys:
															__lowercase=			signature_names.index(__UpperCamelCase					)
															__lowercase=			label_key
													__lowercase=			sorted(tuple_index_mapping.items()					)
													# Initialize a list with their default values, update the values and convert to a tuple
													__lowercase=			[]

													for name in signature_names:
															if name != "kwargs":
																	list_input.append(signature[name].default					)

													for index, value in sorted_tuple_index_mapping:
															__lowercase=			prepared_for_class[value]

													__lowercase=			tuple(__UpperCamelCase					)

													# Send to model
													__lowercase=			model(tuple_input[:-1]					)[0]

													self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]					)


							def 			_A       (self					):
									(
									    (
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),								
									)=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase					)


							def 			_A       (self					):
									(
									    (
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),								
									)=			self.model_tester.prepare_config_and_inputs()
									for type in ["absolute", "relative_key", "relative_key_query"]:
											__lowercase=			type
											self.model_tester.create_and_check_model(__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase					)


							def 			_A       (self					):
									(
									    (
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),								
									)=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(
									    __UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase					)


							def 			_A       (self					):
									(
									    (
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),								
									)=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(
									    __UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase					)


							def 			_A       (self					):
									(
									    (
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),							(
									    __lowercase	
									),								
									)=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(
									    __UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase      ,				__UpperCamelCase					)







							@slow
							def 			_A       (self					):
									for model_name in TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowercase=			TFLayoutLMvaModel.from_pretrained(__UpperCamelCase					)
											self.assertIsNotNone(__UpperCamelCase					)







def        _lowerCamelCase(	)						->	Optional[int]:

		'''simple docstring'''







		__lowercase=			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'	)
		return image





@require_tf
class       A    (   unittest.TestCase ):


							@cached_property
							def 			_A       (self					):
									return LayoutLMvaImageProcessor(apply_ocr=__UpperCamelCase					) if is_vision_available() else None







							@slow
							def 			_A       (self					):
									__lowercase=			TFLayoutLMvaModel.from_pretrained('microsoft/layoutlmv3-base'					)

									__lowercase=			self.default_image_processor
									__lowercase=			prepare_img()
									__lowercase=			image_processor(images=__UpperCamelCase      ,				return_tensors='tf'					).pixel_values

									__lowercase=			tf.constant([[1, 2]]					)
									__lowercase=			tf.expand_dims(tf.constant([[1, 2, 3, 4], [5, 6, 7, 8]]					)      ,				axis=0					)

									# forward pass
									__lowercase=			model(input_ids=__UpperCamelCase      ,				bbox=__UpperCamelCase      ,				pixel_values=__UpperCamelCase      ,				training=__UpperCamelCase					)

									# verify the logits
									__lowercase=			(1, 1_9_9, 7_6_8)
									self.assertEqual(outputs.last_hidden_state.shape      ,				__UpperCamelCase					)

									__lowercase=			tf.constant(
									    [[-0.05_29, 0.36_18, 0.16_32], [-0.15_87, -0.16_67, -0.04_00], [-0.15_57, -0.16_71, -0.05_05]]					)

									self.assertTrue(np.allclose(outputs.last_hidden_state[0, :3, :3]      ,				__UpperCamelCase      ,				atol=1E-4					)					)













"""simple docstring"""
import argparse

import torch
from torch import nn

from transformers import SpeechaTextConfig, SpeechaTextForConditionalGeneration






def 					A__				(			UpperCamelCase       ):
							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 					A__				(			UpperCamelCase       ):
							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 					A__				(			UpperCamelCase       ):
							A,	A		=  emb.weight.shape
							A		=  nn.Linear(UpperCamelCase					,  UpperCamelCase					,  bias=UpperCamelCase       )
							A		=  emb.weight.data
							return lin_layer






def 					A__				(			UpperCamelCase					,  UpperCamelCase       ):
							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=200					,  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__":
		_snake_case     :		Optional[int]       						= 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.')
		_snake_case     :		str       						= parser.parse_args()
		convert_fairseq_sat_checkpoint_to_tfms(args.fairseq_path, args.pytorch_dump_folder_path)


