






"""simple docstring"""


import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VivitConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor


if is_torch_available():
       import torch
       from torch import nn

       from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VivitForVideoClassification, VivitModel
       from transformers.models.vivit.modeling_vivit import VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
       from transformers import VivitImageProcessor


class    snake_case						:


   '''simple docstring'''

   def __init__(      self					:	Optional[Any],			_lowerCamelCase					:	int,			_lowerCamelCase					:	Any=2,			_lowerCamelCase					:	Tuple=True,			_lowerCamelCase					:	Optional[int]=True,			_lowerCamelCase					:	int=10,			_lowerCamelCase					:	Optional[int]=10,			_lowerCamelCase					:	List[str]=8,			_lowerCamelCase					:	int=[2, 4, 4],			_lowerCamelCase					:	Any=3,			_lowerCamelCase					:	List[str]=7_68,			_lowerCamelCase					:	Dict=5,			_lowerCamelCase					:	Optional[int]=4,			_lowerCamelCase					:	List[str]=37,			_lowerCamelCase					:	int="gelu_fast",			_lowerCamelCase					:	Any=0.0,			_lowerCamelCase					:	Tuple=0.0,			_lowerCamelCase					:	Any=0.02,			_lowerCamelCase					:	List[str]=1e-06,			_lowerCamelCase					:	str=True,			_lowerCamelCase					:	Union[str, Any]=None,			):

     '''simple docstring'''
     __A		     =					parent
     __A		     =					batch_size
     __A		     =					is_training
     __A		     =					use_labels
     __A		     =					num_labels
     __A		     =					image_size
     __A		     =					num_frames
     __A		     =					tubelet_size
     __A		     =					num_channels
     __A		     =					hidden_size
     __A		     =					num_hidden_layers
     __A		     =					num_attention_heads
     __A		     =					intermediate_size
     __A		     =					hidden_act
     __A		     =					hidden_dropout_prob
     __A		     =					attention_probs_dropout_prob
     __A		     =					initializer_range
     __A		     =					layer_norm_eps
     __A		     =					qkv_bias
     __A		     =					scope

     __A		     =					(
         (self.image_size // self.tubelet_size[2])
         * (self.image_size // self.tubelet_size[1])
         * (self.num_frames // self.tubelet_size[0])
     ) + 1  # CLS token


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Dict    ):

     '''simple docstring'''
     __A		     =					floats_tensor(
         [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]    )

     __A		     =					None
     if self.use_labels:
       __A		     =					ids_tensor([self.batch_size],			self.num_labels    )

     __A		     =					self.get_config()

     return config, pixel_values, labels


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Union[str, Any]    ):

     '''simple docstring'''
     __A		     =					VivitConfig(
         num_frames=self.num_frames,			image_size=self.image_size,			tubelet_size=self.tubelet_size,			num_channels=self.num_channels,			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,			initializer_range=self.initializer_range,			layer_norm_eps=self.layer_norm_eps,			qkv_bias=self.qkv_bias,			)
     __A		     =					self.num_labels
     return config


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Dict,			_lowerCamelCase					:	str,			_lowerCamelCase					:	Union[str, Any],			_lowerCamelCase					:	str    ):

     '''simple docstring'''
     __A		     =					VivitModel(config=_lowerCamelCase    )
     model.to(_lowerCamelCase    )
     model.eval()
     __A		     =					model(_lowerCamelCase    )
     self.parent.assertEqual(result.last_hidden_state.shape,			(self.batch_size, self.seq_length, self.hidden_size)    )


   def 							_SCREAMING_SNAKE_CASE							(      self					:	str,			_lowerCamelCase					:	int,			_lowerCamelCase					:	Any,			_lowerCamelCase					:	Union[str, Any]    ):

     '''simple docstring'''
     __A		     =					VivitForVideoClassification(_lowerCamelCase    )
     model.to(_lowerCamelCase    )
     model.eval()

     __A		     =					model(_lowerCamelCase    )

     # verify the logits shape
     __A		     =					torch.Size((self.batch_size, self.num_labels)    )
     self.parent.assertEqual(result.logits.shape,			_lowerCamelCase    )






   def 							_SCREAMING_SNAKE_CASE							(      self					:	str    ):

     '''simple docstring'''
     __A		     =					self.prepare_config_and_inputs()
     __A     ,       __A     ,       __A		     =					config_and_inputs
     __A		     =					{'''pixel_values''': pixel_values}
     return config, inputs_dict





