





import unittest

from transformers import AutoTokenizer, FalconConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 (
        FalconForCausalLM,
        FalconForQuestionAnswering,
        FalconForSequenceClassification,
        FalconForTokenClassification,
        FalconModel,
    )





class  A__    :




   """simple docstring"""



   def __init__(					self					,  lowercase					,  lowercase=3					,  lowercase=7					,  lowercase=True					,  lowercase=True					,  lowercase=False					,  lowercase=True					,  lowercase=99					,  lowercase=32					,  lowercase=5					,  lowercase=4					,  lowercase=37					,  lowercase="gelu"					,  lowercase=0.1					,  lowercase=0.1					,  lowercase=512					,  lowercase=16					,  lowercase=2					,  lowercase=0.02					,  lowercase=3					,  lowercase=4					,  lowercase=None					,  )			->						Any:







          '''simple docstring'''

          a__						:	Tuple =				parent
          a__						:	str =				batch_size
          a__						:	Union[str, Any] =				seq_length
          a__						:	Optional[int] =				is_training
          a__						:	str =				use_input_mask
          a__						:	int =				use_token_type_ids
          a__						:	int =				use_labels
          a__						:	List[Any] =				vocab_size
          a__						:	Dict =				hidden_size
          a__						:	List[Any] =				num_hidden_layers
          a__						:	Tuple =				num_attention_heads
          a__						:	Tuple =				intermediate_size
          a__						:	Tuple =				hidden_act
          a__						:	Dict =				hidden_dropout_prob
          a__						:	Tuple =				attention_probs_dropout_prob
          a__						:	Optional[int] =				max_position_embeddings
          a__						:	Tuple =				type_vocab_size
          a__						:	Optional[int] =				type_sequence_label_size
          a__						:	Union[str, Any] =				initializer_range
          a__						:	Any =				num_labels
          a__						:	Any =				num_choices
          a__						:	List[Any] =				scope

   def 							__lowercase		(					self)			->						int:







          '''simple docstring'''

          a__						:	Optional[int] =				ids_tensor([self.batch_size, self.seq_length]					,  self.vocab_size)

          a__						:	int =				None
          if self.use_input_mask:
                 a__						:	Optional[int] =				random_attention_mask([self.batch_size, self.seq_length])

          a__						:	Any =				None

          a__						:	str =				None
          a__						:	int =				None
          a__						:	Dict =				None
          if self.use_labels:
                 a__						:	List[Any] =				ids_tensor([self.batch_size]					,  self.type_sequence_label_size)
                 a__						:	Optional[Any] =				ids_tensor([self.batch_size, self.seq_length]					,  self.num_labels)
                 a__						:	Optional[int] =				ids_tensor([self.batch_size]					,  self.num_choices)

          a__						:	List[str] =				self.get_config()

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

   def 							__lowercase		(					self)			->						Optional[int]:







          '''simple docstring'''

          return FalconConfig(
              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					,  is_decoder=lowercase					,  initializer_range=self.initializer_range					,  pad_token_id=1					,  new_decoder_architecture=lowercase					,  )

   def 							__lowercase		(					self					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase)			->						int:







          '''simple docstring'''

          a__						:	Tuple =				FalconModel(config=lowercase)
          model.to(lowercase)
          model.eval()
          a__						:	Tuple =				model(lowercase					,  attention_mask=lowercase)
          a__						:	Any =				model(lowercase)
          self.parent.assertEqual(result.last_hidden_state.shape					,  (self.batch_size, self.seq_length, self.hidden_size))

   def 							__lowercase		(					self					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  )			->						Optional[int]:







          '''simple docstring'''

          a__						:	str =				True
          a__						:	Dict =				FalconModel(lowercase)
          model.to(lowercase)
          model.eval()
          a__						:	Union[str, Any] =				model(
              lowercase					,  attention_mask=lowercase					,  encoder_hidden_states=lowercase					,  encoder_attention_mask=lowercase					,  )
          a__						:	int =				model(
              lowercase					,  attention_mask=lowercase					,  encoder_hidden_states=lowercase					,  )
          a__						:	str =				model(lowercase					,  attention_mask=lowercase)
          self.parent.assertEqual(result.last_hidden_state.shape					,  (self.batch_size, self.seq_length, self.hidden_size))

   def 							__lowercase		(					self					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  )			->						Optional[int]:







          '''simple docstring'''

          a__						:	List[str] =				FalconForCausalLM(config=lowercase)
          model.to(lowercase)
          model.eval()
          a__						:	Any =				model(lowercase					,  attention_mask=lowercase					,  labels=lowercase)
          self.parent.assertEqual(result.logits.shape					,  (self.batch_size, self.seq_length, self.vocab_size))

   def 							__lowercase		(					self					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  lowercase					,  )			->						Any:







          '''simple docstring'''

          a__						:	List[str] =				True
          a__						:	Dict =				True
          a__						:	Optional[int] =				FalconForCausalLM(config=lowercase)
          model.to(lowercase)
          model.eval()

          # first forward pass
          a__						:	str =				model(
              lowercase					,  attention_mask=lowercase					,  encoder_hidden_states=lowercase					,  encoder_attention_mask=lowercase					,  use_cache=lowercase					,  )
          a__						:	Union[str, Any] =				outputs.past_key_values

          # create hypothetical multiple next token and extent to next_input_ids
          a__						:	Optional[int] =				ids_tensor((self.batch_size, 3)					,  config.vocab_size)
          a__						:	Optional[Any] =				ids_tensor((self.batch_size, 3)					,  vocab_size=2)

          # append to next input_ids and
          a__						:	Optional[int] =				torch.cat([input_ids, next_tokens]					,  dim=-1)
          a__						:	Optional[Any] =				torch.cat([input_mask, next_mask]					,  dim=-1)

          a__						:	List[Any] =				model(
              lowercase					,  attention_mask=lowercase					,  encoder_hidden_states=lowercase					,  encoder_attention_mask=lowercase					,  output_hidden_states=lowercase					,  )['hidden_states'][0]
          a__						:	List[Any] =				model(
              lowercase					,  attention_mask=lowercase					,  encoder_hidden_states=lowercase					,  encoder_attention_mask=lowercase					,  past_key_values=lowercase					,  output_hidden_states=lowercase					,  )['hidden_states'][0]

          # select random slice
          a__						:	Any =				ids_tensor((1,)					,  output_from_past.shape[-1]).item()
          a__						:	Optional[Any] =				output_from_no_past[:, -3:, random_slice_idx].detach()
          a__						:	Dict =				output_from_past[:, :, random_slice_idx].detach()

          self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1])

          # test that outputs are equal for slice
          self.parent.assertTrue(torch.allclose(lowercase					,  lowercase					,  atol=1e-3))

   def 							__lowercase		(					self)			->						Tuple:







          '''simple docstring'''

          a__						:	Optional[Any] =				self.prepare_config_and_inputs()
          (
              (
              a__
          ) ,							(
              a__
          ) ,							(
              a__
          ) ,							(
              a__
          ) ,							(
              a__
          ) ,							(
              a__
          ) ,							(
              a__
          ) ,							
          )						:	Tuple =				config_and_inputs
          a__						:	Union[str, Any] =				{'input_ids': input_ids, 'attention_mask': input_mask}
          return config, inputs_dict





