




'''simple docstring'''


import os
import tempfile
import unittest

from transformers import DistilBertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

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


if is_torch_available():
		import torch

		from transformers import (
		    DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    DistilBertForMaskedLM,
		    DistilBertForMultipleChoice,
		    DistilBertForQuestionAnswering,
		    DistilBertForSequenceClassification,
		    DistilBertForTokenClassification,
		    DistilBertModel,
		)





class    __lowercase						(  __magic_name__ ):







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







			def 		UpperCamelCase__			(	self      )				->    Dict:
					__a			=					ids_tensor([self.batch_size, self.seq_length]      ,							self.vocab_size      )

					__a			=					None
					if self.use_input_mask:
							__a			=					random_attention_mask([self.batch_size, self.seq_length]      )

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

					__a			=					self.get_config()

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







			def 		UpperCamelCase__			(	self      )				->    Dict:
					return DistilBertConfig(
					    vocab_size=self.vocab_size      ,							dim=self.hidden_size      ,							n_layers=self.num_hidden_layers      ,							n_heads=self.num_attention_heads      ,							hidden_dim=self.intermediate_size      ,							hidden_act=self.hidden_act      ,							dropout=self.hidden_dropout_prob      ,							attention_dropout=self.attention_probs_dropout_prob      ,							max_position_embeddings=self.max_position_embeddings      ,							initializer_range=self.initializer_range      ,							)







			def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    Tuple:
					__a			=					DistilBertModel(config=UpperCamelCase      )
					model.to(UpperCamelCase      )
					model.eval()
					__a			=					model(UpperCamelCase      ,							UpperCamelCase      )
					__a			=					model(UpperCamelCase      )
					self.parent.assertEqual(result.last_hidden_state.shape      ,							(self.batch_size, self.seq_length, self.hidden_size)      )







			def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    Tuple:
					__a			=					DistilBertForMaskedLM(config=UpperCamelCase      )
					model.to(UpperCamelCase      )
					model.eval()
					__a			=					model(UpperCamelCase      ,							attention_mask=UpperCamelCase      ,							labels=UpperCamelCase      )
					self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.seq_length, self.vocab_size)      )







			def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    int:
					__a			=					DistilBertForQuestionAnswering(config=UpperCamelCase      )
					model.to(UpperCamelCase      )
					model.eval()
					__a			=					model(
					    UpperCamelCase      ,							attention_mask=UpperCamelCase      ,							start_positions=UpperCamelCase      ,							end_positions=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 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    Tuple:
					__a			=					self.num_labels
					__a			=					DistilBertForSequenceClassification(UpperCamelCase      )
					model.to(UpperCamelCase      )
					model.eval()
					__a			=					model(UpperCamelCase      ,							attention_mask=UpperCamelCase      ,							labels=UpperCamelCase      )
					self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.num_labels)      )







			def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    List[str]:
					__a			=					self.num_labels
					__a			=					DistilBertForTokenClassification(config=UpperCamelCase      )
					model.to(UpperCamelCase      )
					model.eval()

					__a			=					model(UpperCamelCase      ,							attention_mask=UpperCamelCase      ,							labels=UpperCamelCase      )
					self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.seq_length, self.num_labels)      )







			def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    str:
					__a			=					self.num_choices
					__a			=					DistilBertForMultipleChoice(config=UpperCamelCase      )
					model.to(UpperCamelCase      )
					model.eval()
					__a			=					input_ids.unsqueeze(1      ).expand(-1      ,							self.num_choices      ,							-1      ).contiguous()
					__a			=					input_mask.unsqueeze(1      ).expand(-1      ,							self.num_choices      ,							-1      ).contiguous()
					__a			=					model(
					    UpperCamelCase      ,							attention_mask=UpperCamelCase      ,							labels=UpperCamelCase      ,							)
					self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.num_choices)      )







			def 		UpperCamelCase__			(	self      )				->    int:
					__a			=					self.prepare_config_and_inputs()
					((__a)	,       (__a)	,       (__a)	,       (__a)	,       (__a)	,       (__a))			=					config_and_inputs
					__a			=					{'input_ids': input_ids, 'attention_mask': input_mask}
					return config, inputs_dict





