
import unittest

from transformers import DebertaConfig, 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 (
					    DebertaForMaskedLM,
					    DebertaForQuestionAnswering,
					    DebertaForSequenceClassification,
					    DebertaForTokenClassification,
					    DebertaModel,
					)
					from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  str      ,				snake_case__  :  Tuple      ,				snake_case__  :  Optional[Any]=13      ,				snake_case__  :  List[Any]=7      ,				snake_case__  :  Any=True      ,				snake_case__  :  List[str]=True      ,				snake_case__  :  Optional[Any]=True      ,				snake_case__  :  Union[str, Any]=True      ,				snake_case__  :  List[str]=99      ,				snake_case__  :  Tuple=32      ,				snake_case__  :  Tuple=5      ,				snake_case__  :  Union[str, Any]=4      ,				snake_case__  :  List[str]=37      ,				snake_case__  :  List[str]="gelu"      ,				snake_case__  :  Union[str, Any]=0.1      ,				snake_case__  :  str=0.1      ,				snake_case__  :  Tuple=512      ,				snake_case__  :  Any=16      ,				snake_case__  :  Optional[Any]=2      ,				snake_case__  :  Tuple=0.0_2      ,				snake_case__  :  List[Any]=False      ,				snake_case__  :  Dict=True      ,				snake_case__  :  Dict="None"      ,				snake_case__  :  Optional[Any]=3      ,				snake_case__  :  List[str]=4      ,				snake_case__  :  Dict=None      ,				):
								"""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       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								__lowerCAmelCase         =							ids_tensor([self.batch_size, self.seq_length]      ,				self.vocab_size )

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

								__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         =							ids_tensor([self.batch_size]      ,				self.num_choices )

								__lowerCAmelCase         =							self.get_config()

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







							def       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								return DebertaConfig(
								    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  :  Dict ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.get_config()
								__lowerCAmelCase         =							300
								return config







							def       UpperCAmelCase__					(						self  :  Dict      ,				snake_case__  :  str ):
								"""simple docstring"""







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







							def       UpperCAmelCase__					(						self  :  List[Any]      ,				snake_case__  :  Any      ,				snake_case__  :  str      ,				snake_case__  :  Optional[int]      ,				snake_case__  :  int      ,				snake_case__  :  Optional[Any]      ,				snake_case__  :  int      ,				snake_case__  :  Optional[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							DebertaModel(config=snake_case__ )
								model.to(snake_case__ )
								model.eval()
								__lowerCAmelCase         =							model(snake_case__      ,				attention_mask=snake_case__      ,				token_type_ids=snake_case__ )[0]
								__lowerCAmelCase         =							model(snake_case__      ,				token_type_ids=snake_case__ )[0]
								__lowerCAmelCase         =							model(snake_case__ )[0]

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







							def       UpperCAmelCase__					(						self  :  Optional[Any]      ,				snake_case__  :  Union[str, Any]      ,				snake_case__  :  Union[str, Any]      ,				snake_case__  :  Any      ,				snake_case__  :  List[str]      ,				snake_case__  :  List[Any]      ,				snake_case__  :  Any      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							DebertaForMaskedLM(config=snake_case__ )
								model.to(snake_case__ )
								model.eval()
								__lowerCAmelCase         =							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       UpperCAmelCase__					(						self  :  Tuple      ,				snake_case__  :  int      ,				snake_case__  :  Dict      ,				snake_case__  :  Optional[int]      ,				snake_case__  :  Tuple      ,				snake_case__  :  Dict      ,				snake_case__  :  Tuple      ,				snake_case__  :  Union[str, Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.num_labels
								__lowerCAmelCase         =							DebertaForSequenceClassification(snake_case__ )
								model.to(snake_case__ )
								model.eval()
								__lowerCAmelCase         =							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       UpperCAmelCase__					(						self  :  str      ,				snake_case__  :  Optional[Any]      ,				snake_case__  :  Optional[int]      ,				snake_case__  :  List[Any]      ,				snake_case__  :  List[str]      ,				snake_case__  :  Dict      ,				snake_case__  :  Union[str, Any]      ,				snake_case__  :  List[str] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.num_labels
								__lowerCAmelCase         =							DebertaForTokenClassification(config=snake_case__ )
								model.to(snake_case__ )
								model.eval()
								__lowerCAmelCase         =							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       UpperCAmelCase__					(						self  :  Optional[int]      ,				snake_case__  :  Optional[int]      ,				snake_case__  :  int      ,				snake_case__  :  Any      ,				snake_case__  :  int      ,				snake_case__  :  str      ,				snake_case__  :  List[str]      ,				snake_case__  :  List[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							DebertaForQuestionAnswering(config=snake_case__ )
								model.to(snake_case__ )
								model.eval()
								__lowerCAmelCase         =							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       UpperCAmelCase__					(						self  :  Optional[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_torch
class       a		(   __UpperCAmelCase      ,	__UpperCAmelCase      ,	unittest.TestCase					):
							lowercase_		:						Any   							=  (
							    (
							        DebertaModel,
							        DebertaForMaskedLM,
							        DebertaForSequenceClassification,
							        DebertaForTokenClassification,
							        DebertaForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							lowercase_		:						List[str]   							=  (
							    {
							        'feature-extraction': DebertaModel,
							        'fill-mask': DebertaForMaskedLM,
							        'question-answering': DebertaForQuestionAnswering,
							        'text-classification': DebertaForSequenceClassification,
							        'token-classification': DebertaForTokenClassification,
							        'zero-shot': DebertaForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)

							lowercase_		:						int   							=  True
							lowercase_		:						Any   							=  False
							lowercase_		:						Dict   							=  False
							lowercase_		:						List[str]   							=  False
							lowercase_		:						Dict   							=  False







							def       UpperCAmelCase__					(						self  :  Union[str, Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							DebertaModelTester(self )
								__lowerCAmelCase         =							ConfigTester(self      ,				config_class=snake_case__      ,				hidden_size=37 )







							def       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								self.config_tester.run_common_tests()







							def       UpperCAmelCase__					(						self  :  Union[str, Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_model(*snake_case__ )







							def       UpperCAmelCase__					(						self  :  List[str] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_sequence_classification(*snake_case__ )







							def       UpperCAmelCase__					(						self  :  Dict ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_masked_lm(*snake_case__ )







							def       UpperCAmelCase__					(						self  :  Optional[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_question_answering(*snake_case__ )







							def       UpperCAmelCase__					(						self  :  Any ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_token_classification(*snake_case__ )







							@slow
							def       UpperCAmelCase__					(						self  :  Any ):
								"""simple docstring"""







								for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									__lowerCAmelCase         =							DebertaModel.from_pretrained(snake_case__ )
									self.assertIsNotNone(snake_case__ )

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







							@unittest.skip(reason="Model not available yet" )
							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								pass







							@slow
							def       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								__lowerCAmelCase         =							DebertaModel.from_pretrained("microsoft/deberta-base" )

								__lowerCAmelCase         =							torch.tensor([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]] )
								__lowerCAmelCase         =							torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
								with torch.no_grad():
									__lowerCAmelCase         =							model(snake_case__      ,				attention_mask=snake_case__ )[0]
								# compare the actual values for a slice.
								__lowerCAmelCase         =							torch.tensor(
								    [[[-0.5_9_8_6, -0.8_0_5_5, -0.8_4_6_2], [1.4_4_8_4, -0.9_3_4_8, -0.8_0_5_9], [0.3_1_2_3, 0.0_0_3_2, -1.4_1_3_1]]] )
								self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,				snake_case__      ,				atol=1E-4 )      ,				F"{output[:, 1:4, 1:4]}" )








# limitations under the License.

# NOTE: This file is deprecated and will be removed in a future version.
# It only exists so that temporarely `from diffusers.pipelines import DiffusionPipeline` works

from .pipelines import DiffusionPipeline, ImagePipelineOutput  # noqa: F401
from .utils import deprecate


deprecate(
    "pipelines_utils",
    "0.22.0",
    "Importing `DiffusionPipeline` or `ImagePipelineOutput` from diffusers.pipeline_utils is deprecated. Please import from diffusers.pipelines.pipeline_utils instead.",
    standard_warn=False,
    stacklevel=3,
)






