




"""simple docstring"""







import unittest

from transformers import (
    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    Pipeline,
    ZeroShotClassificationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_tf, require_torch, slow

from .test_pipelines_common import ANY


# These 2 model types require different inputs than those of the usual text models.
a      =							{'LayoutLMv2Config', 'LayoutLMv3Config'}






@is_pipeline_test
class       SCREAMING_SNAKE_CASE__					(					unittest.TestCase					):
						_a    						=						MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
						_a    						=						TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

						if model_mapping is not None:
												_a    						=						{config: model for config, model in model_mapping.items() if config.__name__ not in _TO_SKIP}
						if tf_model_mapping is not None:
												_a    						=						{
												    config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
												}


						def   __lowercase (							self				:			Optional[Any]						,						lowerCAmelCase				:			Any						,						lowerCAmelCase				:			Any						,						lowerCAmelCase				:			Optional[int]					):
										lowerCAmelCase  =				ZeroShotClassificationPipeline(
										    model=lowerCAmelCase						,						tokenizer=lowerCAmelCase						,						candidate_labels=["""polics""", """health"""]					)
										return classifier, ["Who are you voting for in 2020?", "My stomach hurts."]


						def   __lowercase (							self				:			Tuple						,						lowerCAmelCase				:			Optional[Any]						,						lowerCAmelCase				:			str					):
										lowerCAmelCase  =				classifier("""Who are you voting for in 2020?"""						,						candidate_labels="""politics"""					)
										self.assertEqual(lowerCAmelCase						,						{"""sequence""": ANY(lowerCAmelCase					), """labels""": [ANY(lowerCAmelCase					)], """scores""": [ANY(lowerCAmelCase					)]}					)

										# No kwarg
										lowerCAmelCase  =				classifier("""Who are you voting for in 2020?"""						,						["""politics"""]					)
										self.assertEqual(lowerCAmelCase						,						{"""sequence""": ANY(lowerCAmelCase					), """labels""": [ANY(lowerCAmelCase					)], """scores""": [ANY(lowerCAmelCase					)]}					)

										lowerCAmelCase  =				classifier("""Who are you voting for in 2020?"""						,						candidate_labels=["""politics"""]					)
										self.assertEqual(lowerCAmelCase						,						{"""sequence""": ANY(lowerCAmelCase					), """labels""": [ANY(lowerCAmelCase					)], """scores""": [ANY(lowerCAmelCase					)]}					)

										lowerCAmelCase  =				classifier("""Who are you voting for in 2020?"""						,						candidate_labels="""politics, public health"""					)
										self.assertEqual(
										    lowerCAmelCase						,						{"""sequence""": ANY(lowerCAmelCase					), """labels""": [ANY(lowerCAmelCase					), ANY(lowerCAmelCase					)], """scores""": [ANY(lowerCAmelCase					), ANY(lowerCAmelCase					)]}					)
										self.assertAlmostEqual(sum(nested_simplify(outputs["""scores"""]					)					)						,						1.0					)

										lowerCAmelCase  =				classifier("""Who are you voting for in 2020?"""						,						candidate_labels=["""politics""", """public health"""]					)
										self.assertEqual(
										    lowerCAmelCase						,						{"""sequence""": ANY(lowerCAmelCase					), """labels""": [ANY(lowerCAmelCase					), ANY(lowerCAmelCase					)], """scores""": [ANY(lowerCAmelCase					), ANY(lowerCAmelCase					)]}					)
										self.assertAlmostEqual(sum(nested_simplify(outputs["""scores"""]					)					)						,						1.0					)

										lowerCAmelCase  =				classifier(
										    """Who are you voting for in 2020?"""						,						candidate_labels="""politics"""						,						hypothesis_template="""This text is about {}"""					)
										self.assertEqual(lowerCAmelCase						,						{"""sequence""": ANY(lowerCAmelCase					), """labels""": [ANY(lowerCAmelCase					)], """scores""": [ANY(lowerCAmelCase					)]}					)

										# https://github.com/huggingface/transformers/issues/13846
										lowerCAmelCase  =				classifier(["""I am happy"""]						,						["""positive""", """negative"""]					)
										self.assertEqual(
										    lowerCAmelCase						,						[
										        {"""sequence""": ANY(lowerCAmelCase					), """labels""": [ANY(lowerCAmelCase					), ANY(lowerCAmelCase					)], """scores""": [ANY(lowerCAmelCase					), ANY(lowerCAmelCase					)]}
										        for i in range(1					)
										    ]						,						)
										lowerCAmelCase  =				classifier(["""I am happy""", """I am sad"""]						,						["""positive""", """negative"""]					)
										self.assertEqual(
										    lowerCAmelCase						,						[
										        {"""sequence""": ANY(lowerCAmelCase					), """labels""": [ANY(lowerCAmelCase					), ANY(lowerCAmelCase					)], """scores""": [ANY(lowerCAmelCase					), ANY(lowerCAmelCase					)]}
										        for i in range(2					)
										    ]						,						)

										with self.assertRaises(lowerCAmelCase					):
														classifier(""""""						,						candidate_labels="""politics"""					)

										with self.assertRaises(lowerCAmelCase					):
														classifier(lowerCAmelCase						,						candidate_labels="""politics"""					)

										with self.assertRaises(lowerCAmelCase					):
														classifier("""Who are you voting for in 2020?"""						,						candidate_labels=""""""					)

										with self.assertRaises(lowerCAmelCase					):
														classifier("""Who are you voting for in 2020?"""						,						candidate_labels=lowerCAmelCase					)

										with self.assertRaises(lowerCAmelCase					):
														classifier(
														    """Who are you voting for in 2020?"""						,						candidate_labels="""politics"""						,						hypothesis_template="""Not formatting template"""						,						)

										with self.assertRaises(lowerCAmelCase					):
														classifier(
														    """Who are you voting for in 2020?"""						,						candidate_labels="""politics"""						,						hypothesis_template=lowerCAmelCase						,						)

										self.run_entailment_id(lowerCAmelCase					)


						def   __lowercase (							self				:			List[Any]						,						lowerCAmelCase				:			Pipeline					):
										lowerCAmelCase  =				zero_shot_classifier.model.config
										lowerCAmelCase  =				config.labelaid
										lowerCAmelCase  =				zero_shot_classifier.entailment_id

										lowerCAmelCase  =				{"""LABEL_0""": 0, """LABEL_1""": 1, """LABEL_2""": 2}
										self.assertEqual(zero_shot_classifier.entailment_id						,						-1					)

										lowerCAmelCase  =				{"""entailment""": 0, """neutral""": 1, """contradiction""": 2}
										self.assertEqual(zero_shot_classifier.entailment_id						,						0					)

										lowerCAmelCase  =				{"""ENTAIL""": 0, """NON-ENTAIL""": 1}
										self.assertEqual(zero_shot_classifier.entailment_id						,						0					)

										lowerCAmelCase  =				{"""ENTAIL""": 2, """NEUTRAL""": 1, """CONTR""": 0}
										self.assertEqual(zero_shot_classifier.entailment_id						,						2					)

										lowerCAmelCase  =				original_labelaid
										self.assertEqual(lowerCAmelCase						,						zero_shot_classifier.entailment_id					)


						@require_torch
						def   __lowercase (							self				:			str					):
										lowerCAmelCase  =				pipeline(
										    """zero-shot-classification"""						,						model="""sshleifer/tiny-distilbert-base-cased-distilled-squad"""						,						framework="""pt"""						,						)
										# There was a regression in 4.10 for this
										# Adding a test so we don't make the mistake again.
										# https://github.com/huggingface/transformers/issues/13381#issuecomment-912343499
										zero_shot_classifier(
										    """Who are you voting for in 2020?""" * 100						,						candidate_labels=["""politics""", """public health""", """science"""]					)


						@require_torch
						def   __lowercase (							self				:			Dict					):
										lowerCAmelCase  =				pipeline(
										    """zero-shot-classification"""						,						model="""sshleifer/tiny-distilbert-base-cased-distilled-squad"""						,						framework="""pt"""						,						)
										lowerCAmelCase  =				zero_shot_classifier(
										    """Who are you voting for in 2020?"""						,						candidate_labels=["""politics""", """public health""", """science"""]					)

										self.assertEqual(
										    nested_simplify(lowerCAmelCase					)						,						{
										        """sequence""": """Who are you voting for in 2020?""",
										        """labels""": ["""science""", """public health""", """politics"""],
										        """scores""": [0.333, 0.333, 0.333],
										    }						,						)


						@require_tf
						def   __lowercase (							self				:			int					):
										lowerCAmelCase  =				pipeline(
										    """zero-shot-classification"""						,						model="""sshleifer/tiny-distilbert-base-cased-distilled-squad"""						,						framework="""tf"""						,						)
										lowerCAmelCase  =				zero_shot_classifier(
										    """Who are you voting for in 2020?"""						,						candidate_labels=["""politics""", """public health""", """science"""]					)

										self.assertEqual(
										    nested_simplify(lowerCAmelCase					)						,						{
										        """sequence""": """Who are you voting for in 2020?""",
										        """labels""": ["""science""", """public health""", """politics"""],
										        """scores""": [0.333, 0.333, 0.333],
										    }						,						)


						@slow
						@require_torch
						def   __lowercase (							self				:			Optional[Any]					):
										lowerCAmelCase  =				pipeline("""zero-shot-classification"""						,						model="""roberta-large-mnli"""						,						framework="""pt"""					)
										lowerCAmelCase  =				zero_shot_classifier(
										    """Who are you voting for in 2020?"""						,						candidate_labels=["""politics""", """public health""", """science"""]					)

										self.assertEqual(
										    nested_simplify(lowerCAmelCase					)						,						{
										        """sequence""": """Who are you voting for in 2020?""",
										        """labels""": ["""politics""", """public health""", """science"""],
										        """scores""": [0.976, 0.015, 0.009],
										    }						,						)
										lowerCAmelCase  =				zero_shot_classifier(
										    """The dominant sequence transduction models are based on complex recurrent or convolutional neural networks"""
										    """ in an encoder-decoder configuration. The best performing models also connect the encoder and decoder"""
										    """ through an attention mechanism. We propose a new simple network architecture, the Transformer, based"""
										    """ solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two"""
										    """ machine translation tasks show these models to be superior in quality while being more parallelizable"""
										    """ and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014"""
										    """ English-to-German translation task, improving over the existing best results, including ensembles by"""
										    """ over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new"""
										    """ single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small"""
										    """ fraction of the training costs of the best models from the literature. We show that the Transformer"""
										    """ generalizes well to other tasks by applying it successfully to English constituency parsing both with"""
										    """ large and limited training data."""						,						candidate_labels=["""machine learning""", """statistics""", """translation""", """vision"""]						,						multi_label=lowerCAmelCase						,						)
										self.assertEqual(
										    nested_simplify(lowerCAmelCase					)						,						{
										        """sequence""": (
										            """The dominant sequence transduction models are based on complex recurrent or convolutional neural"""
										            """ networks in an encoder-decoder configuration. The best performing models also connect the"""
										            """ encoder and decoder through an attention mechanism. We propose a new simple network"""
										            """ architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence"""
										            """ and convolutions entirely. Experiments on two machine translation tasks show these models to be"""
										            """ superior in quality while being more parallelizable and requiring significantly less time to"""
										            """ train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task,"""
										            """ improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014"""
										            """ English-to-French translation task, our model establishes a new single-model state-of-the-art"""
										            """ BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training"""
										            """ costs of the best models from the literature. We show that the Transformer generalizes well to"""
										            """ other tasks by applying it successfully to English constituency parsing both with large and"""
										            """ limited training data."""
										        ),
										        """labels""": ["""translation""", """machine learning""", """vision""", """statistics"""],
										        """scores""": [0.817, 0.713, 0.018, 0.018],
										    }						,						)




						@slow
						@require_tf
						def   __lowercase (							self				:			str					):
										lowerCAmelCase  =				pipeline("""zero-shot-classification"""						,						model="""roberta-large-mnli"""						,						framework="""tf"""					)
										lowerCAmelCase  =				zero_shot_classifier(
										    """Who are you voting for in 2020?"""						,						candidate_labels=["""politics""", """public health""", """science"""]					)

										self.assertEqual(
										    nested_simplify(lowerCAmelCase					)						,						{
										        """sequence""": """Who are you voting for in 2020?""",
										        """labels""": ["""politics""", """public health""", """science"""],
										        """scores""": [0.976, 0.015, 0.009],
										    }						,						)
										lowerCAmelCase  =				zero_shot_classifier(
										    """The dominant sequence transduction models are based on complex recurrent or convolutional neural networks"""
										    """ in an encoder-decoder configuration. The best performing models also connect the encoder and decoder"""
										    """ through an attention mechanism. We propose a new simple network architecture, the Transformer, based"""
										    """ solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two"""
										    """ machine translation tasks show these models to be superior in quality while being more parallelizable"""
										    """ and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014"""
										    """ English-to-German translation task, improving over the existing best results, including ensembles by"""
										    """ over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new"""
										    """ single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small"""
										    """ fraction of the training costs of the best models from the literature. We show that the Transformer"""
										    """ generalizes well to other tasks by applying it successfully to English constituency parsing both with"""
										    """ large and limited training data."""						,						candidate_labels=["""machine learning""", """statistics""", """translation""", """vision"""]						,						multi_label=lowerCAmelCase						,						)
										self.assertEqual(
										    nested_simplify(lowerCAmelCase					)						,						{
										        """sequence""": (
										            """The dominant sequence transduction models are based on complex recurrent or convolutional neural"""
										            """ networks in an encoder-decoder configuration. The best performing models also connect the"""
										            """ encoder and decoder through an attention mechanism. We propose a new simple network"""
										            """ architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence"""
										            """ and convolutions entirely. Experiments on two machine translation tasks show these models to be"""
										            """ superior in quality while being more parallelizable and requiring significantly less time to"""
										            """ train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task,"""
										            """ improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014"""
										            """ English-to-French translation task, our model establishes a new single-model state-of-the-art"""
										            """ BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training"""
										            """ costs of the best models from the literature. We show that the Transformer generalizes well to"""
										            """ other tasks by applying it successfully to English constituency parsing both with large and"""
										            """ limited training data."""
										        ),
										        """labels""": ["""translation""", """machine learning""", """vision""", """statistics"""],
										        """scores""": [0.817, 0.713, 0.018, 0.018],
										    }						,						)









"""simple docstring"""







import inspect
import unittest

from transformers import ViTMSNConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
		import torch
		from torch import nn

		from transformers import ViTMSNForImageClassification, ViTMSNModel
		from transformers.models.vit_msn.modeling_vit_msn import VIT_MSN_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import ViTImageProcessor






class       SCREAMING_SNAKE_CASE__					:


						def __init__(							self				:			List[Any]						,						lowerCAmelCase				:			Tuple						,						lowerCAmelCase				:			Optional[int]=13						,						lowerCAmelCase				:			List[str]=30						,						lowerCAmelCase				:			Dict=2						,						lowerCAmelCase				:			Any=3						,						lowerCAmelCase				:			str=True						,						lowerCAmelCase				:			List[Any]=True						,						lowerCAmelCase				:			Dict=32						,						lowerCAmelCase				:			Dict=5						,						lowerCAmelCase				:			str=4						,						lowerCAmelCase				:			List[Any]=37						,						lowerCAmelCase				:			List[Any]="gelu"						,						lowerCAmelCase				:			List[Any]=0.1						,						lowerCAmelCase				:			List[Any]=0.1						,						lowerCAmelCase				:			Optional[int]=10						,						lowerCAmelCase				:			List[str]=0.02						,						lowerCAmelCase				:			List[str]=None						,						):
										lowerCAmelCase  =				parent
										lowerCAmelCase  =				batch_size
										lowerCAmelCase  =				image_size
										lowerCAmelCase  =				patch_size
										lowerCAmelCase  =				num_channels
										lowerCAmelCase  =				is_training
										lowerCAmelCase  =				use_labels
										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  =				type_sequence_label_size
										lowerCAmelCase  =				initializer_range
										lowerCAmelCase  =				scope

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


						def   __lowercase (							self				:			List[str]					):
										lowerCAmelCase  =				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

										lowerCAmelCase  =				None
										if self.use_labels:
														lowerCAmelCase  =				ids_tensor([self.batch_size]						,						self.type_sequence_label_size					)

										lowerCAmelCase  =				self.get_config()

										return config, pixel_values, labels


						def   __lowercase (							self				:			Tuple					):
										return ViTMSNConfig(
										    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						,						initializer_range=self.initializer_range						,						)


						def   __lowercase (							self				:			Any						,						lowerCAmelCase				:			Any						,						lowerCAmelCase				:			Tuple						,						lowerCAmelCase				:			Tuple					):
										lowerCAmelCase  =				ViTMSNModel(config=lowerCAmelCase					)
										model.to(lowerCAmelCase					)
										model.eval()
										lowerCAmelCase  =				model(lowerCAmelCase					)
										self.parent.assertEqual(result.last_hidden_state.shape						,						(self.batch_size, self.seq_length, self.hidden_size)					)


						def   __lowercase (							self				:			List[str]						,						lowerCAmelCase				:			int						,						lowerCAmelCase				:			str						,						lowerCAmelCase				:			int					):
										lowerCAmelCase  =				self.type_sequence_label_size
										lowerCAmelCase  =				ViTMSNForImageClassification(lowerCAmelCase					)
										model.to(lowerCAmelCase					)
										model.eval()
										lowerCAmelCase  =				model(lowerCAmelCase						,						labels=lowerCAmelCase					)
										print("""Pixel and labels shape: {pixel_values.shape}, {labels.shape}"""					)
										print("""Labels: {labels}"""					)
										self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.type_sequence_label_size)					)

										# test greyscale images
										lowerCAmelCase  =				1
										lowerCAmelCase  =				ViTMSNForImageClassification(lowerCAmelCase					)
										model.to(lowerCAmelCase					)
										model.eval()

										lowerCAmelCase  =				floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
										lowerCAmelCase  =				model(lowerCAmelCase					)
										self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.type_sequence_label_size)					)




						def   __lowercase (							self				:			Optional[Any]					):
										lowerCAmelCase  =				self.prepare_config_and_inputs()
										lowerCAmelCase ,						lowerCAmelCase ,						lowerCAmelCase  =				config_and_inputs
										lowerCAmelCase  =				{"""pixel_values""": pixel_values}
										return config, inputs_dict






