



import types
from typing import List, Optional, Tuple, Union

import torch
from transformers import CLIPTextModelWithProjection, CLIPTokenizer
from transformers.models.clip.modeling_clip import CLIPTextModelOutput

from diffusers.models import PriorTransformer
from diffusers.pipelines import DiffusionPipeline, StableDiffusionImageVariationPipeline
from diffusers.schedulers import UnCLIPScheduler
from diffusers.utils import logging, randn_tensor


UpperCamelCase__			=    logging.get_logger(__name__)  # pylint: disable=invalid-name






def 			UpperCAmelCase__     (     self    ,							lowercase__    ,							lowercase__    ,							lowercase__    ,							lowercase__ )			->   str:
						__lowercase											=					image.to(device=lowercase__ )
						__lowercase											=					image  # take image as image_embeddings
						__lowercase											=					image_embeddings.unsqueeze(1 )

						# duplicate image embeddings for each generation per prompt, using mps friendly method
						__lowercase						,      __lowercase						,      __lowercase											=					image_embeddings.shape
						__lowercase											=					image_embeddings.repeat(1    ,							lowercase__    ,							1 )
						__lowercase											=					image_embeddings.view(bs_embed * num_images_per_prompt    ,							lowercase__    ,							-1 )

						if do_classifier_free_guidance:
												__lowercase											=					torch.zeros_like(lowercase__ )

												# For classifier free guidance, we need to do two forward passes.
												# Here we concatenate the unconditional and text embeddings into a single batch
												# to avoid doing two forward passes
												__lowercase											=					torch.cat([uncond_embeddings, image_embeddings] )

						return image_embeddings







