"""simple docstring"""







from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import ConvNextConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

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


if is_tf_available():
     import tensorflow as tf

     from transformers import TFConvNextForImageClassification, TFConvNextModel


if is_vision_available():
     from PIL import Image

     from transformers import ConvNextImageProcessor






class      _SCREAMING_SNAKE_CASE							:



   '''simple docstring'''



   def __init__(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE=13 ,				_SCREAMING_SNAKE_CASE=32 ,				_SCREAMING_SNAKE_CASE=3 ,				_SCREAMING_SNAKE_CASE=4 ,				_SCREAMING_SNAKE_CASE=[10, 20, 30, 40] ,				_SCREAMING_SNAKE_CASE=[2, 2, 3, 2] ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=37 ,				_SCREAMING_SNAKE_CASE="gelu" ,				_SCREAMING_SNAKE_CASE=10 ,				_SCREAMING_SNAKE_CASE=0.02 ,				_SCREAMING_SNAKE_CASE=3 ,				_SCREAMING_SNAKE_CASE=None ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					parent
      __lowerCamelCase    		=					batch_size
      __lowerCamelCase    		=					image_size
      __lowerCamelCase    		=					num_channels
      __lowerCamelCase    		=					num_stages
      __lowerCamelCase    		=					hidden_sizes
      __lowerCamelCase    		=					depths
      __lowerCamelCase    		=					is_training
      __lowerCamelCase    		=					use_labels
      __lowerCamelCase    		=					intermediate_size
      __lowerCamelCase    		=					hidden_act
      __lowerCamelCase    		=					type_sequence_label_size
      __lowerCamelCase    		=					initializer_range
      __lowerCamelCase    		=					scope







   def    _A				(	self	):


      '''simple docstring'''

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

      __lowerCamelCase    		=					None
      if self.use_labels:
         __lowerCamelCase    		=					ids_tensor([self.batch_size] ,				self.type_sequence_label_size	)

      __lowerCamelCase    		=					self.get_config()

      return config, pixel_values, labels







   def    _A				(	self	):


      '''simple docstring'''

      return ConvNextConfig(
          num_channels=self.num_channels ,				hidden_sizes=self.hidden_sizes ,				depths=self.depths ,				num_stages=self.num_stages ,				hidden_act=self.hidden_act ,				is_decoder=lowercase_ ,				initializer_range=self.initializer_range ,				)







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE	):


      '''simple docstring'''

      __lowerCamelCase    		=					TFConvNextModel(config=lowercase_	)
      __lowerCamelCase    		=					model(lowercase_ ,				training=lowercase_	)
      # expected last hidden states: B, C, H // 32, W // 32
      self.parent.assertEqual(
          result.last_hidden_state.shape ,				(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32) ,				)







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.type_sequence_label_size
      __lowerCamelCase    		=					TFConvNextForImageClassification(lowercase_	)
      __lowerCamelCase    		=					model(lowercase_ ,				labels=lowercase_ ,				training=lowercase_	)
      self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.type_sequence_label_size)	)







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.prepare_config_and_inputs()
      __lowerCamelCase    		=					config_and_inputs
      __lowerCamelCase    		=					{"pixel_values": pixel_values}
      return config, inputs_dict






