'''simple docstring'''





import gc
import unittest

from transformers import CTRLConfig, 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 (
			    CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
			    CTRLForSequenceClassification,
			    CTRLLMHeadModel,
			    CTRLModel,
			)




class 		SCREAMING_SNAKE_CASE  :







				'''simple docstring'''





				def __init__(    self       :    List[str]							,		lowercase__       :    Union[str, Any]							,		lowercase__       :    Optional[Any]=14							,		lowercase__       :    Optional[int]=7							,		lowercase__       :    Union[str, Any]=True							,		lowercase__       :    List[Any]=True							,		lowercase__       :    Tuple=True							,		lowercase__       :    List[Any]=True							,		lowercase__       :    Dict=True							,		lowercase__       :    Dict=99							,		lowercase__       :    Any=32							,		lowercase__       :    str=5							,		lowercase__       :    int=4							,		lowercase__       :    Tuple=37							,		lowercase__       :    Optional[int]="gelu"							,		lowercase__       :    Optional[int]=0.1							,		lowercase__       :    Optional[int]=0.1							,		lowercase__       :    Tuple=512							,		lowercase__       :    Any=16							,		lowercase__       :    Dict=2							,		lowercase__       :    Dict=0.0_2							,		lowercase__       :    List[str]=3							,		lowercase__       :    Tuple=4							,		lowercase__       :    int=None							,		)				->Union[str, Any]:


										'''simple docstring'''




										_UpperCamelCase      :      List[str]       =    parent
										_UpperCamelCase      :      List[str]       =    batch_size
										_UpperCamelCase      :      Any       =    seq_length
										_UpperCamelCase      :      Tuple       =    is_training
										_UpperCamelCase      :      Optional[int]       =    use_token_type_ids
										_UpperCamelCase      :      Any       =    use_input_mask
										_UpperCamelCase      :      int       =    use_labels
										_UpperCamelCase      :      Optional[Any]       =    use_mc_token_ids
										_UpperCamelCase      :      Any       =    vocab_size
										_UpperCamelCase      :      Optional[int]       =    hidden_size
										_UpperCamelCase      :      Any       =    num_hidden_layers
										_UpperCamelCase      :      int       =    num_attention_heads
										_UpperCamelCase      :      Optional[int]       =    intermediate_size
										_UpperCamelCase      :      List[str]       =    hidden_act
										_UpperCamelCase      :      Optional[int]       =    hidden_dropout_prob
										_UpperCamelCase      :      Optional[int]       =    attention_probs_dropout_prob
										_UpperCamelCase      :      Dict       =    max_position_embeddings
										_UpperCamelCase      :      Optional[Any]       =    type_vocab_size
										_UpperCamelCase      :      List[Any]       =    type_sequence_label_size
										_UpperCamelCase      :      Dict       =    initializer_range
										_UpperCamelCase      :      str       =    num_labels
										_UpperCamelCase      :      Any       =    num_choices
										_UpperCamelCase      :      Dict       =    scope
										_UpperCamelCase      :      Optional[int]       =    self.vocab_size - 1





				def 			snake_case__					(    self       :    str       )				->Optional[Any]:


										'''simple docstring'''




										_UpperCamelCase      :      Optional[Any]       =    ids_tensor([self.batch_size, self.seq_length]							,		self.vocab_size       )

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

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

										_UpperCamelCase      :      str       =    None
										if self.use_mc_token_ids:
																_UpperCamelCase      :      List[Any]       =    ids_tensor([self.batch_size, self.num_choices]							,		self.seq_length       )

										_UpperCamelCase      :      Optional[int]       =    None
										_UpperCamelCase      :      Tuple       =    None
										_UpperCamelCase      :      Optional[int]       =    None
										if self.use_labels:
																_UpperCamelCase      :      Any       =    ids_tensor([self.batch_size]							,		self.type_sequence_label_size       )
																_UpperCamelCase      :      Tuple       =    ids_tensor([self.batch_size, self.seq_length]							,		self.num_labels       )
																_UpperCamelCase      :      Union[str, Any]       =    ids_tensor([self.batch_size]							,		self.num_choices       )

										_UpperCamelCase      :      List[Any]       =    self.get_config()

										_UpperCamelCase      :      List[Any]       =    ids_tensor([self.num_hidden_layers, self.num_attention_heads]							,		2       )

										return (
										    config,
										    input_ids,
										    input_mask,
										    head_mask,
										    token_type_ids,
										    mc_token_ids,
										    sequence_labels,
										    token_labels,
										    choice_labels,
										)





				def 			snake_case__					(    self       :    Tuple       )				->List[Any]:


										'''simple docstring'''




										return CTRLConfig(
										    vocab_size=self.vocab_size							,		n_embd=self.hidden_size							,		n_layer=self.num_hidden_layers							,		n_head=self.num_attention_heads							,		n_positions=self.max_position_embeddings							,		pad_token_id=self.pad_token_id							,		)





				def 			snake_case__					(    self       :    Union[str, Any]							,		lowercase__       :    Any							,		lowercase__       :    List[str]							,		lowercase__       :    Dict							,		lowercase__       :    Optional[Any]							,		lowercase__       :    Dict							,		*lowercase__       :    Any       )				->Optional[Any]:


										'''simple docstring'''




										_UpperCamelCase      :      Tuple       =    CTRLModel(config=lowercase__       )
										model.to(lowercase__       )
										model.eval()

										model(lowercase__							,		token_type_ids=lowercase__							,		head_mask=lowercase__       )
										model(lowercase__							,		token_type_ids=lowercase__       )
										_UpperCamelCase      :      Dict       =    model(lowercase__       )
										self.parent.assertEqual(result.last_hidden_state.shape							,		(self.batch_size, self.seq_length, self.hidden_size)       )
										self.parent.assertEqual(len(result.past_key_values       )							,		config.n_layer       )





				def 			snake_case__					(    self       :    Optional[int]							,		lowercase__       :    Any							,		lowercase__       :    List[Any]							,		lowercase__       :    List[str]							,		lowercase__       :    Optional[Any]							,		lowercase__       :    List[str]							,		*lowercase__       :    Dict       )				->Optional[int]:


										'''simple docstring'''




										_UpperCamelCase      :      Dict       =    CTRLLMHeadModel(lowercase__       )
										model.to(lowercase__       )
										model.eval()

										_UpperCamelCase      :      int       =    model(lowercase__							,		token_type_ids=lowercase__							,		labels=lowercase__       )
										self.parent.assertEqual(result.loss.shape							,		()       )
										self.parent.assertEqual(result.logits.shape							,		(self.batch_size, self.seq_length, self.vocab_size)       )





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


										'''simple docstring'''




										_UpperCamelCase      :      Optional[Any]       =    self.prepare_config_and_inputs()

										(
										    _UpperCamelCase
										)      :      Tuple       =    config_and_inputs

										_UpperCamelCase      :      List[str]       =    {"input_ids": input_ids, "token_type_ids": token_type_ids, "head_mask": head_mask}

										return config, inputs_dict







				def 			snake_case__					(    self       :    Any							,		lowercase__       :    List[Any]							,		lowercase__       :    str							,		lowercase__       :    Optional[Any]							,		lowercase__       :    int							,		*lowercase__       :    Dict       )				->int:


										'''simple docstring'''




										_UpperCamelCase      :      Optional[Any]       =    self.num_labels
										_UpperCamelCase      :      Union[str, Any]       =    CTRLForSequenceClassification(lowercase__       )
										model.to(lowercase__       )
										model.eval()
										_UpperCamelCase      :      str       =    ids_tensor([self.batch_size]							,		self.type_sequence_label_size       )
										_UpperCamelCase      :      int       =    model(lowercase__							,		token_type_ids=lowercase__							,		labels=lowercase__       )
										self.parent.assertEqual(result.logits.shape							,		(self.batch_size, self.num_labels)       )





