
"""simple docstring"""



import argparse
import json

import requests
import torch
from huggingface_hub import hf_hub_download
from PIL import Image

from transformers import ViTImageProcessor, ViTMSNConfig, ViTMSNModel
from transformers.image_utils import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD


torch.set_grad_enabled(False)






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Optional[int]     ,  SCREAMING_SNAKE_CASE:					int=False						):






							"""simple docstring"""



							_lowerCAmelCase  	=			[]
							for i in range(config.num_hidden_layers						):
														# encoder layers: output projection, 2 feedforward neural networks and 2 layernorms
														rename_keys.append((f"""module.blocks.{i}.norm1.weight""", f"""vit.encoder.layer.{i}.layernorm_before.weight""")						)
														rename_keys.append((f"""module.blocks.{i}.norm1.bias""", f"""vit.encoder.layer.{i}.layernorm_before.bias""")						)
														rename_keys.append(
														    (f"""module.blocks.{i}.attn.proj.weight""", f"""vit.encoder.layer.{i}.attention.output.dense.weight""")						)
														rename_keys.append((f"""module.blocks.{i}.attn.proj.bias""", f"""vit.encoder.layer.{i}.attention.output.dense.bias""")						)
														rename_keys.append((f"""module.blocks.{i}.norm2.weight""", f"""vit.encoder.layer.{i}.layernorm_after.weight""")						)
														rename_keys.append((f"""module.blocks.{i}.norm2.bias""", f"""vit.encoder.layer.{i}.layernorm_after.bias""")						)
														rename_keys.append((f"""module.blocks.{i}.mlp.fc1.weight""", f"""vit.encoder.layer.{i}.intermediate.dense.weight""")						)
														rename_keys.append((f"""module.blocks.{i}.mlp.fc1.bias""", f"""vit.encoder.layer.{i}.intermediate.dense.bias""")						)
														rename_keys.append((f"""module.blocks.{i}.mlp.fc2.weight""", f"""vit.encoder.layer.{i}.output.dense.weight""")						)
														rename_keys.append((f"""module.blocks.{i}.mlp.fc2.bias""", f"""vit.encoder.layer.{i}.output.dense.bias""")						)

							# projection layer + position embeddings
							rename_keys.extend(
							    [
							        ('module.cls_token', 'vit.embeddings.cls_token'),
							        ('module.patch_embed.proj.weight', 'vit.embeddings.patch_embeddings.projection.weight'),
							        ('module.patch_embed.proj.bias', 'vit.embeddings.patch_embeddings.projection.bias'),
							        ('module.pos_embed', 'vit.embeddings.position_embeddings'),
							    ]						)

							if base_model:
														# layernorm + pooler
														rename_keys.extend(
														    [
														        ('module.norm.weight', 'layernorm.weight'),
														        ('module.norm.bias', 'layernorm.bias'),
														    ]						)

														# if just the base model, we should remove "vit" from all keys that start with "vit"
														_lowerCAmelCase  	=			[(pair[0], pair[1][4:]) if pair[1].startswith('vit'						) else pair for pair in rename_keys]
							else:
														# layernorm + classification head
														rename_keys.extend(
														    [
														        ('norm.weight', 'vit.layernorm.weight'),
														        ('norm.bias', 'vit.layernorm.bias'),
														        ('head.weight', 'classifier.weight'),
														        ('head.bias', 'classifier.bias'),
														    ]						)

							return rename_keys






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Optional[int]     ,  SCREAMING_SNAKE_CASE:					str     ,  SCREAMING_SNAKE_CASE:					Tuple=False						):






							"""simple docstring"""



							for i in range(config.num_hidden_layers						):
														if base_model:
																					_lowerCAmelCase  	=			""""""
														else:
																					_lowerCAmelCase  	=			"""vit."""
														# read in weights + bias of input projection layer (in timm, this is a single matrix + bias)
														_lowerCAmelCase  	=			state_dict.pop(f"""module.blocks.{i}.attn.qkv.weight"""						)
														_lowerCAmelCase  	=			state_dict.pop(f"""module.blocks.{i}.attn.qkv.bias"""						)
														# next, add query, keys and values (in that order) to the state dict
														_lowerCAmelCase  	=			in_proj_weight[
														    : config.hidden_size, :
														]
														_lowerCAmelCase  	=			in_proj_bias[: config.hidden_size]
														_lowerCAmelCase  	=			in_proj_weight[
														    config.hidden_size : config.hidden_size * 2, :
														]
														_lowerCAmelCase  	=			in_proj_bias[
														    config.hidden_size : config.hidden_size * 2
														]
														_lowerCAmelCase  	=			in_proj_weight[
														    -config.hidden_size :, :
														]
														_lowerCAmelCase  	=			in_proj_bias[-config.hidden_size :]






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Optional[Any]						):






							"""simple docstring"""



							_lowerCAmelCase  	=			["""head.weight""", """head.bias"""]
							for k in ignore_keys:
														state_dict.pop(__UpperCamelCase     ,  __UpperCamelCase						)






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Tuple						):






							"""simple docstring"""



							_lowerCAmelCase  	=			[
							    """module.fc.fc1.weight""",
							    """module.fc.fc1.bias""",
							    """module.fc.bn1.weight""",
							    """module.fc.bn1.bias""",
							    """module.fc.bn1.running_mean""",
							    """module.fc.bn1.running_var""",
							    """module.fc.bn1.num_batches_tracked""",
							    """module.fc.fc2.weight""",
							    """module.fc.fc2.bias""",
							    """module.fc.bn2.weight""",
							    """module.fc.bn2.bias""",
							    """module.fc.bn2.running_mean""",
							    """module.fc.bn2.running_var""",
							    """module.fc.bn2.num_batches_tracked""",
							    """module.fc.fc3.weight""",
							    """module.fc.fc3.bias""",
							]
							for k in ignore_keys:
														state_dict.pop(__UpperCamelCase     ,  __UpperCamelCase						)






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Union[str, Any]     ,  SCREAMING_SNAKE_CASE:					int     ,  SCREAMING_SNAKE_CASE:					List[Any]						):






							"""simple docstring"""



							_lowerCAmelCase  	=			dct.pop(__UpperCamelCase						)
							_lowerCAmelCase  	=			val






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					int     ,  SCREAMING_SNAKE_CASE:					Tuple						):






							"""simple docstring"""



							_lowerCAmelCase  	=			ViTMSNConfig()
							_lowerCAmelCase  	=			1000

							_lowerCAmelCase  	=			"""datasets/huggingface/label-files"""
							_lowerCAmelCase  	=			"""imagenet-1k-id2label.json"""
							_lowerCAmelCase  	=			json.load(open(hf_hub_download(__UpperCamelCase     ,  __UpperCamelCase						)     ,  'r'						)						)
							_lowerCAmelCase  	=			{int(__UpperCamelCase						): v for k, v in idalabel.items()}
							_lowerCAmelCase  	=			idalabel
							_lowerCAmelCase  	=			{v: k for k, v in idalabel.items()}

							if "s16" in checkpoint_url:
														_lowerCAmelCase  	=			384
														_lowerCAmelCase  	=			1536
														_lowerCAmelCase  	=			6
							elif "l16" in checkpoint_url:
														_lowerCAmelCase  	=			1024
														_lowerCAmelCase  	=			4096
														_lowerCAmelCase  	=			24
														_lowerCAmelCase  	=			16
														_lowerCAmelCase  	=			0.1
							elif "b4" in checkpoint_url:
														_lowerCAmelCase  	=			4
							elif "l7" in checkpoint_url:
														_lowerCAmelCase  	=			7
														_lowerCAmelCase  	=			1024
														_lowerCAmelCase  	=			4096
														_lowerCAmelCase  	=			24
														_lowerCAmelCase  	=			16
														_lowerCAmelCase  	=			0.1

							_lowerCAmelCase  	=			ViTMSNModel(__UpperCamelCase						)

							_lowerCAmelCase  	=			torch.hub.load_state_dict_from_url(__UpperCamelCase     ,  map_location='cpu'						)["""target_encoder"""]

							_lowerCAmelCase  	=			ViTImageProcessor(size=config.image_size						)

							remove_projection_head(__UpperCamelCase						)
							_lowerCAmelCase  	=			create_rename_keys(__UpperCamelCase     ,  base_model=__UpperCamelCase						)

							for src, dest in rename_keys:
														rename_key(__UpperCamelCase     ,  __UpperCamelCase     ,  __UpperCamelCase						)
							read_in_q_k_v(__UpperCamelCase     ,  __UpperCamelCase     ,  base_model=__UpperCamelCase						)

							model.load_state_dict(__UpperCamelCase						)
							model.eval()

							_lowerCAmelCase  	=			"""http://images.cocodataset.org/val2017/000000039769.jpg"""

							_lowerCAmelCase  	=			Image.open(requests.get(__UpperCamelCase     ,  stream=__UpperCamelCase						).raw						)
							_lowerCAmelCase  	=			ViTImageProcessor(
							    size=config.image_size     ,  image_mean=__UpperCamelCase     ,  image_std=__UpperCamelCase						)
							_lowerCAmelCase  	=			image_processor(images=__UpperCamelCase     ,  return_tensors='pt'						)

							# forward pass
							torch.manual_seed(2						)
							_lowerCAmelCase  	=			model(**__UpperCamelCase						)
							_lowerCAmelCase  	=			outputs.last_hidden_state

							# The following Colab Notebook was used to generate these outputs:
							# https://colab.research.google.com/gist/sayakpaul/3672419a04f5997827503fd84079bdd1/scratchpad.ipynb
							if "s16" in checkpoint_url:
														_lowerCAmelCase  	=			torch.tensor([[-1.09_15, -1.48_76, -1.18_09]]						)
							elif "b16" in checkpoint_url:
														_lowerCAmelCase  	=			torch.tensor([[14.28_89, -18.90_45, 11.72_81]]						)
							elif "l16" in checkpoint_url:
														_lowerCAmelCase  	=			torch.tensor([[41.50_28, -22.86_81, 45.64_75]]						)
							elif "b4" in checkpoint_url:
														_lowerCAmelCase  	=			torch.tensor([[-4.38_68, 5.29_32, -0.41_37]]						)
							else:
														_lowerCAmelCase  	=			torch.tensor([[-0.17_92, -0.64_65, 2.42_63]]						)

							# verify logits
							assert torch.allclose(last_hidden_state[:, 0, :3]     ,  __UpperCamelCase     ,  atol=1e-4						)

							print(f"""Saving model to {pytorch_dump_folder_path}"""						)
							model.save_pretrained(__UpperCamelCase						)

							print(f"""Saving image processor to {pytorch_dump_folder_path}"""						)
							image_processor.save_pretrained(__UpperCamelCase						)


