


"""simple docstring"""







import os
from datetime import datetime as dt

from github import Github


a__    :							List[Any]            =					[
    '''good first issue''',
    '''good second issue''',
    '''good difficult issue''',
    '''enhancement''',
    '''new pipeline/model''',
    '''new scheduler''',
    '''wip''',
]




def        UpperCAmelCase__	():




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    Github(os.environ["GITHUB_TOKEN"]       )
					__SCREAMING_SNAKE_CASE						       =    g.get_repo("huggingface/diffusers"       )
					__SCREAMING_SNAKE_CASE						       =    repo.get_issues(state="open"       )

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




"""simple docstring"""







import inspect
import unittest

import numpy as np

from transformers import ViTConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
		import jax

		from transformers.models.vit.modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel




class 			UpperCamelCase_     (			unittest.TestCase):

	"""simple docstring"""





	def __init__(			self      :    Optional[Any]      ,      UpperCAmelCase__      :    Optional[Any]      ,      UpperCAmelCase__      :    Tuple=1_3      ,      UpperCAmelCase__      :    Optional[int]=3_0      ,      UpperCAmelCase__      :    Any=2      ,      UpperCAmelCase__      :    List[str]=3      ,      UpperCAmelCase__      :    Optional[Any]=True      ,      UpperCAmelCase__      :    Optional[int]=True      ,      UpperCAmelCase__      :    int=3_2      ,      UpperCAmelCase__      :    Any=5      ,      UpperCAmelCase__      :    Union[str, Any]=4      ,      UpperCAmelCase__      :    List[str]=3_7      ,      UpperCAmelCase__      :    Tuple="gelu"      ,      UpperCAmelCase__      :    List[str]=0.1      ,      UpperCAmelCase__      :    str=0.1      ,      UpperCAmelCase__      :    Any=1_0      ,      UpperCAmelCase__      :    str=0.02      ,      )	->     Tuple:
						__SCREAMING_SNAKE_CASE						       =    parent
						__SCREAMING_SNAKE_CASE						       =    batch_size
						__SCREAMING_SNAKE_CASE						       =    image_size
						__SCREAMING_SNAKE_CASE						       =    patch_size
						__SCREAMING_SNAKE_CASE						       =    num_channels
						__SCREAMING_SNAKE_CASE						       =    is_training
						__SCREAMING_SNAKE_CASE						       =    use_labels
						__SCREAMING_SNAKE_CASE						       =    hidden_size
						__SCREAMING_SNAKE_CASE						       =    num_hidden_layers
						__SCREAMING_SNAKE_CASE						       =    num_attention_heads
						__SCREAMING_SNAKE_CASE						       =    intermediate_size
						__SCREAMING_SNAKE_CASE						       =    hidden_act
						__SCREAMING_SNAKE_CASE						       =    hidden_dropout_prob
						__SCREAMING_SNAKE_CASE						       =    attention_probs_dropout_prob
						__SCREAMING_SNAKE_CASE						       =    type_sequence_label_size
						__SCREAMING_SNAKE_CASE						       =    initializer_range

						# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
						__SCREAMING_SNAKE_CASE						       =    (image_size // patch_size) ** 2
						__SCREAMING_SNAKE_CASE						       =    num_patches + 1




	def   UpperCAmelCase_				(			self      :    Union[str, Any]       )	->     Tuple:
						__SCREAMING_SNAKE_CASE						       =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

						__SCREAMING_SNAKE_CASE						       =    ViTConfig(
						    image_size=self.image_size      ,      patch_size=self.patch_size      ,      num_channels=self.num_channels      ,      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      ,      is_decoder=UpperCAmelCase__      ,      initializer_range=self.initializer_range      ,      )

						return config, pixel_values




	def   UpperCAmelCase_				(			self      :    Tuple      ,      UpperCAmelCase__      :    str      ,      UpperCAmelCase__      :    List[str]       )	->     Any:
						__SCREAMING_SNAKE_CASE						       =    FlaxViTModel(config=UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__       )
						# expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
						__SCREAMING_SNAKE_CASE						       =    (self.image_size, self.image_size)
						__SCREAMING_SNAKE_CASE						       =    (self.patch_size, self.patch_size)
						__SCREAMING_SNAKE_CASE						       =    (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
						self.parent.assertEqual(result.last_hidden_state.shape      ,      (self.batch_size, num_patches + 1, self.hidden_size)       )




	def   UpperCAmelCase_				(			self      :    str      ,      UpperCAmelCase__      :    List[str]      ,      UpperCAmelCase__      :    Tuple       )	->     Tuple:
						__SCREAMING_SNAKE_CASE						       =    self.type_sequence_label_size
						__SCREAMING_SNAKE_CASE						       =    FlaxViTForImageClassification(config=UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__       )
						self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.type_sequence_label_size)       )

						# test greyscale images
						__SCREAMING_SNAKE_CASE						       =    1
						__SCREAMING_SNAKE_CASE						       =    FlaxViTForImageClassification(UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]       )
						__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Union[str, Any]       )	->     List[Any]:
						__SCREAMING_SNAKE_CASE						       =    self.prepare_config_and_inputs()
						(
						    (
						    __SCREAMING_SNAKE_CASE
						)       ,  (
						    __SCREAMING_SNAKE_CASE
						)       ,  
						)						       =    config_and_inputs
						__SCREAMING_SNAKE_CASE						       =    {"pixel_values": pixel_values}
						return config, inputs_dict




