code: 
  
  
  
  
  
  
  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 							_A :
      """simple docstring"""
  
      lowerCamelCase  :       List[Any]   =   MarianConfig
      lowerCamelCase  :       Optional[Any]   =   {}
      lowerCamelCase  :       Union[str, Any]   =   'gelu'
  
  
  
      def __init__(							self			:    List[Any]   ,    __SCREAMING_SNAKE_CASE			:    Tuple   ,    __SCREAMING_SNAKE_CASE			:    Any=13   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]=7   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]=True   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]=False   ,    __SCREAMING_SNAKE_CASE			:    int=99   ,    __SCREAMING_SNAKE_CASE			:    int=32   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]=2   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]=4   ,    __SCREAMING_SNAKE_CASE			:    int=37   ,    __SCREAMING_SNAKE_CASE			:    Dict=0.1   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]=0.1   ,    __SCREAMING_SNAKE_CASE			:    List[str]=20   ,    __SCREAMING_SNAKE_CASE			:    str=2   ,    __SCREAMING_SNAKE_CASE			:    List[str]=1   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]=0   ,    )			->       Optional[int]:
             __UpperCAmelCase    							=parent
             __UpperCAmelCase    							=batch_size
             __UpperCAmelCase    							=seq_length
             __UpperCAmelCase    							=is_training
             __UpperCAmelCase    							=use_labels
             __UpperCAmelCase    							=vocab_size
             __UpperCAmelCase    							=hidden_size
             __UpperCAmelCase    							=num_hidden_layers
             __UpperCAmelCase    							=num_attention_heads
             __UpperCAmelCase    							=intermediate_size
  
             __UpperCAmelCase    							=hidden_dropout_prob
             __UpperCAmelCase    							=attention_probs_dropout_prob
             __UpperCAmelCase    							=max_position_embeddings
             __UpperCAmelCase    							=eos_token_id
             __UpperCAmelCase    							=pad_token_id
             __UpperCAmelCase    							=bos_token_id
  
  
  
      def _a       (							self			:    Any			)			->       int:
             __UpperCAmelCase    							=ids_tensor([self.batch_size, self.seq_length - 1]   ,    self.vocab_size			)
             __UpperCAmelCase    							=tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size			)   ,    1			)
             __UpperCAmelCase    							=tf.concat([input_ids, eos_tensor]   ,    axis=1			)
  
             __UpperCAmelCase    							=ids_tensor([self.batch_size, self.seq_length]   ,    self.vocab_size			)
  
             __UpperCAmelCase    							=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   ,    )
             __UpperCAmelCase    							=prepare_marian_inputs_dict(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
             return config, inputs_dict
  
  
  
      def _a       (							self			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    str   ,    __SCREAMING_SNAKE_CASE			:    int			)			->       Tuple:
             __UpperCAmelCase    							=TFMarianModel(config=__SCREAMING_SNAKE_CASE			).get_decoder()
             __UpperCAmelCase    							=inputs_dict["""input_ids"""]
  
             __UpperCAmelCase    							=input_ids[:1, :]
             __UpperCAmelCase    							=inputs_dict["""attention_mask"""][:1, :]
             __UpperCAmelCase    							=inputs_dict["""head_mask"""]
             __UpperCAmelCase    							=1
  
             # first forward pass
             __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE   ,    attention_mask=__SCREAMING_SNAKE_CASE   ,    head_mask=__SCREAMING_SNAKE_CASE   ,    use_cache=__SCREAMING_SNAKE_CASE			)
  
             __UpperCAmelCase							,   __UpperCAmelCase    							=outputs.to_tuple()
  
             # create hypothetical next token and extent to next_input_ids
             __UpperCAmelCase    							=ids_tensor((self.batch_size, 3)   ,    config.vocab_size			)
             __UpperCAmelCase    							=tf.cast(ids_tensor((self.batch_size, 3)   ,    2			)   ,    tf.inta			)
  
             # append to next input_ids and
             __UpperCAmelCase    							=tf.concat([input_ids, next_tokens]   ,    axis=-1			)
             __UpperCAmelCase    							=tf.concat([attention_mask, next_attn_mask]   ,    axis=-1			)
  
             __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE   ,    attention_mask=__SCREAMING_SNAKE_CASE			)[0]
             __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE   ,    attention_mask=__SCREAMING_SNAKE_CASE   ,    past_key_values=__SCREAMING_SNAKE_CASE			)[0]
  
             self.parent.assertEqual(next_tokens.shape[1]   ,    output_from_past.shape[1]			)
  
             # select random slice
             __UpperCAmelCase    							=int(ids_tensor((1,)   ,    output_from_past.shape[-1]			)			)
             __UpperCAmelCase    							=output_from_no_past[:, -3:, random_slice_idx]
             __UpperCAmelCase    							=output_from_past[:, :, random_slice_idx]
  
             # test that outputs are equal for slice
             tf.debugging.assert_near(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE   ,    rtol=1e-3			)
  
  
  
  
  
  
  
  def 			lowercase__  (				A_:	Any     ,			A_:	Dict     ,			A_:	List[str]     ,			A_:	Union[str, Any]=None     ,			A_:	Tuple=None     ,			A_:	Union[str, Any]=None     ,			A_:	Tuple=None     ,			A_:	Dict=None     ,			)  ->							Optional[int]:
  
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
         if attention_mask is None:
                __UpperCAmelCase    							=tf.cast(tf.math.not_equal(A_     ,			config.pad_token_id		)     ,			tf.inta		)
         if decoder_attention_mask is None:
                __UpperCAmelCase    							=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:
                __UpperCAmelCase    							=tf.ones((config.encoder_layers, config.encoder_attention_heads)		)
         if decoder_head_mask is None:
                __UpperCAmelCase    							=tf.ones((config.decoder_layers, config.decoder_attention_heads)		)
         if cross_attn_head_mask is None:
                __UpperCAmelCase    							=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 							_A (    UpperCamelCase				,				UpperCamelCase				,				unittest.TestCase							):
      """simple docstring"""
  
      lowerCamelCase  :       Union[str, Any]   =   (TFMarianMTModel, TFMarianModel) if is_tf_available() else ()
      lowerCamelCase  :       Optional[int]   =   (TFMarianMTModel,) if is_tf_available() else ()
      lowerCamelCase  :       Optional[Any]   =   (
          {
              'conversational': TFMarianMTModel,
              'feature-extraction': TFMarianModel,
              'summarization': TFMarianMTModel,
              'text2text-generation': TFMarianMTModel,
              'translation': TFMarianMTModel,
          }
          if is_tf_available()
          else {}
      )
      lowerCamelCase  :       Tuple   =   True
      lowerCamelCase  :       int   =   False
      lowerCamelCase  :       str   =   False
  
  
  
      def _a       (							self			:    str			)			->       Dict:
             __UpperCAmelCase    							=TFMarianModelTester(self			)
             __UpperCAmelCase    							=ConfigTester(self   ,    config_class=__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Optional[Any]			)			->       List[str]:
             self.config_tester.run_common_tests()
  
  
  
      def _a       (							self			:    Dict			)			->       Any:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs_for_common()
             self.model_tester.check_decoder_model_past_large_inputs(*__SCREAMING_SNAKE_CASE			)
  
  
  
  
  @require_tf
  class 							_A (    unittest.TestCase							):
      """simple docstring"""
  
      lowerCamelCase  :       Dict   =   1_000  # show more chars for failing integration tests
  
  
  
      @classmethod
      def _a       (							cls			:    Dict			)			->       None:
             __UpperCAmelCase    							=f'''Helsinki-NLP/opus-mt-{cls.src}-{cls.tgt}'''
             return cls
  
  
  
      @cached_property
      def _a       (							self			:    Tuple			)			->       MarianTokenizer:
             return AutoTokenizer.from_pretrained(self.model_name			)
  
  
  
      @property
      def _a       (							self			:    Dict			)			->       int:
             return self.tokenizer.eos_token_id
  
  
  
      @cached_property
      def _a       (							self			:    Any			)			->       List[str]:
             warnings.simplefilter("""error"""			)
             __UpperCAmelCase    							=TFAutoModelForSeqaSeqLM.from_pretrained(self.model_name			)
             assert isinstance(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
             __UpperCAmelCase    							=model.config
             self.assertListEqual(c.bad_words_ids   ,    [[c.pad_token_id]]			)
             self.assertEqual(c.max_length   ,    512			)
             self.assertEqual(c.decoder_start_token_id   ,    c.pad_token_id			)
             return model
  
  
  
      def _a       (							self			:    Union[str, Any]   ,    **__SCREAMING_SNAKE_CASE			:    List[Any]			)			->       Union[str, Any]:
             __UpperCAmelCase    							=self.translate_src_text(**__SCREAMING_SNAKE_CASE			)
             self.assertListEqual(self.expected_text   ,    __SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    str   ,    **__SCREAMING_SNAKE_CASE			:    List[str]			)			->       List[Any]:
             __UpperCAmelCase    							=self.tokenizer(self.src_text   ,    **__SCREAMING_SNAKE_CASE   ,    padding=__SCREAMING_SNAKE_CASE   ,    return_tensors="""tf"""			)
             __UpperCAmelCase    							=self.model.generate(
                 model_inputs.input_ids   ,    attention_mask=model_inputs.attention_mask   ,    num_beams=2   ,    max_length=128			)
             __UpperCAmelCase    							=self.tokenizer.batch_decode(generated_ids.numpy()   ,    skip_special_tokens=__SCREAMING_SNAKE_CASE			)
             return generated_words
  
  
  
  
  @require_sentencepiece
  @require_tokenizers
  @require_tf
  class 							_A (    UpperCamelCase							):
      """simple docstring"""
  
      lowerCamelCase  :       int   =   'mt'
      lowerCamelCase  :       Optional[int]   =   'en'
      lowerCamelCase  :       Optional[Any]   =   ['Billi messu b\'mod ġentili, Ġesù fejjaq raġel li kien milqut bil - marda kerha tal - ġdiem.']
      lowerCamelCase  :       Dict   =   ['Touching gently, Jesus healed a man who was affected by the sad disease of leprosy.']
  
  
  
      @unittest.skip("""Skipping until #12647 is resolved."""			)
      @slow
      def _a       (							self			:    Dict			)			->       int:
             self._assert_generated_batch_equal_expected()
  
  
  
  
  @require_sentencepiece
  @require_tokenizers
  @require_tf
  class 							_A (    UpperCamelCase							):
      """simple docstring"""
  
      lowerCamelCase  :       Optional[Any]   =   'en'
      lowerCamelCase  :       Dict   =   'zh'
      lowerCamelCase  :       Optional[Any]   =   ['My name is Wolfgang and I live in Berlin']
      lowerCamelCase  :       Dict   =   ['我叫沃尔夫冈 我住在柏林']
  
  
  
      @unittest.skip("""Skipping until #12647 is resolved."""			)
      @slow
      def _a       (							self			:    Optional[int]			)			->       int:
             self._assert_generated_batch_equal_expected()
  
  
  
  
  @require_sentencepiece
  @require_tokenizers
  @require_tf
  class 							_A (    UpperCamelCase							):
      """simple docstring"""
  
      lowerCamelCase  :       Dict   =   'en'
      lowerCamelCase  :       Any   =   'ROMANCE'
      lowerCamelCase  :       Union[str, Any]   =   [
          '>>fr<< Don\'t spend so much time watching TV.',
          '>>pt<< Your message has been sent.',
          '>>es<< He\'s two years older than me.',
      ]
      lowerCamelCase  :       int   =   [
          '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 _a       (							self			:    Optional[int]			)			->       List[Any]:
             self._assert_generated_batch_equal_expected()
  
  
  
      @unittest.skip("""Skipping until #12647 is resolved."""			)
      @slow
      def _a       (							self			:    str			)			->       Any:
             __UpperCAmelCase    							=TranslationPipeline(self.model   ,    self.tokenizer   ,    framework="""tf"""			)
             __UpperCAmelCase    							=pipeline(self.src_text			)
             self.assertEqual(self.expected_text   ,    [x["""translation_text"""] for x in output]			)
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  __A  							=  [0.485, 0.456, 0.406]
  __A  							=  [0.229, 0.224, 0.225]
  __A  							=  [0.5, 0.5, 0.5]
  __A  							=  [0.5, 0.5, 0.5]
  __A  							=  [0.4814_5466, 0.457_8275, 0.4082_1073]
  __A  							=  [0.2686_2954, 0.2613_0258, 0.2757_7711]
  
  
  
  
  