


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 						__a (							unittest.TestCase     ):
		@slow
		def       UpperCAmelCase__							(     self		)					->			List[str]:




									"""simple docstring"""





									_UpperCAmelCase											=     AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'		)
									_UpperCAmelCase											=     AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'		)
									model.to(_SCREAMING_SNAKE_CASE		)

									from datasets import load_dataset

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

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

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

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

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

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




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


lowerCAmelCase__    :Tuple       =				{'''configuration_deit''': ['''DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DeiTConfig''', '''DeiTOnnxConfig''']}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCAmelCase__    :List[Any]       =				['''DeiTFeatureExtractor''']
		lowerCAmelCase__    :Union[str, Any]       =				['''DeiTImageProcessor''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCAmelCase__    :Tuple       =				[
		    '''DEIT_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''DeiTForImageClassification''',
		    '''DeiTForImageClassificationWithTeacher''',
		    '''DeiTForMaskedImageModeling''',
		    '''DeiTModel''',
		    '''DeiTPreTrainedModel''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCAmelCase__    :Union[str, Any]       =				[
		    '''TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFDeiTForImageClassification''',
		    '''TFDeiTForImageClassificationWithTeacher''',
		    '''TFDeiTForMaskedImageModeling''',
		    '''TFDeiTModel''',
		    '''TFDeiTPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_deit import DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP, DeiTConfig, DeiTOnnxConfig

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_deit import DeiTFeatureExtractor
				from .image_processing_deit import DeiTImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_deit import (
				    DEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DeiTForImageClassification,
				    DeiTForImageClassificationWithTeacher,
				    DeiTForMaskedImageModeling,
				    DeiTModel,
				    DeiTPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_deit import (
				    TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFDeiTForImageClassification,
				    TFDeiTForImageClassificationWithTeacher,
				    TFDeiTForMaskedImageModeling,
				    TFDeiTModel,
				    TFDeiTPreTrainedModel,
				)


else:
		import sys

		lowerCAmelCase__    :List[str]       =				_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