@require_flax
class 			UpperCamelCase_     (			UpperCamelCase      ,  unittest.TestCase):

	"""simple docstring"""





	snake_case__    :  List[str]    =      (FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()




	def   UpperCAmelCase_				(			self      :    int       )	->     None:
						__SCREAMING_SNAKE_CASE						       =    FlaxViTModelTester(self       )
						__SCREAMING_SNAKE_CASE						       =    ConfigTester(self      ,      config_class=UpperCAmelCase__      ,      has_text_modality=UpperCAmelCase__      ,      hidden_size=3_7       )




	def   UpperCAmelCase_				(			self      :    int       )	->     Union[str, Any]:
						self.config_tester.run_common_tests()




	def   UpperCAmelCase_				(			self      :    Tuple       )	->     List[str]:
						__SCREAMING_SNAKE_CASE						       =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Dict       )	->     Dict:
						__SCREAMING_SNAKE_CASE						       =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Tuple       )	->     Any:
						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
											__SCREAMING_SNAKE_CASE						       =    model_class(UpperCAmelCase__       )
											__SCREAMING_SNAKE_CASE						       =    inspect.signature(model.__call__       )
											# signature.parameters is an OrderedDict => so arg_names order is deterministic
											__SCREAMING_SNAKE_CASE						       =    [*signature.parameters.keys()]

											__SCREAMING_SNAKE_CASE						       =    ["pixel_values"]
											self.assertListEqual(arg_names[:1]      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Any       )	->     List[Any]:
						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
											with self.subTest(model_class.__name__       ):
																__SCREAMING_SNAKE_CASE						       =    self._prepare_for_class(UpperCAmelCase__      ,      UpperCAmelCase__       )
																__SCREAMING_SNAKE_CASE						       =    model_class(UpperCAmelCase__       )

																@jax.jit
																def model_jitted(UpperCAmelCase__      :    Optional[int]      ,      **UpperCAmelCase__      :    Any       ):
																					return model(pixel_values=UpperCAmelCase__      ,      **UpperCAmelCase__       )

																with self.subTest("JIT Enabled"       ):
																					__SCREAMING_SNAKE_CASE						       =    model_jitted(**UpperCAmelCase__       ).to_tuple()

																with self.subTest("JIT Disabled"       ):
																					with jax.disable_jit():
																										__SCREAMING_SNAKE_CASE						       =    model_jitted(**UpperCAmelCase__       ).to_tuple()

																self.assertEqual(len(UpperCAmelCase__       )      ,      len(UpperCAmelCase__       )       )
																for jitted_output, output in zip(UpperCAmelCase__      ,      UpperCAmelCase__       ):
																					self.assertEqual(jitted_output.shape      ,      output.shape       )




	@slow
	def   UpperCAmelCase_				(			self      :    int       )	->     Union[str, Any]:
						for model_class_name in self.all_model_classes:
											__SCREAMING_SNAKE_CASE						       =    model_class_name.from_pretrained("google/vit-base-patch16-224"       )
											__SCREAMING_SNAKE_CASE						       =    model(np.ones((1, 3, 2_2_4, 2_2_4)       )       )
											self.assertIsNotNone(UpperCAmelCase__       )
