


from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
 import tensorflow as tf

 from transformers import (
     TF_MODEL_FOR_PRETRAINING_MAPPING,
     TFMobileBertForMaskedLM,
     TFMobileBertForMultipleChoice,
     TFMobileBertForNextSentencePrediction,
     TFMobileBertForPreTraining,
     TFMobileBertForQuestionAnswering,
     TFMobileBertForSequenceClassification,
     TFMobileBertForTokenClassification,
     TFMobileBertModel,
 )


@require_tf
class 		_SCREAMING_SNAKE_CASE     (						A							,	A							,	unittest.TestCase     ):
     __SCREAMING_SNAKE_CASE     					=    (
         (
             TFMobileBertModel,
             TFMobileBertForMaskedLM,
             TFMobileBertForNextSentencePrediction,
             TFMobileBertForPreTraining,
             TFMobileBertForQuestionAnswering,
             TFMobileBertForSequenceClassification,
             TFMobileBertForTokenClassification,
             TFMobileBertForMultipleChoice,
         )
         if is_tf_available()
         else ()
     )
     __SCREAMING_SNAKE_CASE     					=    (
         {
             '''feature-extraction''': TFMobileBertModel,
             '''fill-mask''': TFMobileBertForMaskedLM,
             '''question-answering''': TFMobileBertForQuestionAnswering,
             '''text-classification''': TFMobileBertForSequenceClassification,
             '''token-classification''': TFMobileBertForTokenClassification,
             '''zero-shot''': TFMobileBertForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     __SCREAMING_SNAKE_CASE     					=    False
     __SCREAMING_SNAKE_CASE     					=    False


     def        __snake_case(  self							,					A_							,					A_							,					A_=False    ):
       _UpperCAmelCase		:							Tuple							=     super()._prepare_for_class(A_							,					A_							,					return_labels=A_    )

       if return_labels:
         if model_class in get_values(A_    ):
           _UpperCAmelCase		:							Tuple							=     tf.zeros(self.model_tester.batch_size							,					dtype=tf.intaa    )

       return inputs_dict


     class 		_SCREAMING_SNAKE_CASE     (						A     ):


          def __init__(  self							,					A_							,					A_=13							,					A_=7							,					A_=True							,					A_=True							,					A_=True							,					A_=True							,					A_=99							,					A_=32							,					A_=32							,					A_=2							,					A_=4							,					A_=37							,					A_="gelu"							,					A_=0.1							,					A_=0.1							,					A_=5_12							,					A_=16							,					A_=2							,					A_=0.0_2							,					A_=3							,					A_=4							,					A_=None							,					):
            _UpperCAmelCase		:							str							=     parent
            _UpperCAmelCase		:							int							=     batch_size
            _UpperCAmelCase		:							int							=     seq_length
            _UpperCAmelCase		:							Optional[Any]							=     is_training
            _UpperCAmelCase		:							Tuple							=     use_input_mask
            _UpperCAmelCase		:							Optional[Any]							=     use_token_type_ids
            _UpperCAmelCase		:							Any							=     use_labels
            _UpperCAmelCase		:							Any							=     vocab_size
            _UpperCAmelCase		:							List[Any]							=     hidden_size
            _UpperCAmelCase		:							Dict							=     num_hidden_layers
            _UpperCAmelCase		:							Union[str, Any]							=     num_attention_heads
            _UpperCAmelCase		:							Tuple							=     intermediate_size
            _UpperCAmelCase		:							Tuple							=     hidden_act
            _UpperCAmelCase		:							List[str]							=     hidden_dropout_prob
            _UpperCAmelCase		:							Union[str, Any]							=     attention_probs_dropout_prob
            _UpperCAmelCase		:							Tuple							=     max_position_embeddings
            _UpperCAmelCase		:							int							=     type_vocab_size
            _UpperCAmelCase		:							Union[str, Any]							=     type_sequence_label_size
            _UpperCAmelCase		:							Optional[Any]							=     initializer_range
            _UpperCAmelCase		:							Dict							=     num_labels
            _UpperCAmelCase		:							List[Any]							=     num_choices
            _UpperCAmelCase		:							Optional[int]							=     scope
            _UpperCAmelCase		:							List[Any]							=     embedding_size


          def        __snake_case(  self    ):
            _UpperCAmelCase		:							str							=     ids_tensor([self.batch_size, self.seq_length]							,					self.vocab_size    )

            _UpperCAmelCase		:							Dict							=     None
            if self.use_input_mask:
              _UpperCAmelCase		:							int							=     random_attention_mask([self.batch_size, self.seq_length]    )

            _UpperCAmelCase		:							str							=     None
            if self.use_token_type_ids:
              _UpperCAmelCase		:							int							=     ids_tensor([self.batch_size, self.seq_length]							,					self.type_vocab_size    )

            _UpperCAmelCase		:							Optional[int]							=     None
            _UpperCAmelCase		:							Optional[int]							=     None
            _UpperCAmelCase		:							Any							=     None
            if self.use_labels:
              _UpperCAmelCase		:							Optional[Any]							=     ids_tensor([self.batch_size]							,					self.type_sequence_label_size    )
              _UpperCAmelCase		:							Any							=     ids_tensor([self.batch_size, self.seq_length]							,					self.num_labels    )
              _UpperCAmelCase		:							Dict							=     ids_tensor([self.batch_size]							,					self.num_choices    )

            _UpperCAmelCase		:							Optional[Any]							=     MobileBertConfig(
                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							,					embedding_size=self.embedding_size							,					)

            return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


          def        __snake_case(  self							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_    ):
            _UpperCAmelCase		:							Tuple							=     TFMobileBertModel(config=A_    )
            _UpperCAmelCase		:							List[Any]							=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            _UpperCAmelCase		:							Optional[Any]							=     model(A_    )

            _UpperCAmelCase		:							Optional[int]							=     [input_ids, input_mask]
            _UpperCAmelCase		:							List[str]							=     model(A_    )

            _UpperCAmelCase		:							str							=     model(A_    )

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


          def        __snake_case(  self							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_    ):
            _UpperCAmelCase		:							Optional[int]							=     TFMobileBertForMaskedLM(config=A_    )
            _UpperCAmelCase		:							Tuple							=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            _UpperCAmelCase		:							List[Any]							=     model(A_    )
            self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.vocab_size)    )


          def        __snake_case(  self							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_    ):
            _UpperCAmelCase		:							Any							=     TFMobileBertForNextSentencePrediction(config=A_    )
            _UpperCAmelCase		:							List[Any]							=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            _UpperCAmelCase		:							List[str]							=     model(A_    )
            self.parent.assertEqual(result.logits.shape							,					(self.batch_size, 2)    )


          def        __snake_case(  self							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_    ):
            _UpperCAmelCase		:							Union[str, Any]							=     TFMobileBertForPreTraining(config=A_    )
            _UpperCAmelCase		:							int							=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            _UpperCAmelCase		:							Dict							=     model(A_    )
            self.parent.assertEqual(
                result.prediction_logits.shape							,					(self.batch_size, self.seq_length, self.vocab_size)    )
            self.parent.assertEqual(result.seq_relationship_logits.shape							,					(self.batch_size, 2)    )


          def        __snake_case(  self							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_    ):
            _UpperCAmelCase		:							Optional[int]							=     self.num_labels
            _UpperCAmelCase		:							Union[str, Any]							=     TFMobileBertForSequenceClassification(config=A_    )
            _UpperCAmelCase		:							Dict							=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            _UpperCAmelCase		:							List[Any]							=     model(A_    )
            self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_labels)    )


          def        __snake_case(  self							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_    ):
            _UpperCAmelCase		:							int							=     self.num_choices
            _UpperCAmelCase		:							Dict							=     TFMobileBertForMultipleChoice(config=A_    )
            _UpperCAmelCase		:							List[str]							=     tf.tile(tf.expand_dims(A_							,					1    )							,					(1, self.num_choices, 1)    )
            _UpperCAmelCase		:							List[str]							=     tf.tile(tf.expand_dims(A_							,					1    )							,					(1, self.num_choices, 1)    )
            _UpperCAmelCase		:							int							=     tf.tile(tf.expand_dims(A_							,					1    )							,					(1, self.num_choices, 1)    )
            _UpperCAmelCase		:							Any							=     {
                """input_ids""": multiple_choice_inputs_ids,
                """attention_mask""": multiple_choice_input_mask,
                """token_type_ids""": multiple_choice_token_type_ids,
            }
            _UpperCAmelCase		:							List[str]							=     model(A_    )
            self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_choices)    )


          def        __snake_case(  self							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_    ):
            _UpperCAmelCase		:							Union[str, Any]							=     self.num_labels
            _UpperCAmelCase		:							int							=     TFMobileBertForTokenClassification(config=A_    )
            _UpperCAmelCase		:							List[Any]							=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            _UpperCAmelCase		:							str							=     model(A_    )
            self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.num_labels)    )


          def        __snake_case(  self							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_							,					A_    ):
            _UpperCAmelCase		:							Union[str, Any]							=     TFMobileBertForQuestionAnswering(config=A_    )
            _UpperCAmelCase		:							Tuple							=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            _UpperCAmelCase		:							Optional[int]							=     model(A_    )
            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        __snake_case(  self    ):
            _UpperCAmelCase		:							Dict							=     self.prepare_config_and_inputs()
            (
                (
                _UpperCAmelCase
            ),(
                _UpperCAmelCase
            ),(
                _UpperCAmelCase
            ),(
                _UpperCAmelCase
            ),(
                _UpperCAmelCase
            ),(
                _UpperCAmelCase
            ),(
                _UpperCAmelCase
            ),
            )		:							Tuple							=     config_and_inputs
            _UpperCAmelCase		:							Union[str, Any]							=     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
            return config, inputs_dict


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Tuple							=     TFMobileBertModelTest.TFMobileBertModelTester(self    )
       _UpperCAmelCase		:							int							=     ConfigTester(self							,					config_class=A_							,					hidden_size=37    )


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


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Any							=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_model(*A_    )


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Tuple							=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_masked_lm(*A_    )


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Any							=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_multiple_choice(*A_    )


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Dict							=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*A_    )


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							List[str]							=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_pretraining(*A_    )


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Dict							=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_question_answering(*A_    )


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							List[Any]							=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_sequence_classification(*A_    )


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							List[Any]							=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_token_classification(*A_    )




     @slow
     def        __snake_case(  self    ):
       # for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       for model_name in ["google/mobilebert-uncased"]:
         _UpperCAmelCase		:							Tuple							=     TFMobileBertModel.from_pretrained(A_    )
         self.assertIsNotNone(A_    )


