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


_UpperCAmelCase		:       Optional[Any]						    =	logging.get_logger(__name__)

_UpperCAmelCase		:       List[Any]						    =	{
    "alibaba-damo/mgp-str-base": "https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json",
}







class 			lowercase    (	SCREAMING_SNAKE_CASE__      ):
				__SCREAMING_SNAKE_CASE :			List[Any]	      =      'mgp-str'




				def __init__( self				,       snake_case=[32, 128]				,       snake_case=4				,       snake_case=3				,       snake_case=27				,       snake_case=38				,       snake_case=5_0257				,       snake_case=3_0522				,       snake_case=768				,       snake_case=12				,       snake_case=12				,       snake_case=4.0				,       snake_case=True				,       snake_case=False				,       snake_case=1e-5				,       snake_case=0.0				,       snake_case=0.0				,       snake_case=0.0				,       snake_case=False				,       snake_case=0.02				,       **snake_case				,       ):
											super().__init__(**a_	)

											snake_case_          =   image_size
											snake_case_          =   patch_size
											snake_case_          =   num_channels
											snake_case_          =   max_token_length
											snake_case_          =   num_character_labels
											snake_case_          =   num_bpe_labels
											snake_case_          =   num_wordpiece_labels
											snake_case_          =   hidden_size
											snake_case_          =   num_hidden_layers
											snake_case_          =   num_attention_heads
											snake_case_          =   mlp_ratio
											snake_case_          =   distilled
											snake_case_          =   layer_norm_eps
											snake_case_          =   drop_rate
											snake_case_          =   qkv_bias
											snake_case_          =   attn_drop_rate
											snake_case_          =   drop_path_rate
											snake_case_          =   output_aa_attentions
											snake_case_          =   initializer_range







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 			lowercase    (	unittest.TestCase      ):




				@slow
				def    a							( self	):
											snake_case_          =   AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'	)
											snake_case_          =   AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'	)
											model.to(snake_case	)

											from datasets import load_dataset

											snake_case_          =   load_dataset('nielsr/rvlcdip-demo'	)

											snake_case_          =   dataset['train'][0]['image'].convert('RGB'	)

											snake_case_          =   image_processor(snake_case				,       return_tensors='pt'	).to(snake_case	)

											# forward pass
											with torch.no_grad():
																		snake_case_          =   model(**snake_case	)
																		snake_case_          =   outputs.logits

											snake_case_          =   torch.Size((1, 16)	)
											self.assertEqual(logits.shape				,       snake_case	)

											snake_case_          =   torch.tensor(
											    [-0.41_58, -0.40_92, -0.43_47]				,       device=snake_case				,       dtype=torch.float				,       )
											self.assertTrue(torch.allclose(logits[0, :3]				,       snake_case				,       atol=1e-4	)	)




