





"""simple docstring"""





import inspect
import unittest

from transformers import DataaVecVisionConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, 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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch
						from torch import nn

						from transformers import (
						    MODEL_MAPPING,
						    DataaVecVisionForImageClassification,
						    DataaVecVisionForSemanticSegmentation,
						    DataaVecVisionModel,
						)
						from transformers.models.dataavec.modeling_dataavec_vision import DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import BeitImageProcessor





class 							_lowerCamelCase   :


						def __init__(self ,				__a ,				__a=1_00 ,				__a=13 ,				__a=30 ,				__a=2 ,				__a=3 ,				__a=True ,				__a=True ,				__a=32 ,				__a=4 ,				__a=4 ,				__a=37 ,				__a="gelu" ,				__a=0.1 ,				__a=0.1 ,				__a=10 ,				__a=0.02 ,				__a=3 ,				__a=None ,				__a=[0, 1, 2, 3] ,				)			-> Union[str, Any]:
								UpperCamelCase =						parent
								UpperCamelCase =						1_00
								UpperCamelCase =						batch_size
								UpperCamelCase =						image_size
								UpperCamelCase =						patch_size
								UpperCamelCase =						num_channels
								UpperCamelCase =						is_training
								UpperCamelCase =						use_labels
								UpperCamelCase =						hidden_size
								UpperCamelCase =						num_hidden_layers
								UpperCamelCase =						num_attention_heads
								UpperCamelCase =						intermediate_size
								UpperCamelCase =						hidden_act
								UpperCamelCase =						hidden_dropout_prob
								UpperCamelCase =						attention_probs_dropout_prob
								UpperCamelCase =						type_sequence_label_size
								UpperCamelCase =						initializer_range
								UpperCamelCase =						scope
								UpperCamelCase =						out_indices
								UpperCamelCase =						num_labels

								# in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
								UpperCamelCase =						(image_size // patch_size) ** 2
								UpperCamelCase =						num_patches + 1


						def      snake_case_ (self		)			-> Tuple:
								UpperCamelCase =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

								UpperCamelCase =						None
								UpperCamelCase =						None
								if self.use_labels:
										UpperCamelCase =						ids_tensor([self.batch_size] ,				self.type_sequence_label_size		)
										UpperCamelCase =						ids_tensor([self.batch_size, self.image_size, self.image_size] ,				self.num_labels		)

								UpperCamelCase =						self.get_config()

								return config, pixel_values, labels, pixel_labels


						def      snake_case_ (self		)			-> Tuple:
								return DataaVecVisionConfig(
								    vocab_size=self.vocab_size ,				image_size=self.image_size ,				patch_size=self.patch_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 ,				is_decoder=__a ,				initializer_range=self.initializer_range ,				out_indices=self.out_indices ,				)


						def      snake_case_ (self ,				__a ,				__a ,				__a ,				__a		)			-> Dict:
								UpperCamelCase =						DataaVecVisionModel(config=__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase =						model(__a		)
								# expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
								UpperCamelCase =						(self.image_size // self.patch_size) ** 2
								self.parent.assertEqual(result.last_hidden_state.shape ,				(self.batch_size, num_patches + 1, self.hidden_size)		)


						def      snake_case_ (self ,				__a ,				__a ,				__a ,				__a		)			-> Union[str, Any]:
								UpperCamelCase =						self.type_sequence_label_size
								UpperCamelCase =						DataaVecVisionForImageClassification(__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase =						model(__a ,				labels=__a		)
								self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.type_sequence_label_size)		)


						def      snake_case_ (self ,				__a ,				__a ,				__a ,				__a		)			-> List[str]:
								UpperCamelCase =						self.num_labels
								UpperCamelCase =						DataaVecVisionForSemanticSegmentation(__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase =						model(__a		)
								self.parent.assertEqual(
								    result.logits.shape ,				(self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)		)
								UpperCamelCase =						model(__a ,				labels=__a		)
								self.parent.assertEqual(
								    result.logits.shape ,				(self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)		)




						def      snake_case_ (self		)			-> List[str]:
								UpperCamelCase =						self.prepare_config_and_inputs()
								UpperCamelCase ,					UpperCamelCase ,					UpperCamelCase ,					UpperCamelCase =						config_and_inputs
								UpperCamelCase =						{"pixel_values": pixel_values}
								return config, inputs_dict





@require_torch
class 							_lowerCamelCase   (							_a	,      _a	,      unittest.TestCase			):
						UpperCAmelCase_			=      (
						    (DataaVecVisionModel, DataaVecVisionForImageClassification, DataaVecVisionForSemanticSegmentation)
						    if is_torch_available()
						    else ()
						)
						UpperCAmelCase_			=      (
						    {
						        "feature-extraction": DataaVecVisionModel,
						        "image-classification": DataaVecVisionForImageClassification,
						        "image-segmentation": DataaVecVisionForSemanticSegmentation,
						    }
						    if is_torch_available()
						    else {}
						)

						UpperCAmelCase_			=      False
						UpperCAmelCase_			=      False
						UpperCAmelCase_			=      False


						def      snake_case_ (self		)			-> Union[str, Any]:
								UpperCamelCase =						DataaVecVisionModelTester(self		)
								UpperCamelCase =						ConfigTester(
								    self ,				config_class=__a ,				has_text_modality=__a ,				hidden_size=37		)


						def      snake_case_ (self		)			-> str:
								self.config_tester.run_common_tests()


						def      snake_case_ (self		)			-> Union[str, Any]:
								# Data2VecVision does not use inputs_embeds
								pass


						@require_torch_multi_gpu
						@unittest.skip(
						    reason="Data2VecVision has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`"		)
						def      snake_case_ (self		)			-> Any:
								pass


						def      snake_case_ (self		)			-> Optional[Any]:
								UpperCamelCase ,					UpperCamelCase =						self.model_tester.prepare_config_and_inputs_for_common()

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


						def      snake_case_ (self		)			-> List[str]:
								UpperCamelCase ,					UpperCamelCase =						self.model_tester.prepare_config_and_inputs_for_common()

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

										UpperCamelCase =						["pixel_values"]
										self.assertListEqual(arg_names[:1] ,				__a		)


						def      snake_case_ (self		)			-> Optional[int]:
								UpperCamelCase =						self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__a		)


						def      snake_case_ (self		)			-> Any:
								UpperCamelCase =						self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_segmentation(*__a		)


						def      snake_case_ (self		)			-> int:
								if not self.model_tester.is_training:
										return

								UpperCamelCase ,					UpperCamelCase =						self.model_tester.prepare_config_and_inputs_for_common()
								UpperCamelCase =						True

								for model_class in self.all_model_classes:
										if model_class in [*get_values(__a		)]:
												continue

										UpperCamelCase =						model_class(__a		)
										model.to(__a		)
										model.train()
										UpperCamelCase =						self._prepare_for_class(__a ,				__a ,				return_labels=__a		)
										UpperCamelCase =						model(**__a		).loss
										loss.backward()


						def      snake_case_ (self		)			-> Optional[Any]:
								UpperCamelCase ,					UpperCamelCase =						self.model_tester.prepare_config_and_inputs_for_common()
								if not self.model_tester.is_training:
										return

								UpperCamelCase =						False
								UpperCamelCase =						True

								for model_class in self.all_model_classes:
										if model_class in [*get_values(__a		)] or not model_class.supports_gradient_checkpointing:
												continue
										# TODO: remove the following 3 lines once we have a MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING
										# this can then be incorporated into _prepare_for_class in test_modeling_common.py
										elif model_class.__name__ == "Data2VecVisionForSemanticSegmentation":
												UpperCamelCase ,					UpperCamelCase ,					UpperCamelCase ,					UpperCamelCase =						inputs_dict["pixel_values"].shape
												UpperCamelCase =						torch.zeros(
												    [self.model_tester.batch_size, height, width] ,				device=__a		).long()
										UpperCamelCase =						model_class(__a		)
										model.gradient_checkpointing_enable()
										model.to(__a		)
										model.train()
										UpperCamelCase =						self._prepare_for_class(__a ,				__a ,				return_labels=__a		)
										UpperCamelCase =						model(**__a		).loss
										loss.backward()


						def      snake_case_ (self		)			-> Tuple:
								UpperCamelCase ,					UpperCamelCase =						self.model_tester.prepare_config_and_inputs_for_common()

								UpperCamelCase =						_config_zero_init(__a		)
								for model_class in self.all_model_classes:
										UpperCamelCase =						model_class(config=__a		)
										for name, param in model.named_parameters():
												# we skip lambda parameters as these require special initial values
												# determined by config.layer_scale_init_value
												if "lambda" in name:
														continue
												if param.requires_grad:
														self.assertIn(
														    ((param.data.mean() * 1e9).round() / 1e9).item() ,				[0.0, 1.0] ,				msg=F"Parameter {name} of model {model_class} seems not properly initialized" ,				)


						def      snake_case_ (self ,				__a ,				__a ,				__a ,				__a=2e-4 ,				__a="outputs" ,				__a=None		)			-> Optional[Any]:
								# We override with a slightly higher tol value, as semseg models tend to diverge a bit more
								super().check_pt_tf_outputs(__a ,				__a ,				__a ,				__a ,				__a ,				__a		)


						def      snake_case_ (self		)			-> Dict:
								UpperCamelCase =						self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*__a		)




						@slow
						def      snake_case_ (self		)			-> str:
								for model_name in DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										UpperCamelCase =						DataaVecVisionModel.from_pretrained(__a		)
										self.assertIsNotNone(__a		)



def    a__       (       ):




		"""simple docstring"""


		UpperCamelCase =						Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     )
		return image






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


						@cached_property
						def      snake_case_ (self		)			-> Dict:
								return (
								    BeitImageProcessor.from_pretrained("facebook/data2vec-vision-base-ft1k"		) if is_vision_available() else None
								)




						@slow
						def      snake_case_ (self		)			-> Optional[int]:
								UpperCamelCase =						DataaVecVisionForImageClassification.from_pretrained("facebook/data2vec-vision-base-ft1k"		).to(
								    __a		)

								UpperCamelCase =						self.default_image_processor
								UpperCamelCase =						prepare_img()
								UpperCamelCase =						image_processor(images=__a ,				return_tensors="pt"		).to(__a		)

								# forward pass
								with torch.no_grad():
										UpperCamelCase =						model(**__a		)
								UpperCamelCase =						outputs.logits

								# verify the logits
								UpperCamelCase =						torch.Size((1, 10_00)		)
								self.assertEqual(logits.shape ,				__a		)

								UpperCamelCase =						torch.tensor([0.3277, -0.1395, 0.0911]		).to(__a		)

								self.assertTrue(torch.allclose(logits[0, :3] ,				__a ,				atol=1e-4		)		)

								UpperCamelCase =						[model.config.labelaid[i] for i in ["remote control, remote", "tabby, tabby cat"]]
								self.assertEqual(logits[0].topk(2		).indices.cpu().tolist() ,				__a		)













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 		_lowerCAmelCase:

  """simple docstring"""







  def __init__(   self    ,							UpperCAmelCase    ,							)->   List[Any]:
     __A    =  parent
     __A    =  13
     __A    =  7
     __A    =  True
     __A    =  True
     __A    =  True
     __A    =  True
     __A    =  True
     __A    =  False
     __A    =  False
     __A    =  False
     __A    =  2
     __A    =  99
     __A    =  0
     __A    =  32
     __A    =  2
     __A    =  4
     __A    =  0.1
     __A    =  0.1
     __A    =  5_12
     __A    =  16
     __A    =  2
     __A    =  0.02
     __A    =  3
     __A    =  4
     __A    =  '''last'''
     __A    =  True
     __A    =  None
     __A    =  0

  def 						SCREAMING_SNAKE_CASE__			(   self      )->   Optional[Any]:
     __A    =  ids_tensor([self.batch_size, self.seq_length]    ,							self.vocab_size      )
     __A    =  random_attention_mask([self.batch_size, self.seq_length]    ,							dtype=tf.floataa      )

     __A    =  None
     if self.use_input_lengths:
        __A    =  (
            ids_tensor([self.batch_size]    ,							vocab_size=2      ) + self.seq_length - 2
        )  # small variation of seq_length

     __A    =  None
     if self.use_token_type_ids:
        __A    =  ids_tensor([self.batch_size, self.seq_length]    ,							self.n_langs      )

     __A    =  None
     __A    =  None
     __A    =  None
     if self.use_labels:
        __A    =  ids_tensor([self.batch_size]    ,							self.type_sequence_label_size      )
        __A    =  ids_tensor([self.batch_size, self.seq_length]    ,							self.num_labels      )
        __A    =  ids_tensor([self.batch_size]    ,							2    ,							dtype=tf.floataa      )
        __A    =  ids_tensor([self.batch_size]    ,							self.num_choices      )

     __A    =  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 						SCREAMING_SNAKE_CASE__			(   self    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							)->   Optional[Any]:
     __A    =  TFXLMModel(config=UpperCAmelCase      )
     __A    =  {'''input_ids''': input_ids, '''lengths''': input_lengths, '''langs''': token_type_ids}
     __A    =  model(UpperCAmelCase      )

     __A    =  [input_ids, input_mask]
     __A    =  model(UpperCAmelCase      )
     self.parent.assertEqual(result.last_hidden_state.shape    ,							(self.batch_size, self.seq_length, self.hidden_size)      )

  def 						SCREAMING_SNAKE_CASE__			(   self    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							)->   Tuple:
     __A    =  TFXLMWithLMHeadModel(UpperCAmelCase      )

     __A    =  {'''input_ids''': input_ids, '''lengths''': input_lengths, '''langs''': token_type_ids}
     __A    =  model(UpperCAmelCase      )

     __A    =  outputs

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

  def 						SCREAMING_SNAKE_CASE__			(   self    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							)->   Dict:
     __A    =  TFXLMForQuestionAnsweringSimple(UpperCAmelCase      )

     __A    =  {'''input_ids''': input_ids, '''lengths''': input_lengths}

     __A    =  model(UpperCAmelCase      )

     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 						SCREAMING_SNAKE_CASE__			(   self    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							)->   Union[str, Any]:
     __A    =  TFXLMForSequenceClassification(UpperCAmelCase      )

     __A    =  {'''input_ids''': input_ids, '''lengths''': input_lengths}

     __A    =  model(UpperCAmelCase      )

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

  def 						SCREAMING_SNAKE_CASE__			(   self    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							)->   Tuple:
     __A    =  self.num_labels
     __A    =  TFXLMForTokenClassification(config=UpperCAmelCase      )
     __A    =  {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     __A    =  model(UpperCAmelCase      )
     self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.seq_length, self.num_labels)      )

  def 						SCREAMING_SNAKE_CASE__			(   self    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							)->   Union[str, Any]:
     __A    =  self.num_choices
     __A    =  TFXLMForMultipleChoice(config=UpperCAmelCase      )
     __A    =  tf.tile(tf.expand_dims(UpperCAmelCase    ,							1      )    ,							(1, self.num_choices, 1)      )
     __A    =  tf.tile(tf.expand_dims(UpperCAmelCase    ,							1      )    ,							(1, self.num_choices, 1)      )
     __A    =  tf.tile(tf.expand_dims(UpperCAmelCase    ,							1      )    ,							(1, self.num_choices, 1)      )
     __A    =  {
         '''input_ids''': multiple_choice_inputs_ids,
         '''attention_mask''': multiple_choice_input_mask,
         '''token_type_ids''': multiple_choice_token_type_ids,
     }
     __A    =  model(UpperCAmelCase      )
     self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.num_choices)      )





  def 						SCREAMING_SNAKE_CASE__			(   self      )->   Optional[Any]:
     __A    =  self.prepare_config_and_inputs()
     (
         (
         __A
     )   ,		(
         __A
     )   ,		(
         __A
     )   ,		(
         __A
     )   ,		(
         __A
     )   ,		(
         __A
     )   ,		(
         __A
     )   ,		(
         __A
     )   ,		(
         __A
     )   ,		
     )    =  config_and_inputs
     __A    =  {
         '''input_ids''': input_ids,
         '''token_type_ids''': token_type_ids,
         '''langs''': token_type_ids,
         '''lengths''': input_lengths,
     }
     return config, inputs_dict







