
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_   (			__lowerCamelCase   ):




	'''simple docstring'''


	def __init__(       self		,    snake_case		,    snake_case=13		,    snake_case=7		,    snake_case=True		,    snake_case=True		,    snake_case=True		,    snake_case=True		,    snake_case=99		,    snake_case=32		,    snake_case=5		,    snake_case=4		,    snake_case=37		,    snake_case="gelu"		,    snake_case=0.1		,    snake_case=0.1		,    snake_case=512		,    snake_case=16		,    snake_case=2		,    snake_case=0.02		,    snake_case=False		,    snake_case=True		,    snake_case="None"		,    snake_case=3		,    snake_case=4		,    snake_case=None		,    ):
		lowercase       =    parent
		lowercase       =    batch_size
		lowercase       =    seq_length
		lowercase       =    is_training
		lowercase       =    use_input_mask
		lowercase       =    use_token_type_ids
		lowercase       =    use_labels
		lowercase       =    vocab_size
		lowercase       =    hidden_size
		lowercase       =    num_hidden_layers
		lowercase       =    num_attention_heads
		lowercase       =    intermediate_size
		lowercase       =    hidden_act
		lowercase       =    hidden_dropout_prob
		lowercase       =    attention_probs_dropout_prob
		lowercase       =    max_position_embeddings
		lowercase       =    type_vocab_size
		lowercase       =    type_sequence_label_size
		lowercase       =    initializer_range
		lowercase       =    num_labels
		lowercase       =    num_choices
		lowercase       =    relative_attention
		lowercase       =    position_biased_input
		lowercase       =    pos_att_type
		lowercase       =    scope





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    ids_tensor([self.batch_size, self.seq_length]		,    self.vocab_size       )

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

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

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

		lowercase       =    self.get_config()

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





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		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 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.get_config()
		lowercase       =    300
		return config





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case       ):
		self.parent.assertListEqual(list(result.loss.size()       )		,    []       )





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case       ):
		lowercase       =    DebertaModel(config=snake_case       )
		model.to(snake_case       )
		model.eval()
		lowercase       =    model(snake_case		,    attention_mask=snake_case		,    token_type_ids=snake_case       )[0]
		lowercase       =    model(snake_case		,    token_type_ids=snake_case       )[0]
		lowercase       =    model(snake_case       )[0]

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





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case       ):
		lowercase       =    DebertaForMaskedLM(config=snake_case       )
		model.to(snake_case       )
		model.eval()
		lowercase       =    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 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case       ):
		lowercase       =    self.num_labels
		lowercase       =    DebertaForSequenceClassification(snake_case       )
		model.to(snake_case       )
		model.eval()
		lowercase       =    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 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case       ):
		lowercase       =    self.num_labels
		lowercase       =    DebertaForTokenClassification(config=snake_case       )
		model.to(snake_case       )
		model.eval()
		lowercase       =    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 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case		,    snake_case       ):
		lowercase       =    DebertaForQuestionAnswering(config=snake_case       )
		model.to(snake_case       )
		model.eval()
		lowercase       =    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 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.prepare_config_and_inputs()
		(
		    (
		    lowercase
		)  ,					(
		    lowercase
		)  ,					(
		    lowercase
		)  ,					(
		    lowercase
		)  ,					(
		    lowercase
		)  ,					(
		    lowercase
		)  ,					(
		    lowercase
		)  ,					
		)       =    config_and_inputs
		lowercase       =    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
		return config, inputs_dict