@require_torch
class    snake_case						(				_lowerCAmelCase  ,      unittest.TestCase		):


   '''simple docstring'''

   A_		:      Dict							=					(VivitModel, VivitForVideoClassification) if is_torch_available() else ()

   A_		:      int							=					False
   A_		:      Union[str, Any]							=					False
   A_		:      Any							=					False
   A_		:      Union[str, Any]							=					False


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Union[str, Any]    ):

     '''simple docstring'''
     __A		     =					VivitModelTester(self    )
     __A		     =					ConfigTester(self,			config_class=_lowerCamelCase,			has_text_modality=_lowerCamelCase,			hidden_size=37    )


   def 							_SCREAMING_SNAKE_CASE							(      self					:	List[Any],			_lowerCamelCase					:	Any,			_lowerCamelCase					:	int,			_lowerCamelCase					:	int=False    ):

     '''simple docstring'''
     __A		     =					copy.deepcopy(_lowerCamelCase    )

     if return_labels:
       if model_class in get_values(_lowerCamelCase    ):
         __A		     =					torch.zeros(
             self.model_tester.batch_size,			dtype=torch.long,			device=_lowerCamelCase    )

     return inputs_dict


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Tuple    ):

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


   @unittest.skip(reason='''Vivit does not use inputs_embeds'''    )
   def 							_SCREAMING_SNAKE_CASE							(      self					:	Optional[Any]    ):

     '''simple docstring'''
     pass


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Optional[int]    ):

     '''simple docstring'''
     __A     ,       __A		     =					self.model_tester.prepare_config_and_inputs_for_common()

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


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Dict    ):

     '''simple docstring'''
     __A     ,       __A		     =					self.model_tester.prepare_config_and_inputs_for_common()

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

       __A		     =					['''pixel_values''', '''head_mask''']
       self.assertListEqual(arg_names[:2],			_lowerCamelCase    )


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Tuple    ):

     '''simple docstring'''
     __A		     =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*_lowerCamelCase    )


   def 							_SCREAMING_SNAKE_CASE							(      self					:	List[Any]    ):

     '''simple docstring'''
     __A		     =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_video_classification(*_lowerCamelCase    )


   @slow
   def 							_SCREAMING_SNAKE_CASE							(      self					:	Tuple    ):

     '''simple docstring'''
     for model_name in VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       __A		     =					VivitModel.from_pretrained(_lowerCamelCase    )
       self.assertIsNotNone(_lowerCamelCase    )


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Any    ):

     '''simple docstring'''
     __A     ,       __A		     =					self.model_tester.prepare_config_and_inputs_for_common()
     __A		     =					True

     for model_class in self.all_model_classes:
       __A		     =					self.model_tester.seq_length

       __A		     =					True
       __A		     =					False
       __A		     =					True
       __A		     =					model_class(_lowerCamelCase    )
       model.to(_lowerCamelCase    )
       model.eval()
       with torch.no_grad():
         __A		     =					model(**self._prepare_for_class(_lowerCamelCase,			_lowerCamelCase    )    )
       __A		     =					outputs.attentions
       self.assertEqual(len(_lowerCamelCase    ),			self.model_tester.num_hidden_layers    )

       # check that output_attentions also work using config
       del inputs_dict["output_attentions"]
       __A		     =					True
       __A		     =					model_class(_lowerCamelCase    )
       model.to(_lowerCamelCase    )
       model.eval()
       with torch.no_grad():
         __A		     =					model(**self._prepare_for_class(_lowerCamelCase,			_lowerCamelCase    )    )
       __A		     =					outputs.attentions
       self.assertEqual(len(_lowerCamelCase    ),			self.model_tester.num_hidden_layers    )

       self.assertListEqual(
           list(attentions[0].shape[-3:]    ),			[self.model_tester.num_attention_heads, seq_len, seq_len],			)
       __A		     =					len(_lowerCamelCase    )

       # Check attention is always last and order is fine
       __A		     =					True
       __A		     =					True
       __A		     =					model_class(_lowerCamelCase    )
       model.to(_lowerCamelCase    )
       model.eval()
       with torch.no_grad():
         __A		     =					model(**self._prepare_for_class(_lowerCamelCase,			_lowerCamelCase    )    )

       self.assertEqual(out_len + 1,			len(_lowerCamelCase    )    )

       __A		     =					outputs.attentions

       self.assertEqual(len(_lowerCamelCase    ),			self.model_tester.num_hidden_layers    )

       self.assertListEqual(
           list(self_attentions[0].shape[-3:]    ),			[self.model_tester.num_attention_heads, seq_len, seq_len],			)


   def 							_SCREAMING_SNAKE_CASE							(      self					:	List[Any]    ):

     '''simple docstring'''
     def check_hidden_states_output(_lowerCamelCase					:	str,			_lowerCamelCase					:	int,			_lowerCamelCase					:	int    ):
       __A		     =					model_class(_lowerCamelCase    )
       model.to(_lowerCamelCase    )
       model.eval()

       with torch.no_grad():
         __A		     =					model(**self._prepare_for_class(_lowerCamelCase,			_lowerCamelCase    )    )

       __A		     =					outputs.hidden_states
       __A		     =					self.model_tester.num_hidden_layers + 1
       self.assertEqual(len(_lowerCamelCase    ),			_lowerCamelCase    )

       __A		     =					self.model_tester.seq_length

       self.assertListEqual(
           list(hidden_states[0].shape[-2:]    ),			[seq_length, self.model_tester.hidden_size],			)

     __A     ,       __A		     =					self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
       __A		     =					True
       check_hidden_states_output(_lowerCamelCase,			_lowerCamelCase,			_lowerCamelCase    )

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

       check_hidden_states_output(_lowerCamelCase,			_lowerCamelCase,			_lowerCamelCase    )






   @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''    )
   def 							_SCREAMING_SNAKE_CASE							(      self					:	Optional[int]    ):

     '''simple docstring'''
     pass