@require_tf
class 		_lowerCAmelCase(		_a						,       _a						,       unittest.TestCase):

  """simple docstring"""







  lowerCamelCase__     	=       (
      (
          TFXLMModel,
          TFXLMWithLMHeadModel,
          TFXLMForSequenceClassification,
          TFXLMForQuestionAnsweringSimple,
          TFXLMForTokenClassification,
          TFXLMForMultipleChoice,
      )
      if is_tf_available()
      else ()
  )
  lowerCamelCase__     	=       (
      (TFXLMWithLMHeadModel,) if is_tf_available() else ()
  )  # TODO (PVP): Check other models whether language generation is also applicable
  lowerCamelCase__     	=       (
      {
          '''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 {}
  )
  lowerCamelCase__     	=       False
  lowerCamelCase__     	=       False

  def 						SCREAMING_SNAKE_CASE__			(   self    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase    ,							UpperCAmelCase      )->   List[Any]:
     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 						SCREAMING_SNAKE_CASE__			(   self      )->   Any:
     __A    =  TFXLMModelTester(self      )
     __A    =  ConfigTester(self    ,							config_class=UpperCAmelCase    ,							emb_dim=37      )

  def 						SCREAMING_SNAKE_CASE__			(   self      )->   List[str]:
     self.config_tester.run_common_tests()

  def 						SCREAMING_SNAKE_CASE__			(   self      )->   Any:
     __A    =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_model(*UpperCAmelCase      )

  def 						SCREAMING_SNAKE_CASE__			(   self      )->   Any:
     __A    =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_lm_head(*UpperCAmelCase      )

  def 						SCREAMING_SNAKE_CASE__			(   self      )->   List[Any]:
     __A    =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_qa(*UpperCAmelCase      )

  def 						SCREAMING_SNAKE_CASE__			(   self      )->   Any:
     __A    =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_sequence_classif(*UpperCAmelCase      )

  def 						SCREAMING_SNAKE_CASE__			(   self      )->   Tuple:
     __A    =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_for_token_classification(*UpperCAmelCase      )

  def 						SCREAMING_SNAKE_CASE__			(   self      )->   int:
     __A    =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_xlm_for_multiple_choice(*UpperCAmelCase      )





  @slow
  def 						SCREAMING_SNAKE_CASE__			(   self      )->   Optional[int]:
     for model_name in TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        __A    =  TFXLMModel.from_pretrained(UpperCAmelCase      )
        self.assertIsNotNone(UpperCAmelCase      )







@require_tf
class 		_lowerCAmelCase(		unittest.TestCase):

  """simple docstring"""







  @slow
  def 						SCREAMING_SNAKE_CASE__			(   self      )->   int:
     __A    =  TFXLMWithLMHeadModel.from_pretrained('''xlm-mlm-en-2048'''      )
     __A    =  tf.convert_to_tensor([[14, 4_47]]    ,							dtype=tf.intaa      )  # the president
     __A    =  [
         14,
         4_47,
         14,
         4_47,
         14,
         4_47,
         14,
         4_47,
         14,
         4_47,
         14,
         4_47,
         14,
         4_47,
         14,
         4_47,
         14,
         4_47,
         14,
         4_47,
     ]  # 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
     __A    =  model.generate(UpperCAmelCase    ,							do_sample=UpperCAmelCase      )
     self.assertListEqual(output_ids[0].numpy().tolist()    ,							UpperCAmelCase      )

