


'''simple docstring'''



import pickle

import numpy as np
from matplotlib import pyplot as plt





class 							__UpperCamelCase    :




	def __init__(       self						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a=0.2						,    __a=0.2							):

						'''simple docstring'''





						__a      :	List[str]    =  bp_numa
						__a      :	Union[str, Any]    =  bp_numa
						__a      :	Union[str, Any]    =  bp_numa
						__a      :	Optional[int]    =  conva_get[:2]
						__a      :	List[str]    =  conva_get[2]
						__a      :	str    =  size_pa
						__a      :	Optional[Any]    =  rate_w
						__a      :	Any    =  rate_t
						__a      :	Dict    =  [
						    np.mat(-1 * np.random.rand(self.conva[0]						,    self.conva[0]							) + 0.5							)
						    for i in range(self.conva[1]							)
						]
						__a      :	Any    =  np.mat(-1 * np.random.rand(self.num_bpa						,    self.num_bpa							) + 0.5							)
						__a      :	List[str]    =  np.mat(-1 * np.random.rand(self.num_bpa						,    self.num_bpa							) + 0.5							)
						__a      :	Dict    =  -2 * np.random.rand(self.conva[1]							) + 1
						__a      :	int    =  -2 * np.random.rand(self.num_bpa							) + 1
						__a      :	Tuple    =  -2 * np.random.rand(self.num_bpa							) + 1




	def 				__UpperCAmelCase							(       self						,    __a							):

						'''simple docstring'''





						__a      :	List[str]    =  {
						    'num_bp1': self.num_bpa,
						    'num_bp2': self.num_bpa,
						    'num_bp3': self.num_bpa,
						    'conv1': self.conva,
						    'step_conv1': self.step_conva,
						    'size_pooling1': self.size_poolinga,
						    'rate_weight': self.rate_weight,
						    'rate_thre': self.rate_thre,
						    'w_conv1': self.w_conva,
						    'wkj': self.wkj,
						    'vji': self.vji,
						    'thre_conv1': self.thre_conva,
						    'thre_bp2': self.thre_bpa,
						    'thre_bp3': self.thre_bpa,
						}
						with open(__a						,    'wb'							) as f:
											pickle.dump(__a						,    __a							)

						print(f"""Model saved： {save_path}"""							)




	@classmethod
	def 				__UpperCAmelCase							(       cls						,    __a							):

						'''simple docstring'''





						with open(__a						,    'rb'							) as f:
											__a      :	List[Any]    =  pickle.load(__a							)  # noqa: S301

						__a      :	Union[str, Any]    =  model_dic.get('conv1'							)
						conv_get.append(model_dic.get('step_conv1'							)							)
						__a      :	List[Any]    =  model_dic.get('size_pooling1'							)
						__a      :	List[str]    =  model_dic.get('num_bp1'							)
						__a      :	List[Any]    =  model_dic.get('num_bp2'							)
						__a      :	Optional[int]    =  model_dic.get('num_bp3'							)
						__a      :	Tuple    =  model_dic.get('rate_weight'							)
						__a      :	Optional[int]    =  model_dic.get('rate_thre'							)
						# create model instance
						__a      :	str    =  CNN(__a						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a							)
						# modify model parameter
						__a      :	List[Any]    =  model_dic.get('w_conv1'							)
						__a      :	int    =  model_dic.get('wkj'							)
						__a      :	List[Any]    =  model_dic.get('vji'							)
						__a      :	int    =  model_dic.get('thre_conv1'							)
						__a      :	Optional[int]    =  model_dic.get('thre_bp2'							)
						__a      :	Dict    =  model_dic.get('thre_bp3'							)
						return conv_ins




	def 				__UpperCAmelCase							(       self						,    __a							):

						'''simple docstring'''





						return 1 / (1 + np.exp(-1 * x							))




	def 				__UpperCAmelCase							(       self						,    __a							):

						'''simple docstring'''





						return round(__a						,    3							)




	def 				__UpperCAmelCase							(       self						,    __a						,    __a						,    __a						,    __a						,    __a							):

						'''simple docstring'''





						__a      :	List[str]    =  convs[0]
						__a      :	Dict    =  convs[1]
						__a      :	Tuple    =  np.shape(__a							)[0]
						# get the data slice of original image data, data_focus
						__a      :	Optional[Any]    =  []
						for i_focus in range(0						,    size_data - size_conv + 1						,    __a							):
											for j_focus in range(0						,    size_data - size_conv + 1						,    __a							):
																__a      :	Tuple    =  data[
																    i_focus : i_focus + size_conv, j_focus : j_focus + size_conv
																]
																data_focus.append(__a							)
        # calculate the feature map of every single kernel, and saved as list of matrix
						__a      :	Dict    =  []
						__a      :	str    =  int((size_data - size_conv) / conv_step + 1							)
						for i_map in range(__a							):
											__a      :	int    =  []
											for i_focus in range(len(__a							)							):
																__a      :	Optional[Any]    =  (
																    np.sum(np.multiply(data_focus[i_focus]						,    w_convs[i_map]							)							)
																    - thre_convs[i_map]
																)
																featuremap.append(self.sig(__a							)							)
											__a      :	Tuple    =  np.asmatrix(__a							).reshape(
											    __a						,    __a							)
											data_featuremap.append(__a							)

						# expanding the data slice to One dimenssion
						__a      :	Optional[int]    =  []
						for each_focus in data_focus:
											focusa_list.extend(self.Expand_Mat(__a							)							)
						__a      :	Tuple    =  np.asarray(__a							)
						return focus_list, data_featuremap




	def 				__UpperCAmelCase							(       self						,    __a						,    __a						,    __a="average_pool"							):

						'''simple docstring'''





						__a      :	List[Any]    =  len(featuremaps[0]							)
						__a      :	Dict    =  int(size_map / size_pooling							)
						__a      :	Optional[int]    =  []
						for i_map in range(len(__a							)							):
											__a      :	List[str]    =  featuremaps[i_map]
											__a      :	Dict    =  []
											for i_focus in range(0						,    __a						,    __a							):
																for j_focus in range(0						,    __a						,    __a							):
																					__a      :	Dict    =  feature_map[
																					    i_focus : i_focus + size_pooling,
																					    j_focus : j_focus + size_pooling,
																					]
																					if pooling_type == "average_pool":
																										# average pooling
																										map_pooled.append(np.average(__a							)							)
																					elif pooling_type == "max_pooling":
																										# max pooling
																										map_pooled.append(np.max(__a							)							)
											__a      :	Dict    =  np.asmatrix(__a							).reshape(__a						,    __a							)
											featuremap_pooled.append(__a							)
						return featuremap_pooled




	def 				__UpperCAmelCase							(       self						,    __a							):

						'''simple docstring'''





						__a      :	List[Any]    =  []
						for i in range(len(__a							)							):
											__a      :	str    =  np.shape(data[i]							)
											__a      :	Optional[Any]    =  data[i].reshape(1						,    shapes[0] * shapes[1]							)
											__a      :	Optional[int]    =  data_listed.getA().tolist()[0]
											data_expanded.extend(__a							)
						__a      :	Any    =  np.asarray(__a							)
						return data_expanded




	def 				__UpperCAmelCase							(       self						,    __a							):

						'''simple docstring'''





						__a      :	Union[str, Any]    =  np.asarray(__a							)
						__a      :	str    =  np.shape(__a							)
						__a      :	Dict    =  data_mat.reshape(1						,    shapes[0] * shapes[1]							)
						return data_expanded




	def 				__UpperCAmelCase							(       self						,    __a						,    __a						,    __a						,    __a						,    __a							):

						'''simple docstring'''





						__a      :	int    =  []
						__a      :	int    =  0
						for i_map in range(__a							):
											__a      :	Tuple    =  np.ones((size_map, size_map)							)
											for i in range(0						,    __a						,    __a							):
																for j in range(0						,    __a						,    __a							):
																					__a      :	List[Any]    =  pd_pool[
																					    i_pool
																					]
																					__a      :	Union[str, Any]    =  i_pool + 1
											__a      :	str    =  np.multiply(
											    __a						,    np.multiply(out_map[i_map]						,    (1 - out_map[i_map])							)							)
											pd_all.append(__a							)
						return pd_all




	def 				__UpperCAmelCase							(       self						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a=bool							):

						'''simple docstring'''





						print('----------------------Start Training-------------------------'							)
						print((' - - Shape: Train_Data  ', np.shape(__a							))							)
						print((' - - Shape: Teach_Data  ', np.shape(__a							))							)
						__a      :	Union[str, Any]    =  0
						__a      :	Optional[int]    =  []
						__a      :	List[str]    =  1_0000
						while rp < n_repeat and mse >= error_accuracy:
											__a      :	Optional[int]    =  0
											print(f"""-------------Learning Time {rp}--------------"""							)
											for p in range(len(__a							)							):
																# print('------------Learning Image: %d--------------'%p)
																__a      :	Any    =  np.asmatrix(datas_train[p]							)
																__a      :	str    =  np.asarray(datas_teach[p]							)
																__a   ,    __a      :	Optional[Any]    =  self.convolute(
																    __a						,    self.conva						,    self.w_conva						,    self.thre_conva						,    conv_step=self.step_conva						,    )
																__a      :	Optional[int]    =  self.pooling(__a						,    self.size_poolinga							)
																__a      :	List[Any]    =  np.shape(__a							)
																__a      :	str    =  self._expand(__a							)
																__a      :	Optional[int]    =  data_bp_input

																__a      :	Optional[Any]    =  np.dot(__a						,    self.vji.T							) - self.thre_bpa
																__a      :	str    =  self.sig(__a							)
																__a      :	Any    =  np.dot(__a						,    self.wkj.T							) - self.thre_bpa
																__a      :	Dict    =  self.sig(__a							)

																# --------------Model Leaning ------------------------
																# calculate error and gradient---------------
																__a      :	str    =  np.multiply(
																    (data_teach - bp_outa)						,    np.multiply(__a						,    (1 - bp_outa)							)							)
																__a      :	Optional[int]    =  np.multiply(
																    np.dot(__a						,    self.wkj							)						,    np.multiply(__a						,    (1 - bp_outa)							)							)
																__a      :	Tuple    =  np.dot(__a						,    self.vji							)

																__a      :	Any    =  pd_i_all / (self.size_poolinga * self.size_poolinga)
																__a      :	Optional[Any]    =  pd_conva_pooled.T.getA().tolist()
																__a      :	Any    =  self._calculate_gradient_from_pool(
																    __a						,    __a						,    shape_featuremapa[0]						,    shape_featuremapa[1]						,    self.size_poolinga						,    )
																# weight and threshold learning process---------
																# convolution layer
																for k_conv in range(self.conva[1]							):
																					__a      :	List[str]    =  self._expand_mat(pd_conva_all[k_conv]							)
																					__a      :	Union[str, Any]    =  self.rate_weight * np.dot(__a						,    __a							)

																					__a      :	List[Any]    =  self.w_conva[k_conv] + delta_w.reshape(
																					    (self.conva[0], self.conva[0])							)

																					__a      :	Union[str, Any]    =  (
																					    self.thre_conva[k_conv]
																					    - np.sum(pd_conva_all[k_conv]							) * self.rate_thre
																					)
																# all connected layer
																__a      :	Any    =  self.wkj + pd_k_all.T * bp_outa * self.rate_weight
																__a      :	List[Any]    =  self.vji + pd_j_all.T * bp_outa * self.rate_weight
																__a      :	Union[str, Any]    =  self.thre_bpa - pd_k_all * self.rate_thre
																__a      :	str    =  self.thre_bpa - pd_j_all * self.rate_thre
																# calculate the sum error of all single image
																__a      :	Tuple    =  np.sum(abs(data_teach - bp_outa							)							)
																error_count += errors
																# print('   ----Teach      ',data_teach)
																# print('   ----BP_output  ',bp_out3)
											__a      :	int    =  rp + 1
											__a      :	Tuple    =  error_count / patterns
											all_mse.append(__a							)

						def draw_error():
											__a      :	Union[str, Any]    =  [error_accuracy for i in range(int(n_repeat * 1.2							)							)]
											plt.plot(__a						,    '+-'							)
											plt.plot(__a						,    'r--'							)
											plt.xlabel('Learning Times'							)
											plt.ylabel('All_mse'							)
											plt.grid(__a						,    alpha=0.5							)
											plt.show()

						print('------------------Training Complished---------------------'							)
						print((' - - Training epoch: ', rp, f"""     - - Mse: {mse:.6f}""")							)
						if draw_e:
											draw_error()
						return mse




	def 				__UpperCAmelCase							(       self						,    __a							):

						'''simple docstring'''





						__a      :	Any    =  []
						print('-------------------Start Testing-------------------------'							)
						print((' - - Shape: Test_Data  ', np.shape(__a							))							)
						for p in range(len(__a							)							):
											__a      :	Optional[int]    =  np.asmatrix(datas_test[p]							)
											__a   ,    __a      :	int    =  self.convolute(
											    __a						,    self.conva						,    self.w_conva						,    self.thre_conva						,    conv_step=self.step_conva						,    )
											__a      :	Optional[int]    =  self.pooling(__a						,    self.size_poolinga							)
											__a      :	List[str]    =  self._expand(__a							)

											__a      :	Dict    =  data_bp_input
											__a      :	int    =  bp_outa * self.vji.T - self.thre_bpa
											__a      :	Any    =  self.sig(__a							)
											__a      :	List[Any]    =  bp_outa * self.wkj.T - self.thre_bpa
											__a      :	Optional[int]    =  self.sig(__a							)
											produce_out.extend(bp_outa.getA().tolist()							)
						__a      :	Dict    =  [list(map(self.do_round						,    __a							)							) for each in produce_out]
						return np.asarray(__a							)





	def 				__UpperCAmelCase							(       self						,    __a							):

						'''simple docstring'''





						__a      :	Tuple    =  np.asmatrix(__a							)
						__a   ,    __a      :	int    =  self.convolute(
						    __a						,    self.conva						,    self.w_conva						,    self.thre_conva						,    conv_step=self.step_conva						,    )
						__a      :	Tuple    =  self.pooling(__a						,    self.size_poolinga							)

						return data_conveda, data_pooleda