@require_torch
class 		SCREAMING_SNAKE_CASE  (       SCREAMING_SNAKE_CASE ,			SCREAMING_SNAKE_CASE ,			SCREAMING_SNAKE_CASE ,			unittest.TestCase						):







				'''simple docstring'''
				UpperCAmelCase__					      =				(CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
				UpperCAmelCase__					      =				(CTRLLMHeadModel,) if is_torch_available() else ()
				UpperCAmelCase__					      =				(
				    {
				        '''feature-extraction''': CTRLModel,
				        '''text-classification''': CTRLForSequenceClassification,
				        '''text-generation''': CTRLLMHeadModel,
				        '''zero-shot''': CTRLForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				UpperCAmelCase__					      =				True
				UpperCAmelCase__					      =				False
				UpperCAmelCase__					      =				False





				def 			snake_case__					(    self       :    Optional[int]							,		lowercase__       :    List[str]							,		lowercase__       :    List[Any]							,		lowercase__       :    Tuple							,		lowercase__       :    str							,		lowercase__       :    Optional[Any]       )				->Tuple:


										'''simple docstring'''




										if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
																# Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
																# `CTRLConfig` was never used in pipeline tests, either because of a missing checkpoint or because a tiny
																# config could not be created.
																return True

										return False





				def 			snake_case__					(    self       :    List[str]       )				->int:


										'''simple docstring'''




										_UpperCamelCase      :      List[str]       =    CTRLModelTester(self       )
										_UpperCamelCase      :      List[str]       =    ConfigTester(self							,		config_class=lowercase__							,		n_embd=37       )





				def 			snake_case__					(    self       :    List[Any]       )				->Optional[Any]:


										'''simple docstring'''




										super().tearDown()
										# clean-up as much as possible GPU memory occupied by PyTorch
										gc.collect()
										torch.cuda.empty_cache()





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


										'''simple docstring'''




										self.config_tester.run_common_tests()





				def 			snake_case__					(    self       :    List[Any]       )				->Dict:


										'''simple docstring'''




										_UpperCamelCase      :      Union[str, Any]       =    self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_ctrl_model(*lowercase__       )





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


										'''simple docstring'''




										_UpperCamelCase      :      Optional[Any]       =    self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_lm_head_model(*lowercase__       )





				@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."       )
				def 			snake_case__					(    self       :    Any       )				->Optional[Any]:


										'''simple docstring'''




										pass





				@slow
				def 			snake_case__					(    self       :    Dict       )				->Optional[Any]:


										'''simple docstring'''




										for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																_UpperCamelCase      :      List[str]       =    CTRLModel.from_pretrained(lowercase__       )
																self.assertIsNotNone(lowercase__       )







				@unittest.skip("The model doesn't support left padding"       )  # and it's not used enough to be worth fixing :)
				def 			snake_case__					(    self       :    int       )				->int:


										'''simple docstring'''




										pass





@require_torch
class 		SCREAMING_SNAKE_CASE  (       unittest.TestCase						):







				'''simple docstring'''





				def 			snake_case__					(    self       :    str       )				->Optional[Any]:


										'''simple docstring'''




										super().tearDown()
										# clean-up as much as possible GPU memory occupied by PyTorch
										gc.collect()
										torch.cuda.empty_cache()







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


										'''simple docstring'''




										_UpperCamelCase      :      Optional[Any]       =    CTRLLMHeadModel.from_pretrained("ctrl"       )
										model.to(lowercase__       )
										_UpperCamelCase      :      List[str]       =    torch.tensor(
										    [[11_859, 0, 1_611, 8]]							,		dtype=torch.long							,		device=lowercase__       )  # Legal the president is
										_UpperCamelCase      :      List[Any]       =    [
										    11_859,
										    0,
										    1_611,
										    8,
										    5,
										    150,
										    26_449,
										    2,
										    19,
										    348,
										    469,
										    3,
										    2_595,
										    48,
										    20_740,
										    246_533,
										    246_533,
										    19,
										    30,
										    5,
										]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

										_UpperCamelCase      :      Union[str, Any]       =    model.generate(lowercase__							,		do_sample=lowercase__       )
										self.assertListEqual(output_ids[0].tolist()							,		lowercase__       )






'''simple docstring'''


import inspect
import math
import tempfile
import unittest

import numpy as np

from transformers import ViTMAEConfig
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 ViTMAEForPreTraining, ViTMAEModel
      from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import ViTImageProcessor







class 							__magic_name__	:

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     lowerCamelCase=13			,     lowerCamelCase=30			,     lowerCamelCase=2			,     lowerCamelCase=3			,     lowerCamelCase=True			,     lowerCamelCase=True			,     lowerCamelCase=32			,     lowerCamelCase=5			,     lowerCamelCase=4			,     lowerCamelCase=37			,     lowerCamelCase="gelu"			,     lowerCamelCase=0.1			,     lowerCamelCase=0.1			,     lowerCamelCase=10			,     lowerCamelCase=0.02			,     lowerCamelCase=3			,     lowerCamelCase=0.6			,     lowerCamelCase=None			,     ):


          '''simple docstring'''





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

          # in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
          # (we add 1 for the [CLS] token)
          __A	:       Optional[int]      =							(image_size // patch_size) ** 2
          __A	:       List[Any]      =							int(math.ceil((1 - mask_ratio) * (num_patches + 1)		)		)


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Optional[Any]      =							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

          __A	:       Tuple      =							None
          if self.use_labels:
               __A	:       Union[str, Any]      =							ids_tensor([self.batch_size]			,     self.type_sequence_label_size		)

          __A	:       Optional[int]      =							self.get_config()

          return config, pixel_values, labels


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          return ViTMAEConfig(
              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=lowerCamelCase			,     initializer_range=self.initializer_range			,     mask_ratio=self.mask_ratio			,     )


     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       Optional[Any]      =							ViTMAEModel(config=lowerCamelCase		)
          model.to(lowerCamelCase		)
          model.eval()
          __A	:       List[Any]      =							model(lowerCamelCase		)
          self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, self.seq_length, self.hidden_size)		)


     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       str      =							ViTMAEForPreTraining(lowerCamelCase		)
          model.to(lowerCamelCase		)
          model.eval()
          __A	:       Optional[Any]      =							model(lowerCamelCase		)
          __A	:       List[str]      =							(self.image_size // self.patch_size) ** 2
          __A	:       List[Any]      =							self.patch_size**2 * self.num_channels
          self.parent.assertEqual(result.logits.shape			,     (self.batch_size, num_patches, expected_num_channels)		)

          # test greyscale images
          __A	:       List[str]      =							1
          __A	:       str      =							ViTMAEForPreTraining(lowerCamelCase		)
          model.to(lowerCamelCase		)
          model.eval()
          __A	:       str      =							floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
          __A	:       int      =							model(lowerCamelCase		)
          __A	:       Union[str, Any]      =							self.patch_size**2
          self.parent.assertEqual(result.logits.shape			,     (self.batch_size, num_patches, expected_num_channels)		)


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       List[str]      =							self.prepare_config_and_inputs()
          __A  ,__A  ,__A	:       List[Any]      =							config_and_inputs
          __A	:       Tuple      =							{"pixel_values": pixel_values}
          return config, inputs_dict







@require_torch
class 							__magic_name__	(       lowerCAmelCase    ,		lowerCAmelCase    ,		unittest.TestCase ):

     """simple docstring"""






     lowerCamelCase__       						=				(ViTMAEModel, ViTMAEForPreTraining) if is_torch_available() else ()
     lowerCamelCase__       						=				{'feature-extraction': ViTMAEModel} if is_torch_available() else {}

     lowerCamelCase__       						=				False
     lowerCamelCase__       						=				False
     lowerCamelCase__       						=				False
     lowerCamelCase__       						=				False


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Union[str, Any]      =							ViTMAEModelTester(self		)
          __A	:       Tuple      =							ConfigTester(self			,     config_class=lowerCamelCase			,     has_text_modality=lowerCamelCase			,     hidden_size=37		)


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          self.config_tester.run_common_tests()


     @unittest.skip(reason="ViTMAE does not use inputs_embeds"		)
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          pass


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





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

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


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A  ,__A	:       List[str]      =							self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               __A	:       int      =							model_class(lowerCamelCase		)
               __A	:       Union[str, Any]      =							inspect.signature(model.forward		)
               # signature.parameters is an OrderedDict => so arg_names order is deterministic
               __A	:       Optional[Any]      =							[*signature.parameters.keys()]

               __A	:       Any      =							["pixel_values"]
               self.assertListEqual(arg_names[:1]			,     lowerCamelCase		)


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Optional[Any]      =							self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*lowerCamelCase		)


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Union[str, Any]      =							self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_pretraining(*lowerCamelCase		)


     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase		):


          '''simple docstring'''





          np.random.seed(2		)

          __A	:       Tuple      =							int((pt_model.config.image_size // pt_model.config.patch_size) ** 2		)
          __A	:       Optional[Any]      =							np.random.uniform(size=(self.model_tester.batch_size, num_patches)		)
          __A	:       Optional[Any]      =							torch.from_numpy(lowerCamelCase		)

          # Add `noise` argument.
          # PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
          __A	:       int      =							pt_noise

          super().check_pt_tf_models(lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase		)


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A  ,__A	:       List[str]      =							self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               __A	:       int      =							model_class(lowerCamelCase		)
               model.to(lowerCamelCase		)
               model.eval()
               # make random mask reproducible
               torch.manual_seed(2		)
               with torch.no_grad():
                    __A	:       List[str]      =							model(**self._prepare_for_class(lowerCamelCase			,     lowerCamelCase		)		)

               __A	:       Tuple      =							outputs[0].cpu().numpy()
               __A	:       List[Any]      =							0

               with tempfile.TemporaryDirectory() as tmpdirname:
                    model.save_pretrained(lowerCamelCase		)
                    __A	:       List[Any]      =							model_class.from_pretrained(lowerCamelCase		)
                    model.to(lowerCamelCase		)
                    # make random mask reproducible
                    torch.manual_seed(2		)
                    with torch.no_grad():
                         __A	:       Optional[Any]      =							model(**self._prepare_for_class(lowerCamelCase			,     lowerCamelCase		)		)

                    # Make sure we don't have nans
                    __A	:       List[Any]      =							after_outputs[0].cpu().numpy()
                    __A	:       List[str]      =							0
                    __A	:       int      =							np.amax(np.abs(out_a - out_a		)		)
                    self.assertLessEqual(lowerCamelCase			,     1E-5		)


     @unittest.skip(
         reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results."		)
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          pass


     @unittest.skip(
         reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results."		)
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          pass


     @unittest.skip(
         reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results."		)
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          pass


     @unittest.skip(reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load"		)
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          pass


     @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."		)
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          pass


     @slow
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __A	:       List[Any]      =							ViTMAEModel.from_pretrained(lowerCamelCase		)
               self.assertIsNotNone(lowerCamelCase		)


def 		_lowercase ():




     '''simple docstring'''





     __A	:       Union[str, Any]      =							Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"							)
     return image







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

     """simple docstring"""






     @cached_property
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          return ViTImageProcessor.from_pretrained("facebook/vit-mae-base"		) if is_vision_available() else None


     @slow
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          np.random.seed(2		)

          __A	:       Dict      =							ViTMAEForPreTraining.from_pretrained("facebook/vit-mae-base"		).to(lowerCamelCase		)

          __A	:       str      =							self.default_image_processor
          __A	:       List[Any]      =							prepare_img()
          __A	:       Union[str, Any]      =							image_processor(images=lowerCamelCase			,     return_tensors="pt"		).to(lowerCamelCase		)

          # prepare a noise vector that will be also used for testing the TF model
          # (this way we can ensure that the PT and TF models operate on the same inputs)
          __A	:       Optional[Any]      =							ViTMAEConfig()
          __A	:       List[str]      =							int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2		)
          __A	:       Any      =							np.random.uniform(size=(1, num_patches)		)

          # forward pass
          with torch.no_grad():
               __A	:       str      =							model(**lowerCamelCase			,     noise=torch.from_numpy(lowerCamelCase		).to(device=lowerCamelCase		)		)

          # verify the logits
          __A	:       Union[str, Any]      =							torch.Size((1, 196, 768)		)
          self.assertEqual(outputs.logits.shape			,     lowerCamelCase		)

          __A	:       int      =							torch.tensor(
              [[-0.0548, -1.7023, -0.9325], [0.3721, -0.5670, -0.2233], [0.8235, -1.3878, -0.3524]]		)

          self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]			,     expected_slice.to(lowerCamelCase		)			,     atol=1E-4		)		)