@require_tf
class 		_SCREAMING_SNAKE_CASE     (						unittest.TestCase     ):


     @slow
     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Dict							=     TFMobileBertForPreTraining.from_pretrained("""google/mobilebert-uncased"""    )
       _UpperCAmelCase		:							str							=     tf.constant([[0, 1, 2, 3, 4, 5]]    )
       _UpperCAmelCase		:							List[str]							=     model(A_    )[0]

       _UpperCAmelCase		:							Tuple							=     [1, 6, 3_05_22]
       self.assertEqual(output.shape							,					A_    )

       _UpperCAmelCase		:							Union[str, Any]							=     tf.constant(
           [
               [
                   [-4.5_9_1_9_5_4_7, -9.2_4_8_2_9_5, -9.6_4_5_2_5_6],
                   [-6.7_3_0_6_1_7_5, -6.4_4_0_2_8_4, -6.6_0_5_2_8_3_7],
                   [-7.2_7_4_3_5_0_6, -6.7_8_4_7_9_1_5, -6.0_2_4_6_7_3],
               ]
           ]    )
       tf.debugging.assert_near(output[:, :3, :3]							,					A_							,					atol=1e-4    )









from __future__ import annotations

import unittest

from transformers import BlenderbotConfig, BlenderbotTokenizer, is_tf_available
from transformers.testing_utils import 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, TFBlenderbotForConditionalGeneration, TFBlenderbotModel


