






import math
from dataclasses import dataclass
from typing import List, Optional, Tuple, Union

import numpy as np
import torch

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, logging, randn_tensor
from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin


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




@dataclass
# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput with DDPM->EulerAncestralDiscrete
class        snake_case_					(						__UpperCamelCase			):

						"""simple docstring"""



						snake_case__   					=			42
						snake_case__   					=			None







def 						a_      (__A							,					__A=0.999							,					__A="cosine"							,					)							->	Union[str, Any]:



					"""simple docstring"""
					if alpha_transform_type == "cosine":

										def alpha_bar_fn(__A			):
															return math.cos((t + 0.008) / 1.008 * math.pi / 2			) ** 2

					elif alpha_transform_type == "exp":

										def alpha_bar_fn(__A			):
															return math.exp(t * -12.0			)

					else:
										raise ValueError(f'Unsupported alpha_tranform_type: {alpha_transform_type}'			)

					__a				:	Any			=				[]
					for i in range(__A			):
										__a				:	List[Any]			=				i / num_diffusion_timesteps
										__a				:	List[Any]			=				(i + 1) / num_diffusion_timesteps
										betas.append(min(1 - alpha_bar_fn(__A			) / alpha_bar_fn(__A			)							,					__A			)			)
					return torch.tensor(__A							,					dtype=torch.floataa			)