@require_tf
class      _SCREAMING_SNAKE_CASE							(			lowercase__    ,				lowercase__    ,				unittest.TestCase				):



   '''simple docstring'''



   __UpperCAmelCase	:							str    =    (TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
   __UpperCAmelCase	:							Dict    =    (
       {"""feature-extraction""": TFConvNextModel, """image-classification""": TFConvNextForImageClassification}
       if is_tf_available()
       else {}
   )

   __UpperCAmelCase	:							Tuple    =    False
   __UpperCAmelCase	:							Union[str, Any]    =    False
   __UpperCAmelCase	:							Union[str, Any]    =    False
   __UpperCAmelCase	:							str    =    False
   __UpperCAmelCase	:							Any    =    False







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					TFConvNextModelTester(self	)
      __lowerCamelCase    		=					ConfigTester(
          self ,				config_class=lowercase_ ,				has_text_modality=lowercase_ ,				hidden_size=37 ,				)







   @unittest.skip(reason='ConvNext does not use inputs_embeds'	)
   def    _A				(	self	):


      '''simple docstring'''

      pass







   @unittest.skipIf(
       not is_tf_available() or len(tf.config.list_physical_devices('GPU'	)	) == 0 ,				reason='TF does not support backprop for grouped convolutions on CPU.' ,				)
   @slow
   def    _A				(	self	):


      '''simple docstring'''

      super().test_keras_fit()







   @unittest.skip(reason='ConvNext does not support input and output embeddings'	)
   def    _A				(	self	):


      '''simple docstring'''

      pass







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
         __lowerCamelCase    		=					model_class(lowercase_	)
         __lowerCamelCase    		=					inspect.signature(model.call	)
         # signature.parameters is an OrderedDict => so arg_names order is deterministic
         __lowerCamelCase    		=					[*signature.parameters.keys()]

         __lowerCamelCase    		=					["pixel_values"]
         self.assertListEqual(arg_names[:1] ,				lowercase_	)







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*lowercase_	)







   @unittest.skipIf(
       not is_tf_available() or len(tf.config.list_physical_devices('GPU'	)	) == 0 ,				reason='TF does not support backprop for grouped convolutions on CPU.' ,				)
   def    _A				(	self	):


      '''simple docstring'''

      super().test_dataset_conversion()







   def    _A				(	self	):


      '''simple docstring'''

      def check_hidden_states_output(_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE	):
         __lowerCamelCase    		=					model_class(lowercase_	)

         __lowerCamelCase    		=					model(**self._prepare_for_class(lowercase_ ,				lowercase_	)	)
         __lowerCamelCase    		=					outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

         __lowerCamelCase    		=					self.model_tester.num_stages
         self.assertEqual(len(lowercase_	) ,				expected_num_stages + 1	)

         # ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
         self.assertListEqual(
             list(hidden_states[0].shape[-2:]	) ,				[self.model_tester.image_size // 4, self.model_tester.image_size // 4] ,				)

      __lowerCamelCase    		=					self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
         __lowerCamelCase    		=					True
         check_hidden_states_output(lowercase_ ,				lowercase_ ,				lowercase_	)

         # check that output_hidden_states also work using config
         del inputs_dict["output_hidden_states"]
         __lowerCamelCase    		=					True

         check_hidden_states_output(lowercase_ ,				lowercase_ ,				lowercase_	)







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.model_tester.prepare_config_and_inputs_for_common()

      def check_equivalence(_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE={}	):
         __lowerCamelCase    		=					model(lowercase_ ,				return_dict=lowercase_ ,				**lowercase_	)
         __lowerCamelCase    		=					model(lowercase_ ,				return_dict=lowercase_ ,				**lowercase_	).to_tuple()

         def recursive_check(_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE	):
            if isinstance(lowercase_ ,				(List, Tuple)	):
               for tuple_iterable_value, dict_iterable_value in zip(lowercase_ ,				lowercase_	):
                  recursive_check(lowercase_ ,				lowercase_	)
            elif tuple_object is None:
               return
            else:
               self.assertTrue(
                   all(tf.equal(lowercase_ ,				lowercase_	)	) ,				msg=(
                       'Tuple and dict output are not equal. Difference:'
                       F''' {tf.math.reduce_max(tf.abs(tuple_object - dict_object	)	)}'''
                   ) ,				)

            recursive_check(lowercase_ ,				lowercase_	)

      for model_class in self.all_model_classes:
         __lowerCamelCase    		=					model_class(lowercase_	)

         __lowerCamelCase    		=					self._prepare_for_class(lowercase_ ,				lowercase_	)
         __lowerCamelCase    		=					self._prepare_for_class(lowercase_ ,				lowercase_	)
         check_equivalence(lowercase_ ,				lowercase_ ,				lowercase_	)

         __lowerCamelCase    		=					self._prepare_for_class(lowercase_ ,				lowercase_ ,				return_labels=lowercase_	)
         __lowerCamelCase    		=					self._prepare_for_class(lowercase_ ,				lowercase_ ,				return_labels=lowercase_	)
         check_equivalence(lowercase_ ,				lowercase_ ,				lowercase_	)

         __lowerCamelCase    		=					self._prepare_for_class(lowercase_ ,				lowercase_	)
         __lowerCamelCase    		=					self._prepare_for_class(lowercase_ ,				lowercase_	)
         check_equivalence(lowercase_ ,				lowercase_ ,				lowercase_ ,				{'output_hidden_states': True}	)

         __lowerCamelCase    		=					self._prepare_for_class(lowercase_ ,				lowercase_ ,				return_labels=lowercase_	)
         __lowerCamelCase    		=					self._prepare_for_class(lowercase_ ,				lowercase_ ,				return_labels=lowercase_	)
         check_equivalence(lowercase_ ,				lowercase_ ,				lowercase_ ,				{'output_hidden_states': True}	)







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_classification(*lowercase_	)







   @slow
   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					TFConvNextModel.from_pretrained('facebook/convnext-tiny-224'	)
      self.assertIsNotNone(lowercase_	)



def       A__    (	)  ->							Dict:
   __lowerCamelCase    		=					Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
   return image






@require_tf
@require_vision
class      _SCREAMING_SNAKE_CASE							(			unittest.TestCase				):



   '''simple docstring'''



   @cached_property
   def    _A				(	self	):


      '''simple docstring'''

      return ConvNextImageProcessor.from_pretrained('facebook/convnext-tiny-224'	) if is_vision_available() else None







   @slow
   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					TFConvNextForImageClassification.from_pretrained('facebook/convnext-tiny-224'	)

      __lowerCamelCase    		=					self.default_image_processor
      __lowerCamelCase    		=					prepare_img()
      __lowerCamelCase    		=					image_processor(images=lowercase_ ,				return_tensors='tf'	)

      # forward pass
      __lowerCamelCase    		=					model(**lowercase_	)

      # verify the logits
      __lowerCamelCase    		=					tf.TensorShape((1, 1000)	)
      self.assertEqual(outputs.logits.shape ,				lowercase_	)

      __lowerCamelCase    		=					tf.constant([-0.0260, -0.4739, 0.1911]	)

      tf.debugging.assert_near(outputs.logits[0, :3] ,				lowercase_ ,				atol=1E-4	)








"""simple docstring"""





from __future__ import annotations

import unittest

from transformers import is_tf_available
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_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFXLMForMultipleChoice,
        TFXLMForQuestionAnsweringSimple,
        TFXLMForSequenceClassification,
        TFXLMForTokenClassification,
        TFXLMModel,
        TFXLMWithLMHeadModel,
        XLMConfig,
    )


class A_      :




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   Optional[Any]     	=       parent
     UpperCAmelCase_   :   Any     	=       13
     UpperCAmelCase_   :   Dict     	=       7
     UpperCAmelCase_   :   str     	=       True
     UpperCAmelCase_   :   Optional[int]     	=       True
     UpperCAmelCase_   :   Optional[Any]     	=       True
     UpperCAmelCase_   :   Tuple     	=       True
     UpperCAmelCase_   :   Tuple     	=       True
     UpperCAmelCase_   :   str     	=       False
     UpperCAmelCase_   :   Optional[Any]     	=       False
     UpperCAmelCase_   :   Any     	=       False
     UpperCAmelCase_   :   Tuple     	=       2
     UpperCAmelCase_   :   str     	=       99
     UpperCAmelCase_   :   str     	=       0
     UpperCAmelCase_   :   Dict     	=       32
     UpperCAmelCase_   :   Dict     	=       2
     UpperCAmelCase_   :   Union[str, Any]     	=       4
     UpperCAmelCase_   :   Union[str, Any]     	=       0.1
     UpperCAmelCase_   :   Dict     	=       0.1
     UpperCAmelCase_   :   Optional[Any]     	=       512
     UpperCAmelCase_   :   Any     	=       16
     UpperCAmelCase_   :   Tuple     	=       2
     UpperCAmelCase_   :   int     	=       0.02
     UpperCAmelCase_   :   Union[str, Any]     	=       3
     UpperCAmelCase_   :   str     	=       4
     UpperCAmelCase_   :   Union[str, Any]     	=       "last"
     UpperCAmelCase_   :   Optional[int]     	=       True
     UpperCAmelCase_   :   str     	=       None
     UpperCAmelCase_   :   Dict     	=       0







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Optional[int]     	=       ids_tensor([self.batch_size, self.seq_length]							,  self.vocab_size    )
     UpperCAmelCase_   :   Any     	=       random_attention_mask([self.batch_size, self.seq_length]							,  dtype=tf.floataa    )

     UpperCAmelCase_   :   Union[str, Any]     	=       None
     if self.use_input_lengths:
        UpperCAmelCase_   :   Dict     	=       (
            ids_tensor([self.batch_size]							,  vocab_size=2    ) + self.seq_length - 2
        )  # small variation of seq_length

     UpperCAmelCase_   :   Union[str, Any]     	=       None
     if self.use_token_type_ids:
        UpperCAmelCase_   :   int     	=       ids_tensor([self.batch_size, self.seq_length]							,  self.n_langs    )

     UpperCAmelCase_   :   Dict     	=       None
     UpperCAmelCase_   :   int     	=       None
     UpperCAmelCase_   :   str     	=       None
     if self.use_labels:
        UpperCAmelCase_   :   Optional[Any]     	=       ids_tensor([self.batch_size]							,  self.type_sequence_label_size    )
        UpperCAmelCase_   :   Optional[int]     	=       ids_tensor([self.batch_size, self.seq_length]							,  self.num_labels    )
        UpperCAmelCase_   :   Optional[int]     	=       ids_tensor([self.batch_size]							,  2							,  dtype=tf.floataa    )
        UpperCAmelCase_   :   Dict     	=       ids_tensor([self.batch_size]							,  self.num_choices    )

     UpperCAmelCase_   :   Optional[Any]     	=       XLMConfig(
         vocab_size=self.vocab_size							,  n_special=self.n_special							,  emb_dim=self.hidden_size							,  n_layers=self.num_hidden_layers							,  n_heads=self.num_attention_heads							,  dropout=self.hidden_dropout_prob							,  attention_dropout=self.attention_probs_dropout_prob							,  gelu_activation=self.gelu_activation							,  sinusoidal_embeddings=self.sinusoidal_embeddings							,  asm=self.asm							,  causal=self.causal							,  n_langs=self.n_langs							,  max_position_embeddings=self.max_position_embeddings							,  initializer_range=self.initializer_range							,  summary_type=self.summary_type							,  use_proj=self.use_proj							,  bos_token_id=self.bos_token_id							,  )

     return (
         config,
         input_ids,
         token_type_ids,
         input_lengths,
         sequence_labels,
         token_labels,
         is_impossible_labels,
         choice_labels,
         input_mask,
     )







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   Optional[Any]     	=       TFXLMModel(config=lowercase_    )
     UpperCAmelCase_   :   Any     	=       {"input_ids": input_ids, "lengths": input_lengths, "langs": token_type_ids}
     UpperCAmelCase_   :   Tuple     	=       model(lowercase_    )

     UpperCAmelCase_   :   Any     	=       [input_ids, input_mask]
     UpperCAmelCase_   :   Union[str, Any]     	=       model(lowercase_    )
     self.parent.assertEqual(result.last_hidden_state.shape							,  (self.batch_size, self.seq_length, self.hidden_size)    )







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   Tuple     	=       TFXLMWithLMHeadModel(lowercase_    )

     UpperCAmelCase_   :   List[Any]     	=       {"input_ids": input_ids, "lengths": input_lengths, "langs": token_type_ids}
     UpperCAmelCase_   :   Dict     	=       model(lowercase_    )

     UpperCAmelCase_   :   Optional[int]     	=       outputs

     self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.vocab_size)    )







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   int     	=       TFXLMForQuestionAnsweringSimple(lowercase_    )

     UpperCAmelCase_   :   Any     	=       {"input_ids": input_ids, "lengths": input_lengths}

     UpperCAmelCase_   :   Union[str, Any]     	=       model(lowercase_    )

     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 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   Union[str, Any]     	=       TFXLMForSequenceClassification(lowercase_    )

     UpperCAmelCase_   :   Optional[int]     	=       {"input_ids": input_ids, "lengths": input_lengths}

     UpperCAmelCase_   :   Any     	=       model(lowercase_    )

     self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.type_sequence_label_size)    )







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   Dict     	=       self.num_labels
     UpperCAmelCase_   :   Any     	=       TFXLMForTokenClassification(config=lowercase_    )
     UpperCAmelCase_   :   Any     	=       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     UpperCAmelCase_   :   List[Any]     	=       model(lowercase_    )
     self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.num_labels)    )







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   Any     	=       self.num_choices
     UpperCAmelCase_   :   Any     	=       TFXLMForMultipleChoice(config=lowercase_    )
     UpperCAmelCase_   :   Union[str, Any]     	=       tf.tile(tf.expand_dims(lowercase_							,  1    )							,  (1, self.num_choices, 1)    )
     UpperCAmelCase_   :   Any     	=       tf.tile(tf.expand_dims(lowercase_							,  1    )							,  (1, self.num_choices, 1)    )
     UpperCAmelCase_   :   int     	=       tf.tile(tf.expand_dims(lowercase_							,  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_   :   int     	=       model(lowercase_    )
     self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.num_choices)    )







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   List[str]     	=       self.prepare_config_and_inputs()
     (
         (
         UpperCAmelCase_
     )	,  (
         UpperCAmelCase_
     )	,  (
         UpperCAmelCase_
     )	,  (
         UpperCAmelCase_
     )	,  (
         UpperCAmelCase_
     )	,  (
         UpperCAmelCase_
     )	,  (
         UpperCAmelCase_
     )	,  (
         UpperCAmelCase_
     )	,  (
         UpperCAmelCase_
     )	,  
     )   :   Dict     	=       config_and_inputs
     UpperCAmelCase_   :   Optional[int]     	=       {
         "input_ids": input_ids,
         "token_type_ids": token_type_ids,
         "langs": token_type_ids,
         "lengths": input_lengths,
     }
     return config, inputs_dict