if __name__ == "__main__":
	pass







'''simple docstring'''



import unittest

from transformers import DebertaVaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import (
	    DebertaVaForMaskedLM,
	    DebertaVaForMultipleChoice,
	    DebertaVaForQuestionAnswering,
	    DebertaVaForSequenceClassification,
	    DebertaVaForTokenClassification,
	    DebertaVaModel,
	)
	from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST





class 							__UpperCamelCase    (		lowerCAmelCase_ ):




	def __init__(       self						,    __a						,    __a=13						,    __a=7						,    __a=True						,    __a=True						,    __a=True						,    __a=True						,    __a=99						,    __a=32						,    __a=5						,    __a=4						,    __a=37						,    __a="gelu"						,    __a=0.1						,    __a=0.1						,    __a=512						,    __a=16						,    __a=2						,    __a=0.02						,    __a=False						,    __a=True						,    __a="None"						,    __a=3						,    __a=4						,    __a=None						,    ):

						'''simple docstring'''





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




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	Union[str, Any]    =  ids_tensor([self.batch_size, self.seq_length]						,    self.vocab_size							)

						__a      :	List[Any]    =  None
						if self.use_input_mask:
											__a      :	Any    =  ids_tensor([self.batch_size, self.seq_length]						,    vocab_size=2							)

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

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

						__a      :	Optional[int]    =  self.get_config()

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




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						return 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						,    initializer_range=self.initializer_range						,    relative_attention=self.relative_attention						,    position_biased_input=self.position_biased_input						,    pos_att_type=self.pos_att_type						,    )




	def 				__UpperCAmelCase							(       self						,    __a							):

						'''simple docstring'''





						self.parent.assertListEqual(list(result.loss.size()							)						,    []							)




	def 				__UpperCAmelCase							(       self						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a							):

						'''simple docstring'''





						__a      :	Dict    =  DebertaVaModel(config=__a							)
						model.to(__a							)
						model.eval()
						__a      :	Optional[int]    =  model(__a						,    attention_mask=__a						,    token_type_ids=__a							)[0]
						__a      :	str    =  model(__a						,    token_type_ids=__a							)[0]
						__a      :	Optional[int]    =  model(__a							)[0]

						self.parent.assertListEqual(list(sequence_output.size()							)						,    [self.batch_size, self.seq_length, self.hidden_size]							)




	def 				__UpperCAmelCase							(       self						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a							):

						'''simple docstring'''





						__a      :	int    =  DebertaVaForMaskedLM(config=__a							)
						model.to(__a							)
						model.eval()
						__a      :	List[Any]    =  model(__a						,    attention_mask=__a						,    token_type_ids=__a						,    labels=__a							)

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




	def 				__UpperCAmelCase							(       self						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a							):

						'''simple docstring'''





						__a      :	Optional[Any]    =  self.num_labels
						__a      :	List[Any]    =  DebertaVaForSequenceClassification(__a							)
						model.to(__a							)
						model.eval()
						__a      :	Any    =  model(__a						,    attention_mask=__a						,    token_type_ids=__a						,    labels=__a							)
						self.parent.assertListEqual(list(result.logits.size()							)						,    [self.batch_size, self.num_labels]							)
						self.check_loss_output(__a							)




	def 				__UpperCAmelCase							(       self						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a							):

						'''simple docstring'''





						__a      :	Any    =  self.num_labels
						__a      :	Dict    =  DebertaVaForTokenClassification(config=__a							)
						model.to(__a							)
						model.eval()
						__a      :	str    =  model(__a						,    attention_mask=__a						,    token_type_ids=__a						,    labels=__a							)
						self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.seq_length, self.num_labels)							)




	def 				__UpperCAmelCase							(       self						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a							):

						'''simple docstring'''





						__a      :	List[str]    =  DebertaVaForQuestionAnswering(config=__a							)
						model.to(__a							)
						model.eval()
						__a      :	str    =  model(
						    __a						,    attention_mask=__a						,    token_type_ids=__a						,    start_positions=__a						,    end_positions=__a						,    )
						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						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a						,    __a							):

						'''simple docstring'''





						__a      :	Optional[int]    =  DebertaVaForMultipleChoice(config=__a							)
						model.to(__a							)
						model.eval()
						__a      :	Any    =  input_ids.unsqueeze(1							).expand(-1						,    self.num_choices						,    -1							).contiguous()
						__a      :	Optional[Any]    =  token_type_ids.unsqueeze(1							).expand(-1						,    self.num_choices						,    -1							).contiguous()
						__a      :	Optional[int]    =  input_mask.unsqueeze(1							).expand(-1						,    self.num_choices						,    -1							).contiguous()
						__a      :	int    =  model(
						    __a						,    attention_mask=__a						,    token_type_ids=__a						,    labels=__a						,    )
						self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.num_choices)							)





	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	int    =  self.prepare_config_and_inputs()
						(
						    (
						    __a
						)   ,    (
						    __a
						)   ,    (
						    __a
						)   ,    (
						    __a
						)   ,    (
						    __a
						)   ,    (
						    __a
						)   ,    (
						    __a
						)   ,    
						)      :	Dict    =  config_and_inputs
						__a      :	Optional[int]    =  {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
						return config, inputs_dict





@require_torch
class 							__UpperCamelCase    (		lowerCAmelCase_		,				lowerCAmelCase_		,				unittest.TestCase ):
	A_           =   (
	    (
	        DebertaVaModel,
	        DebertaVaForMaskedLM,
	        DebertaVaForSequenceClassification,
	        DebertaVaForTokenClassification,
	        DebertaVaForQuestionAnswering,
	        DebertaVaForMultipleChoice,
	    )
	    if is_torch_available()
	    else ()
	)
	A_           =   (
	    {
	        "feature-extraction": DebertaVaModel,
	        "fill-mask": DebertaVaForMaskedLM,
	        "question-answering": DebertaVaForQuestionAnswering,
	        "text-classification": DebertaVaForSequenceClassification,
	        "token-classification": DebertaVaForTokenClassification,
	        "zero-shot": DebertaVaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	A_           =   True
	A_           =   False
	A_           =   False
	A_           =   False
	A_           =   False




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	Union[str, Any]    =  DebertaVaModelTester(self							)
						__a      :	List[str]    =  ConfigTester(self						,    config_class=__a						,    hidden_size=37							)




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						self.config_tester.run_common_tests()




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	Optional[Any]    =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_model(*__a							)




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	Dict    =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_sequence_classification(*__a							)




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	int    =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_masked_lm(*__a							)




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





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




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	Tuple    =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_token_classification(*__a							)




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





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





	@slow
	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__a      :	str    =  DebertaVaModel.from_pretrained(__a							)
											self.assertIsNotNone(__a							)





@require_torch
@require_sentencepiece
@require_tokenizers
class 							__UpperCamelCase    (		unittest.TestCase ):




	@unittest.skip(reason='Model not available yet'							)
	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						pass





	@slow
	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	Optional[int]    =  DebertaVaModel.from_pretrained('microsoft/deberta-v2-xlarge'							)

						__a      :	Optional[Any]    =  torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]							)
						__a      :	str    =  torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
						with torch.no_grad():
											__a      :	int    =  model(__a						,    attention_mask=__a							)[0]
						# compare the actual values for a slice.
						__a      :	str    =  torch.tensor(
						    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]							)
						self.assertTrue(torch.allclose(output[:, 1:4, 1:4]						,    __a						,    atol=1E-4							)						,    f"""{output[:, 1:4, 1:4]}"""							)