class        snake_case_					(						__UpperCamelCase		,       __UpperCamelCase			):

						"""simple docstring"""



						snake_case__   					=			[e.name for e in KarrasDiffusionSchedulers]
						snake_case__   					=			1



						@register_to_config
						def __init__(self:				Optional[int]   ,				__UpperCAmelCase:				int = 1000   ,				__UpperCAmelCase:				float = 0.00_01   ,				__UpperCAmelCase:				float = 0.02   ,				__UpperCAmelCase:				str = "linear"   ,				__UpperCAmelCase:				Optional[Union[np.ndarray, List[float]]] = None   ,				__UpperCAmelCase:				str = "epsilon"   ,				__UpperCAmelCase:				str = "linspace"   ,				__UpperCAmelCase:				int = 0   ,				)						->    int:




											'''simple docstring'''



											if trained_betas is not None:
																__a				:	Optional[int]			=				torch.tensor(__UpperCAmelCase   ,				dtype=torch.floataa      )
											elif beta_schedule == "linear":
																__a				:	str			=				torch.linspace(__UpperCAmelCase   ,				__UpperCAmelCase   ,				__UpperCAmelCase   ,				dtype=torch.floataa      )
											elif beta_schedule == "scaled_linear":
																# this schedule is very specific to the latent diffusion model.
																__a				:	str			=				(
																    torch.linspace(beta_start**0.5   ,				beta_end**0.5   ,				__UpperCAmelCase   ,				dtype=torch.floataa      ) ** 2
																)
											elif beta_schedule == "squaredcos_cap_v2":
																# Glide cosine schedule
																__a				:	List[Any]			=				betas_for_alpha_bar(__UpperCAmelCase      )
											else:
																raise NotImplementedError(f'{beta_schedule} does is not implemented for {self.__class__}'      )

											__a				:	str			=				1.0 - self.betas
											__a				:	Union[str, Any]			=				torch.cumprod(self.alphas   ,				dim=0      )

											__a				:	List[str]			=				np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5      )
											__a				:	int			=				np.concatenate([sigmas[::-1], [0.0]]      ).astype(np.floataa      )
											__a				:	str			=				torch.from_numpy(__UpperCAmelCase      )

											# setable values
											__a				:	int			=				None
											__a				:	Optional[Any]			=				np.linspace(0   ,				num_train_timesteps - 1   ,				__UpperCAmelCase   ,				dtype=__UpperCAmelCase      )[::-1].copy()
											__a				:	Optional[Any]			=				torch.from_numpy(__UpperCAmelCase      )
											__a				:	Tuple			=				False



						@property
						def 					UpperCAmelCase__				(self:				str      )						->    List[Any]:




											'''simple docstring'''



											if self.config.timestep_spacing in ["linspace", "trailing"]:
																return self.sigmas.max()

											return (self.sigmas.max() ** 2 + 1) ** 0.5



						def 					UpperCAmelCase__				(self:				Any   ,				__UpperCAmelCase:				torch.FloatTensor   ,				__UpperCAmelCase:				Union[float, torch.FloatTensor]      )						->    torch.FloatTensor:




											'''simple docstring'''



											if isinstance(__UpperCAmelCase   ,				torch.Tensor      ):
																__a				:	Dict			=				timestep.to(self.timesteps.device      )
											__a				:	Optional[Any]			=				(self.timesteps == timestep).nonzero().item()
											__a				:	List[str]			=				self.sigmas[step_index]
											__a				:	str			=				sample / ((sigma**2 + 1) ** 0.5)
											__a				:	Union[str, Any]			=				True
											return sample



						def 					UpperCAmelCase__				(self:				str   ,				__UpperCAmelCase:				int   ,				__UpperCAmelCase:				Union[str, torch.device] = None      )						->    int:




											'''simple docstring'''



											__a				:	Tuple			=				num_inference_steps

											# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
											if self.config.timestep_spacing == "linspace":
																__a				:	str			=				np.linspace(0   ,				self.config.num_train_timesteps - 1   ,				__UpperCAmelCase   ,				dtype=__UpperCAmelCase      )[
																    ::-1
																].copy()
											elif self.config.timestep_spacing == "leading":
																__a				:	Union[str, Any]			=				self.config.num_train_timesteps // self.num_inference_steps
																# creates integer timesteps by multiplying by ratio
																# casting to int to avoid issues when num_inference_step is power of 3
																__a				:	Dict			=				(np.arange(0   ,				__UpperCAmelCase      ) * step_ratio).round()[::-1].copy().astype(__UpperCAmelCase      )
																timesteps += self.config.steps_offset
											elif self.config.timestep_spacing == "trailing":
																__a				:	Union[str, Any]			=				self.config.num_train_timesteps / self.num_inference_steps
																# creates integer timesteps by multiplying by ratio
																# casting to int to avoid issues when num_inference_step is power of 3
																__a				:	Optional[Any]			=				(np.arange(self.config.num_train_timesteps   ,				0   ,				-step_ratio      )).round().copy().astype(__UpperCAmelCase      )
																timesteps -= 1
											else:
																raise ValueError(
																    f'{self.config.timestep_spacing} is not supported. Please make sure to choose one of \'linspace\', \'leading\' or \'trailing\'.'      )

											__a				:	Optional[int]			=				np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5      )
											__a				:	Dict			=				np.interp(__UpperCAmelCase   ,				np.arange(0   ,				len(__UpperCAmelCase      )      )   ,				__UpperCAmelCase      )
											__a				:	Any			=				np.concatenate([sigmas, [0.0]]      ).astype(np.floataa      )
											__a				:	Tuple			=				torch.from_numpy(__UpperCAmelCase      ).to(device=__UpperCAmelCase      )
											if str(__UpperCAmelCase      ).startswith("mps"      ):
																# mps does not support float64
																__a				:	Dict			=				torch.from_numpy(__UpperCAmelCase      ).to(__UpperCAmelCase   ,				dtype=torch.floataa      )
											else:
																__a				:	str			=				torch.from_numpy(__UpperCAmelCase      ).to(device=__UpperCAmelCase      )



						def 					UpperCAmelCase__				(self:				str   ,				__UpperCAmelCase:				torch.FloatTensor   ,				__UpperCAmelCase:				Union[float, torch.FloatTensor]   ,				__UpperCAmelCase:				torch.FloatTensor   ,				__UpperCAmelCase:				Optional[torch.Generator] = None   ,				__UpperCAmelCase:				bool = True   ,				)						->    Union[EulerAncestralDiscreteSchedulerOutput, Tuple]:




											'''simple docstring'''



											if (
											    isinstance(__UpperCAmelCase   ,				__UpperCAmelCase      )
											    or isinstance(__UpperCAmelCase   ,				torch.IntTensor      )
											    or isinstance(__UpperCAmelCase   ,				torch.LongTensor      )
											):
																raise ValueError(
																    (
																        "Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to"
																        " `EulerDiscreteScheduler.step()` is not supported. Make sure to pass"
																        " one of the `scheduler.timesteps` as a timestep."
																    )   ,				)

											if not self.is_scale_input_called:
																logger.warning(
																    "The `scale_model_input` function should be called before `step` to ensure correct denoising. "
																    "See `StableDiffusionPipeline` for a usage example."      )

											if isinstance(__UpperCAmelCase   ,				torch.Tensor      ):
																__a				:	Optional[int]			=				timestep.to(self.timesteps.device      )

											__a				:	Union[str, Any]			=				(self.timesteps == timestep).nonzero().item()
											__a				:	List[str]			=				self.sigmas[step_index]

											# 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
											if self.config.prediction_type == "epsilon":
																__a				:	Optional[Any]			=				sample - sigma * model_output
											elif self.config.prediction_type == "v_prediction":
																# * c_out + input * c_skip
																__a				:	int			=				model_output * (-sigma / (sigma**2 + 1) ** 0.5) + (sample / (sigma**2 + 1))
											elif self.config.prediction_type == "sample":
																raise NotImplementedError("prediction_type not implemented yet: sample"      )
											else:
																raise ValueError(
																    f'prediction_type given as {self.config.prediction_type} must be one of `epsilon`, or `v_prediction`'      )

											__a				:	Tuple			=				self.sigmas[step_index]
											__a				:	str			=				self.sigmas[step_index + 1]
											__a				:	Union[str, Any]			=				(sigma_to**2 * (sigma_from**2 - sigma_to**2) / sigma_from**2) ** 0.5
											__a				:	Tuple			=				(sigma_to**2 - sigma_up**2) ** 0.5

											# 2. Convert to an ODE derivative
											__a				:	Optional[Any]			=				(sample - pred_original_sample) / sigma

											__a				:	Tuple			=				sigma_down - sigma

											__a				:	List[str]			=				sample + derivative * dt

											__a				:	List[Any]			=				model_output.device
											__a				:	List[Any]			=				randn_tensor(model_output.shape   ,				dtype=model_output.dtype   ,				device=__UpperCAmelCase   ,				generator=__UpperCAmelCase      )

											__a				:	Optional[int]			=				prev_sample + noise * sigma_up

											if not return_dict:
																return (prev_sample,)

											return EulerAncestralDiscreteSchedulerOutput(
											    prev_sample=__UpperCAmelCase   ,				pred_original_sample=__UpperCAmelCase      )



						def 					UpperCAmelCase__				(self:				Optional[int]   ,				__UpperCAmelCase:				torch.FloatTensor   ,				__UpperCAmelCase:				torch.FloatTensor   ,				__UpperCAmelCase:				torch.FloatTensor   ,				)						->    torch.FloatTensor:




											'''simple docstring'''



											__a				:	Optional[Any]			=				self.sigmas.to(device=original_samples.device   ,				dtype=original_samples.dtype      )
											if original_samples.device.type == "mps" and torch.is_floating_point(__UpperCAmelCase      ):
																# mps does not support float64
																__a				:	Union[str, Any]			=				self.timesteps.to(original_samples.device   ,				dtype=torch.floataa      )
																__a				:	List[str]			=				timesteps.to(original_samples.device   ,				dtype=torch.floataa      )
											else:
																__a				:	Any			=				self.timesteps.to(original_samples.device      )
																__a				:	Union[str, Any]			=				timesteps.to(original_samples.device      )

											__a				:	Optional[int]			=				[(schedule_timesteps == t).nonzero().item() for t in timesteps]

											__a				:	int			=				sigmas[step_indices].flatten()
											while len(sigma.shape      ) < len(original_samples.shape      ):
																__a				:	Dict			=				sigma.unsqueeze(-1      )

											__a				:	Union[str, Any]			=				original_samples + noise * sigma
											return noisy_samples



						def __len__(self:				List[str]      )						->    Any:




											'''simple docstring'''



											return self.config.num_train_timesteps













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

						"""simple docstring"""



						def __init__(self:				List[Any]   ,				__UpperCAmelCase:				str   ,				)						->    int:




											'''simple docstring'''



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



						def 					UpperCAmelCase__				(self:				int      )						->    str:




											'''simple docstring'''



											__a				:	Optional[Any]			=				ids_tensor([self.batch_size, self.seq_length]   ,				self.vocab_size      )
											__a				:	Union[str, Any]			=				random_attention_mask([self.batch_size, self.seq_length]   ,				dtype=tf.floataa      )

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

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

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

											__a				:	str			=				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:				int   ,				__UpperCAmelCase:				Union[str, Any]   ,				__UpperCAmelCase:				List[str]   ,				__UpperCAmelCase:				List[str]   ,				__UpperCAmelCase:				List[Any]   ,				__UpperCAmelCase:				int   ,				__UpperCAmelCase:				Dict   ,				__UpperCAmelCase:				Dict   ,				__UpperCAmelCase:				Optional[int]   ,				__UpperCAmelCase:				Any   ,				)						->    List[Any]:




											'''simple docstring'''



											__a				:	Union[str, Any]			=				TFXLMModel(config=__UpperCAmelCase      )
											__a				:	Tuple			=				{"input_ids": input_ids, "lengths": input_lengths, "langs": token_type_ids}
											__a				:	List[str]			=				model(__UpperCAmelCase      )

											__a				:	List[Any]			=				[input_ids, input_mask]
											__a				:	str			=				model(__UpperCAmelCase      )
											self.parent.assertEqual(result.last_hidden_state.shape   ,				(self.batch_size, self.seq_length, self.hidden_size)      )



						def 					UpperCAmelCase__				(self:				Tuple   ,				__UpperCAmelCase:				Optional[Any]   ,				__UpperCAmelCase:				Tuple   ,				__UpperCAmelCase:				int   ,				__UpperCAmelCase:				List[str]   ,				__UpperCAmelCase:				Optional[int]   ,				__UpperCAmelCase:				Dict   ,				__UpperCAmelCase:				Optional[Any]   ,				__UpperCAmelCase:				List[Any]   ,				__UpperCAmelCase:				List[str]   ,				)						->    Union[str, Any]:




											'''simple docstring'''



											__a				:	int			=				TFXLMWithLMHeadModel(__UpperCAmelCase      )

											__a				:	List[Any]			=				{"input_ids": input_ids, "lengths": input_lengths, "langs": token_type_ids}
											__a				:	int			=				model(__UpperCAmelCase      )

											__a				:	int			=				outputs

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



						def 					UpperCAmelCase__				(self:				Optional[int]   ,				__UpperCAmelCase:				Any   ,				__UpperCAmelCase:				Dict   ,				__UpperCAmelCase:				List[str]   ,				__UpperCAmelCase:				Optional[Any]   ,				__UpperCAmelCase:				Dict   ,				__UpperCAmelCase:				List[str]   ,				__UpperCAmelCase:				Union[str, Any]   ,				__UpperCAmelCase:				Optional[Any]   ,				__UpperCAmelCase:				List[Any]   ,				)						->    List[str]:




											'''simple docstring'''



											__a				:	Tuple			=				TFXLMForQuestionAnsweringSimple(__UpperCAmelCase      )

											__a				:	Union[str, Any]			=				{"input_ids": input_ids, "lengths": input_lengths}

											__a				:	int			=				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 					UpperCAmelCase__				(self:				List[Any]   ,				__UpperCAmelCase:				List[str]   ,				__UpperCAmelCase:				Any   ,				__UpperCAmelCase:				List[str]   ,				__UpperCAmelCase:				Optional[int]   ,				__UpperCAmelCase:				Any   ,				__UpperCAmelCase:				str   ,				__UpperCAmelCase:				int   ,				__UpperCAmelCase:				Any   ,				__UpperCAmelCase:				Dict   ,				)						->    str:




											'''simple docstring'''



											__a				:	Dict			=				TFXLMForSequenceClassification(__UpperCAmelCase      )

											__a				:	Union[str, Any]			=				{"input_ids": input_ids, "lengths": input_lengths}

											__a				:	Any			=				model(__UpperCAmelCase      )

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



						def 					UpperCAmelCase__				(self:				Dict   ,				__UpperCAmelCase:				List[str]   ,				__UpperCAmelCase:				Optional[Any]   ,				__UpperCAmelCase:				Dict   ,				__UpperCAmelCase:				str   ,				__UpperCAmelCase:				Optional[int]   ,				__UpperCAmelCase:				Tuple   ,				__UpperCAmelCase:				Tuple   ,				__UpperCAmelCase:				Tuple   ,				__UpperCAmelCase:				int   ,				)						->    int:




											'''simple docstring'''



											__a				:	Optional[int]			=				self.num_labels
											__a				:	Any			=				TFXLMForTokenClassification(config=__UpperCAmelCase      )
											__a				:	Dict			=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
											__a				:	List[Any]			=				model(__UpperCAmelCase      )
											self.parent.assertEqual(result.logits.shape   ,				(self.batch_size, self.seq_length, self.num_labels)      )



						def 					UpperCAmelCase__				(self:				Optional[int]   ,				__UpperCAmelCase:				Dict   ,				__UpperCAmelCase:				List[Any]   ,				__UpperCAmelCase:				Optional[int]   ,				__UpperCAmelCase:				Tuple   ,				__UpperCAmelCase:				List[Any]   ,				__UpperCAmelCase:				Optional[int]   ,				__UpperCAmelCase:				Optional[int]   ,				__UpperCAmelCase:				Optional[int]   ,				__UpperCAmelCase:				Optional[int]   ,				)						->    List[str]:




											'''simple docstring'''



											__a				:	List[str]			=				self.num_choices
											__a				:	str			=				TFXLMForMultipleChoice(config=__UpperCAmelCase      )
											__a				:	List[str]			=				tf.tile(tf.expand_dims(__UpperCAmelCase   ,				1      )   ,				(1, self.num_choices, 1)      )
											__a				:	Tuple			=				tf.tile(tf.expand_dims(__UpperCAmelCase   ,				1      )   ,				(1, self.num_choices, 1)      )
											__a				:	int			=				tf.tile(tf.expand_dims(__UpperCAmelCase   ,				1      )   ,				(1, self.num_choices, 1)      )
											__a				:	Dict			=				{
											    "input_ids": multiple_choice_inputs_ids,
											    "attention_mask": multiple_choice_input_mask,
											    "token_type_ids": multiple_choice_token_type_ids,
											}
											__a				:	Optional[Any]			=				model(__UpperCAmelCase      )
											self.parent.assertEqual(result.logits.shape   ,				(self.batch_size, self.num_choices)      )



						def 					UpperCAmelCase__				(self:				Tuple      )						->    Optional[Any]:




											'''simple docstring'''



											__a				:	Tuple			=				self.prepare_config_and_inputs()
											(
											    (
											    __a
											)			, (
											    __a
											)			, (
											    __a
											)			, (
											    __a
											)			, (
											    __a
											)			, (
											    __a
											)			, (
											    __a
											)			, (
											    __a
											)			, (
											    __a
											)			, 
											)				:	List[Any]			=				config_and_inputs
											__a				:	Optional[Any]			=				{
											    "input_ids": input_ids,
											    "token_type_ids": token_type_ids,
											    "langs": token_type_ids,
											    "lengths": input_lengths,
											}
											return config, inputs_dict