@require_torch
class    __lowercase						(  __magic_name__       ,							__magic_name__       ,							unittest.TestCase ):
			_a							=      (
			    (
			        DistilBertModel,
			        DistilBertForMaskedLM,
			        DistilBertForMultipleChoice,
			        DistilBertForQuestionAnswering,
			        DistilBertForSequenceClassification,
			        DistilBertForTokenClassification,
			    )
			    if is_torch_available()
			    else None
			)
			_a							=      (
			    {
			        """feature-extraction""": DistilBertModel,
			        """fill-mask""": DistilBertForMaskedLM,
			        """question-answering""": DistilBertForQuestionAnswering,
			        """text-classification""": DistilBertForSequenceClassification,
			        """token-classification""": DistilBertForTokenClassification,
			        """zero-shot""": DistilBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			_a							=      True
			_a							=      True
			_a							=      True
			_a							=      True







			def 		UpperCamelCase__			(	self      )				->    int:
					__a			=					DistilBertModelTester(self      )
					__a			=					ConfigTester(self      ,							config_class=UpperCamelCase      ,							dim=37      )







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







			def 		UpperCamelCase__			(	self      )				->    int:
					__a			=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_distilbert_model(*UpperCamelCase      )







			def 		UpperCamelCase__			(	self      )				->    Dict:
					__a			=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_distilbert_for_masked_lm(*UpperCamelCase      )







			def 		UpperCamelCase__			(	self      )				->    Optional[Any]:
					__a			=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_distilbert_for_question_answering(*UpperCamelCase      )







			def 		UpperCamelCase__			(	self      )				->    Optional[Any]:
					__a			=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_distilbert_for_sequence_classification(*UpperCamelCase      )







			def 		UpperCamelCase__			(	self      )				->    Optional[Any]:
					__a			=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_distilbert_for_token_classification(*UpperCamelCase      )







			def 		UpperCamelCase__			(	self      )				->    List[Any]:
					__a			=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_distilbert_for_multiple_choice(*UpperCamelCase      )







			@slow
			def 		UpperCamelCase__			(	self      )				->    List[str]:
					for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__a			=					DistilBertModel.from_pretrained(UpperCamelCase      )
							self.assertIsNotNone(UpperCamelCase      )







			@slow
			@require_torch_gpu
			def 		UpperCamelCase__			(	self      )				->    str:
					__a	,       __a			=					self.model_tester.prepare_config_and_inputs_for_common()
					for model_class in self.all_model_classes:
							# BertForMultipleChoice behaves incorrectly in JIT environments.
							if model_class == DistilBertForMultipleChoice:
									return

							__a			=					True
							__a			=					model_class(config=UpperCamelCase      )

							__a			=					self._prepare_for_class(UpperCamelCase      ,							UpperCamelCase      )
							__a			=					torch.jit.trace(
							    UpperCamelCase      ,							(inputs_dict['input_ids'].to('cpu'      ), inputs_dict['attention_mask'].to('cpu'      ))      )

							with tempfile.TemporaryDirectory() as tmp:
									torch.jit.save(UpperCamelCase      ,							os.path.join(UpperCamelCase      ,							'traced_model.pt'      )      )
									__a			=					torch.jit.load(os.path.join(UpperCamelCase      ,							'traced_model.pt'      )      ,							map_location=UpperCamelCase      )
									loaded(inputs_dict['input_ids'].to(UpperCamelCase      )      ,							inputs_dict['attention_mask'].to(UpperCamelCase      )      )





@require_torch
class    __lowercase						(  unittest.TestCase ):







			@slow
			def 		UpperCamelCase__			(	self      )				->    Tuple:
					__a			=					DistilBertModel.from_pretrained('distilbert-base-uncased'      )
					__a			=					torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]      )
					__a			=					torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
					with torch.no_grad():
							__a			=					model(UpperCamelCase      ,							attention_mask=UpperCamelCase      )[0]
					__a			=					torch.Size((1, 11, 768)      )
					self.assertEqual(output.shape      ,							UpperCamelCase      )
					__a			=					torch.tensor(
					    [[[-0.1_639, 0.3_299, 0.1_648], [-0.1_746, 0.3_289, 0.1_710], [-0.1_884, 0.3_357, 0.1_810]]]      )

					self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,							UpperCamelCase      ,							atol=1e-4      )      )









'''simple docstring'''


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 						SCREAMING_SNAKE_CASE       (      ):
  __a			=					Github(os.environ['GITHUB_TOKEN']			)
  __a			=					g.get_repo('huggingface/diffusers'			)
  __a			=					repo.get_issues(state='open'			)

  for issue in open_issues:
    __a			=					sorted(issue.get_comments()				,					key=lambda a_			: i.created_at				,					reverse=a_			)
    __a			=					comments[0] if len(a_			) > 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()