def    lowerCAmelCase							(       ):




  """simple docstring"""







  __A		     =					hf_hub_download(
      repo_id='''hf-internal-testing/spaghetti-video'''						,			filename='''eating_spaghetti_32_frames.npy'''						,			repo_type='''dataset'''					)
  __A		     =					np.load(__UpperCamelCase					)
  return list(__UpperCamelCase					)





@require_torch
@require_vision
class    snake_case						(				unittest.TestCase		):


   '''simple docstring'''

   @cached_property
   def 							_SCREAMING_SNAKE_CASE							(      self					:	List[str]    ):

     '''simple docstring'''
     return VivitImageProcessor() if is_vision_available() else None






   @slow
   def 							_SCREAMING_SNAKE_CASE							(      self					:	Optional[Any]    ):

     '''simple docstring'''
     __A		     =					VivitForVideoClassification.from_pretrained('''google/vivit-b-16x2-kinetics400'''    ).to(_lowerCamelCase    )

     __A		     =					self.default_image_processor
     __A		     =					prepare_video()
     __A		     =					image_processor(_lowerCamelCase,			return_tensors='''pt'''    ).to(_lowerCamelCase    )

     # forward pass
     with torch.no_grad():
       __A		     =					model(**_lowerCamelCase    )

     # verify the logits
     __A		     =					torch.Size((1, 4_00)    )
     self.assertEqual(outputs.logits.shape,			_lowerCamelCase    )

     # taken from original model
     __A		     =					torch.tensor([-1.05_43, 2.07_64, -0.21_04, 0.44_39, -0.96_58]    ).to(_lowerCamelCase    )

     self.assertTrue(torch.allclose(outputs.logits[0, :5],			_lowerCamelCase,			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_    )