@require_tf
class A_      (lowercase__							,lowercase__							,unittest.TestCase ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__     :		Any    	=						(
      (
          TFXLMModel,
          TFXLMWithLMHeadModel,
          TFXLMForSequenceClassification,
          TFXLMForQuestionAnsweringSimple,
          TFXLMForTokenClassification,
          TFXLMForMultipleChoice,
      )
      if is_tf_available()
      else ()
  )
  SCREAMING_SNAKE_CASE__     :		List[Any]    	=						(
      (TFXLMWithLMHeadModel,) if is_tf_available() else ()
  )  # TODO (PVP): Check other models whether language generation is also applicable
  SCREAMING_SNAKE_CASE__     :		Any    	=						(
      {
          """feature-extraction""": TFXLMModel,
          """fill-mask""": TFXLMWithLMHeadModel,
          """question-answering""": TFXLMForQuestionAnsweringSimple,
          """text-classification""": TFXLMForSequenceClassification,
          """text-generation""": TFXLMWithLMHeadModel,
          """token-classification""": TFXLMForTokenClassification,
          """zero-shot""": TFXLMForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )
  SCREAMING_SNAKE_CASE__     :		List[str]    	=						False
  SCREAMING_SNAKE_CASE__     :		Optional[Any]    	=						False







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_    ):

     """simple docstring"""
     if (
         pipeline_test_casse_name == "QAPipelineTests"
         and tokenizer_name is not None
         and not tokenizer_name.endswith("Fast"    )
     ):
        # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
        # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
        # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
        return True

     return False







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   List[Any]     	=       TFXLMModelTester(self    )
     UpperCAmelCase_   :   List[str]     	=       ConfigTester(self							,  config_class=lowercase_							,  emb_dim=37    )







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     self.config_tester.run_common_tests()







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Optional[int]     	=       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_model(*lowercase_    )







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   int     	=       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_lm_head(*lowercase_    )







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Optional[Any]     	=       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_qa(*lowercase_    )







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Optional[Any]     	=       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_sequence_classif(*lowercase_    )







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Optional[int]     	=       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_for_token_classification(*lowercase_    )







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Dict     	=       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_for_multiple_choice(*lowercase_    )







  @slow
  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     for model_name in TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        UpperCAmelCase_   :   Tuple     	=       TFXLMModel.from_pretrained(lowercase_    )
        self.assertIsNotNone(lowercase_    )




@require_tf
class A_      (unittest.TestCase ):




  '''simple docstring'''







  @slow
  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Union[str, Any]     	=       TFXLMWithLMHeadModel.from_pretrained("xlm-mlm-en-2048"    )
     UpperCAmelCase_   :   Optional[Any]     	=       tf.convert_to_tensor([[14, 447]]							,  dtype=tf.intaa    )  # the president
     UpperCAmelCase_   :   Optional[int]     	=       [
         14,
         447,
         14,
         447,
         14,
         447,
         14,
         447,
         14,
         447,
         14,
         447,
         14,
         447,
         14,
         447,
         14,
         447,
         14,
         447,
     ]  # the president the president the president the president the president the president the president the president the president the president
     # TODO(PVP): this and other input_ids I tried for generation give pretty bad results. Not sure why. Model might just not be made for auto-regressive inference
     UpperCAmelCase_   :   str     	=       model.generate(lowercase_							,  do_sample=lowercase_    )
     self.assertListEqual(output_ids[0].numpy().tolist()							,  lowercase_    )


