"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging


_a      :		str           =   logging.get_logger(__name__)

_a      :		Optional[Any]           =   {
    'sayakpaul/vit-msn-base': 'https://huggingface.co/sayakpaul/vit-msn-base/resolve/main/config.json',
    # See all ViT MSN models at https://huggingface.co/models?filter=vit_msn
}
class 						__A							( SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:			Optional[int]							=		"vit_msn"






     def __init__(		self				,     a__=768				,     a__=12				,     a__=12				,     a__=3072				,     a__="gelu"				,     a__=0.0				,     a__=0.0				,     a__=0.0_2				,     a__=1e-06				,     a__=224				,     a__=16				,     a__=3				,     a__=True				,     **a__				,     ):
       super().__init__(**a__  )

       _lowerCAmelCase						:       List[str]  			=     hidden_size
       _lowerCAmelCase						:       Union[str, Any]  			=     num_hidden_layers
       _lowerCAmelCase						:       List[str]  			=     num_attention_heads
       _lowerCAmelCase						:       int  			=     intermediate_size
       _lowerCAmelCase						:       int  			=     hidden_act
       _lowerCAmelCase						:       Union[str, Any]  			=     hidden_dropout_prob
       _lowerCAmelCase						:       Union[str, Any]  			=     attention_probs_dropout_prob
       _lowerCAmelCase						:       Union[str, Any]  			=     initializer_range
       _lowerCAmelCase						:       Union[str, Any]  			=     layer_norm_eps
       _lowerCAmelCase						:       Tuple  			=     image_size
       _lowerCAmelCase						:       Dict  			=     patch_size
       _lowerCAmelCase						:       Optional[int]  			=     num_channels
       _lowerCAmelCase						:       Union[str, Any]  			=     qkv_bias








'''simple docstring'''



import unittest

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


if is_torch_available():
      import torch

      from transformers import AutoModelForImageClassification

if is_vision_available():
      from transformers import AutoImageProcessor





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





    """simple docstring"""






    @slow
    def       lowercase_				(							self	)				->     List[str]:
         __lowerCamelCase   :	Any								=		AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'	)
         __lowerCamelCase   :	Tuple								=		AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'	)
         model.to(SCREAMING_SNAKE_CASE_	)

         from datasets import load_dataset

         __lowerCamelCase   :	str								=		load_dataset('nielsr/rvlcdip-demo'	)

         __lowerCamelCase   :	List[Any]								=		dataset['train'][0]['image'].convert('RGB'	)

         __lowerCamelCase   :	str								=		image_processor(SCREAMING_SNAKE_CASE_			,     return_tensors='pt'	).to(SCREAMING_SNAKE_CASE_	)

         # forward pass
         with torch.no_grad():
              __lowerCamelCase   :	str								=		model(**SCREAMING_SNAKE_CASE_	)
              __lowerCamelCase   :	int								=		outputs.logits

         __lowerCamelCase   :	List[Any]								=		torch.Size((1, 16)	)
         self.assertEqual(logits.shape			,     SCREAMING_SNAKE_CASE_	)

         __lowerCamelCase   :	Optional[Any]								=		torch.tensor(
             [-0.4_1_5_8, -0.4_0_9_2, -0.4_3_4_7]			,     device=SCREAMING_SNAKE_CASE_			,     dtype=torch.float			,     )
         self.assertTrue(torch.allclose(logits[0, :3]			,     SCREAMING_SNAKE_CASE_			,     atol=1E-4	)	)






