



'''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 				SCREAMING_SNAKE_CASE(							A__			):







	"""simple docstring"""






	def __init__(						self			:     List[Any]		,			__snake_case			:     Tuple		,			__snake_case			:     Dict=13		,			__snake_case			:     Dict=7		,			__snake_case			:     Optional[Any]=True		,			__snake_case			:     int=True		,			__snake_case			:     Union[str, Any]=True		,			__snake_case			:     Tuple=True		,			__snake_case			:     List[str]=99		,			__snake_case			:     List[str]=32		,			__snake_case			:     List[str]=5		,			__snake_case			:     Tuple=4		,			__snake_case			:     Dict=37		,			__snake_case			:     Optional[int]="gelu"		,			__snake_case			:     int=0.1		,			__snake_case			:     Tuple=0.1		,			__snake_case			:     Any=512		,			__snake_case			:     Optional[int]=16		,			__snake_case			:     List[Any]=2		,			__snake_case			:     List[str]=0.02		,			__snake_case			:     Union[str, Any]=False		,			__snake_case			:     List[Any]=True		,			__snake_case			:     Optional[int]="None"		,			__snake_case			:     Optional[int]=3		,			__snake_case			:     Dict=4		,			__snake_case			:     Tuple=None		,			)			->		Optional[int]:
								UpperCAmelCase :       Tuple 							=		parent
								UpperCAmelCase :       List[str] 							=		batch_size
								UpperCAmelCase :       Any 							=		seq_length
								UpperCAmelCase :       Any 							=		is_training
								UpperCAmelCase :       Optional[int] 							=		use_input_mask
								UpperCAmelCase :       Optional[int] 							=		use_token_type_ids
								UpperCAmelCase :       Optional[int] 							=		use_labels
								UpperCAmelCase :       Dict 							=		vocab_size
								UpperCAmelCase :       Tuple 							=		hidden_size
								UpperCAmelCase :       List[str] 							=		num_hidden_layers
								UpperCAmelCase :       Dict 							=		num_attention_heads
								UpperCAmelCase :       Optional[Any] 							=		intermediate_size
								UpperCAmelCase :       List[str] 							=		hidden_act
								UpperCAmelCase :       int 							=		hidden_dropout_prob
								UpperCAmelCase :       Optional[Any] 							=		attention_probs_dropout_prob
								UpperCAmelCase :       int 							=		max_position_embeddings
								UpperCAmelCase :       int 							=		type_vocab_size
								UpperCAmelCase :       List[Any] 							=		type_sequence_label_size
								UpperCAmelCase :       Optional[Any] 							=		initializer_range
								UpperCAmelCase :       Union[str, Any] 							=		num_labels
								UpperCAmelCase :       Optional[Any] 							=		num_choices
								UpperCAmelCase :       List[str] 							=		relative_attention
								UpperCAmelCase :       int 							=		position_biased_input
								UpperCAmelCase :       str 							=		pos_att_type
								UpperCAmelCase :       List[Any] 							=		scope







	def      A	(						self			:     Optional[Any]		)			->		Any:
								UpperCAmelCase :       int 							=		ids_tensor([self.batch_size, self.seq_length]		,			self.vocab_size		)

								UpperCAmelCase :       Optional[Any] 							=		None
								if self.use_input_mask:
															UpperCAmelCase :       int 							=		ids_tensor([self.batch_size, self.seq_length]		,			vocab_size=2		)

								UpperCAmelCase :       Optional[Any] 							=		None
								if self.use_token_type_ids:
															UpperCAmelCase :       Dict 							=		ids_tensor([self.batch_size, self.seq_length]		,			self.type_vocab_size		)

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

								UpperCAmelCase :       Tuple 							=		self.get_config()

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







	def      A	(						self			:     List[Any]		)			->		Tuple:
								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      A	(						self			:     Optional[int]		,			__snake_case			:     Optional[int]		)			->		int:
								self.parent.assertListEqual(list(result.loss.size()		)		,			[]		)







	def      A	(						self			:     int		,			__snake_case			:     List[Any]		,			__snake_case			:     int		,			__snake_case			:     Optional[Any]		,			__snake_case			:     List[str]		,			__snake_case			:     Optional[Any]		,			__snake_case			:     List[str]		,			__snake_case			:     Union[str, Any]		)			->		Tuple:
								UpperCAmelCase :       Any 							=		DebertaVaModel(config=__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       Any 							=		model(__snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		)[0]
								UpperCAmelCase :       Optional[int] 							=		model(__snake_case		,			token_type_ids=__snake_case		)[0]
								UpperCAmelCase :       Dict 							=		model(__snake_case		)[0]

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







	def      A	(						self			:     Any		,			__snake_case			:     Union[str, Any]		,			__snake_case			:     List[Any]		,			__snake_case			:     str		,			__snake_case			:     str		,			__snake_case			:     Optional[int]		,			__snake_case			:     Dict		,			__snake_case			:     int		)			->		str:
								UpperCAmelCase :       List[Any] 							=		DebertaVaForMaskedLM(config=__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       int 							=		model(__snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		,			labels=__snake_case		)

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







	def      A	(						self			:     Optional[int]		,			__snake_case			:     Any		,			__snake_case			:     str		,			__snake_case			:     List[Any]		,			__snake_case			:     List[str]		,			__snake_case			:     Optional[int]		,			__snake_case			:     Any		,			__snake_case			:     Optional[Any]		)			->		List[Any]:
								UpperCAmelCase :       Dict 							=		self.num_labels
								UpperCAmelCase :       Optional[Any] 							=		DebertaVaForSequenceClassification(__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       Any 							=		model(__snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		,			labels=__snake_case		)
								self.parent.assertListEqual(list(result.logits.size()		)		,			[self.batch_size, self.num_labels]		)
								self.check_loss_output(__snake_case		)







	def      A	(						self			:     str		,			__snake_case			:     Dict		,			__snake_case			:     Optional[int]		,			__snake_case			:     Optional[int]		,			__snake_case			:     Dict		,			__snake_case			:     Union[str, Any]		,			__snake_case			:     List[str]		,			__snake_case			:     Dict		)			->		Any:
								UpperCAmelCase :       Dict 							=		self.num_labels
								UpperCAmelCase :       int 							=		DebertaVaForTokenClassification(config=__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       str 							=		model(__snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		,			labels=__snake_case		)
								self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.seq_length, self.num_labels)		)







	def      A	(						self			:     List[Any]		,			__snake_case			:     Optional[int]		,			__snake_case			:     int		,			__snake_case			:     Optional[Any]		,			__snake_case			:     str		,			__snake_case			:     List[Any]		,			__snake_case			:     Any		,			__snake_case			:     Dict		)			->		Optional[int]:
								UpperCAmelCase :       Optional[int] 							=		DebertaVaForQuestionAnswering(config=__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       Any 							=		model(
								    __snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		,			start_positions=__snake_case		,			end_positions=__snake_case		,			)
								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      A	(						self			:     str		,			__snake_case			:     Union[str, Any]		,			__snake_case			:     Dict		,			__snake_case			:     List[str]		,			__snake_case			:     Tuple		,			__snake_case			:     Optional[int]		,			__snake_case			:     Dict		,			__snake_case			:     Any		)			->		Union[str, Any]:
								UpperCAmelCase :       Optional[int] 							=		DebertaVaForMultipleChoice(config=__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       str 							=		input_ids.unsqueeze(1		).expand(-1		,			self.num_choices		,			-1		).contiguous()
								UpperCAmelCase :       Tuple 							=		token_type_ids.unsqueeze(1		).expand(-1		,			self.num_choices		,			-1		).contiguous()
								UpperCAmelCase :       List[str] 							=		input_mask.unsqueeze(1		).expand(-1		,			self.num_choices		,			-1		).contiguous()
								UpperCAmelCase :       Any 							=		model(
								    __snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		,			labels=__snake_case		,			)
								self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.num_choices)		)







	def      A	(						self			:     str		)			->		List[str]:
								UpperCAmelCase :       Any 							=		self.prepare_config_and_inputs()
								(
								    (
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		
								) :       int 							=		config_and_inputs
								UpperCAmelCase :       Any 							=		{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict

@require_torch
class 				SCREAMING_SNAKE_CASE(							A__							,		A__							,		unittest.TestCase			):







	"""simple docstring"""






	lowerCamelCase__			 =       (
	    (
	        DebertaVaModel,
	        DebertaVaForMaskedLM,
	        DebertaVaForSequenceClassification,
	        DebertaVaForTokenClassification,
	        DebertaVaForQuestionAnswering,
	        DebertaVaForMultipleChoice,
	    )
	    if is_torch_available()
	    else ()
	)
	lowerCamelCase__			 =       (
	    {
	        """feature-extraction""": DebertaVaModel,
	        """fill-mask""": DebertaVaForMaskedLM,
	        """question-answering""": DebertaVaForQuestionAnswering,
	        """text-classification""": DebertaVaForSequenceClassification,
	        """token-classification""": DebertaVaForTokenClassification,
	        """zero-shot""": DebertaVaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	lowerCamelCase__			 =       True
	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False







	def      A	(						self			:     int		)			->		Optional[Any]:
								UpperCAmelCase :       Tuple 							=		DebertaVaModelTester(self		)
								UpperCAmelCase :       int 							=		ConfigTester(self		,			config_class=__snake_case		,			hidden_size=37		)







	def      A	(						self			:     Optional[int]		)			->		Tuple:
								self.config_tester.run_common_tests()







	def      A	(						self			:     List[Any]		)			->		Any:
								UpperCAmelCase :       Tuple 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_model(*__snake_case		)







	def      A	(						self			:     Any		)			->		Any:
								UpperCAmelCase :       Optional[Any] 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_sequence_classification(*__snake_case		)







	def      A	(						self			:     Any		)			->		Dict:
								UpperCAmelCase :       Optional[Any] 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_masked_lm(*__snake_case		)







	def      A	(						self			:     Optional[int]		)			->		List[Any]:
								UpperCAmelCase :       Union[str, Any] 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_question_answering(*__snake_case		)







	def      A	(						self			:     Any		)			->		Dict:
								UpperCAmelCase :       int 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_token_classification(*__snake_case		)







	def      A	(						self			:     List[Any]		)			->		Optional[Any]:
								UpperCAmelCase :       Optional[Any] 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_multiple_choice(*__snake_case		)







	@slow
	def      A	(						self			:     List[str]		)			->		List[str]:
								for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															UpperCAmelCase :       int 							=		DebertaVaModel.from_pretrained(__snake_case		)
															self.assertIsNotNone(__snake_case		)

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







	"""simple docstring"""






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







	@slow
	def      A	(						self			:     Optional[Any]		)			->		Optional[Any]:
								UpperCAmelCase :       List[str] 							=		DebertaVaModel.from_pretrained('''microsoft/deberta-v2-xlarge'''		)

								UpperCAmelCase :       Union[str, Any] 							=		torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]		)
								UpperCAmelCase :       Optional[int] 							=		torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
								with torch.no_grad():
															UpperCAmelCase :       int 							=		model(__snake_case		,			attention_mask=__snake_case		)[0]
								# compare the actual values for a slice.
								UpperCAmelCase :       List[Any] 							=		torch.tensor(
								    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]		)
								self.assertTrue(torch.allclose(output[:, 1:4, 1:4]		,			__snake_case		,			atol=1E-4		)		,			F"""{output[:, 1:4, 1:4]}"""		)










'''simple docstring'''






# coding=utf-8
# Copyright 2020 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# this script dumps information about the environment

import os
import sys

import transformers


UpperCamelCase__:   Optional[int]								=			"3"

print("Python version:", sys.version)
print("transformers version:", transformers.__version__)

try:
						import torch

						print("Torch version:", torch.__version__)
						print("Cuda available:", torch.cuda.is_available())
						print("Cuda version:", torch.version.cuda)
						print("CuDNN version:", torch.backends.cudnn.version())
						print("Number of GPUs available:", torch.cuda.device_count())
						print("NCCL version:", torch.cuda.nccl.version())
except ImportError:
						print("Torch version:", None)

try:
						import deepspeed

						print("DeepSpeed version:", deepspeed.__version__)
except ImportError:
						print("DeepSpeed version:", None)

try:
						import tensorflow as tf

						print("TensorFlow version:", tf.__version__)
						print("TF GPUs available:", bool(tf.config.list_physical_devices("GPU")))
						print("Number of TF GPUs available:", len(tf.config.list_physical_devices("GPU")))
except ImportError:
						print("TensorFlow version:", None)





