



"""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 			lowercase__			(      unittest.TestCase    ):
							'''simple docstring'''







							@slow
							def        lowerCamelCase_   (  self						)			->							Dict:
									_UpperCAmelCase							 =		AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'						)
									_UpperCAmelCase							 =		AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'						)
									model.to(snake_case						)

									from datasets import load_dataset

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

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

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

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

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

									_UpperCAmelCase							 =		torch.tensor(
									    [-0.4158, -0.4092, -0.4347]	,       device=snake_case	,       dtype=torch.float	,       )
									self.assertTrue(torch.allclose(logits[0, :3]	,       snake_case	,       atol=1E-4						)						)







"""simple docstring"""





from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase  							=					logging.get_logger(__name__)

lowercase  							=					{
    '''microsoft/beit-base-patch16-224-pt22k''': (
        '''https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json'''
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}




class 			lowercase__			(      A    ):
							'''simple docstring'''







							_UpperCAmelCase      				=					'''beit'''






							def __init__(  self	,       snake_case=8192	,       snake_case=768	,       snake_case=12	,       snake_case=12	,       snake_case=3072	,       snake_case="gelu"	,       snake_case=0.0	,       snake_case=0.0	,       snake_case=0.02	,       snake_case=1E-12	,       snake_case=224	,       snake_case=16	,       snake_case=3	,       snake_case=False	,       snake_case=False	,       snake_case=False	,       snake_case=False	,       snake_case=0.1	,       snake_case=0.1	,       snake_case=True	,       snake_case=[3, 5, 7, 11]	,       snake_case=[1, 2, 3, 6]	,       snake_case=True	,       snake_case=0.4	,       snake_case=256	,       snake_case=1	,       snake_case=False	,       snake_case=255	,       **snake_case	,       )			->							str:
									super().__init__(**snake_case						)

									_UpperCAmelCase							 =		vocab_size
									_UpperCAmelCase							 =		hidden_size
									_UpperCAmelCase							 =		num_hidden_layers
									_UpperCAmelCase							 =		num_attention_heads
									_UpperCAmelCase							 =		intermediate_size
									_UpperCAmelCase							 =		hidden_act
									_UpperCAmelCase							 =		hidden_dropout_prob
									_UpperCAmelCase							 =		attention_probs_dropout_prob
									_UpperCAmelCase							 =		initializer_range
									_UpperCAmelCase							 =		layer_norm_eps

									_UpperCAmelCase							 =		image_size
									_UpperCAmelCase							 =		patch_size
									_UpperCAmelCase							 =		num_channels
									_UpperCAmelCase							 =		use_mask_token
									_UpperCAmelCase							 =		use_absolute_position_embeddings
									_UpperCAmelCase							 =		use_relative_position_bias
									_UpperCAmelCase							 =		use_shared_relative_position_bias
									_UpperCAmelCase							 =		layer_scale_init_value
									_UpperCAmelCase							 =		drop_path_rate
									_UpperCAmelCase							 =		use_mean_pooling
									# decode head attributes (semantic segmentation)
									_UpperCAmelCase							 =		out_indices
									_UpperCAmelCase							 =		pool_scales
									# auxiliary head attributes (semantic segmentation)
									_UpperCAmelCase							 =		use_auxiliary_head
									_UpperCAmelCase							 =		auxiliary_loss_weight
									_UpperCAmelCase							 =		auxiliary_channels
									_UpperCAmelCase							 =		auxiliary_num_convs
									_UpperCAmelCase							 =		auxiliary_concat_input
									_UpperCAmelCase							 =		semantic_loss_ignore_index







class 			lowercase__			(      A    ):
							'''simple docstring'''







							_UpperCAmelCase      				=					version.parse('''1.11'''    )






							@property
							def        lowerCamelCase_   (  self						)			->							Mapping[str, Mapping[int, str]]:
									return OrderedDict(
									    [
									        ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
									    ]						)






							@property
							def        lowerCamelCase_   (  self						)			->							float:
									return 1E-4