@require_torch
class       SCREAMING_SNAKE_CASE__					(					_a						,				_a						,				unittest.TestCase					):
						_a    						=						(ViTMSNModel, ViTMSNForImageClassification) if is_torch_available() else ()
						_a    						=						(
						    {'feature-extraction': ViTMSNModel, 'image-classification': ViTMSNForImageClassification}
						    if is_torch_available()
						    else {}
						)

						_a    						=						False
						_a    						=						False
						_a    						=						False
						_a    						=						False


						def   __lowercase (							self				:			Tuple					):
										lowerCAmelCase  =				ViTMSNModelTester(self					)
										lowerCAmelCase  =				ConfigTester(self						,						config_class=lowerCAmelCase						,						has_text_modality=lowerCAmelCase						,						hidden_size=37					)


						def   __lowercase (							self				:			Dict					):
										self.config_tester.run_common_tests()


						@unittest.skip(reason="""ViTMSN does not use inputs_embeds"""					)
						def   __lowercase (							self				:			Optional[Any]					):
										pass


						def   __lowercase (							self				:			int					):
										lowerCAmelCase ,						lowerCAmelCase  =				self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
														lowerCAmelCase  =				model_class(lowerCAmelCase					)
														self.assertIsInstance(model.get_input_embeddings()						,						(nn.Module)					)
														lowerCAmelCase  =				model.get_output_embeddings()
														self.assertTrue(x is None or isinstance(lowerCAmelCase						,						nn.Linear					)					)


						def   __lowercase (							self				:			Optional[int]					):
										lowerCAmelCase ,						lowerCAmelCase  =				self.model_tester.prepare_config_and_inputs_for_common()

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

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


						def   __lowercase (							self				:			Union[str, Any]					):
										lowerCAmelCase  =				self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCAmelCase					)


						def   __lowercase (							self				:			Union[str, Any]					):
										lowerCAmelCase  =				self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase					)




						@slow
						def   __lowercase (							self				:			Optional[Any]					):
										for model_name in VIT_MSN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														lowerCAmelCase  =				ViTMSNModel.from_pretrained(lowerCAmelCase					)
														self.assertIsNotNone(lowerCAmelCase					)