@require_torch
class  A__    (							__UpperCAmelCase ,  __UpperCAmelCase ,  __UpperCAmelCase ,  unittest.TestCase	):




   """simple docstring"""



   __A   :				Union[str, Any]         =  (
       (
           FalconModel,
           FalconForCausalLM,
           FalconForSequenceClassification,
           FalconForTokenClassification,
           FalconForQuestionAnswering,
       )
       if is_torch_available()
       else ()
   )
   __A   :				List[str]         =  (FalconForCausalLM,) if is_torch_available() else ()
   __A   :				Tuple         =  (
       {
           '''feature-extraction''': FalconModel,
           '''text-classification''': FalconForSequenceClassification,
           '''text-generation''': FalconForCausalLM,
           '''question-answering''': FalconForQuestionAnswering,
           '''token-classification''': FalconForTokenClassification,
           '''zero-shot''': FalconForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   __A   :				Any         =  False
   __A   :				Any         =  False

   def 							__lowercase		(					self)			->						Dict:







          '''simple docstring'''

          a__						:	int =				FalconModelTester(self)
          a__						:	Dict =				ConfigTester(self					,  config_class=lowercase					,  hidden_size=37)

   def 							__lowercase		(					self)			->						List[Any]:







          '''simple docstring'''

          self.config_tester.run_common_tests()

   def 							__lowercase		(					self)			->						Dict:







          '''simple docstring'''

          a__						:	str =				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*lowercase)

   def 							__lowercase		(					self)			->						Dict:







          '''simple docstring'''

          a__ ,							*a__						:	Union[str, Any] =				self.model_tester.prepare_config_and_inputs()
          for alibi in [True, False]:
                 a__						:	Tuple =				alibi
                 self.model_tester.create_and_check_model(lowercase					,  *lowercase)

   def 							__lowercase		(					self)			->						str:







          '''simple docstring'''

          a__ ,							a__						:	int =				self.model_tester.prepare_config_and_inputs_for_common()
          a__						:	List[str] =				3
          a__						:	str =				input_dict['input_ids']
          a__						:	Optional[Any] =				input_ids.ne(1).to(lowercase)
          a__						:	Tuple =				ids_tensor([self.model_tester.batch_size]					,  self.model_tester.type_sequence_label_size)
          a__						:	List[Any] =				FalconForSequenceClassification(lowercase)
          model.to(lowercase)
          model.eval()
          a__						:	Any =				model(lowercase					,  attention_mask=lowercase					,  labels=lowercase)
          self.assertEqual(result.logits.shape					,  (self.model_tester.batch_size, self.model_tester.num_labels))

   def 							__lowercase		(					self)			->						List[Any]:







          '''simple docstring'''

          a__ ,							a__						:	int =				self.model_tester.prepare_config_and_inputs_for_common()
          a__						:	int =				3
          a__						:	Any =				'single_label_classification'
          a__						:	Any =				input_dict['input_ids']
          a__						:	Any =				input_ids.ne(1).to(lowercase)
          a__						:	Optional[Any] =				ids_tensor([self.model_tester.batch_size]					,  self.model_tester.type_sequence_label_size)
          a__						:	Tuple =				FalconForSequenceClassification(lowercase)
          model.to(lowercase)
          model.eval()
          a__						:	Tuple =				model(lowercase					,  attention_mask=lowercase					,  labels=lowercase)
          self.assertEqual(result.logits.shape					,  (self.model_tester.batch_size, self.model_tester.num_labels))

   def 							__lowercase		(					self)			->						int:







          '''simple docstring'''

          a__ ,							a__						:	Tuple =				self.model_tester.prepare_config_and_inputs_for_common()
          a__						:	List[str] =				input_dict['input_ids']
          a__						:	Optional[Any] =				FalconForCausalLM(lowercase)
          model.to(lowercase)
          model.eval()
          a__						:	Tuple =				model(lowercase					,  use_cache=lowercase)
          a__						:	List[Any] =				input_ids.shape[0]
          a__						:	int =				model._convert_to_rw_cache(result.past_key_values)
          a__						:	Optional[Any] =				model._convert_cache_to_standard_format(lowercase					,  lowercase)
          for layer in range(len(lowercase)):
                 for tensor_idx in range(2):
                        self.assertTrue(rw_cache[layer][tensor_idx].ndim == 3)
                        self.assertTrue(result.past_key_values[layer][tensor_idx].ndim == 4)
                        self.assertTrue(
                            torch.all(result.past_key_values[layer][tensor_idx] == standard_cache[layer][tensor_idx]))

   def 							__lowercase		(					self)			->						Union[str, Any]:







          '''simple docstring'''

          a__ ,							a__						:	List[str] =				self.model_tester.prepare_config_and_inputs_for_common()
          a__						:	Optional[Any] =				3
          a__						:	Tuple =				'multi_label_classification'
          a__						:	Union[str, Any] =				input_dict['input_ids']
          a__						:	List[str] =				input_ids.ne(1).to(lowercase)
          a__						:	Any =				ids_tensor(
              [self.model_tester.batch_size, config.num_labels]					,  self.model_tester.type_sequence_label_size).to(torch.float)
          a__						:	List[str] =				FalconForSequenceClassification(lowercase)
          model.to(lowercase)
          model.eval()
          a__						:	Dict =				model(lowercase					,  attention_mask=lowercase					,  labels=lowercase)
          self.assertEqual(result.logits.shape					,  (self.model_tester.batch_size, self.model_tester.num_labels))

   def 							__lowercase		(					self)			->						Optional[Any]:







          '''simple docstring'''

          for model_class in self.all_generative_model_classes:
                 a__ ,							a__						:	Optional[int] =				self.model_tester.prepare_config_and_inputs_for_common()

                 # If it doesn't support cache, pass the test
                 if not hasattr(lowercase					,  'use_cache'):
                        return

                 a__						:	Optional[int] =				model_class(lowercase).to(lowercase)
                 if "use_cache" not in inputs:
                        a__						:	Dict =				True
                 a__						:	List[str] =				model(**lowercase)

                 # If "past_key_values" is not returned, pass the test (e.g. RWKV uses a different cache name and format)
                 if "past_key_values" not in outputs:
                        return

                 a__						:	Optional[int] =				(
                     getattr(lowercase					,  'decoder_layers'					,  lowercase)
                     or getattr(lowercase					,  'num_decoder_layers'					,  lowercase)
                     or config.num_hidden_layers
                 )
                 a__						:	Tuple =				getattr(lowercase					,  'num_kv_heads'					,  config.num_attention_heads)
                 a__						:	int =				getattr(lowercase					,  'd_model'					,  config.hidden_size)
                 a__						:	Optional[Any] =				embed_dim // num_attention_heads

                 a__						:	Any =				outputs['past_key_values']
                 self.assertEqual(len(lowercase)					,  lowercase)

                 a__ ,							a__						:	Optional[Any] =				inputs['input_ids'].shape
                 for i in range(lowercase):
                        if config.new_decoder_architecture:
                               a__						:	int =				config.num_attention_heads
                        elif config.multi_query:
                               a__						:	Dict =				1
                        self.assertEqual(len(past_kv[0])					,  2)  # K V for the decoder = 2
                        self.assertEqual(
                            past_kv[i][0].shape					,  (batch_size, num_attention_heads, seq_length, per_head_embed_dim))
                        self.assertEqual(
                            past_kv[i][1].shape					,  (batch_size, num_attention_heads, seq_length, per_head_embed_dim))





@require_torch
class  A__    (							unittest.TestCase	):




   """simple docstring"""



   @slow
   def 							__lowercase		(					self)			->						Tuple:







          '''simple docstring'''

          a__						:	Optional[int] =				AutoTokenizer.from_pretrained('Rocketknight1/falcon-rw-1b')
          a__						:	List[str] =				FalconForCausalLM.from_pretrained('Rocketknight1/falcon-rw-1b')
          model.eval()
          model.to(lowercase)
          a__						:	int =				tokenizer('My favorite food is'					,  return_tensors='pt').to(lowercase)

          a__						:	Union[str, Any] =				(
              'My favorite food is pizza. I love it so much that I have a pizza party every year for my birthday.'
          )

          a__						:	List[Any] =				model.generate(**lowercase					,  do_sample=lowercase					,  max_new_tokens=19)
          a__						:	Tuple =				tokenizer.batch_decode(lowercase)[0]

          self.assertEqual(lowercase					,  lowercase)

   @slow
   def 							__lowercase		(					self)			->						Tuple:







          '''simple docstring'''

          for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
                 a__						:	int =				AutoTokenizer.from_pretrained(lowercase)
                 a__						:	List[Any] =				FalconForCausalLM.from_pretrained(lowercase)
                 model.eval()
                 model.to(lowercase)
                 a__						:	List[str] =				tokenizer('My favorite food is'					,  return_tensors='pt').to(lowercase)

                 # We just test that these run without errors - the models are randomly initialized
                 # and so the actual text outputs will be garbage
                 model.generate(**lowercase					,  do_sample=lowercase					,  max_new_tokens=4)
                 model.generate(**lowercase					,  do_sample=lowercase					,  max_new_tokens=4)
                 model.generate(**lowercase					,  num_beams=2					,  max_new_tokens=4)

   @slow
   def 							__lowercase		(					self)			->						List[str]:







          '''simple docstring'''

          with torch.no_grad():
                 for repo in [
                     "Rocketknight1/falcon-rw-1b",
                     "Rocketknight1/tiny-random-falcon-7b",
                     "Rocketknight1/tiny-random-falcon-40b",
                 ]:
                        a__						:	List[str] =				AutoTokenizer.from_pretrained(lowercase)
                        a__						:	int =				FalconForCausalLM.from_pretrained(lowercase)
                        model.eval()
                        model.to(device=lowercase)
                        a__						:	int =				tokenizer('My favorite food is'					,  return_tensors='pt').to(lowercase)

                        # Test results are the same with and without cache
                        a__						:	List[Any] =				model.generate(**lowercase					,  do_sample=lowercase					,  max_new_tokens=20					,  use_cache=lowercase)
                        a__						:	Optional[Any] =				model.generate(**lowercase					,  do_sample=lowercase					,  max_new_tokens=20					,  use_cache=lowercase)
                        self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0)









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  A__    :




   """simple docstring"""



   def __init__(					self					,  lowercase					,  lowercase=13					,  lowercase=30					,  lowercase=2					,  lowercase=3					,  lowercase=True					,  lowercase=True					,  lowercase=32					,  lowercase=5					,  lowercase=4					,  lowercase=37					,  lowercase="gelu"					,  lowercase=0.1					,  lowercase=0.1					,  lowercase=10					,  lowercase=0.02					,  lowercase=None					,  )			->						Union[str, Any]:







          '''simple docstring'''

          a__						:	Optional[int] =				parent
          a__						:	List[str] =				batch_size
          a__						:	List[str] =				image_size
          a__						:	Dict =				patch_size
          a__						:	Optional[Any] =				num_channels
          a__						:	List[Any] =				is_training
          a__						:	str =				use_labels
          a__						:	Dict =				hidden_size
          a__						:	Tuple =				num_hidden_layers
          a__						:	Tuple =				num_attention_heads
          a__						:	Union[str, Any] =				intermediate_size
          a__						:	List[str] =				hidden_act
          a__						:	List[str] =				hidden_dropout_prob
          a__						:	Any =				attention_probs_dropout_prob
          a__						:	Dict =				type_sequence_label_size
          a__						:	Tuple =				initializer_range
          a__						:	Optional[int] =				scope

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

   def 							__lowercase		(					self)			->						int:







          '''simple docstring'''

          a__						:	Tuple =				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

          a__						:	Tuple =				None
          if self.use_labels:
                 a__						:	List[Any] =				ids_tensor([self.batch_size]					,  self.type_sequence_label_size)

          a__						:	List[str] =				self.get_config()

          return config, pixel_values, labels

   def 							__lowercase		(					self)			->						Optional[int]:







          '''simple docstring'''

          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					,  lowercase					,  lowercase					,  lowercase)			->						List[str]:







          '''simple docstring'''

          a__						:	int =				ViTMSNModel(config=lowercase)
          model.to(lowercase)
          model.eval()
          a__						:	int =				model(lowercase)
          self.parent.assertEqual(result.last_hidden_state.shape					,  (self.batch_size, self.seq_length, self.hidden_size))

   def 							__lowercase		(					self					,  lowercase					,  lowercase					,  lowercase)			->						Tuple:







          '''simple docstring'''

          a__						:	Optional[Any] =				self.type_sequence_label_size
          a__						:	List[str] =				ViTMSNForImageClassification(lowercase)
          model.to(lowercase)
          model.eval()
          a__						:	int =				model(lowercase					,  labels=lowercase)
          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
          a__						:	List[str] =				1
          a__						:	Optional[int] =				ViTMSNForImageClassification(lowercase)
          model.to(lowercase)
          model.eval()

          a__						:	Dict =				floats_tensor([self.batch_size, 1, self.image_size, self.image_size])
          a__						:	Dict =				model(lowercase)
          self.parent.assertEqual(result.logits.shape					,  (self.batch_size, self.type_sequence_label_size))

   def 							__lowercase		(					self)			->						Tuple:







          '''simple docstring'''

          a__						:	List[Any] =				self.prepare_config_and_inputs()
          a__ ,							a__ ,							a__						:	Optional[Any] =				config_and_inputs
          a__						:	Dict =				{'pixel_values': pixel_values}
          return config, inputs_dict





