
import gc
import random
import tempfile
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.stable_diffusion_safe import StableDiffusionPipelineSafe as StableDiffusionPipeline
from diffusers.utils import floats_tensor, nightly, torch_device
from diffusers.utils.testing_utils import require_torch_gpu





class    __A(					unittest.TestCase							):

					def  lowercase__   (						self       :  Any ):
												# clean up the VRAM after each test
												super().tearDown()
												gc.collect()
												torch.cuda.empty_cache()

					@property
					def  lowercase__   (						self       :  Any ):
												lowerCamelCase_					=       1
												lowerCamelCase_					=       3
												lowerCamelCase_					=       (3_2, 3_2)

												lowerCamelCase_					=       floats_tensor((batch_size, num_channels) + sizes ,       rng=random.Random(0 ) ).to(__UpperCamelCase )
												return image

					@property
					def  lowercase__   (						self       :  Any ):
												torch.manual_seed(0 )
												lowerCamelCase_					=       UNetaDConditionModel(
												    block_out_channels=(3_2, 6_4) ,       layers_per_block=2 ,       sample_size=3_2 ,       in_channels=4 ,       out_channels=4 ,       down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""") ,       up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""") ,       cross_attention_dim=3_2 ,       )
												return model

					@property
					def  lowercase__   (						self       :  Optional[Any] ):
												torch.manual_seed(0 )
												lowerCamelCase_					=       AutoencoderKL(
												    block_out_channels=[3_2, 6_4] ,       in_channels=3 ,       out_channels=3 ,       down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""] ,       up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""] ,       latent_channels=4 ,       )
												return model

					@property
					def  lowercase__   (						self       :  List[Any] ):
												torch.manual_seed(0 )
												lowerCamelCase_					=       CLIPTextConfig(
												    bos_token_id=0 ,       eos_token_id=2 ,       hidden_size=3_2 ,       intermediate_size=3_7 ,       layer_norm_eps=1E-05 ,       num_attention_heads=4 ,       num_hidden_layers=5 ,       pad_token_id=1 ,       vocab_size=1_0_0_0 ,       )
												return CLIPTextModel(__UpperCamelCase )

					@property
					def  lowercase__   (						self       :  Optional[int] ):
												def extract(*__UpperCamelCase       :  Optional[int] ,       **__UpperCamelCase       :  Tuple ):





																			class    __A:

																								def __init__(						self       :  Any ):
																															lowerCamelCase_					=       torch.ones([0] )



																								def  lowercase__   (						self       :  Optional[int] ,       __UpperCamelCase       :  List[Any] ):
																															self.pixel_values.to(__UpperCamelCase )
																															return self
																			return Out()

												return extract

					def  lowercase__   (						self       :  Optional[Any] ):
												lowerCamelCase_					=       """cpu"""  # ensure determinism for the device-dependent torch.Generator
												lowerCamelCase_					=       self.dummy_cond_unet
												lowerCamelCase_					=       DDIMScheduler(
												    beta_start=0.00085 ,       beta_end=0.012 ,       beta_schedule="""scaled_linear""" ,       clip_sample=__UpperCamelCase ,       set_alpha_to_one=__UpperCamelCase ,       )

												lowerCamelCase_					=       self.dummy_vae
												lowerCamelCase_					=       self.dummy_text_encoder
												lowerCamelCase_					=       CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip""" )

												# make sure here that pndm scheduler skips prk
												lowerCamelCase_					=       StableDiffusionPipeline(
												    unet=__UpperCamelCase ,       scheduler=__UpperCamelCase ,       vae=__UpperCamelCase ,       text_encoder=__UpperCamelCase ,       tokenizer=__UpperCamelCase ,       safety_checker=__UpperCamelCase ,       feature_extractor=self.dummy_extractor ,       )
												lowerCamelCase_					=       sd_pipe.to(__UpperCamelCase )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase )

												lowerCamelCase_					=       """A painting of a squirrel eating a burger"""

												lowerCamelCase_					=       torch.Generator(device=__UpperCamelCase ).manual_seed(0 )
												lowerCamelCase_					=       sd_pipe([prompt] ,       generator=__UpperCamelCase ,       guidance_scale=6.0 ,       num_inference_steps=2 ,       output_type="""np""" )
												lowerCamelCase_					=       output.images

												lowerCamelCase_					=       torch.Generator(device=__UpperCamelCase ).manual_seed(0 )
												lowerCamelCase_					=       sd_pipe(
												    [prompt] ,       generator=__UpperCamelCase ,       guidance_scale=6.0 ,       num_inference_steps=2 ,       output_type="""np""" ,       return_dict=__UpperCamelCase ,       )[0]

												lowerCamelCase_					=       image[0, -3:, -3:, -1]
												lowerCamelCase_					=       image_from_tuple[0, -3:, -3:, -1]

												assert image.shape == (1, 6_4, 6_4, 3)
												lowerCamelCase_					=       np.array([0.5756, 0.6118, 0.5005, 0.5041, 0.5471, 0.4726, 0.4976, 0.4865, 0.4864] )

												assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-2
												assert np.abs(image_from_tuple_slice.flatten() - expected_slice ).max() < 1E-2

					def  lowercase__   (						self       :  List[Any] ):
												lowerCamelCase_					=       """cpu"""  # ensure determinism for the device-dependent torch.Generator
												lowerCamelCase_					=       self.dummy_cond_unet
												lowerCamelCase_					=       PNDMScheduler(skip_prk_steps=__UpperCamelCase )
												lowerCamelCase_					=       self.dummy_vae
												lowerCamelCase_					=       self.dummy_text_encoder
												lowerCamelCase_					=       CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip""" )

												# make sure here that pndm scheduler skips prk
												lowerCamelCase_					=       StableDiffusionPipeline(
												    unet=__UpperCamelCase ,       scheduler=__UpperCamelCase ,       vae=__UpperCamelCase ,       text_encoder=__UpperCamelCase ,       tokenizer=__UpperCamelCase ,       safety_checker=__UpperCamelCase ,       feature_extractor=self.dummy_extractor ,       )
												lowerCamelCase_					=       sd_pipe.to(__UpperCamelCase )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase )

												lowerCamelCase_					=       """A painting of a squirrel eating a burger"""
												lowerCamelCase_					=       torch.Generator(device=__UpperCamelCase ).manual_seed(0 )
												lowerCamelCase_					=       sd_pipe([prompt] ,       generator=__UpperCamelCase ,       guidance_scale=6.0 ,       num_inference_steps=2 ,       output_type="""np""" )

												lowerCamelCase_					=       output.images

												lowerCamelCase_					=       torch.Generator(device=__UpperCamelCase ).manual_seed(0 )
												lowerCamelCase_					=       sd_pipe(
												    [prompt] ,       generator=__UpperCamelCase ,       guidance_scale=6.0 ,       num_inference_steps=2 ,       output_type="""np""" ,       return_dict=__UpperCamelCase ,       )[0]

												lowerCamelCase_					=       image[0, -3:, -3:, -1]
												lowerCamelCase_					=       image_from_tuple[0, -3:, -3:, -1]

												assert image.shape == (1, 6_4, 6_4, 3)
												lowerCamelCase_					=       np.array([0.5125, 0.5716, 0.4828, 0.5060, 0.5650, 0.4768, 0.5185, 0.4895, 0.4993] )

												assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-2
												assert np.abs(image_from_tuple_slice.flatten() - expected_slice ).max() < 1E-2

					def  lowercase__   (						self       :  List[str] ):
												lowerCamelCase_					=       StableDiffusionPipeline.from_pretrained(
												    """hf-internal-testing/tiny-stable-diffusion-lms-pipe""" ,       safety_checker=__UpperCamelCase )
												assert isinstance(__UpperCamelCase ,       __UpperCamelCase )
												assert isinstance(pipe.scheduler ,       __UpperCamelCase )
												assert pipe.safety_checker is None

												lowerCamelCase_					=       pipe("""example prompt""" ,       num_inference_steps=2 ).images[0]
												assert image is not None

												# check that there's no error when saving a pipeline with one of the models being None
												with tempfile.TemporaryDirectory() as tmpdirname:
																			pipe.save_pretrained(__UpperCamelCase )
																			lowerCamelCase_					=       StableDiffusionPipeline.from_pretrained(__UpperCamelCase )

												# sanity check that the pipeline still works
												assert pipe.safety_checker is None
												lowerCamelCase_					=       pipe("""example prompt""" ,       num_inference_steps=2 ).images[0]
												assert image is not None



					@unittest.skipIf(torch_device != """cuda""" ,       """This test requires a GPU""" )
					def  lowercase__   (						self       :  str ):
												lowerCamelCase_					=       self.dummy_cond_unet
												lowerCamelCase_					=       PNDMScheduler(skip_prk_steps=__UpperCamelCase )
												lowerCamelCase_					=       self.dummy_vae
												lowerCamelCase_					=       self.dummy_text_encoder
												lowerCamelCase_					=       CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip""" )

												# put models in fp16
												lowerCamelCase_					=       unet.half()
												lowerCamelCase_					=       vae.half()
												lowerCamelCase_					=       bert.half()

												# make sure here that pndm scheduler skips prk
												lowerCamelCase_					=       StableDiffusionPipeline(
												    unet=__UpperCamelCase ,       scheduler=__UpperCamelCase ,       vae=__UpperCamelCase ,       text_encoder=__UpperCamelCase ,       tokenizer=__UpperCamelCase ,       safety_checker=__UpperCamelCase ,       feature_extractor=self.dummy_extractor ,       )
												lowerCamelCase_					=       sd_pipe.to(__UpperCamelCase )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase )

												lowerCamelCase_					=       """A painting of a squirrel eating a burger"""
												lowerCamelCase_					=       sd_pipe([prompt] ,       num_inference_steps=2 ,       output_type="""np""" ).images

												assert image.shape == (1, 6_4, 6_4, 3)





@nightly
@require_torch_gpu
class    __A(					unittest.TestCase							):

					def  lowercase__   (						self       :  List[str] ):
												# clean up the VRAM after each test
												super().tearDown()
												gc.collect()
												torch.cuda.empty_cache()

					def  lowercase__   (						self       :  Any ):
												lowerCamelCase_					=       StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5""" ,       safety_checker=__UpperCamelCase )
												lowerCamelCase_					=       LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config )
												lowerCamelCase_					=       sd_pipe.to(__UpperCamelCase )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase )

												lowerCamelCase_					=       (
												    """portrait of girl with smokey eyes makeup in abandoned hotel, grange clothes, redshift, wide high angle"""
												    """ coloured polaroid photograph with flash, kodak film, hyper real, stunning moody cinematography, with"""
												    """ anamorphic lenses, by maripol, fallen angels by wong kar - wai, style of suspiria and neon demon and"""
												    """ children from bahnhof zoo, detailed """
												)
												lowerCamelCase_					=       4_0_0_3_6_6_0_3_4_6
												lowerCamelCase_					=       7

												# without safety guidance (sld_guidance_scale = 0)
												lowerCamelCase_					=       torch.manual_seed(__UpperCamelCase )
												lowerCamelCase_					=       sd_pipe(
												    [prompt] ,       generator=__UpperCamelCase ,       guidance_scale=__UpperCamelCase ,       num_inference_steps=5_0 ,       output_type="""np""" ,       width=5_1_2 ,       height=5_1_2 ,       sld_guidance_scale=0 ,       )

												lowerCamelCase_					=       output.images
												lowerCamelCase_					=       image[0, -3:, -3:, -1]
												lowerCamelCase_					=       [0.2278, 0.2231, 0.2249, 0.2333, 0.2303, 0.1885, 0.2273, 0.2144, 0.2176]

												assert image.shape == (1, 5_1_2, 5_1_2, 3)

												assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-2

												# without safety guidance (strong configuration)
												lowerCamelCase_					=       torch.manual_seed(__UpperCamelCase )
												lowerCamelCase_					=       sd_pipe(
												    [prompt] ,       generator=__UpperCamelCase ,       guidance_scale=__UpperCamelCase ,       num_inference_steps=5_0 ,       output_type="""np""" ,       width=5_1_2 ,       height=5_1_2 ,       sld_guidance_scale=2_0_0_0 ,       sld_warmup_steps=7 ,       sld_threshold=0.025 ,       sld_momentum_scale=0.5 ,       sld_mom_beta=0.7 ,       )

												lowerCamelCase_					=       output.images
												lowerCamelCase_					=       image[0, -3:, -3:, -1]
												lowerCamelCase_					=       [0.2383, 0.2276, 0.236, 0.2192, 0.2186, 0.2053, 0.1971, 0.1901, 0.1719]

												assert image.shape == (1, 5_1_2, 5_1_2, 3)

												assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-2

					def  lowercase__   (						self       :  Optional[int] ):
												lowerCamelCase_					=       StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5""" ,       safety_checker=__UpperCamelCase )
												lowerCamelCase_					=       LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config )
												lowerCamelCase_					=       sd_pipe.to(__UpperCamelCase )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase )

												lowerCamelCase_					=       """padme amidala taking a bath artwork, safe for work, no nudity"""
												lowerCamelCase_					=       2_7_3_4_9_7_1_7_5_5
												lowerCamelCase_					=       7

												lowerCamelCase_					=       torch.manual_seed(__UpperCamelCase )
												lowerCamelCase_					=       sd_pipe(
												    [prompt] ,       generator=__UpperCamelCase ,       guidance_scale=__UpperCamelCase ,       num_inference_steps=5_0 ,       output_type="""np""" ,       width=5_1_2 ,       height=5_1_2 ,       sld_guidance_scale=0 ,       )

												lowerCamelCase_					=       output.images
												lowerCamelCase_					=       image[0, -3:, -3:, -1]
												lowerCamelCase_					=       [0.3502, 0.3622, 0.3396, 0.3642, 0.3478, 0.3318, 0.35, 0.3348, 0.3297]

												assert image.shape == (1, 5_1_2, 5_1_2, 3)

												assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-2

												lowerCamelCase_					=       torch.manual_seed(__UpperCamelCase )
												lowerCamelCase_					=       sd_pipe(
												    [prompt] ,       generator=__UpperCamelCase ,       guidance_scale=__UpperCamelCase ,       num_inference_steps=5_0 ,       output_type="""np""" ,       width=5_1_2 ,       height=5_1_2 ,       sld_guidance_scale=2_0_0_0 ,       sld_warmup_steps=7 ,       sld_threshold=0.025 ,       sld_momentum_scale=0.5 ,       sld_mom_beta=0.7 ,       )

												lowerCamelCase_					=       output.images
												lowerCamelCase_					=       image[0, -3:, -3:, -1]
												lowerCamelCase_					=       [0.5531, 0.5206, 0.4895, 0.5156, 0.5182, 0.4751, 0.4802, 0.4803, 0.4443]

												assert image.shape == (1, 5_1_2, 5_1_2, 3)

												assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-2



					def  lowercase__   (						self       :  List[str] ):
												lowerCamelCase_					=       StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5""" )
												lowerCamelCase_					=       sd_pipe.to(__UpperCamelCase )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase )

												lowerCamelCase_					=       (
												    """the four horsewomen of the apocalypse, painting by tom of finland, gaston bussiere, craig mullins, j. c."""
												    """ leyendecker"""
												)
												lowerCamelCase_					=       1_0_4_4_3_5_5_2_3_4
												lowerCamelCase_					=       1_2

												lowerCamelCase_					=       torch.manual_seed(__UpperCamelCase )
												lowerCamelCase_					=       sd_pipe(
												    [prompt] ,       generator=__UpperCamelCase ,       guidance_scale=__UpperCamelCase ,       num_inference_steps=5_0 ,       output_type="""np""" ,       width=5_1_2 ,       height=5_1_2 ,       sld_guidance_scale=0 ,       )

												lowerCamelCase_					=       output.images
												lowerCamelCase_					=       image[0, -3:, -3:, -1]
												lowerCamelCase_					=       np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] )

												assert image.shape == (1, 5_1_2, 5_1_2, 3)

												assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-7

												lowerCamelCase_					=       torch.manual_seed(__UpperCamelCase )
												lowerCamelCase_					=       sd_pipe(
												    [prompt] ,       generator=__UpperCamelCase ,       guidance_scale=__UpperCamelCase ,       num_inference_steps=5_0 ,       output_type="""np""" ,       width=5_1_2 ,       height=5_1_2 ,       sld_guidance_scale=2_0_0_0 ,       sld_warmup_steps=7 ,       sld_threshold=0.025 ,       sld_momentum_scale=0.5 ,       sld_mom_beta=0.7 ,       )

												lowerCamelCase_					=       output.images
												lowerCamelCase_					=       image[0, -3:, -3:, -1]
												lowerCamelCase_					=       np.array([0.5818, 0.6285, 0.6835, 0.6019, 0.625, 0.6754, 0.6096, 0.6334, 0.6561] )
												assert image.shape == (1, 5_1_2, 5_1_2, 3)

												assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-2