@require_tf
class 		_SCREAMING_SNAKE_CASE     :
     __SCREAMING_SNAKE_CASE     					=    BlenderbotConfig
     __SCREAMING_SNAKE_CASE     					=    {}
     __SCREAMING_SNAKE_CASE     					=    '''gelu'''


     def __init__(  self							,					A_							,					A_=13							,					A_=7							,					A_=True							,					A_=False							,					A_=99							,					A_=32							,					A_=2							,					A_=4							,					A_=37							,					A_=0.1							,					A_=0.1							,					A_=20							,					A_=2							,					A_=1							,					A_=0							,					):
       _UpperCAmelCase		:							List[str]							=     parent
       _UpperCAmelCase		:							Union[str, Any]							=     batch_size
       _UpperCAmelCase		:							Optional[Any]							=     seq_length
       _UpperCAmelCase		:							List[Any]							=     is_training
       _UpperCAmelCase		:							Union[str, Any]							=     use_labels
       _UpperCAmelCase		:							Tuple							=     vocab_size
       _UpperCAmelCase		:							Optional[int]							=     hidden_size
       _UpperCAmelCase		:							int							=     num_hidden_layers
       _UpperCAmelCase		:							List[Any]							=     num_attention_heads
       _UpperCAmelCase		:							List[Any]							=     intermediate_size

       _UpperCAmelCase		:							Union[str, Any]							=     hidden_dropout_prob
       _UpperCAmelCase		:							str							=     attention_probs_dropout_prob
       _UpperCAmelCase		:							Optional[int]							=     max_position_embeddings
       _UpperCAmelCase		:							Optional[Any]							=     eos_token_id
       _UpperCAmelCase		:							Optional[Any]							=     pad_token_id
       _UpperCAmelCase		:							Tuple							=     bos_token_id


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

       _UpperCAmelCase		:							int							=     ids_tensor([self.batch_size, self.seq_length]							,					self.vocab_size    )

       _UpperCAmelCase		:							List[Any]							=     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		:							Dict							=     prepare_blenderbot_inputs_dict(A_							,					A_							,					A_    )
       return config, inputs_dict




     def        __snake_case(  self							,					A_							,					A_    ):
       _UpperCAmelCase		:							Union[str, Any]							=     TFBlenderbotModel(config=A_    ).get_decoder()
       _UpperCAmelCase		:							List[Any]							=     inputs_dict["""input_ids"""]

       _UpperCAmelCase		:							Any							=     input_ids[:1, :]
       _UpperCAmelCase		:							List[str]							=     inputs_dict["""attention_mask"""][:1, :]
       _UpperCAmelCase		:							Tuple							=     inputs_dict["""head_mask"""]
       _UpperCAmelCase		:							Union[str, Any]							=     1

       # first forward pass
       _UpperCAmelCase		:							List[str]							=     model(A_							,					attention_mask=A_							,					head_mask=A_							,					use_cache=A_    )

       _UpperCAmelCase,_UpperCAmelCase		:							List[str]							=     outputs.to_tuple()

       # create hypothetical next token and extent to next_input_ids
       _UpperCAmelCase		:							List[Any]							=     ids_tensor((self.batch_size, 3)							,					config.vocab_size    )
       _UpperCAmelCase		:							List[str]							=     tf.cast(ids_tensor((self.batch_size, 3)							,					2    )							,					tf.inta    )

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

       _UpperCAmelCase		:							Tuple							=     model(A_							,					attention_mask=A_    )[0]
       _UpperCAmelCase		:							int							=     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
       _UpperCAmelCase		:							Tuple							=     int(ids_tensor((1,)							,					output_from_past.shape[-1]    )    )
       _UpperCAmelCase		:							str							=     output_from_no_past[:, -3:, random_slice_idx]
       _UpperCAmelCase		:							str							=     output_from_past[:, :, random_slice_idx]

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




