



import inspect
import unittest

from transformers import DPTConfig
from transformers.file_utils import is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import MODEL_MAPPING, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTModel
      from transformers.models.dpt.modeling_dpt import DPT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import DPTImageProcessor



class        __snake_case		:




       def __init__( self  : Union[str, Any]       ,       A_  : Union[str, Any]       ,       A_  : List[Any]=2       ,       A_  : Any=3_2       ,       A_  : Optional[Any]=1_6       ,       A_  : Optional[int]=3       ,       A_  : Optional[int]=True       ,       A_  : List[str]=True       ,       A_  : Union[str, Any]=3_2       ,       A_  : Optional[Any]=4       ,       A_  : List[str]=[0, 1, 2, 3]       ,       A_  : List[str]=4       ,       A_  : Any=3_7       ,       A_  : List[Any]="gelu"       ,       A_  : int=0.1       ,       A_  : List[Any]=0.1       ,       A_  : Dict=0.02       ,       A_  : str=3       ,       A_  : int=False       ,       A_  : Union[str, Any]=None       ,       ):
         lowerCAmelCase_    :  int             =				parent
         lowerCAmelCase_    :  Optional[Any]             =				batch_size
         lowerCAmelCase_    :  Union[str, Any]             =				image_size
         lowerCAmelCase_    :  Any             =				patch_size
         lowerCAmelCase_    :  Any             =				num_channels
         lowerCAmelCase_    :  List[Any]             =				is_training
         lowerCAmelCase_    :  List[str]             =				use_labels
         lowerCAmelCase_    :  Union[str, Any]             =				hidden_size
         lowerCAmelCase_    :  Dict             =				num_hidden_layers
         lowerCAmelCase_    :  Any             =				backbone_out_indices
         lowerCAmelCase_    :  Optional[Any]             =				num_attention_heads
         lowerCAmelCase_    :  Union[str, Any]             =				intermediate_size
         lowerCAmelCase_    :  str             =				hidden_act
         lowerCAmelCase_    :  Any             =				hidden_dropout_prob
         lowerCAmelCase_    :  Any             =				attention_probs_dropout_prob
         lowerCAmelCase_    :  List[Any]             =				initializer_range
         lowerCAmelCase_    :  Union[str, Any]             =				num_labels
         lowerCAmelCase_    :  List[Any]             =				scope
         lowerCAmelCase_    :  Optional[int]             =				is_hybrid
         # sequence length of DPT = num_patches + 1 (we add 1 for the [CLS] token)
         lowerCAmelCase_    :  Dict             =				(image_size // patch_size) ** 2
         lowerCAmelCase_    :  Optional[Any]             =				num_patches + 1




       def      UpperCAmelCase__    ( self  : List[str]):
         lowerCAmelCase_    :  str             =				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

         lowerCAmelCase_    :  int             =				None
         if self.use_labels:
           lowerCAmelCase_    :  Optional[int]             =				ids_tensor([self.batch_size, self.image_size, self.image_size]       ,       self.num_labels)

         lowerCAmelCase_    :  List[str]             =				self.get_config()

         return config, pixel_values, labels




       def      UpperCAmelCase__    ( self  : Optional[int]):
         return DPTConfig(
             image_size=self.image_size       ,       patch_size=self.patch_size       ,       num_channels=self.num_channels       ,       hidden_size=self.hidden_size       ,       num_hidden_layers=self.num_hidden_layers       ,       backbone_out_indices=self.backbone_out_indices       ,       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       ,       is_decoder=__snake_case       ,       initializer_range=self.initializer_range       ,       is_hybrid=self.is_hybrid       ,       )




       def      UpperCAmelCase__    ( self  : Union[str, Any]       ,       A_  : Optional[int]       ,       A_  : Any       ,       A_  : str):
         lowerCAmelCase_    :  str             =				DPTModel(config=__snake_case)
         model.to(__snake_case)
         model.eval()
         lowerCAmelCase_    :  List[Any]             =				model(__snake_case)
         self.parent.assertEqual(result.last_hidden_state.shape       ,       (self.batch_size, self.seq_length, self.hidden_size))




       def      UpperCAmelCase__    ( self  : Union[str, Any]       ,       A_  : Optional[int]       ,       A_  : Tuple       ,       A_  : int):
         lowerCAmelCase_    :  List[str]             =				self.num_labels
         lowerCAmelCase_    :  int             =				DPTForDepthEstimation(__snake_case)
         model.to(__snake_case)
         model.eval()
         lowerCAmelCase_    :  int             =				model(__snake_case)
         self.parent.assertEqual(result.predicted_depth.shape       ,       (self.batch_size, self.image_size, self.image_size))




       def      UpperCAmelCase__    ( self  : Tuple       ,       A_  : Union[str, Any]       ,       A_  : Dict       ,       A_  : str):
         lowerCAmelCase_    :  List[Any]             =				self.num_labels
         lowerCAmelCase_    :  Union[str, Any]             =				DPTForSemanticSegmentation(__snake_case)
         model.to(__snake_case)
         model.eval()
         lowerCAmelCase_    :  int             =				model(__snake_case       ,       labels=__snake_case)
         self.parent.assertEqual(
             result.logits.shape       ,       (self.batch_size, self.num_labels, self.image_size, self.image_size))







       def      UpperCAmelCase__    ( self  : int):
         lowerCAmelCase_    :  List[str]             =				self.prepare_config_and_inputs()
         lowerCAmelCase_      ,						lowerCAmelCase_      ,						lowerCAmelCase_    :  Union[str, Any]             =				config_and_inputs
         lowerCAmelCase_    :  Tuple             =				{'''pixel_values''': pixel_values}
         return config, inputs_dict





@require_torch
class        __snake_case		(  snake_case__		,snake_case__		,unittest.TestCase		):
       _a       =				(DPTModel, DPTForDepthEstimation, DPTForSemanticSegmentation) if is_torch_available() else ()
       _a       =				(
           {
               '''depth-estimation''': DPTForDepthEstimation,
               '''feature-extraction''': DPTModel,
               '''image-segmentation''': DPTForSemanticSegmentation,
           }
           if is_torch_available()
           else {}
       )

       _a       =				False
       _a       =				False
       _a       =				False




       def      UpperCAmelCase__    ( self  : int):
         lowerCAmelCase_    :  Tuple             =				DPTModelTester(self)
         lowerCAmelCase_    :  Dict             =				ConfigTester(self       ,       config_class=__snake_case       ,       has_text_modality=__snake_case       ,       hidden_size=3_7)




       def      UpperCAmelCase__    ( self  : Optional[int]):
         self.config_tester.run_common_tests()




       @unittest.skip(reason='''DPT does not use inputs_embeds''')
       def      UpperCAmelCase__    ( self  : Dict):
         pass




       def      UpperCAmelCase__    ( self  : Optional[Any]):
         lowerCAmelCase_      ,						lowerCAmelCase_    :  Union[str, Any]             =				self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           lowerCAmelCase_    :  int             =				model_class(__snake_case)
           self.assertIsInstance(model.get_input_embeddings()       ,       (nn.Module))
           lowerCAmelCase_    :  Dict             =				model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(__snake_case       ,       nn.Linear))




       def      UpperCAmelCase__    ( self  : List[str]):
         lowerCAmelCase_      ,						lowerCAmelCase_    :  int             =				self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           lowerCAmelCase_    :  Optional[int]             =				model_class(__snake_case)
           lowerCAmelCase_    :  Any             =				inspect.signature(model.forward)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           lowerCAmelCase_    :  int             =				[*signature.parameters.keys()]

           lowerCAmelCase_    :  List[str]             =				['''pixel_values''']
           self.assertListEqual(arg_names[:1]       ,       __snake_case)




       def      UpperCAmelCase__    ( self  : List[str]):
         lowerCAmelCase_    :  Optional[int]             =				self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__snake_case)




       def      UpperCAmelCase__    ( self  : List[str]):
         lowerCAmelCase_    :  List[Any]             =				self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_depth_estimation(*__snake_case)




       def      UpperCAmelCase__    ( self  : Tuple):
         lowerCAmelCase_    :  List[str]             =				self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_semantic_segmentation(*__snake_case)




       def      UpperCAmelCase__    ( self  : Dict):
         for model_class in self.all_model_classes:
           if model_class.__name__ == "DPTForDepthEstimation":
             continue

           lowerCAmelCase_      ,						lowerCAmelCase_    :  Dict             =				self.model_tester.prepare_config_and_inputs_for_common()
           lowerCAmelCase_    :  Any             =				True

           if model_class in get_values(__snake_case):
             continue

           lowerCAmelCase_    :  List[str]             =				model_class(__snake_case)
           model.to(__snake_case)
           model.train()
           lowerCAmelCase_    :  int             =				self._prepare_for_class(__snake_case       ,       __snake_case       ,       return_labels=__snake_case)
           lowerCAmelCase_    :  Any             =				model(**__snake_case).loss
           loss.backward()




       def      UpperCAmelCase__    ( self  : Tuple):
         for model_class in self.all_model_classes:
           if model_class.__name__ == "DPTForDepthEstimation":
             continue

           lowerCAmelCase_      ,						lowerCAmelCase_    :  Optional[int]             =				self.model_tester.prepare_config_and_inputs_for_common()
           lowerCAmelCase_    :  Optional[int]             =				False
           lowerCAmelCase_    :  Tuple             =				True

           if model_class in get_values(__snake_case) or not model_class.supports_gradient_checkpointing:
             continue
           lowerCAmelCase_    :  List[Any]             =				model_class(__snake_case)
           model.to(__snake_case)
           model.gradient_checkpointing_enable()
           model.train()
           lowerCAmelCase_    :  List[Any]             =				self._prepare_for_class(__snake_case       ,       __snake_case       ,       return_labels=__snake_case)
           lowerCAmelCase_    :  int             =				model(**__snake_case).loss
           loss.backward()




       def      UpperCAmelCase__    ( self  : List[Any]):
         lowerCAmelCase_      ,						lowerCAmelCase_    :  Dict             =				self.model_tester.prepare_config_and_inputs_for_common()

         lowerCAmelCase_    :  Tuple             =				_config_zero_init(__snake_case)
         for model_class in self.all_model_classes:
           lowerCAmelCase_    :  str             =				model_class(config=__snake_case)
           # Skip the check for the backbone
           lowerCAmelCase_    :  Dict             =				[]
           for name, module in model.named_modules():
             if module.__class__.__name__ == "DPTViTHybridEmbeddings":
               lowerCAmelCase_    :  Dict             =				[F"""{name}.{key}""" for key in module.state_dict().keys()]
               break

           for name, param in model.named_parameters():
             if param.requires_grad:
               if name in backbone_params:
                 continue
               self.assertIn(
                   ((param.data.mean() * 1e9).round() / 1e9).item()       ,       [0.0, 1.0]       ,       msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""       ,       )




       @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.''')
       def      UpperCAmelCase__    ( self  : Union[str, Any]):
         pass







       @slow
       def      UpperCAmelCase__    ( self  : Dict):
         for model_name in DPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           lowerCAmelCase_    :  Optional[int]             =				DPTModel.from_pretrained(__snake_case)
           self.assertIsNotNone(__snake_case)





def     UpperCamelCase(						):
  lowerCAmelCase_    :  int             =				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				)
  return image





@require_torch
@require_vision
@slow
class        __snake_case		(  unittest.TestCase		):




       def      UpperCAmelCase__    ( self  : List[str]):
         lowerCAmelCase_    :  str             =				DPTImageProcessor.from_pretrained('''Intel/dpt-large''')
         lowerCAmelCase_    :  Tuple             =				DPTForDepthEstimation.from_pretrained('''Intel/dpt-large''').to(__snake_case)

         lowerCAmelCase_    :  Optional[int]             =				prepare_img()
         lowerCAmelCase_    :  Dict             =				image_processor(images=__snake_case       ,       return_tensors='''pt''').to(__snake_case)

         # forward pass
         with torch.no_grad():
           lowerCAmelCase_    :  Union[str, Any]             =				model(**__snake_case)
           lowerCAmelCase_    :  Union[str, Any]             =				outputs.predicted_depth

         # verify the predicted depth
         lowerCAmelCase_    :  int             =				torch.Size((1, 3_8_4, 3_8_4))
         self.assertEqual(predicted_depth.shape       ,       __snake_case)

         lowerCAmelCase_    :  Optional[Any]             =				torch.tensor(
             [[6.3199, 6.3629, 6.4148], [6.3850, 6.3615, 6.4166], [6.3519, 6.3176, 6.3575]]).to(__snake_case)

         self.assertTrue(torch.allclose(outputs.predicted_depth[0, :3, :3]       ,       __snake_case       ,       atol=1e-4))




       def      UpperCAmelCase__    ( self  : Dict):
         lowerCAmelCase_    :  List[Any]             =				DPTImageProcessor.from_pretrained('''Intel/dpt-large-ade''')
         lowerCAmelCase_    :  int             =				DPTForSemanticSegmentation.from_pretrained('''Intel/dpt-large-ade''').to(__snake_case)

         lowerCAmelCase_    :  Tuple             =				prepare_img()
         lowerCAmelCase_    :  Optional[int]             =				image_processor(images=__snake_case       ,       return_tensors='''pt''').to(__snake_case)

         # forward pass
         with torch.no_grad():
           lowerCAmelCase_    :  Optional[Any]             =				model(**__snake_case)

         # verify the logits
         lowerCAmelCase_    :  Tuple             =				torch.Size((1, 1_5_0, 4_8_0, 4_8_0))
         self.assertEqual(outputs.logits.shape       ,       __snake_case)

         lowerCAmelCase_    :  Tuple             =				torch.tensor(
             [[4.0480, 4.2420, 4.4360], [4.3124, 4.5693, 4.8261], [4.5768, 4.8965, 5.2163]]).to(__snake_case)

         self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]       ,       __snake_case       ,       atol=1e-4))







       def      UpperCAmelCase__    ( self  : Optional[Any]):
         lowerCAmelCase_    :  Dict             =				DPTImageProcessor.from_pretrained('''Intel/dpt-large-ade''')
         lowerCAmelCase_    :  Optional[int]             =				DPTForSemanticSegmentation.from_pretrained('''Intel/dpt-large-ade''').to(__snake_case)

         lowerCAmelCase_    :  Any             =				prepare_img()
         lowerCAmelCase_    :  List[str]             =				image_processor(images=__snake_case       ,       return_tensors='''pt''').to(__snake_case)

         # forward pass
         with torch.no_grad():
           lowerCAmelCase_    :  int             =				model(**__snake_case)

         lowerCAmelCase_    :  Optional[Any]             =				outputs.logits.detach().cpu()

         lowerCAmelCase_    :  Union[str, Any]             =				image_processor.post_process_semantic_segmentation(outputs=__snake_case       ,       target_sizes=[(5_0_0, 3_0_0)])
         lowerCAmelCase_    :  Dict             =				torch.Size((5_0_0, 3_0_0))
         self.assertEqual(segmentation[0].shape       ,       __snake_case)

         lowerCAmelCase_    :  Union[str, Any]             =				image_processor.post_process_semantic_segmentation(outputs=__snake_case)
         lowerCAmelCase_    :  str             =				torch.Size((4_8_0, 4_8_0))
         self.assertEqual(segmentation[0].shape       ,       __snake_case)










from __future__ import annotations

import unittest
import warnings

from transformers import AutoTokenizer, MarianConfig, MarianTokenizer, TranslationPipeline, is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow
from transformers.utils import cached_property

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


if is_tf_available():
						import tensorflow as tf

						from transformers import TFAutoModelForSeqaSeqLM, TFMarianModel, TFMarianMTModel



@require_tf
class        __snake_case		:
							_a       =				MarianConfig
							_a       =				{}
							_a       =				'''gelu'''




							def __init__( self  : Dict       ,       A_  : Optional[int]       ,       A_  : Any=1_3       ,       A_  : Any=7       ,       A_  : int=True       ,       A_  : int=False       ,       A_  : str=9_9       ,       A_  : Tuple=3_2       ,       A_  : Dict=2       ,       A_  : Union[str, Any]=4       ,       A_  : Optional[int]=3_7       ,       A_  : Any=0.1       ,       A_  : str=0.1       ,       A_  : Optional[int]=2_0       ,       A_  : Any=2       ,       A_  : Any=1       ,       A_  : Any=0       ,       ):
									lowerCAmelCase_    :  Any             =				parent
									lowerCAmelCase_    :  Dict             =				batch_size
									lowerCAmelCase_    :  Any             =				seq_length
									lowerCAmelCase_    :  Union[str, Any]             =				is_training
									lowerCAmelCase_    :  Any             =				use_labels
									lowerCAmelCase_    :  Tuple             =				vocab_size
									lowerCAmelCase_    :  Optional[int]             =				hidden_size
									lowerCAmelCase_    :  Optional[int]             =				num_hidden_layers
									lowerCAmelCase_    :  Union[str, Any]             =				num_attention_heads
									lowerCAmelCase_    :  List[str]             =				intermediate_size

									lowerCAmelCase_    :  Union[str, Any]             =				hidden_dropout_prob
									lowerCAmelCase_    :  Union[str, Any]             =				attention_probs_dropout_prob
									lowerCAmelCase_    :  Optional[Any]             =				max_position_embeddings
									lowerCAmelCase_    :  List[str]             =				eos_token_id
									lowerCAmelCase_    :  Optional[Any]             =				pad_token_id
									lowerCAmelCase_    :  Dict             =				bos_token_id




							def      UpperCAmelCase__    ( self  : Tuple):
									lowerCAmelCase_    :  str             =				ids_tensor([self.batch_size, self.seq_length - 1]       ,       self.vocab_size)
									lowerCAmelCase_    :  Optional[int]             =				tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size)       ,       1)
									lowerCAmelCase_    :  List[str]             =				tf.concat([input_ids, eos_tensor]       ,       axis=1)

									lowerCAmelCase_    :  Optional[Any]             =				ids_tensor([self.batch_size, self.seq_length]       ,       self.vocab_size)

									lowerCAmelCase_    :  Optional[int]             =				self.config_cls(
									    vocab_size=self.vocab_size       ,       d_model=self.hidden_size       ,       encoder_layers=self.num_hidden_layers       ,       decoder_layers=self.num_hidden_layers       ,       encoder_attention_heads=self.num_attention_heads       ,       decoder_attention_heads=self.num_attention_heads       ,       encoder_ffn_dim=self.intermediate_size       ,       decoder_ffn_dim=self.intermediate_size       ,       dropout=self.hidden_dropout_prob       ,       attention_dropout=self.attention_probs_dropout_prob       ,       max_position_embeddings=self.max_position_embeddings       ,       eos_token_ids=[2]       ,       bos_token_id=self.bos_token_id       ,       pad_token_id=self.pad_token_id       ,       decoder_start_token_id=self.pad_token_id       ,       **self.config_updates       ,       )
									lowerCAmelCase_    :  int             =				prepare_marian_inputs_dict(A_       ,       A_       ,       A_)
									return config, inputs_dict







							def      UpperCAmelCase__    ( self  : int       ,       A_  : int       ,       A_  : str):
									lowerCAmelCase_    :  Any             =				TFMarianModel(config=A_).get_decoder()
									lowerCAmelCase_    :  List[Any]             =				inputs_dict['''input_ids''']

									lowerCAmelCase_    :  str             =				input_ids[:1, :]
									lowerCAmelCase_    :  List[Any]             =				inputs_dict['''attention_mask'''][:1, :]
									lowerCAmelCase_    :  Dict             =				inputs_dict['''head_mask''']
									lowerCAmelCase_    :  Optional[int]             =				1

									# first forward pass
									lowerCAmelCase_    :  str             =				model(A_       ,       attention_mask=A_       ,       head_mask=A_       ,       use_cache=A_)

									lowerCAmelCase_      ,						lowerCAmelCase_    :  Any             =				outputs.to_tuple()

									# create hypothetical next token and extent to next_input_ids
									lowerCAmelCase_    :  int             =				ids_tensor((self.batch_size, 3)       ,       config.vocab_size)
									lowerCAmelCase_    :  str             =				tf.cast(ids_tensor((self.batch_size, 3)       ,       2)       ,       tf.inta)

									# append to next input_ids and
									lowerCAmelCase_    :  Optional[int]             =				tf.concat([input_ids, next_tokens]       ,       axis=-1)
									lowerCAmelCase_    :  int             =				tf.concat([attention_mask, next_attn_mask]       ,       axis=-1)

									lowerCAmelCase_    :  str             =				model(A_       ,       attention_mask=A_)[0]
									lowerCAmelCase_    :  List[str]             =				model(A_       ,       attention_mask=A_       ,       past_key_values=A_)[0]

									self.parent.assertEqual(next_tokens.shape[1]       ,       output_from_past.shape[1])

									# select random slice
									lowerCAmelCase_    :  Optional[Any]             =				int(ids_tensor((1,)       ,       output_from_past.shape[-1]))
									lowerCAmelCase_    :  Tuple             =				output_from_no_past[:, -3:, random_slice_idx]
									lowerCAmelCase_    :  Optional[Any]             =				output_from_past[:, :, random_slice_idx]

									# test that outputs are equal for slice
									tf.debugging.assert_near(A_       ,       A_       ,       rtol=1e-3)





def     UpperCamelCase(						__UpperCamelCase							:	List[str]  ,__UpperCamelCase							:	int  ,__UpperCamelCase							:	Dict  ,__UpperCamelCase							:	List[str]=None  ,__UpperCamelCase							:	Union[str, Any]=None  ,__UpperCamelCase							:	List[Any]=None  ,__UpperCamelCase							:	str=None  ,__UpperCamelCase							:	Optional[int]=None  ,):
		if attention_mask is None:
				lowerCAmelCase_    :  Optional[int]             =				tf.cast(tf.math.not_equal(__UpperCamelCase  ,config.pad_token_id				)  ,tf.inta				)
		if decoder_attention_mask is None:
				lowerCAmelCase_    :  List[str]             =				tf.concat(
				    [
				        tf.ones(decoder_input_ids[:, :1].shape  ,dtype=tf.inta				),
				        tf.cast(tf.math.not_equal(decoder_input_ids[:, 1:]  ,config.pad_token_id				)  ,tf.inta				),
				    ]  ,axis=-1  ,)
		if head_mask is None:
				lowerCAmelCase_    :  Union[str, Any]             =				tf.ones((config.encoder_layers, config.encoder_attention_heads)				)
		if decoder_head_mask is None:
				lowerCAmelCase_    :  List[str]             =				tf.ones((config.decoder_layers, config.decoder_attention_heads)				)
		if cross_attn_head_mask is None:
				lowerCAmelCase_    :  Union[str, Any]             =				tf.ones((config.decoder_layers, config.decoder_attention_heads)				)
		return {
		    "input_ids": input_ids,
		    "decoder_input_ids": decoder_input_ids,
		    "attention_mask": attention_mask,
		    "decoder_attention_mask": decoder_attention_mask,
		    "head_mask": head_mask,
		    "decoder_head_mask": decoder_head_mask,
		    "cross_attn_head_mask": cross_attn_head_mask,
		}



@require_tf
class        __snake_case		(  UpperCamelCase_		,UpperCamelCase_		,unittest.TestCase		):
							_a       =				(TFMarianMTModel, TFMarianModel) if is_tf_available() else ()
							_a       =				(TFMarianMTModel,) if is_tf_available() else ()
							_a       =				(
							    {
							        '''conversational''': TFMarianMTModel,
							        '''feature-extraction''': TFMarianModel,
							        '''summarization''': TFMarianMTModel,
							        '''text2text-generation''': TFMarianMTModel,
							        '''translation''': TFMarianMTModel,
							    }
							    if is_tf_available()
							    else {}
							)
							_a       =				True
							_a       =				False
							_a       =				False




							def      UpperCAmelCase__    ( self  : Union[str, Any]):
									lowerCAmelCase_    :  Optional[Any]             =				TFMarianModelTester(self)
									lowerCAmelCase_    :  List[str]             =				ConfigTester(self       ,       config_class=A_)




							def      UpperCAmelCase__    ( self  : List[Any]):
									self.config_tester.run_common_tests()







							def      UpperCAmelCase__    ( self  : List[Any]):
									lowerCAmelCase_    :  List[Any]             =				self.model_tester.prepare_config_and_inputs_for_common()
									self.model_tester.check_decoder_model_past_large_inputs(*A_)





@require_tf
class        __snake_case		(  unittest.TestCase		):
							_a       =				1_000  # show more chars for failing integration tests




							@classmethod
							def      UpperCAmelCase__    ( cls  : Optional[Any]):
									lowerCAmelCase_    :  Union[str, Any]             =				F"""Helsinki-NLP/opus-mt-{cls.src}-{cls.tgt}"""
									return cls




							@cached_property
							def      UpperCAmelCase__    ( self  : List[str]):
									return AutoTokenizer.from_pretrained(self.model_name)




							@property
							def      UpperCAmelCase__    ( self  : Dict):
									return self.tokenizer.eos_token_id




							@cached_property
							def      UpperCAmelCase__    ( self  : int):
									warnings.simplefilter('''error''')
									lowerCAmelCase_    :  TFMarianMTModel             =				TFAutoModelForSeqaSeqLM.from_pretrained(self.model_name)
									assert isinstance(A_       ,       A_)
									lowerCAmelCase_    :  int             =				model.config
									self.assertListEqual(c.bad_words_ids       ,       [[c.pad_token_id]])
									self.assertEqual(c.max_length       ,       5_1_2)
									self.assertEqual(c.decoder_start_token_id       ,       c.pad_token_id)
									return model




							def      UpperCAmelCase__    ( self  : Dict       ,       **A_  : Tuple):
									lowerCAmelCase_    :  Optional[int]             =				self.translate_src_text(**A_)
									self.assertListEqual(self.expected_text       ,       A_)







							def      UpperCAmelCase__    ( self  : Any       ,       **A_  : List[str]):
									lowerCAmelCase_    :  List[Any]             =				self.tokenizer(self.src_text       ,       **A_       ,       padding=A_       ,       return_tensors='''tf''')
									lowerCAmelCase_    :  List[str]             =				self.model.generate(
									    model_inputs.input_ids       ,       attention_mask=model_inputs.attention_mask       ,       num_beams=2       ,       max_length=1_2_8)
									lowerCAmelCase_    :  Any             =				self.tokenizer.batch_decode(generated_ids.numpy()       ,       skip_special_tokens=A_)
									return generated_words





@require_sentencepiece
@require_tokenizers
@require_tf
class        __snake_case		(  UpperCamelCase_		):
							_a       =				'''mt'''
							_a       =				'''en'''
							_a       =				['''Billi messu b\'mod ġentili, Ġesù fejjaq raġel li kien milqut bil - marda kerha tal - ġdiem.''']
							_a       =				['''Touching gently, Jesus healed a man who was affected by the sad disease of leprosy.''']




							@unittest.skip('''Skipping until #12647 is resolved.''')
							@slow
							def      UpperCAmelCase__    ( self  : Any):
									self._assert_generated_batch_equal_expected()