from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 (
		    TFDebertaVaForMaskedLM,
		    TFDebertaVaForQuestionAnswering,
		    TFDebertaVaForSequenceClassification,
		    TFDebertaVaForTokenClassification,
		    TFDebertaVaModel,
		)





class    __A:

					def __init__(						self       :  List[Any] ,       __UpperCamelCase       :  Tuple ,       __UpperCamelCase       :  Any=1_3 ,       __UpperCamelCase       :  Optional[int]=7 ,       __UpperCamelCase       :  Any=True ,       __UpperCamelCase       :  Dict=True ,       __UpperCamelCase       :  Optional[Any]=True ,       __UpperCamelCase       :  Dict=True ,       __UpperCamelCase       :  Union[str, Any]=9_9 ,       __UpperCamelCase       :  List[str]=3_2 ,       __UpperCamelCase       :  int=2 ,       __UpperCamelCase       :  Optional[Any]=4 ,       __UpperCamelCase       :  Optional[int]=3_7 ,       __UpperCamelCase       :  Optional[Any]="gelu" ,       __UpperCamelCase       :  int=0.1 ,       __UpperCamelCase       :  str=0.1 ,       __UpperCamelCase       :  Tuple=5_1_2 ,       __UpperCamelCase       :  Any=1_6 ,       __UpperCamelCase       :  Dict=2 ,       __UpperCamelCase       :  Optional[Any]=0.02 ,       __UpperCamelCase       :  Optional[Any]=False ,       __UpperCamelCase       :  Dict=True ,       __UpperCamelCase       :  Any="None" ,       __UpperCamelCase       :  List[Any]=3 ,       __UpperCamelCase       :  Optional[int]=4 ,       __UpperCamelCase       :  Dict=None ,       ):
												lowerCamelCase_					=       parent
												lowerCamelCase_					=       batch_size
												lowerCamelCase_					=       seq_length
												lowerCamelCase_					=       is_training
												lowerCamelCase_					=       use_input_mask
												lowerCamelCase_					=       use_token_type_ids
												lowerCamelCase_					=       use_labels
												lowerCamelCase_					=       vocab_size
												lowerCamelCase_					=       hidden_size
												lowerCamelCase_					=       num_hidden_layers
												lowerCamelCase_					=       num_attention_heads
												lowerCamelCase_					=       intermediate_size
												lowerCamelCase_					=       hidden_act
												lowerCamelCase_					=       hidden_dropout_prob
												lowerCamelCase_					=       attention_probs_dropout_prob
												lowerCamelCase_					=       max_position_embeddings
												lowerCamelCase_					=       type_vocab_size
												lowerCamelCase_					=       type_sequence_label_size
												lowerCamelCase_					=       initializer_range
												lowerCamelCase_					=       num_labels
												lowerCamelCase_					=       num_choices
												lowerCamelCase_					=       relative_attention
												lowerCamelCase_					=       position_biased_input
												lowerCamelCase_					=       pos_att_type
												lowerCamelCase_					=       scope

					def  lowercase__   (						self       :  Optional[Any] ):
												lowerCamelCase_					=       ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size )

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

												lowerCamelCase_					=       None
												if self.use_token_type_ids:
																			lowerCamelCase_					=       ids_tensor([self.batch_size, self.seq_length] ,       self.type_vocab_size )

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

												lowerCamelCase_					=       DebertaVaConfig(
												    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 ,       type_vocab_size=self.type_vocab_size ,       relative_attention=self.relative_attention ,       position_biased_input=self.position_biased_input ,       initializer_range=self.initializer_range ,       return_dict=__UpperCamelCase ,       )

												return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

					def  lowercase__   (						self       :  str ,       __UpperCamelCase       :  Union[str, Any] ,       __UpperCamelCase       :  Optional[int] ,       __UpperCamelCase       :  Optional[Any] ,       __UpperCamelCase       :  Optional[int] ,       __UpperCamelCase       :  Any ,       __UpperCamelCase       :  int ,       __UpperCamelCase       :  List[str] ):
												lowerCamelCase_					=       TFDebertaVaModel(config=__UpperCamelCase )
												lowerCamelCase_					=       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

												lowerCamelCase_					=       [input_ids, input_mask]
												lowerCamelCase_					=       model(__UpperCamelCase )

												lowerCamelCase_					=       model(__UpperCamelCase )

												self.parent.assertEqual(result.last_hidden_state.shape ,       (self.batch_size, self.seq_length, self.hidden_size) )

					def  lowercase__   (						self       :  Optional[int] ,       __UpperCamelCase       :  List[str] ,       __UpperCamelCase       :  str ,       __UpperCamelCase       :  Dict ,       __UpperCamelCase       :  str ,       __UpperCamelCase       :  List[str] ,       __UpperCamelCase       :  Tuple ,       __UpperCamelCase       :  int ):
												lowerCamelCase_					=       TFDebertaVaForMaskedLM(config=__UpperCamelCase )
												lowerCamelCase_					=       {
												    """input_ids""": input_ids,
												    """attention_mask""": input_mask,
												    """token_type_ids""": token_type_ids,
												}
												lowerCamelCase_					=       model(__UpperCamelCase )
												self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.seq_length, self.vocab_size) )

					def  lowercase__   (						self       :  List[Any] ,       __UpperCamelCase       :  Union[str, Any] ,       __UpperCamelCase       :  str ,       __UpperCamelCase       :  int ,       __UpperCamelCase       :  Optional[int] ,       __UpperCamelCase       :  List[Any] ,       __UpperCamelCase       :  str ,       __UpperCamelCase       :  List[Any] ):
												lowerCamelCase_					=       self.num_labels
												lowerCamelCase_					=       TFDebertaVaForSequenceClassification(config=__UpperCamelCase )
												lowerCamelCase_					=       {
												    """input_ids""": input_ids,
												    """attention_mask""": input_mask,
												    """token_type_ids""": token_type_ids,
												}

												lowerCamelCase_					=       model(__UpperCamelCase )
												self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.num_labels) )

					def  lowercase__   (						self       :  int ,       __UpperCamelCase       :  Tuple ,       __UpperCamelCase       :  Any ,       __UpperCamelCase       :  str ,       __UpperCamelCase       :  Optional[int] ,       __UpperCamelCase       :  List[str] ,       __UpperCamelCase       :  List[Any] ,       __UpperCamelCase       :  List[Any] ):
												lowerCamelCase_					=       self.num_labels
												lowerCamelCase_					=       TFDebertaVaForTokenClassification(config=__UpperCamelCase )
												lowerCamelCase_					=       {
												    """input_ids""": input_ids,
												    """attention_mask""": input_mask,
												    """token_type_ids""": token_type_ids,
												}
												lowerCamelCase_					=       model(__UpperCamelCase )
												self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.seq_length, self.num_labels) )

					def  lowercase__   (						self       :  List[Any] ,       __UpperCamelCase       :  Optional[int] ,       __UpperCamelCase       :  Optional[Any] ,       __UpperCamelCase       :  Optional[int] ,       __UpperCamelCase       :  str ,       __UpperCamelCase       :  Optional[Any] ,       __UpperCamelCase       :  List[str] ,       __UpperCamelCase       :  int ):
												lowerCamelCase_					=       TFDebertaVaForQuestionAnswering(config=__UpperCamelCase )
												lowerCamelCase_					=       {
												    """input_ids""": input_ids,
												    """attention_mask""": input_mask,
												    """token_type_ids""": token_type_ids,
												}

												lowerCamelCase_					=       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  lowercase__   (						self       :  Dict ):
												lowerCamelCase_					=       self.prepare_config_and_inputs()
												(
												    (
												    lowerCamelCase_
												)	, (
												    lowerCamelCase_
												)	, (
												    lowerCamelCase_
												)	, (
												    lowerCamelCase_
												)	, (
												    lowerCamelCase_
												)	, (
												    lowerCamelCase_
												)	, (
												    lowerCamelCase_
												)	, 
												)					=       config_and_inputs
												lowerCamelCase_					=       {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
												return config, inputs_dict





@require_tf
class    __A(					UpperCAmelCase  ,		UpperCAmelCase  ,		unittest.TestCase							):
					SCREAMING_SNAKE_CASE           =     (
					    (
					        TFDebertaVaModel,
					        TFDebertaVaForMaskedLM,
					        TFDebertaVaForQuestionAnswering,
					        TFDebertaVaForSequenceClassification,
					        TFDebertaVaForTokenClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					SCREAMING_SNAKE_CASE           =     (
					    {
					        '''feature-extraction''': TFDebertaVaModel,
					        '''fill-mask''': TFDebertaVaForMaskedLM,
					        '''question-answering''': TFDebertaVaForQuestionAnswering,
					        '''text-classification''': TFDebertaVaForSequenceClassification,
					        '''token-classification''': TFDebertaVaForTokenClassification,
					        '''zero-shot''': TFDebertaVaForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)

					SCREAMING_SNAKE_CASE           =     False
					SCREAMING_SNAKE_CASE           =     False

					def  lowercase__   (						self       :  Dict ):
												lowerCamelCase_					=       TFDebertaVaModelTester(self )
												lowerCamelCase_					=       ConfigTester(self ,       config_class=__UpperCamelCase ,       hidden_size=3_7 )

					def  lowercase__   (						self       :  Dict ):
												self.config_tester.run_common_tests()

					def  lowercase__   (						self       :  Optional[Any] ):
												lowerCamelCase_					=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*__UpperCamelCase )

					def  lowercase__   (						self       :  Dict ):
												lowerCamelCase_					=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_masked_lm(*__UpperCamelCase )

					def  lowercase__   (						self       :  List[Any] ):
												lowerCamelCase_					=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_question_answering(*__UpperCamelCase )

					def  lowercase__   (						self       :  Tuple ):
												lowerCamelCase_					=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_sequence_classification(*__UpperCamelCase )

					def  lowercase__   (						self       :  Any ):
												lowerCamelCase_					=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_token_classification(*__UpperCamelCase )



					@slow
					def  lowercase__   (						self       :  int ):
												lowerCamelCase_					=       TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge""" )
												self.assertIsNotNone(__UpperCamelCase )





@require_tf
class    __A(					unittest.TestCase							):

					@unittest.skip(reason="""Model not available yet""" )
					def  lowercase__   (						self       :  Optional[int] ):
												pass



					@slow
					def  lowercase__   (						self       :  Any ):
												lowerCamelCase_					=       TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge""" )
												lowerCamelCase_					=       tf.constant([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]] )
												lowerCamelCase_					=       tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
												lowerCamelCase_					=       model(__UpperCamelCase ,       attention_mask=__UpperCamelCase )[0]

												lowerCamelCase_					=       tf.constant(
												    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]] )
												tf.debugging.assert_near(output[:, 1:4, 1:4] ,       __UpperCamelCase ,       atol=1E-4 )