def    a__    (		snake_case__					:							Optional[Any]						,   snake_case__					:							str						,   snake_case__					:							Dict						,   snake_case__					:							str=None						,   snake_case__					:							Optional[int]=None						,   snake_case__					:							str=None						,   snake_case__					:							List[str]=None						,   snake_case__					:							List[str]=None						,   ):
  if attention_mask is None:
    _UpperCAmelCase		:							List[Any]							=     tf.cast(tf.math.not_equal(snake_case__						,   config.pad_token_id     )						,   tf.inta     )
  if decoder_attention_mask is None:
    _UpperCAmelCase		:							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:
    _UpperCAmelCase		:							List[str]							=     tf.ones((config.encoder_layers, config.encoder_attention_heads)     )
  if decoder_head_mask is None:
    _UpperCAmelCase		:							Tuple							=     tf.ones((config.decoder_layers, config.decoder_attention_heads)     )
  if cross_attn_head_mask is None:
    _UpperCAmelCase		:							Dict							=     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 		_SCREAMING_SNAKE_CASE     (						A							,	A							,	unittest.TestCase     ):
     __SCREAMING_SNAKE_CASE     					=    (TFBlenderbotForConditionalGeneration, TFBlenderbotModel) if is_tf_available() else ()
     __SCREAMING_SNAKE_CASE     					=    (TFBlenderbotForConditionalGeneration,) if is_tf_available() else ()
     __SCREAMING_SNAKE_CASE     					=    (
         {
             '''conversational''': TFBlenderbotForConditionalGeneration,
             '''feature-extraction''': TFBlenderbotModel,
             '''summarization''': TFBlenderbotForConditionalGeneration,
             '''text2text-generation''': TFBlenderbotForConditionalGeneration,
             '''translation''': TFBlenderbotForConditionalGeneration,
         }
         if is_tf_available()
         else {}
     )
     __SCREAMING_SNAKE_CASE     					=    True
     __SCREAMING_SNAKE_CASE     					=    False
     __SCREAMING_SNAKE_CASE     					=    False


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Union[str, Any]							=     TFBlenderbotModelTester(self    )
       _UpperCAmelCase		:							Any							=     ConfigTester(self							,					config_class=A_    )


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




     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Tuple							=     self.model_tester.prepare_config_and_inputs_for_common()
       self.model_tester.check_decoder_model_past_large_inputs(*A_    )


@require_tokenizers
@require_tf
class 		_SCREAMING_SNAKE_CASE     (						unittest.TestCase     ):
     __SCREAMING_SNAKE_CASE     					=    ['''My friends are cool but they eat too many carbs.''']
     __SCREAMING_SNAKE_CASE     					=    '''facebook/blenderbot-400M-distill'''


     @cached_property
     def        __snake_case(  self    ):
       return BlenderbotTokenizer.from_pretrained(self.model_name    )


     @cached_property
     def        __snake_case(  self    ):
       _UpperCAmelCase		:							List[Any]							=     TFAutoModelForSeqaSeqLM.from_pretrained(self.model_name    )
       return model




     @slow
     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Any							=     self.tokenizer(self.src_text							,					return_tensors="""tf"""    )
       _UpperCAmelCase		:							List[Any]							=     self.model.generate(
           model_inputs.input_ids							,					)
       _UpperCAmelCase		:							List[str]							=     self.tokenizer.batch_decode(generated_ids.numpy()							,					skip_special_tokens=A_    )[0]
       assert (
           generated_words
           == " That's unfortunate. Are they trying to lose weight or are they just trying to be healthier?"
       )