@require_torch
class  A__    (							__UpperCAmelCase ,  __UpperCAmelCase ,  unittest.TestCase	):




   """simple docstring"""



   __A   :				Any         =  (ViTMSNModel, ViTMSNForImageClassification) if is_torch_available() else ()
   __A   :				Tuple         =  (
       {'''feature-extraction''': ViTMSNModel, '''image-classification''': ViTMSNForImageClassification}
       if is_torch_available()
       else {}
   )

   __A   :				List[str]         =  False
   __A   :				Optional[Any]         =  False
   __A   :				Union[str, Any]         =  False
   __A   :				Any         =  False

   def 							__lowercase		(					self)			->						List[str]:







          '''simple docstring'''

          a__						:	Optional[int] =				ViTMSNModelTester(self)
          a__						:	Union[str, Any] =				ConfigTester(self					,  config_class=lowercase					,  has_text_modality=lowercase					,  hidden_size=37)

   def 							__lowercase		(					self)			->						List[Any]:







          '''simple docstring'''

          self.config_tester.run_common_tests()

   @unittest.skip(reason='ViTMSN does not use inputs_embeds')
   def 							__lowercase		(					self)			->						Any:







          '''simple docstring'''

          pass

   def 							__lowercase		(					self)			->						Tuple:







          '''simple docstring'''

          a__ ,							a__						:	Tuple =				self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
                 a__						:	Union[str, Any] =				model_class(lowercase)
                 self.assertIsInstance(model.get_input_embeddings()					,  (nn.Module))
                 a__						:	str =				model.get_output_embeddings()
                 self.assertTrue(x is None or isinstance(lowercase					,  nn.Linear))

   def 							__lowercase		(					self)			->						Tuple:







          '''simple docstring'''

          a__ ,							a__						:	Optional[int] =				self.model_tester.prepare_config_and_inputs_for_common()

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

                 a__						:	Optional[Any] =				['pixel_values']
                 self.assertListEqual(arg_names[:1]					,  lowercase)

   def 							__lowercase		(					self)			->						str:







          '''simple docstring'''

          a__						:	List[str] =				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*lowercase)

   def 							__lowercase		(					self)			->						str:







          '''simple docstring'''

          a__						:	Any =				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*lowercase)

   @slow
   def 							__lowercase		(					self)			->						Union[str, Any]:







          '''simple docstring'''

          for model_name in VIT_MSN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 a__						:	Tuple =				ViTMSNModel.from_pretrained(lowercase)
                 self.assertIsNotNone(lowercase)



def A_	(		)  ->		Dict:
       a__						:	List[str] =				Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'				)
       return image





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




   """simple docstring"""



   @cached_property
   def 							__lowercase		(					self)			->						List[Any]:







          '''simple docstring'''

          return ViTImageProcessor.from_pretrained('facebook/vit-msn-small') if is_vision_available() else None

   @slow
   def 							__lowercase		(					self)			->						List[Any]:







          '''simple docstring'''

          torch.manual_seed(2)
          a__						:	List[str] =				ViTMSNForImageClassification.from_pretrained('facebook/vit-msn-small').to(lowercase)

          a__						:	Any =				self.default_image_processor
          a__						:	List[Any] =				prepare_img()
          a__						:	Optional[Any] =				image_processor(images=lowercase					,  return_tensors='pt').to(lowercase)

          # forward pass
          with torch.no_grad():
                 a__						:	Tuple =				model(**lowercase)

          # verify the logits
          a__						:	Union[str, Any] =				torch.Size((1, 1000))
          self.assertEqual(outputs.logits.shape					,  lowercase)

          a__						:	Any =				torch.tensor([-0.08_03, -0.44_54, -0.23_75]).to(lowercase)

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


