




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

import numpy as np
import torch
from scipy import integrate

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


@dataclass
# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput with DDPM->LMSDiscrete
class     __SCREAMING_SNAKE_CASE							(		A__  ):
					_lowerCamelCase		  =			42
					_lowerCamelCase		  =			None






def  snake_case (							A						,       A=0.999						,       A="cosine"						,       )							->							Dict:




	'''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}"      )

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



class     __SCREAMING_SNAKE_CASE							(		A__       ,					A__  ):
					_lowerCamelCase		  =			[e.name for e in KarrasDiffusionSchedulers]
					_lowerCamelCase		  =			1

					@register_to_config
					def __init__(    self			,	__lowercase = 1_000			,	__lowercase = 0.00_01			,	__lowercase = 0.02			,	__lowercase = "linear"			,	__lowercase = None			,	__lowercase = False			,	__lowercase = "epsilon"			,	__lowercase = "linspace"			,	__lowercase = 0			,	):







						'''simple docstring'''




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

						lowerCamelCase_							:		Tuple							       =							1.0 - self.betas
						lowerCamelCase_							:		int							       =							torch.cumprod(self.alphas			,	dim=0 )

						lowerCamelCase_							:		Dict							       =							np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5 )
						lowerCamelCase_							:		Tuple							       =							np.concatenate([sigmas[::-1], [0.0]] ).astype(np.floataa )
						lowerCamelCase_							:		Optional[Any]							       =							torch.from_numpy(snake_case_ )

						# setable values
						lowerCamelCase_							:		Optional[Any]							       =							None
						lowerCamelCase_							:		List[Any]							       =							use_karras_sigmas
						self.set_timesteps(snake_case_			,	snake_case_ )
						lowerCamelCase_							:		Any							       =							[]
						lowerCamelCase_							:		str							       =							False

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




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

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

					def      lowercase_							(    self			,	__lowercase			,	__lowercase ):







						'''simple docstring'''




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

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase ):







						'''simple docstring'''




						def lms_derivative(__lowercase ):
							lowerCamelCase_							:		Optional[int]							       =							1.0
							for k in range(snake_case_ ):
								if current_order == k:
									continue
								prod *= (tau - self.sigmas[t - k]) / (self.sigmas[t - current_order] - self.sigmas[t - k])
							return prod

						lowerCamelCase_							:		Any							       =							integrate.quad(snake_case_			,	self.sigmas[t]			,	self.sigmas[t + 1]			,	epsrel=1E-4 )[0]

						return integrated_coeff

					def      lowercase_							(    self			,	__lowercase			,	__lowercase = None ):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							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":
							lowerCamelCase_							:		Any							       =							np.linspace(0			,	self.config.num_train_timesteps - 1			,	snake_case_			,	dtype=snake_case_ )[
							    ::-1
							].copy()
						elif self.config.timestep_spacing == "leading":
							lowerCamelCase_							:		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
							lowerCamelCase_							:		Tuple							       =							(np.arange(0			,	snake_case_ ) * step_ratio).round()[::-1].copy().astype(snake_case_ )
							timesteps += self.config.steps_offset
						elif self.config.timestep_spacing == "trailing":
							lowerCamelCase_							:		List[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
							lowerCamelCase_							:		List[str]							       =							(np.arange(self.config.num_train_timesteps			,	0			,	-step_ratio )).round().copy().astype(snake_case_ )
							timesteps -= 1
						else:
							raise ValueError(
							    f"{self.config.timestep_spacing} is not supported. Please make sure to choose one of 'linspace', 'leading' or 'trailing'." )

						lowerCamelCase_							:		str							       =							np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5 )
						lowerCamelCase_							:		List[str]							       =							np.log(snake_case_ )
						lowerCamelCase_							:		Dict							       =							np.interp(snake_case_			,	np.arange(0			,	len(snake_case_ ) )			,	snake_case_ )

						if self.use_karras_sigmas:
							lowerCamelCase_							:		Dict							       =							self._convert_to_karras(in_sigmas=snake_case_ )
							lowerCamelCase_							:		Dict							       =							np.array([self._sigma_to_t(snake_case_			,	snake_case_ ) for sigma in sigmas] )

						lowerCamelCase_							:		Union[str, Any]							       =							np.concatenate([sigmas, [0.0]] ).astype(np.floataa )

						lowerCamelCase_							:		Optional[Any]							       =							torch.from_numpy(snake_case_ ).to(device=snake_case_ )
						if str(snake_case_ ).startswith('mps' ):
							# mps does not support float64
							lowerCamelCase_							:		Dict							       =							torch.from_numpy(snake_case_ ).to(snake_case_			,	dtype=torch.floataa )
						else:
							lowerCamelCase_							:		Tuple							       =							torch.from_numpy(snake_case_ ).to(device=snake_case_ )

						lowerCamelCase_							:		Tuple							       =							[]

					def      lowercase_							(    self			,	__lowercase			,	__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							np.log(snake_case_ )

						# get distribution
						lowerCamelCase_							:		Union[str, Any]							       =							log_sigma - log_sigmas[:, np.newaxis]

						# get sigmas range
						lowerCamelCase_							:		Optional[Any]							       =							np.cumsum((dists >= 0)			,	axis=0 ).argmax(axis=0 ).clip(max=log_sigmas.shape[0] - 2 )
						lowerCamelCase_							:		Union[str, Any]							       =							low_idx + 1

						lowerCamelCase_							:		Dict							       =							log_sigmas[low_idx]
						lowerCamelCase_							:		Dict							       =							log_sigmas[high_idx]

						# interpolate sigmas
						lowerCamelCase_							:		Optional[Any]							       =							(low - log_sigma) / (low - high)
						lowerCamelCase_							:		int							       =							np.clip(snake_case_			,	0			,	1 )

						# transform interpolation to time range
						lowerCamelCase_							:		Tuple							       =							(1 - w) * low_idx + w * high_idx
						lowerCamelCase_							:		Optional[int]							       =							t.reshape(sigma.shape )
						return t

					def      lowercase_							(    self			,	__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							in_sigmas[-1].item()
						lowerCamelCase_							:		List[str]							       =							in_sigmas[0].item()

						lowerCamelCase_							:		Union[str, Any]							       =							7.0  # 7.0 is the value used in the paper
						lowerCamelCase_							:		int							       =							np.linspace(0			,	1			,	self.num_inference_steps )
						lowerCamelCase_							:		Union[str, Any]							       =							sigma_min ** (1 / rho)
						lowerCamelCase_							:		str							       =							sigma_max ** (1 / rho)
						lowerCamelCase_							:		int							       =							(max_inv_rho + ramp * (min_inv_rho - max_inv_rho)) ** rho
						return sigmas

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase = 4			,	__lowercase = True			,	):







						'''simple docstring'''




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

						if isinstance(snake_case_			,	torch.Tensor ):
							lowerCamelCase_							:		List[Any]							       =							timestep.to(self.timesteps.device )
						lowerCamelCase_							:		Tuple							       =							(self.timesteps == timestep).nonzero().item()
						lowerCamelCase_							:		Dict							       =							self.sigmas[step_index]

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

						# 2. Convert to an ODE derivative
						lowerCamelCase_							:		Dict							       =							(sample - pred_original_sample) / sigma
						self.derivatives.append(snake_case_ )
						if len(self.derivatives ) > order:
							self.derivatives.pop(0 )

						# 3. Compute linear multistep coefficients
						lowerCamelCase_							:		Tuple							       =							min(step_index + 1			,	snake_case_ )
						lowerCamelCase_							:		str							       =							[self.get_lms_coefficient(snake_case_			,	snake_case_			,	snake_case_ ) for curr_order in range(snake_case_ )]

						# 4. Compute previous sample based on the derivatives path
						lowerCamelCase_							:		str							       =							sample + sum(
						    coeff * derivative for coeff, derivative in zip(snake_case_			,	reversed(self.derivatives ) ) )

						if not return_dict:
							return (prev_sample,)

						return LMSDiscreteSchedulerOutput(prev_sample=snake_case_			,	pred_original_sample=snake_case_ )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




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

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

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

						lowerCamelCase_							:		List[Any]							       =							original_samples + noise * sigma
						return noisy_samples





					def __len__(    self ):







						'''simple docstring'''




						return self.config.num_train_timesteps






from __future__ import annotations

import unittest

from transformers import MPNetConfig, 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.models.mpnet.modeling_tf_mpnet import (
							    TFMPNetForMaskedLM,
							    TFMPNetForMultipleChoice,
							    TFMPNetForQuestionAnswering,
							    TFMPNetForSequenceClassification,
							    TFMPNetForTokenClassification,
							    TFMPNetModel,
							)


class     __SCREAMING_SNAKE_CASE							:

					def __init__(    self			,	__lowercase			,	__lowercase=13			,	__lowercase=7			,	__lowercase=True			,	__lowercase=True			,	__lowercase=False			,	__lowercase=True			,	__lowercase=99			,	__lowercase=64			,	__lowercase=2			,	__lowercase=4			,	__lowercase=64			,	__lowercase="gelu"			,	__lowercase=0.1			,	__lowercase=0.1			,	__lowercase=512			,	__lowercase=16			,	__lowercase=2			,	__lowercase=0.02			,	__lowercase=3			,	__lowercase=4			,	__lowercase=None			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Union[str, Any]							       =							parent
						lowerCamelCase_							:		Optional[Any]							       =							batch_size
						lowerCamelCase_							:		Union[str, Any]							       =							seq_length
						lowerCamelCase_							:		Optional[int]							       =							is_training
						lowerCamelCase_							:		Optional[int]							       =							use_input_mask
						lowerCamelCase_							:		str							       =							use_token_type_ids
						lowerCamelCase_							:		Optional[int]							       =							use_labels
						lowerCamelCase_							:		Dict							       =							vocab_size
						lowerCamelCase_							:		List[str]							       =							hidden_size
						lowerCamelCase_							:		Any							       =							num_hidden_layers
						lowerCamelCase_							:		int							       =							num_attention_heads
						lowerCamelCase_							:		Any							       =							intermediate_size
						lowerCamelCase_							:		Union[str, Any]							       =							hidden_act
						lowerCamelCase_							:		Any							       =							hidden_dropout_prob
						lowerCamelCase_							:		str							       =							attention_probs_dropout_prob
						lowerCamelCase_							:		Optional[Any]							       =							max_position_embeddings
						lowerCamelCase_							:		Dict							       =							type_vocab_size
						lowerCamelCase_							:		Any							       =							type_sequence_label_size
						lowerCamelCase_							:		Any							       =							initializer_range
						lowerCamelCase_							:		Tuple							       =							num_labels
						lowerCamelCase_							:		List[str]							       =							num_choices
						lowerCamelCase_							:		Optional[Any]							       =							scope

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		List[str]							       =							ids_tensor([self.batch_size, self.seq_length]			,	self.vocab_size )

						lowerCamelCase_							:		Optional[int]							       =							None
						if self.use_input_mask:
							lowerCamelCase_							:		List[Any]							       =							random_attention_mask([self.batch_size, self.seq_length] )

						lowerCamelCase_							:		Optional[Any]							       =							None
						lowerCamelCase_							:		Any							       =							None
						lowerCamelCase_							:		int							       =							None
						if self.use_labels:
							lowerCamelCase_							:		int							       =							ids_tensor([self.batch_size]			,	self.type_sequence_label_size )
							lowerCamelCase_							:		Optional[Any]							       =							ids_tensor([self.batch_size, self.seq_length]			,	self.num_labels )
							lowerCamelCase_							:		str							       =							ids_tensor([self.batch_size]			,	self.num_choices )

						lowerCamelCase_							:		Any							       =							MPNetConfig(
						    vocab_size=self.vocab_size			,	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			,	max_position_embeddings=self.max_position_embeddings			,	initializer_range=self.initializer_range			,	)
						return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[Any]							       =							TFMPNetModel(config=__lowercase )
						lowerCamelCase_							:		str							       =							{'input_ids': input_ids, 'attention_mask': input_mask}
						lowerCamelCase_							:		str							       =							model(__lowercase )
						lowerCamelCase_							:		Dict							       =							[input_ids, input_mask]
						lowerCamelCase_							:		Dict							       =							model(__lowercase )
						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.hidden_size) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[int]							       =							TFMPNetForMaskedLM(config=__lowercase )
						lowerCamelCase_							:		List[Any]							       =							{'input_ids': input_ids, 'attention_mask': input_mask}
						lowerCamelCase_							:		int							       =							model(__lowercase )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		List[str]							       =							TFMPNetForQuestionAnswering(config=__lowercase )
						lowerCamelCase_							:		Tuple							       =							{
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						}
						lowerCamelCase_							:		Optional[Any]							       =							model(__lowercase )
						self.parent.assertEqual(result.start_logits.shape			,	(self.batch_size, self.seq_length) )
						self.parent.assertEqual(result.end_logits.shape			,	(self.batch_size, self.seq_length) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		List[str]							       =							self.num_labels
						lowerCamelCase_							:		Union[str, Any]							       =							TFMPNetForSequenceClassification(__lowercase )
						lowerCamelCase_							:		Union[str, Any]							       =							{'input_ids': input_ids, 'attention_mask': input_mask}
						lowerCamelCase_							:		List[Any]							       =							model(__lowercase )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.num_labels) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		str							       =							self.num_choices
						lowerCamelCase_							:		Tuple							       =							TFMPNetForMultipleChoice(__lowercase )
						lowerCamelCase_							:		Dict							       =							tf.tile(tf.expand_dims(__lowercase			,	1 )			,	(1, self.num_choices, 1) )
						lowerCamelCase_							:		Any							       =							tf.tile(tf.expand_dims(__lowercase			,	1 )			,	(1, self.num_choices, 1) )
						lowerCamelCase_							:		Optional[Any]							       =							{
						    'input_ids': multiple_choice_inputs_ids,
						    'attention_mask': multiple_choice_input_mask,
						}
						lowerCamelCase_							:		Union[str, Any]							       =							model(__lowercase )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.num_choices) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							self.num_labels
						lowerCamelCase_							:		str							       =							TFMPNetForTokenClassification(__lowercase )
						lowerCamelCase_							:		Any							       =							{'input_ids': input_ids, 'attention_mask': input_mask}
						lowerCamelCase_							:		str							       =							model(__lowercase )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.num_labels) )





					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							self.prepare_config_and_inputs()
						((lowerCamelCase_)       ,      (lowerCamelCase_)       ,      (lowerCamelCase_)       ,      (lowerCamelCase_)       ,      (lowerCamelCase_)       ,      (lowerCamelCase_))							:		Tuple							       =							config_and_inputs
						lowerCamelCase_							:		str							       =							{'input_ids': input_ids, 'attention_mask': input_mask}
						return config, inputs_dict


@require_tf
class     __SCREAMING_SNAKE_CASE							(		lowerCamelCase       ,					lowerCamelCase       ,					unittest.TestCase  ):
					_lowerCamelCase		  =			(
					    (
					        TFMPNetForMaskedLM,
					        TFMPNetForMultipleChoice,
					        TFMPNetForQuestionAnswering,
					        TFMPNetForSequenceClassification,
					        TFMPNetForTokenClassification,
					        TFMPNetModel,
					    )
					    if is_tf_available()
					    else ()
					)
					_lowerCamelCase		  =			(
					    {
					        """feature-extraction""": TFMPNetModel,
					        """fill-mask""": TFMPNetForMaskedLM,
					        """question-answering""": TFMPNetForQuestionAnswering,
					        """text-classification""": TFMPNetForSequenceClassification,
					        """token-classification""": TFMPNetForTokenClassification,
					        """zero-shot""": TFMPNetForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					_lowerCamelCase		  =			False
					_lowerCamelCase		  =			False

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							TFMPNetModelTester(self )
						lowerCamelCase_							:		str							       =							ConfigTester(self			,	config_class=__lowercase			,	hidden_size=37 )

					def      lowercase_							(    self ):







						'''simple docstring'''




						self.config_tester.run_common_tests()

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		str							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_model(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_masked_lm(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Union[str, Any]							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_question_answering(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_sequence_classification(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_multiple_choice(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Tuple							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_token_classification(*__lowercase )





					@slow
					def      lowercase_							(    self ):







						'''simple docstring'''




						for model_name in ["microsoft/mpnet-base"]:
							lowerCamelCase_							:		str							       =							TFMPNetModel.from_pretrained(__lowercase )
							self.assertIsNotNone(__lowercase )


@require_tf
class     __SCREAMING_SNAKE_CASE							(		unittest.TestCase  ):

					@slow
					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		int							       =							TFMPNetModel.from_pretrained('microsoft/mpnet-base' )
						lowerCamelCase_							:		Optional[int]							       =							tf.constant([[0, 1, 2, 3, 4, 5]] )
						lowerCamelCase_							:		str							       =							model(__lowercase )[0]

						lowerCamelCase_							:		List[Any]							       =							[1, 6, 768]
						self.assertEqual(output.shape			,	__lowercase )

						lowerCamelCase_							:		Any							       =							tf.constant(
						    [
						        [
						            [-0.1_06_71_72, 0.08_21_64_73, 0.0_02_45_43],
						            [-0.03_46_58_79, 0.8_35_41_18, -0.03_25_22_88],
						            [-0.06_56_94_76, -0.12_42_41_11, -0.0_49_44_36],
						        ]
						    ] )
						tf.debugging.assert_near(output[:, :3, :3]			,	__lowercase			,	atol=1E-4 )