@require_torch
class        A_   (			__lowerCamelCase      ,	__lowerCamelCase      ,	unittest.TestCase   ):




	'''simple docstring'''


	_UpperCamelCase     :     Union[str, Any]							 =       (
	    (
	        DebertaModel,
	        DebertaForMaskedLM,
	        DebertaForSequenceClassification,
	        DebertaForTokenClassification,
	        DebertaForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	_UpperCamelCase     :     Optional[Any]							 =       (
	    {
	        """feature-extraction""": DebertaModel,
	        """fill-mask""": DebertaForMaskedLM,
	        """question-answering""": DebertaForQuestionAnswering,
	        """text-classification""": DebertaForSequenceClassification,
	        """token-classification""": DebertaForTokenClassification,
	        """zero-shot""": DebertaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	_UpperCamelCase     :     Optional[Any]							 =       True
	_UpperCamelCase     :     Tuple							 =       False
	_UpperCamelCase     :     Optional[int]							 =       False
	_UpperCamelCase     :     Union[str, Any]							 =       False
	_UpperCamelCase     :     int							 =       False





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    DebertaModelTester(self       )
		lowercase       =    ConfigTester(self		,    config_class=snake_case		,    hidden_size=37       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		self.config_tester.run_common_tests()





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_deberta_model(*snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_deberta_for_sequence_classification(*snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_deberta_for_masked_lm(*snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_deberta_for_question_answering(*snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_deberta_for_token_classification(*snake_case       )





	@slow
	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
			lowercase       =    DebertaModel.from_pretrained(snake_case       )
			self.assertIsNotNone(snake_case       )







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




	'''simple docstring'''


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





	@slow
	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    DebertaModel.from_pretrained('microsoft/deberta-base'       )

		lowercase       =    torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]       )
		lowercase       =    torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
		with torch.no_grad():
			lowercase       =    model(snake_case		,    attention_mask=snake_case       )[0]
		# compare the actual values for a slice.
		lowercase       =    torch.tensor(
		    [[[-0.5_986, -0.8_055, -0.8_462], [1.4_484, -0.9_348, -0.8_059], [0.3_123, 0.0_032, -1.4_131]]]       )
		self.assertTrue(torch.allclose(output[:, 1:4, 1:4]		,    snake_case		,    atol=1E-4       )		,    F'''{output[:, 1:4, 1:4]}'''       )



import os
from datetime import datetime as dt

from github import Github


UpperCAmelCase	      = [
    '''good first issue''',
    '''good second issue''',
    '''good difficult issue''',
    '''enhancement''',
    '''new pipeline/model''',
    '''new scheduler''',
    '''wip''',
]






def 							UpperCAmelCase_		(							):
	lowercase       =    Github(os.environ['GITHUB_TOKEN']							)
	lowercase       =    g.get_repo('huggingface/diffusers'							)
	lowercase       =    repo.get_issues(state='open'							)

	for issue in open_issues:
		lowercase       =    sorted(issue.get_comments() ,							key=lambda __SCREAMING_SNAKE_CASE							: i.created_at ,							reverse=__SCREAMING_SNAKE_CASE							)
		lowercase       =    comments[0] if len(__SCREAMING_SNAKE_CASE							) > 0 else None
		if (
		    last_comment is not None
		    and last_comment.user.login == "github-actions[bot]"
		    and (dt.utcnow() - issue.updated_at).days > 7
		    and (dt.utcnow() - issue.created_at).days >= 30
		    and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()							)
		):
			# Closes the issue after 7 days of inactivity since the Stalebot notification.
			issue.edit(state='closed'							)
		elif (
		    "stale" in issue.get_labels()
		    and last_comment is not None
		    and last_comment.user.login != "github-actions[bot]"
		):
			# Opens the issue if someone other than Stalebot commented.
			issue.edit(state='open'							)
			issue.remove_from_labels('stale'							)
		elif (
		    (dt.utcnow() - issue.updated_at).days > 23
		    and (dt.utcnow() - issue.created_at).days >= 30
		    and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()							)
		):
			# Post a Stalebot notification after 23 days of inactivity.
			issue.create_comment(
			    'This issue has been automatically marked as stale because it has not had '
			    'recent activity. If you think this still needs to be addressed '
			    'please comment on this thread.\n\nPlease note that issues that do not follow the '
			    '[contributing guidelines](https://github.com/huggingface/diffusers/blob/main/CONTRIBUTING.md) '
			    'are likely to be ignored.'							)
			issue.add_to_labels('stale'							)


if __name__ == "__main__":
	main()