class       _lowerCAmelCase (			_UpperCAmelCase      ):






			"""simple docstring"""





			def __init__(					self						:							List[str]      ,  lowercase						:							PriorTransformer      ,  lowercase						:							CLIPTokenizer      ,  lowercase						:							CLIPTextModelWithProjection      ,  lowercase						:							UnCLIPScheduler      ,  lowercase						:							Optional[dict] = None      ,  )    ->       Tuple:
									"""simple docstring"""







									super().__init__()

									__lowercase											=					{"""image_encoder""": None} if decoder_pipe_kwargs is None else decoder_pipe_kwargs

									__lowercase											=					decoder_pipe_kwargs.get("""torch_dtype"""      ,  lowercase ) or prior.dtype

									__lowercase											=					StableDiffusionImageVariationPipeline.from_pretrained(
									    """lambdalabs/sd-image-variations-diffusers"""      ,  **lowercase )

									# replace `_encode_image` method
									__lowercase											=					types.MethodType(_encode_image      ,  self.decoder_pipe )

									self.register_modules(
									    prior=lowercase      ,  tokenizer=lowercase      ,  text_encoder=lowercase      ,  prior_scheduler=lowercase      ,  )





			def 		snake_case__      (					self						:							Union[str, Any]      ,  lowercase						:							Tuple      ,  lowercase						:							Tuple      ,  lowercase						:							Union[str, Any]      ,  lowercase						:							int      ,  lowercase						:							Optional[Union[CLIPTextModelOutput, Tuple]] = None      ,  lowercase						:							Optional[torch.Tensor] = None      ,  )    ->       Dict:
									"""simple docstring"""







									if text_model_output is None:
															__lowercase											=					len(lowercase ) if isinstance(lowercase      ,  lowercase ) else 1
															# get prompt text embeddings
															__lowercase											=					self.tokenizer(
															    lowercase      ,  padding="""max_length"""      ,  max_length=self.tokenizer.model_max_length      ,  return_tensors="""pt"""      ,  )
															__lowercase											=					text_inputs.input_ids
															__lowercase											=					text_inputs.attention_mask.bool().to(lowercase )

															if text_input_ids.shape[-1] > self.tokenizer.model_max_length:
																					__lowercase											=					self.tokenizer.batch_decode(text_input_ids[:, self.tokenizer.model_max_length :] )
																					logger.warning(
																					    """The following part of your input was truncated because CLIP can only handle sequences up to"""
																					    F" {self.tokenizer.model_max_length} tokens: {removed_text}" )
																					__lowercase											=					text_input_ids[:, : self.tokenizer.model_max_length]

															__lowercase											=					self.text_encoder(text_input_ids.to(lowercase ) )

															__lowercase											=					text_encoder_output.text_embeds
															__lowercase											=					text_encoder_output.last_hidden_state

									else:
															__lowercase											=					text_model_output[0].shape[0]
															__lowercase						,      __lowercase											=					text_model_output[0], text_model_output[1]
															__lowercase											=					text_attention_mask

									__lowercase											=					text_embeddings.repeat_interleave(lowercase      ,  dim=0 )
									__lowercase											=					text_encoder_hidden_states.repeat_interleave(lowercase      ,  dim=0 )
									__lowercase											=					text_mask.repeat_interleave(lowercase      ,  dim=0 )

									if do_classifier_free_guidance:
															__lowercase											=					[""""""] * batch_size

															__lowercase											=					self.tokenizer(
															    lowercase      ,  padding="""max_length"""      ,  max_length=self.tokenizer.model_max_length      ,  truncation=lowercase      ,  return_tensors="""pt"""      ,  )
															__lowercase											=					uncond_input.attention_mask.bool().to(lowercase )
															__lowercase											=					self.text_encoder(uncond_input.input_ids.to(lowercase ) )

															__lowercase											=					uncond_embeddings_text_encoder_output.text_embeds
															__lowercase											=					uncond_embeddings_text_encoder_output.last_hidden_state

															# duplicate unconditional embeddings for each generation per prompt, using mps friendly method

															__lowercase											=					uncond_embeddings.shape[1]
															__lowercase											=					uncond_embeddings.repeat(1      ,  lowercase )
															__lowercase											=					uncond_embeddings.view(batch_size * num_images_per_prompt      ,  lowercase )

															__lowercase											=					uncond_text_encoder_hidden_states.shape[1]
															__lowercase											=					uncond_text_encoder_hidden_states.repeat(1      ,  lowercase      ,  1 )
															__lowercase											=					uncond_text_encoder_hidden_states.view(
															    batch_size * num_images_per_prompt      ,  lowercase      ,  -1 )
															__lowercase											=					uncond_text_mask.repeat_interleave(lowercase      ,  dim=0 )

															# done duplicates

															# For classifier free guidance, we need to do two forward passes.
															# Here we concatenate the unconditional and text embeddings into a single batch
															# to avoid doing two forward passes
															__lowercase											=					torch.cat([uncond_embeddings, text_embeddings] )
															__lowercase											=					torch.cat([uncond_text_encoder_hidden_states, text_encoder_hidden_states] )

															__lowercase											=					torch.cat([uncond_text_mask, text_mask] )

									return text_embeddings, text_encoder_hidden_states, text_mask





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







									if self.device != torch.device("""meta""" ) or not hasattr(self.prior      ,  """_hf_hook""" ):
															return self.device
									for module in self.prior.modules():
															if (
															    hasattr(lowercase      ,  """_hf_hook""" )
															    and hasattr(module._hf_hook      ,  """execution_device""" )
															    and module._hf_hook.execution_device is not None
															):
																					return torch.device(module._hf_hook.execution_device )
									return self.device





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







									if latents is None:
															__lowercase											=					randn_tensor(lowercase      ,  generator=lowercase      ,  device=lowercase      ,  dtype=lowercase )
									else:
															if latents.shape != shape:
																					raise ValueError(F"Unexpected latents shape, got {latents.shape}, expected {shape}" )
															__lowercase											=					latents.to(lowercase )

									__lowercase											=					latents * scheduler.init_noise_sigma
									return latents





			def 		snake_case__      (					self						:							List[Any]      ,  lowercase						:							Optional[Union[str, torch.device]] = None )    ->       str:
									"""simple docstring"""







									self.decoder_pipe.to(lowercase )
									super().to(lowercase )







			@torch.no_grad()
			def __call__(					self						:							int      ,  lowercase						:							Optional[Union[str, List[str]]] = None      ,  lowercase						:							Optional[int] = None      ,  lowercase						:							Optional[int] = None      ,  lowercase						:							int = 1      ,  lowercase						:							int = 25      ,  lowercase						:							Optional[torch.Generator] = None      ,  lowercase						:							Optional[torch.FloatTensor] = None      ,  lowercase						:							Optional[Union[CLIPTextModelOutput, Tuple]] = None      ,  lowercase						:							Optional[torch.Tensor] = None      ,  lowercase						:							float = 4.0      ,  lowercase						:							float = 8.0      ,  lowercase						:							int = 50      ,  lowercase						:							Optional[int] = 1      ,  lowercase						:							float = 0.0      ,  lowercase						:							Optional[str] = "pil"      ,  lowercase						:							bool = True      ,  )    ->       List[Any]:
									"""simple docstring"""







									if prompt is not None:
															if isinstance(lowercase      ,  lowercase ):
																					__lowercase											=					1
															elif isinstance(lowercase      ,  lowercase ):
																					__lowercase											=					len(lowercase )
															else:
																					raise ValueError(F"`prompt` has to be of type `str` or `list` but is {type(lowercase )}" )
									else:
															__lowercase											=					text_model_output[0].shape[0]

									__lowercase											=					self._execution_device

									__lowercase											=					batch_size * num_images_per_prompt

									__lowercase											=					prior_guidance_scale > 1.0 or decoder_guidance_scale > 1.0

									__lowercase						,      __lowercase						,      __lowercase											=					self._encode_prompt(
									    lowercase      ,  lowercase      ,  lowercase      ,  lowercase      ,  lowercase      ,  lowercase )

									# prior

									self.prior_scheduler.set_timesteps(lowercase      ,  device=lowercase )
									__lowercase											=					self.prior_scheduler.timesteps

									__lowercase											=					self.prior.config.embedding_dim

									__lowercase											=					self.prepare_latents(
									    (batch_size, embedding_dim)      ,  text_embeddings.dtype      ,  lowercase      ,  lowercase      ,  lowercase      ,  self.prior_scheduler      ,  )

									for i, t in enumerate(self.progress_bar(lowercase ) ):
															# expand the latents if we are doing classifier free guidance
															__lowercase											=					torch.cat([prior_latents] * 2 ) if do_classifier_free_guidance else prior_latents

															__lowercase											=					self.prior(
															    lowercase      ,  timestep=lowercase      ,  proj_embedding=lowercase      ,  encoder_hidden_states=lowercase      ,  attention_mask=lowercase      ,  ).predicted_image_embedding

															if do_classifier_free_guidance:
																					__lowercase						,      __lowercase											=					predicted_image_embedding.chunk(2 )
																					__lowercase											=					predicted_image_embedding_uncond + prior_guidance_scale * (
																					    predicted_image_embedding_text - predicted_image_embedding_uncond
																					)

															if i + 1 == prior_timesteps_tensor.shape[0]:
																					__lowercase											=					None
															else:
																					__lowercase											=					prior_timesteps_tensor[i + 1]

															__lowercase											=					self.prior_scheduler.step(
															    lowercase      ,  timestep=lowercase      ,  sample=lowercase      ,  generator=lowercase      ,  prev_timestep=lowercase      ,  ).prev_sample

									__lowercase											=					self.prior.post_process_latents(lowercase )

									__lowercase											=					prior_latents

									__lowercase											=					self.decoder_pipe(
									    image=lowercase      ,  height=lowercase      ,  width=lowercase      ,  num_inference_steps=lowercase      ,  guidance_scale=lowercase      ,  generator=lowercase      ,  output_type=lowercase      ,  return_dict=lowercase      ,  num_images_per_prompt=lowercase      ,  eta=lowercase      ,  )
									return output










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 )