@require_sentencepiece
@require_tokenizers
@require_tf
class        __snake_case		(  UpperCamelCase_		):
							_a       =				'''en'''
							_a       =				'''zh'''
							_a       =				['''My name is Wolfgang and I live in Berlin''']
							_a       =				['''我叫沃尔夫冈 我住在柏林''']




							@unittest.skip('''Skipping until #12647 is resolved.''')
							@slow
							def      UpperCAmelCase__    ( self  : str):
									self._assert_generated_batch_equal_expected()





@require_sentencepiece
@require_tokenizers
@require_tf
class        __snake_case		(  UpperCamelCase_		):
							_a       =				'''en'''
							_a       =				'''ROMANCE'''
							_a       =				[
							    '''>>fr<< Don\'t spend so much time watching TV.''',
							    '''>>pt<< Your message has been sent.''',
							    '''>>es<< He\'s two years older than me.''',
							]
							_a       =				[
							    '''Ne passez pas autant de temps à regarder la télé.''',
							    '''A sua mensagem foi enviada.''',
							    '''Es dos años más viejo que yo.''',
							]




							@unittest.skip('''Skipping until #12647 is resolved.''')
							@slow
							def      UpperCAmelCase__    ( self  : Union[str, Any]):
									self._assert_generated_batch_equal_expected()







							@unittest.skip('''Skipping until #12647 is resolved.''')
							@slow
							def      UpperCAmelCase__    ( self  : Optional[int]):
									lowerCAmelCase_    :  Dict             =				TranslationPipeline(self.model       ,       self.tokenizer       ,       framework='''tf''')
									lowerCAmelCase_    :  Union[str, Any]             =				pipeline(self.src_text)
									self.assertEqual(self.expected_text       ,       [x['''translation_text'''] for x in output])





