



import argparse

# utilities to import the model weights and config file
import os
import pickle as pkl

# PyTorch + new model classes
import torch
from torch import nn

from transformers import AutoTokenizer, MegaConfig, MegaForMaskedLM


# import the EncoderLayer class used to pretrain
# !! NOTE !! this requires the version of fairseq that is built when you install the Mega source
try:
						from fairseq.modules.mega_layer import MegaEncoderLayer
except ImportError:
						raise ImportError('''You need to install the version of fairseq from the Mega repo!''')



class        __snake_case		(  nn.Module		):




							def __init__( self  : List[Any]       ,       A_  : Dict       ,       A_  : List[str]       ,       A_  : List[str]):
									super().__init__()
									lowerCAmelCase_    :  Optional[int]             =				mega_args
									lowerCAmelCase_    :  Tuple             =				nn.Embedding(A_       ,       self.mega_args.encoder_embed_dim)
									lowerCAmelCase_    :  Any             =				nn.ModuleList([MegaEncoderLayer(self.mega_args) for _ in range(A_)])
									lowerCAmelCase_    :  Optional[Any]             =				depth







							def      UpperCAmelCase__    ( self  : int       ,       A_  : Optional[int]       ,       A_  : Union[str, Any]       ,       A_  : Optional[Any]=True       ,       A_  : Any=0):

									# Mega expects embeddings to be (time, batch, embedding size), but
									# Hugging Face returns tokens as (batch, time)
									if batch_first:
											lowerCAmelCase_    :  List[Any]             =				input_ids.T

									# to make things more confusing, Mega expects the attention mask to
									# be (batch, time), but with values of 0 (normal token) and 1 (ignore token)
									# which is the opposite of what HF returns
									if ignore_mask_value == 0:
											lowerCAmelCase_    :  Dict             =				1 - attention_mask

									# get token embeddings from IDs
									lowerCAmelCase_    :  Tuple             =				self.embedding_layer(A_)

									# pass through the Mega layers
									# input is (time, batch, encoder dim) and output is the same
									for encoder in self.encoders:
											lowerCAmelCase_    :  List[Any]             =				encoder(A_       ,       A_)

									# return according to the shape specified
									if batch_first:
											# (T, B, H) --> (B, T, H)
											return torch.transpose(A_       ,       0       ,       1)
									else:
											return embeds





class        __snake_case		(  nn.Module		):




							def __init__( self  : Tuple       ,       A_  : Optional[Any]       ,       A_  : Dict       ,       A_  : Optional[Any]):
									super().__init__()
									lowerCAmelCase_    :  int             =				MegaLM(A_       ,       A_       ,       A_)
									lowerCAmelCase_    :  Union[str, Any]             =				nn.Linear(mega_args.encoder_embed_dim       ,       A_)
									lowerCAmelCase_    :  Any             =				nn.Dropout(p=0.1)







							def      UpperCAmelCase__    ( self  : List[Any]       ,       A_  : List[Any]       ,       A_  : Dict       ,       A_  : List[Any]=True       ,       A_  : int=0):
									lowerCAmelCase_    :  Optional[Any]             =				self.mega(A_       ,       A_       ,       A_       ,       A_)
									return self.mlm_head(self.dropout(A_))