@require_tf
class        snake_case_					(						__UpperCamelCase		,       __UpperCamelCase		,       unittest.TestCase			):

						"""simple docstring"""



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



						def 					UpperCAmelCase__				(self:				Union[str, Any]   ,				__UpperCAmelCase:				Tuple   ,				__UpperCAmelCase:				Tuple   ,				__UpperCAmelCase:				List[Any]   ,				__UpperCAmelCase:				Union[str, Any]   ,				__UpperCAmelCase:				Tuple      )						->    Tuple:




											'''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:				Optional[Any]      )						->    int:




											'''simple docstring'''



											__a				:	List[Any]			=				TFXLMModelTester(self      )
											__a				:	int			=				ConfigTester(self   ,				config_class=__UpperCAmelCase   ,				emb_dim=37      )



						def 					UpperCAmelCase__				(self:				Tuple      )						->    Optional[Any]:




											'''simple docstring'''



											self.config_tester.run_common_tests()



						def 					UpperCAmelCase__				(self:				Any      )						->    int:




											'''simple docstring'''



											__a				:	Optional[int]			=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_xlm_model(*__UpperCAmelCase      )



						def 					UpperCAmelCase__				(self:				Dict      )						->    Dict:




											'''simple docstring'''



											__a				:	str			=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_xlm_lm_head(*__UpperCAmelCase      )



						def 					UpperCAmelCase__				(self:				Optional[int]      )						->    Optional[int]:




											'''simple docstring'''



											__a				:	List[str]			=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_xlm_qa(*__UpperCAmelCase      )



						def 					UpperCAmelCase__				(self:				Optional[Any]      )						->    Any:




											'''simple docstring'''



											__a				:	List[Any]			=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_xlm_sequence_classif(*__UpperCAmelCase      )



						def 					UpperCAmelCase__				(self:				Optional[int]      )						->    Optional[Any]:




											'''simple docstring'''



											__a				:	Any			=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_xlm_for_token_classification(*__UpperCAmelCase      )



						def 					UpperCAmelCase__				(self:				Any      )						->    List[Any]:




											'''simple docstring'''



											__a				:	List[str]			=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_xlm_for_multiple_choice(*__UpperCAmelCase      )



						@slow
						def 					UpperCAmelCase__				(self:				List[str]      )						->    Optional[int]:




											'''simple docstring'''



											for model_name in TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__a				:	Optional[int]			=				TFXLMModel.from_pretrained(__UpperCAmelCase      )
																self.assertIsNotNone(__UpperCAmelCase      )




@require_tf
class        snake_case_					(						unittest.TestCase			):

						"""simple docstring"""



						@slow
						def 					UpperCAmelCase__				(self:				Optional[int]      )						->    str:




											'''simple docstring'''



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





