



import json
import os
import random
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
			from PIL import Image

			from transformers import FlavaImageProcessor, FlavaProcessor
			from transformers.models.flava.image_processing_flava import (
			    FLAVA_CODEBOOK_MEAN,
			    FLAVA_CODEBOOK_STD,
			    FLAVA_IMAGE_MEAN,
			    FLAVA_IMAGE_STD,
			)
@require_vision
class       _lowerCAmelCase (			unittest.TestCase      ):






			"""simple docstring"""





			def 		snake_case__      (					self						:							Tuple )    ->       List[Any]:
									"""simple docstring"""







									__lowercase											=					tempfile.mkdtemp()

									# fmt: off
									__lowercase											=					["""[UNK]""", """[CLS]""", """[SEP]""", """[PAD]""", """[MASK]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing""", """,""", """low""", """lowest"""]
									# fmt: on
									__lowercase											=					os.path.join(self.tmpdirname      ,  VOCAB_FILES_NAMES["""vocab_file"""] )

									with open(self.vocab_file      ,  """w"""      ,  encoding="""utf-8""" ) as fp:
															fp.write("""""".join([x + """\n""" for x in vocab_tokens] ) )

									__lowercase											=					{
									    """image_mean""": FLAVA_IMAGE_MEAN,
									    """image_std""": FLAVA_IMAGE_STD,
									    """do_normalize""": True,
									    """do_resize""": True,
									    """size""": 224,
									    """do_center_crop""": True,
									    """crop_size""": 224,
									    """input_size_patches""": 14,
									    """total_mask_patches""": 75,
									    """mask_group_max_patches""": None,
									    """mask_group_min_patches""": 16,
									    """mask_group_min_aspect_ratio""": 0.3,
									    """mask_group_max_aspect_ratio""": None,
									    """codebook_do_resize""": True,
									    """codebook_size""": 112,
									    """codebook_do_center_crop""": True,
									    """codebook_crop_size""": 112,
									    """codebook_do_map_pixels""": True,
									    """codebook_do_normalize""": True,
									    """codebook_image_mean""": FLAVA_CODEBOOK_MEAN,
									    """codebook_image_std""": FLAVA_CODEBOOK_STD,
									}

									__lowercase											=					os.path.join(self.tmpdirname      ,  lowercase )
									with open(self.image_processor_file      ,  """w"""      ,  encoding="""utf-8""" ) as fp:
															json.dump(lowercase      ,  lowercase )





			def 		snake_case__      (					self						:							Union[str, Any]      ,  **lowercase						:							Optional[Any] )    ->       List[Any]:
									"""simple docstring"""







									return BertTokenizer.from_pretrained(self.tmpdirname      ,  **lowercase )





			def 		snake_case__      (					self						:							Tuple      ,  **lowercase						:							Union[str, Any] )    ->       Union[str, Any]:
									"""simple docstring"""







									return BertTokenizerFast.from_pretrained(self.tmpdirname      ,  **lowercase )





			def 		snake_case__      (					self						:							Optional[Any]      ,  **lowercase						:							int )    ->       Tuple:
									"""simple docstring"""







									return FlavaImageProcessor.from_pretrained(self.tmpdirname      ,  **lowercase )





			def 		snake_case__      (					self						:							Optional[Any] )    ->       Optional[int]:
									"""simple docstring"""







									shutil.rmtree(self.tmpdirname )





			def 		snake_case__      (					self						:							Dict )    ->       Tuple:
									"""simple docstring"""







									__lowercase											=					[np.random.randint(255      ,  size=(3, 30, 400)      ,  dtype=np.uinta )]

									__lowercase											=					[Image.fromarray(np.moveaxis(lowercase      ,  0      ,  -1 ) ) for x in image_inputs]

									return image_inputs





			def 		snake_case__      (					self						:							Optional[Any] )    ->       Any:
									"""simple docstring"""







									__lowercase											=					self.get_tokenizer()
									__lowercase											=					self.get_rust_tokenizer()
									__lowercase											=					self.get_image_processor()

									__lowercase											=					FlavaProcessor(tokenizer=lowercase      ,  image_processor=lowercase )
									processor_slow.save_pretrained(self.tmpdirname )
									__lowercase											=					FlavaProcessor.from_pretrained(self.tmpdirname      ,  use_fast=lowercase )

									__lowercase											=					FlavaProcessor(tokenizer=lowercase      ,  image_processor=lowercase )
									processor_fast.save_pretrained(self.tmpdirname )
									__lowercase											=					FlavaProcessor.from_pretrained(self.tmpdirname )

									self.assertEqual(processor_slow.tokenizer.get_vocab()      ,  tokenizer_slow.get_vocab() )
									self.assertEqual(processor_fast.tokenizer.get_vocab()      ,  tokenizer_fast.get_vocab() )
									self.assertEqual(tokenizer_slow.get_vocab()      ,  tokenizer_fast.get_vocab() )
									self.assertIsInstance(processor_slow.tokenizer      ,  lowercase )
									self.assertIsInstance(processor_fast.tokenizer      ,  lowercase )

									self.assertEqual(processor_slow.image_processor.to_json_string()      ,  image_processor.to_json_string() )
									self.assertEqual(processor_fast.image_processor.to_json_string()      ,  image_processor.to_json_string() )
									self.assertIsInstance(processor_slow.image_processor      ,  lowercase )
									self.assertIsInstance(processor_fast.image_processor      ,  lowercase )





			def 		snake_case__      (					self						:							int )    ->       str:
									"""simple docstring"""







									__lowercase											=					FlavaProcessor(tokenizer=self.get_tokenizer()      ,  image_processor=self.get_image_processor() )
									processor.save_pretrained(self.tmpdirname )

									__lowercase											=					self.get_tokenizer(bos_token="""(BOS)"""      ,  eos_token="""(EOS)""" )
									__lowercase											=					self.get_image_processor(do_normalize=lowercase      ,  padding_value=1.0 )

									__lowercase											=					FlavaProcessor.from_pretrained(
									    self.tmpdirname      ,  bos_token="""(BOS)"""      ,  eos_token="""(EOS)"""      ,  do_normalize=lowercase      ,  padding_value=1.0 )

									self.assertEqual(processor.tokenizer.get_vocab()      ,  tokenizer_add_kwargs.get_vocab() )
									self.assertIsInstance(processor.tokenizer      ,  lowercase )

									self.assertEqual(processor.image_processor.to_json_string()      ,  image_processor_add_kwargs.to_json_string() )
									self.assertIsInstance(processor.image_processor      ,  lowercase )





			def 		snake_case__      (					self						:							Any )    ->       Optional[Any]:
									"""simple docstring"""







									__lowercase											=					self.get_image_processor()
									__lowercase											=					self.get_tokenizer()

									__lowercase											=					FlavaProcessor(tokenizer=lowercase      ,  image_processor=lowercase )

									__lowercase											=					self.prepare_image_inputs()

									__lowercase											=					image_processor(lowercase      ,  return_tensors="""np""" )
									__lowercase											=					processor(images=lowercase      ,  return_tensors="""np""" )

									for key in input_feat_extract.keys():
															self.assertAlmostEqual(input_feat_extract[key].sum()      ,  input_processor[key].sum()      ,  delta=1E-2 )

									# With rest of the args
									random.seed(1_234 )
									__lowercase											=					image_processor(
									    lowercase      ,  return_image_mask=lowercase      ,  return_codebook_pixels=lowercase      ,  return_tensors="""np""" )
									random.seed(1_234 )
									__lowercase											=					processor(
									    images=lowercase      ,  return_image_mask=lowercase      ,  return_codebook_pixels=lowercase      ,  return_tensors="""np""" )

									for key in input_feat_extract.keys():
															self.assertAlmostEqual(input_feat_extract[key].sum()      ,  input_processor[key].sum()      ,  delta=1E-2 )





			def 		snake_case__      (					self						:							Any )    ->       Tuple:
									"""simple docstring"""







									__lowercase											=					self.get_image_processor()
									__lowercase											=					self.get_tokenizer()

									__lowercase											=					FlavaProcessor(tokenizer=lowercase      ,  image_processor=lowercase )

									__lowercase											=					"""lower newer"""

									__lowercase											=					processor(text=lowercase )

									__lowercase											=					tokenizer(lowercase )

									for key in encoded_tok.keys():
															self.assertListEqual(encoded_tok[key]      ,  encoded_processor[key] )





			def 		snake_case__      (					self						:							Optional[int] )    ->       List[str]:
									"""simple docstring"""







									__lowercase											=					self.get_image_processor()
									__lowercase											=					self.get_tokenizer()

									__lowercase											=					FlavaProcessor(tokenizer=lowercase      ,  image_processor=lowercase )

									__lowercase											=					"""lower newer"""
									__lowercase											=					self.prepare_image_inputs()

									__lowercase											=					processor(text=lowercase      ,  images=lowercase )

									self.assertListEqual(list(inputs.keys() )      ,  ["""input_ids""", """token_type_ids""", """attention_mask""", """pixel_values"""] )

									# add extra args
									__lowercase											=					processor(text=lowercase      ,  images=lowercase      ,  return_codebook_pixels=lowercase      ,  return_image_mask=lowercase )

									self.assertListEqual(
									    list(inputs.keys() )      ,  [
									        """input_ids""",
									        """token_type_ids""",
									        """attention_mask""",
									        """pixel_values""",
									        """codebook_pixel_values""",
									        """bool_masked_pos""",
									    ]      ,  )

									# test if it raises when no input is passed
									with pytest.raises(lowercase ):
															processor()





			def 		snake_case__      (					self						:							Dict )    ->       Tuple:
									"""simple docstring"""







									__lowercase											=					self.get_image_processor()
									__lowercase											=					self.get_tokenizer()

									__lowercase											=					FlavaProcessor(tokenizer=lowercase      ,  image_processor=lowercase )

									__lowercase											=					[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

									__lowercase											=					processor.batch_decode(lowercase )
									__lowercase											=					tokenizer.batch_decode(lowercase )

									self.assertListEqual(lowercase      ,  lowercase )







			def 		snake_case__      (					self						:							Tuple )    ->       Optional[Any]:
									"""simple docstring"""







									__lowercase											=					self.get_image_processor()
									__lowercase											=					self.get_tokenizer()

									__lowercase											=					FlavaProcessor(tokenizer=lowercase      ,  image_processor=lowercase )

									__lowercase											=					"""lower newer"""
									__lowercase											=					self.prepare_image_inputs()

									__lowercase											=					processor(text=lowercase      ,  images=lowercase )

									self.assertListEqual(list(inputs.keys() )      ,  processor.model_input_names )










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						:							Tuple      ,  lowercase						:							str      ,  )    ->       str:
									"""simple docstring"""







									__lowercase											=					parent
									__lowercase											=					13
									__lowercase											=					7
									__lowercase											=					True
									__lowercase											=					True
									__lowercase											=					True
									__lowercase											=					True
									__lowercase											=					True
									__lowercase											=					False
									__lowercase											=					False
									__lowercase											=					False
									__lowercase											=					2
									__lowercase											=					99
									__lowercase											=					0
									__lowercase											=					32
									__lowercase											=					2
									__lowercase											=					4
									__lowercase											=					0.1
									__lowercase											=					0.1
									__lowercase											=					512
									__lowercase											=					16
									__lowercase											=					2
									__lowercase											=					0.02
									__lowercase											=					3
									__lowercase											=					4
									__lowercase											=					"""last"""
									__lowercase											=					True
									__lowercase											=					None
									__lowercase											=					0





			def 		snake_case__      (					self						:							Dict )    ->       Tuple:
									"""simple docstring"""







									__lowercase											=					ids_tensor([self.batch_size, self.seq_length]      ,  self.vocab_size )
									__lowercase											=					random_attention_mask([self.batch_size, self.seq_length]      ,  dtype=tf.floataa )

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

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

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

									__lowercase											=					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 		snake_case__      (					self						:							List[str]      ,  lowercase						:							Tuple      ,  lowercase						:							List[Any]      ,  lowercase						:							Optional[int]      ,  lowercase						:							Optional[int]      ,  lowercase						:							Optional[Any]      ,  lowercase						:							Optional[int]      ,  lowercase						:							Optional[Any]      ,  lowercase						:							int      ,  lowercase						:							List[str]      ,  )    ->       Dict:
									"""simple docstring"""







									__lowercase											=					TFXLMModel(config=lowercase )
									__lowercase											=					{"""input_ids""": input_ids, """lengths""": input_lengths, """langs""": token_type_ids}
									__lowercase											=					model(lowercase )

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





			def 		snake_case__      (					self						:							Dict      ,  lowercase						:							List[str]      ,  lowercase						:							Optional[int]      ,  lowercase						:							Optional[Any]      ,  lowercase						:							List[Any]      ,  lowercase						:							Optional[Any]      ,  lowercase						:							Dict      ,  lowercase						:							Dict      ,  lowercase						:							int      ,  lowercase						:							Union[str, Any]      ,  )    ->       List[Any]:
									"""simple docstring"""







									__lowercase											=					TFXLMWithLMHeadModel(lowercase )

									__lowercase											=					{"""input_ids""": input_ids, """lengths""": input_lengths, """langs""": token_type_ids}
									__lowercase											=					model(lowercase )

									__lowercase											=					outputs

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





			def 		snake_case__      (					self						:							Optional[Any]      ,  lowercase						:							Optional[Any]      ,  lowercase						:							Any      ,  lowercase						:							int      ,  lowercase						:							List[Any]      ,  lowercase						:							Any      ,  lowercase						:							int      ,  lowercase						:							List[Any]      ,  lowercase						:							List[str]      ,  lowercase						:							Optional[Any]      ,  )    ->       Dict:
									"""simple docstring"""







									__lowercase											=					TFXLMForQuestionAnsweringSimple(lowercase )

									__lowercase											=					{"""input_ids""": input_ids, """lengths""": input_lengths}

									__lowercase											=					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 		snake_case__      (					self						:							Optional[int]      ,  lowercase						:							Tuple      ,  lowercase						:							List[str]      ,  lowercase						:							List[Any]      ,  lowercase						:							Optional[int]      ,  lowercase						:							Optional[int]      ,  lowercase						:							Any      ,  lowercase						:							Tuple      ,  lowercase						:							Any      ,  lowercase						:							Dict      ,  )    ->       List[Any]:
									"""simple docstring"""







									__lowercase											=					TFXLMForSequenceClassification(lowercase )

									__lowercase											=					{"""input_ids""": input_ids, """lengths""": input_lengths}

									__lowercase											=					model(lowercase )

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





			def 		snake_case__      (					self						:							Union[str, Any]      ,  lowercase						:							List[str]      ,  lowercase						:							Optional[int]      ,  lowercase						:							List[Any]      ,  lowercase						:							Optional[int]      ,  lowercase						:							Tuple      ,  lowercase						:							Optional[Any]      ,  lowercase						:							Tuple      ,  lowercase						:							List[Any]      ,  lowercase						:							Optional[Any]      ,  )    ->       int:
									"""simple docstring"""







									__lowercase											=					self.num_labels
									__lowercase											=					TFXLMForTokenClassification(config=lowercase )
									__lowercase											=					{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
									__lowercase											=					model(lowercase )
									self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.seq_length, self.num_labels) )





			def 		snake_case__      (					self						:							int      ,  lowercase						:							Tuple      ,  lowercase						:							Optional[Any]      ,  lowercase						:							str      ,  lowercase						:							str      ,  lowercase						:							Dict      ,  lowercase						:							Optional[Any]      ,  lowercase						:							Optional[Any]      ,  lowercase						:							List[str]      ,  lowercase						:							List[str]      ,  )    ->       List[str]:
									"""simple docstring"""







									__lowercase											=					self.num_choices
									__lowercase											=					TFXLMForMultipleChoice(config=lowercase )
									__lowercase											=					tf.tile(tf.expand_dims(lowercase      ,  1 )      ,  (1, self.num_choices, 1) )
									__lowercase											=					tf.tile(tf.expand_dims(lowercase      ,  1 )      ,  (1, self.num_choices, 1) )
									__lowercase											=					tf.tile(tf.expand_dims(lowercase      ,  1 )      ,  (1, self.num_choices, 1) )
									__lowercase											=					{
									    """input_ids""": multiple_choice_inputs_ids,
									    """attention_mask""": multiple_choice_input_mask,
									    """token_type_ids""": multiple_choice_token_type_ids,
									}
									__lowercase											=					model(lowercase )
									self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.num_choices) )







			def 		snake_case__      (					self						:							str )    ->       Optional[int]:
									"""simple docstring"""







									__lowercase											=					self.prepare_config_and_inputs()
									(
									    (
									    __lowercase
									)						,      (
									    __lowercase
									)						,      (
									    __lowercase
									)						,      (
									    __lowercase
									)						,      (
									    __lowercase
									)						,      (
									    __lowercase
									)						,      (
									    __lowercase
									)						,      (
									    __lowercase
									)						,      (
									    __lowercase
									)						,      
									)											=					config_and_inputs
									__lowercase											=					{
									    """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 (			_UpperCAmelCase     ,       _UpperCAmelCase     ,       unittest.TestCase      ):






			"""simple docstring"""





			lowercase__   :	Tuple  			=      (
			    (
			        TFXLMModel,
			        TFXLMWithLMHeadModel,
			        TFXLMForSequenceClassification,
			        TFXLMForQuestionAnsweringSimple,
			        TFXLMForTokenClassification,
			        TFXLMForMultipleChoice,
			    )
			    if is_tf_available()
			    else ()
			)
			lowercase__   :	List[str]  			=      (
			    (TFXLMWithLMHeadModel,) if is_tf_available() else ()
			)  # TODO (PVP): Check other models whether language generation is also applicable
			lowercase__   :	Tuple  			=      (
			    {
			        """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 {}
			)
			lowercase__   :	int  			=      False
			lowercase__   :	int  			=      False





			def 		snake_case__      (					self						:							Optional[int]      ,  lowercase						:							List[str]      ,  lowercase						:							Optional[Any]      ,  lowercase						:							Optional[int]      ,  lowercase						:							List[str]      ,  lowercase						:							Dict )    ->       str:
									"""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 		snake_case__      (					self						:							Tuple )    ->       List[str]:
									"""simple docstring"""







									__lowercase											=					TFXLMModelTester(self )
									__lowercase											=					ConfigTester(self      ,  config_class=lowercase      ,  emb_dim=37 )





			def 		snake_case__      (					self						:							List[str] )    ->       List[str]:
									"""simple docstring"""







									self.config_tester.run_common_tests()





			def 		snake_case__      (					self						:							List[Any] )    ->       List[Any]:
									"""simple docstring"""







									__lowercase											=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_xlm_model(*lowercase )





			def 		snake_case__      (					self						:							str )    ->       str:
									"""simple docstring"""







									__lowercase											=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_xlm_lm_head(*lowercase )





			def 		snake_case__      (					self						:							Optional[int] )    ->       Optional[int]:
									"""simple docstring"""







									__lowercase											=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_xlm_qa(*lowercase )





			def 		snake_case__      (					self						:							Optional[Any] )    ->       str:
									"""simple docstring"""







									__lowercase											=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_xlm_sequence_classif(*lowercase )





			def 		snake_case__      (					self						:							Union[str, Any] )    ->       int:
									"""simple docstring"""







									__lowercase											=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_xlm_for_token_classification(*lowercase )





			def 		snake_case__      (					self						:							Optional[Any] )    ->       Tuple:
									"""simple docstring"""







									__lowercase											=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_xlm_for_multiple_choice(*lowercase )







			@slow
			def 		snake_case__      (					self						:							Optional[int] )    ->       Optional[int]:
									"""simple docstring"""







									for model_name in TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															__lowercase											=					TFXLMModel.from_pretrained(lowercase )
															self.assertIsNotNone(lowercase )





@require_tf
class       _lowerCAmelCase (			unittest.TestCase      ):






			"""simple docstring"""





			@slow
			def 		snake_case__      (					self						:							int )    ->       List[Any]:
									"""simple docstring"""







									__lowercase											=					TFXLMWithLMHeadModel.from_pretrained("""xlm-mlm-en-2048""" )
									__lowercase											=					tf.convert_to_tensor([[14, 447]]      ,  dtype=tf.intaa )  # the president
									__lowercase											=					[
									    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
									__lowercase											=					model.generate(lowercase      ,  do_sample=lowercase )
									self.assertListEqual(output_ids[0].numpy().tolist()      ,  lowercase )