def     UpperCamelCase(						__UpperCamelCase							:	List[str]  ,__UpperCamelCase							:	Any  ,__UpperCamelCase							:	str				):
		with open(os.path.join(__UpperCamelCase  ,'''model_args.pkl'''				)  ,'''rb'''				) as f:
				lowerCAmelCase_    :  Any             =				pkl.load(__UpperCamelCase				)

		# load the original encoder
		lowerCAmelCase_    :  int             =				OriginalMegaForMaskedLM(**__UpperCamelCase				).eval()

		# load its weights
		print(
		    '''Original Mega encoder:'''  ,original_mlm.mega.load_state_dict(
		        torch.load(os.path.join(__UpperCamelCase  ,'''encoder_weights.pt'''				)  ,map_location='''cpu'''				)				)  ,)
		print(
		    '''Original Mega MLM layer:'''  ,original_mlm.mlm_head.load_state_dict(
		        torch.load(os.path.join(__UpperCamelCase  ,'''mlm_head_weights.pt'''				)  ,map_location='''cpu'''				)				)  ,)

		# create a new config from the old one
		lowerCAmelCase_    :  Optional[Any]             =				MegaConfig(
		    num_hidden_layers=mega_original_args['''depth''']  ,vocab_size=mega_original_args['''vocab_size''']  ,hidden_size=mega_original_args['''mega_args'''].encoder_embed_dim  ,shared_representation_size=mega_original_args['''mega_args'''].encoder_z_dim  ,intermediate_size=mega_original_args['''mega_args'''].encoder_hidden_dim  ,ema_projection_size=mega_original_args['''mega_args'''].encoder_n_dim  ,dropout_prob=mega_original_args['''mega_args'''].dropout  ,attention_probs_dropout_prob=mega_original_args['''mega_args'''].attention_dropout  ,hidden_dropout_prob=mega_original_args['''mega_args'''].hidden_dropout  ,activation=mega_original_args['''mega_args'''].activation_fn  ,attention_activation=mega_original_args['''mega_args'''].attention_activation_fn  ,bidirectional=mega_original_args['''mega_args'''].bidirectional  ,use_chunking=mega_original_args['''mega_args'''].encoder_chunk_size > 0  ,chunk_size=mega_original_args['''mega_args'''].encoder_chunk_size  ,truncation=mega_original_args['''mega_args'''].truncation_length  ,normalization_type=mega_original_args['''mega_args'''].normalization_type  ,normalize_before_mega=__UpperCamelCase  ,norm_affine=__UpperCamelCase  ,use_feature_dropout=mega_original_args['''mega_args'''].feature_dropout  ,relative_positional_bias=mega_original_args['''mega_args'''].rel_pos_bias  ,max_positions=mega_original_args['''mega_args'''].max_source_positions  ,nffn_hidden_size=mega_original_args['''mega_args'''].encoder_ffn_embed_dim  ,normalize_before_ffn=mega_original_args['''mega_args'''].normalize_before  ,nffn_activation_dropout_prob=0.0  ,add_token_type_embeddings=__UpperCamelCase  ,add_lm_hidden_dense_layer=__UpperCamelCase  ,)

		lowerCAmelCase_    :  List[Any]             =				MegaForMaskedLM(__UpperCamelCase				).eval()

		# the originl checkpoint just uses nn.Embedding for the word embeddings
		# we use a wrapper module for embeddings to add support for positional embeddings
		lowerCAmelCase_    :  List[str]             =				original_mlm.mega.embedding_layer.weight

		# modify the state dictionary of the original checkpoint to account for naming issues in the Hugging Face
		# ecosystem -- any names containing "beta" or "gamma" aren't safe to use and are renamed upon _load_pretrained,
		# also renaming previously confusing parameter names
		lowerCAmelCase_    :  Any             =				original_mlm.mega.encoders.state_dict()
		lowerCAmelCase_    :  Dict             =				{}
		for module_name in original_state_dict.keys():
				lowerCAmelCase_    :  List[Any]             =				None
				# have to handle gamma, beta, and alpha differently due to their use
				# in multiple modules within the original repository;
				# beta is used in EMA, MovingAverageGatedAttention, and RotaryRelativePositionalBias, and must be renamed due to flax/tf weights
				# the EMA sublayer was renamed from "move" to "ema_gate" for readability, so that is also done here
				if "beta" in module_name:
						# EMA sub-layers were always called "move" in the original repo
						if "move.beta" in module_name:
								lowerCAmelCase_    :  Optional[Any]             =				module_name.replace('''move.beta'''  ,'''ema_gate.ema_expansion_matrix'''				)
						elif "mega_layer.beta" in module_name:
								lowerCAmelCase_    :  Union[str, Any]             =				module_name.replace('''beta'''  ,'''qk_bias'''				)
						else:
								lowerCAmelCase_    :  List[str]             =				module_name.replace('''beta'''  ,'''b_param'''				)
        # beta is used in EMA and MovingAverageGatedAttention, and must be renamed due to flax/tf weights
				elif "gamma" in module_name:
						if "move.gamma" in module_name:
								lowerCAmelCase_    :  List[Any]             =				module_name.replace('''move.gamma'''  ,'''ema_gate.kernel_projection_matrix'''				)
						elif "mega_layer.gamma" in module_name:
								lowerCAmelCase_    :  List[str]             =				module_name.replace('''gamma'''  ,'''qk_weight'''				)
						else:
								lowerCAmelCase_    :  int             =				module_name.replace('''gamma'''  ,'''g_param'''				)
        # alpha is used in EMA and positional bias; renaming to improve readability
				elif "move.alpha" in module_name:
						lowerCAmelCase_    :  Optional[int]             =				module_name.replace('''move.alpha'''  ,'''ema_gate.decay_factor'''				)
				# delta is only used in EMA; renaming to improve readability
				elif "move.delta" in module_name:
						lowerCAmelCase_    :  Tuple             =				module_name.replace('''move.delta'''  ,'''ema_gate.damping_factor'''				)
				# omega is only used in EMA; renaming to improve readability
				elif "omega" in module_name:
						lowerCAmelCase_    :  List[str]             =				module_name.replace('''move.omega'''  ,'''ema_gate.residual_weight'''				)

				if new_module_name:
						lowerCAmelCase_    :  int             =				new_module_name

		if len(__UpperCamelCase				) != 0:
				print(f"""Renaming these keys: {updated_keys.keys()}"""				)
		else:
				print('''No need to rename state dict entries'''				)
		for old, new in updated_keys.items():
				lowerCAmelCase_    :  Optional[Any]             =				original_state_dict.pop(__UpperCamelCase				)

		# now attempt to load the state dictionary with updated names
		# note that we now call it `mega.layers` instead of `mega.encoders` due to hugging face style
		print('''HF Mega encoder:'''  ,hf_mlm.mega.layers.load_state_dict(__UpperCamelCase				)				)

		# load the MLM head weights directly
		print(
		    '''HF Mega MLM layer:'''  ,hf_mlm.mlm_head.load_state_dict(
		        torch.load(os.path.join(__UpperCamelCase  ,'''mlm_head_weights.pt'''				)  ,map_location='''cpu'''				)				)  ,)

		# test on a randomly generated input sequence
		lowerCAmelCase_    :  Optional[int]             =				torch.randint(0  ,hf_config.vocab_size  ,size=(4, 256)				)
		lowerCAmelCase_    :  Optional[int]             =				torch.ones_like(__UpperCamelCase				)
		# mask a few tokens to make sure masking is applied appropriately :)
		lowerCAmelCase_    :  List[str]             =				0

		# run forward passes
		lowerCAmelCase_    :  List[str]             =				original_mlm(__UpperCamelCase  ,__UpperCamelCase  ,batch_first=__UpperCamelCase  ,ignore_mask_value=0				)
		lowerCAmelCase_    :  Any             =				hf_mlm(__UpperCamelCase  ,__UpperCamelCase				)[0]

		# print shapes and diff
		print(f"""original output {original_output.shape}"""				)
		print(f"""hf output {hf_output.shape}"""				)
		print(f"""max diff: {(original_output - hf_output).max()}"""				)  # 0.0
		lowerCAmelCase_    :  List[Any]             =				torch.allclose(__UpperCamelCase  ,__UpperCamelCase  ,atol=1e-3				)

		if success:
				print('''Yay!'''				)
				hf_mlm.save_pretrained(__UpperCamelCase				)
		else:
				raise RuntimeError(f"""Something's broken :(\nOriginal:\n{original_output}\n\nHF\n{hf_output}\n{hf_mlm}"""				)

		if includes_tokenizer:
				print('''Transferring tokenizer'''				)
				lowerCAmelCase_    :  List[str]             =				AutoTokenizer.from_pretrained(__UpperCamelCase				)
				tokenizer.save_pretrained(__UpperCamelCase				)


if __name__ == "__main__":
						A__						:						Union[str, Any]          =      argparse.ArgumentParser()

						parser.add_argument(
						    '''--pretrained_checkpoint_path''',
						    default=None,
						    type=str,
						    required=True,
						    help='''Point to the directory containing your model weights using the official Mega repo''',
						)

						parser.add_argument(
						    '''--output_path''', default=None, type=str, required=True, help='''Location to save the Hugging Face version'''
						)

						parser.add_argument(
						    '''--includes_tokenizer''',
						    action='''store_true''',
						    help='''Use this flag if there is a Hugging Face tokenizer in the original checkpoint repo''',
						)

						A__						:						Optional[int]          =      parser.parse_args()

						convert_checkpoint_to_huggingface(args.pretrained_checkpoint_path, args.output_path, args.includes_tokenizer)










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])