if __name__ == "__main__":
		_snake_case          =						argparse.ArgumentParser()
		# Required parameters
		parser.add_argument(
		    '''--checkpoint_url''',
		    default='''https://dl.fbaipublicfiles.com/msn/vits16_800ep.pth.tar''',
		    type=str,
		    help='''URL of the checkpoint you\'d like to convert.''',
		)
		parser.add_argument(
		    '''--pytorch_dump_folder_path''', default=None, type=str, help='''Path to the output PyTorch model directory.'''
		)

		_snake_case          =						parser.parse_args()
		convert_vit_msn_checkpoint(args.checkpoint_url, args.pytorch_dump_folder_path)








"""simple docstring"""



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






				'''simple docstring'''



				def __init__(					self	:			Dict				,     UpperCAmelCase_	:			Tuple				,     UpperCAmelCase_	:			Optional[int]=13				,     UpperCAmelCase_	:			Tuple=7				,     UpperCAmelCase_	:			Union[str, Any]=True				,     UpperCAmelCase_	:			int=True				,     UpperCAmelCase_	:			int=True				,     UpperCAmelCase_	:			Optional[int]=True				,     UpperCAmelCase_	:			Dict=99				,     UpperCAmelCase_	:			Tuple=32				,     UpperCAmelCase_	:			str=2				,     UpperCAmelCase_	:			int=4				,     UpperCAmelCase_	:			Any=37				,     UpperCAmelCase_	:			str="gelu"				,     UpperCAmelCase_	:			Union[str, Any]=0.1				,     UpperCAmelCase_	:			str=0.1				,     UpperCAmelCase_	:			int=512				,     UpperCAmelCase_	:			str=16				,     UpperCAmelCase_	:			str=2				,     UpperCAmelCase_	:			Union[str, Any]=0.02				,     UpperCAmelCase_	:			List[str]=False				,     UpperCAmelCase_	:			List[Any]=True				,     UpperCAmelCase_	:			Optional[int]="None"				,     UpperCAmelCase_	:			List[Any]=3				,     UpperCAmelCase_	:			Any=4				,     UpperCAmelCase_	:			Tuple=None				,     )		->  Optional[Any]:







											"""simple docstring"""




											_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 				__lowerCamelCase	(					self	:			Tuple  )		->  Optional[Any]:







											"""simple docstring"""




											_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 				__lowerCamelCase	(					self	:			Tuple				,     UpperCAmelCase_	:			Any				,     UpperCAmelCase_	:			Union[str, Any]				,     UpperCAmelCase_	:			Any				,     UpperCAmelCase_	:			List[Any]				,     UpperCAmelCase_	:			Tuple				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			Tuple  )		->  int:







											"""simple docstring"""




											_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 				__lowerCamelCase	(					self	:			Tuple				,     UpperCAmelCase_	:			Dict				,     UpperCAmelCase_	:			List[Any]				,     UpperCAmelCase_	:			Any				,     UpperCAmelCase_	:			Optional[Any]				,     UpperCAmelCase_	:			Union[str, Any]				,     UpperCAmelCase_	:			Optional[Any]				,     UpperCAmelCase_	:			Any  )		->  Optional[int]:







											"""simple docstring"""




											_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 				__lowerCamelCase	(					self	:			Any				,     UpperCAmelCase_	:			List[str]				,     UpperCAmelCase_	:			Any				,     UpperCAmelCase_	:			List[Any]				,     UpperCAmelCase_	:			List[str]				,     UpperCAmelCase_	:			Dict				,     UpperCAmelCase_	:			Optional[Any]				,     UpperCAmelCase_	:			int  )		->  List[str]:







											"""simple docstring"""




											_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 				__lowerCamelCase	(					self	:			int				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			str				,     UpperCAmelCase_	:			List[Any]				,     UpperCAmelCase_	:			List[Any]				,     UpperCAmelCase_	:			Any				,     UpperCAmelCase_	:			List[str]				,     UpperCAmelCase_	:			Optional[Any]  )		->  Tuple:







											"""simple docstring"""




											_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 				__lowerCamelCase	(					self	:			Tuple				,     UpperCAmelCase_	:			Union[str, Any]				,     UpperCAmelCase_	:			Any				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			Union[str, Any]				,     UpperCAmelCase_	:			Tuple				,     UpperCAmelCase_	:			List[Any]				,     UpperCAmelCase_	:			List[str]  )		->  List[Any]:







											"""simple docstring"""




											_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 				__lowerCamelCase	(					self	:			List[Any]  )		->  List[Any]:







											"""simple docstring"""




											_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        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase      ,				UpperCAmelCase      ,				unittest.TestCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							List[str]							=					(
				    (
				        TFDebertaVaModel,
				        TFDebertaVaForMaskedLM,
				        TFDebertaVaForQuestionAnswering,
				        TFDebertaVaForSequenceClassification,
				        TFDebertaVaForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE_:							str							=					(
				    {
				        "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_:							str							=					False
				SCREAMING_SNAKE_CASE_:							List[str]							=					False


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  List[str]:







											"""simple docstring"""




											_lowerCAmelCase  	=			TFDebertaVaModelTester(self  )
											_lowerCAmelCase  	=			ConfigTester(self				,     config_class=UpperCAmelCase_				,     hidden_size=37  )


				def 				__lowerCamelCase	(					self	:			Union[str, Any]  )		->  Any:







											"""simple docstring"""




											self.config_tester.run_common_tests()


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  List[str]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*UpperCAmelCase_  )


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







											"""simple docstring"""




											_lowerCAmelCase  	=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Dict  )		->  List[str]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Any  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Tuple  )		->  Optional[int]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_  )







				@slow
				def 				__lowerCamelCase	(					self	:			List[str]  )		->  List[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'  )
											self.assertIsNotNone(UpperCAmelCase_  )






@require_tf
class        _SCREAMING_SNAKE_CASE  (  unittest.TestCase							):






				'''simple docstring'''



				@unittest.skip(reason='Model not available yet'  )
				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  Tuple:







											"""simple docstring"""




											pass







				@slow
				def 				__lowerCamelCase	(					self	:			Any  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'  )
											_lowerCAmelCase  	=			tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 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  )