def 							lowercase					()     ->  Dict:


				'''simple docstring'''






				lowerCAmelCase  =				Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
				return image






@require_torch
@require_vision
class       SCREAMING_SNAKE_CASE__					(					unittest.TestCase					):


						@cached_property
						def   __lowercase (							self				:			Dict					):
										return ViTImageProcessor.from_pretrained("""facebook/vit-msn-small"""					) if is_vision_available() else None




						@slow
						def   __lowercase (							self				:			Tuple					):
										torch.manual_seed(2					)
										lowerCAmelCase  =				ViTMSNForImageClassification.from_pretrained("""facebook/vit-msn-small"""					).to(lowerCAmelCase					)

										lowerCAmelCase  =				self.default_image_processor
										lowerCAmelCase  =				prepare_img()
										lowerCAmelCase  =				image_processor(images=lowerCAmelCase						,						return_tensors="""pt"""					).to(lowerCAmelCase					)

										# forward pass
										with torch.no_grad():
														lowerCAmelCase  =				model(**lowerCAmelCase					)

										# verify the logits
										lowerCAmelCase  =				torch.Size((1, 1000)					)
										self.assertEqual(outputs.logits.shape						,						lowerCAmelCase					)

										lowerCAmelCase  =				torch.tensor([-0.0803, -0.4454, -0.2375]					).to(lowerCAmelCase					)

										self.assertTrue(torch.allclose(outputs.logits[0, :3]						,						lowerCAmelCase						,						atol=1e-4					)					)





