






'''simple docstring'''




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_torch_available


lowerCAmelCase__          =						{'configuration_speech_encoder_decoder': ['SpeechEncoderDecoderConfig']}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowerCAmelCase__          =						['SpeechEncoderDecoderModel']

try:
  if not is_flax_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowerCAmelCase__          =						['FlaxSpeechEncoderDecoderModel']

if TYPE_CHECKING:
  from .configuration_speech_encoder_decoder import SpeechEncoderDecoderConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_speech_encoder_decoder import SpeechEncoderDecoderModel

  try:
    if not is_flax_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_flax_speech_encoder_decoder import FlaxSpeechEncoderDecoderModel

else:
  import sys

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












'''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    ):

	@slow
	def      __UpperCamelCase							(      self   :						int):
			UpperCamelCase__				:					Union[str, Any]					=					AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip')
			UpperCamelCase__				:					List[str]					=					AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip')
			model.to(UpperCAmelCase_)

			from datasets import load_dataset

			UpperCamelCase__				:					Optional[Any]					=					load_dataset('nielsr/rvlcdip-demo')

			UpperCamelCase__				:					int					=					dataset['train'][0]['image'].convert('RGB')

			UpperCamelCase__				:					Union[str, Any]					=					image_processor(UpperCAmelCase_  ,					return_tensors='pt').to(UpperCAmelCase_)

			# forward pass
			with torch.no_grad():
					UpperCamelCase__				:					Optional[Any]					=					model(**UpperCAmelCase_)
					UpperCamelCase__				:					Tuple					=					outputs.logits

			UpperCamelCase__				:					str					=					torch.Size((1, 16))
			self.assertEqual(logits.shape  ,					UpperCAmelCase_)

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




