


'''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 a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							List[str]   			=       AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'   )
            _lowerCAmelCase    :							List[str]   			=       AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'   )
            model.to(snake_case__   )

            from datasets import load_dataset

            _lowerCAmelCase    :							Dict   			=       load_dataset('nielsr/rvlcdip-demo'   )

            _lowerCAmelCase    :							List[str]   			=       dataset['train'][0]['image'].convert('RGB'   )

            _lowerCAmelCase    :							str   			=       image_processor(snake_case__      ,	return_tensors='pt'   ).to(snake_case__   )

            # forward pass
            with torch.no_grad():
                   _lowerCAmelCase    :							Optional[int]   			=       model(**snake_case__   )
                   _lowerCAmelCase    :							List[Any]   			=       outputs.logits

            _lowerCAmelCase    :							Optional[Any]   			=       torch.Size((1, 16)   )
            self.assertEqual(logits.shape      ,	snake_case__   )

            _lowerCAmelCase    :							List[str]   			=       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 typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


lowerCAmelCase    :     int					=						{
    """configuration_trocr""": ["""TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TrOCRConfig"""],
    """processing_trocr""": ["""TrOCRProcessor"""],
}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase    :     Optional[Any]					=						[
           """TROCR_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """TrOCRForCausalLM""",
           """TrOCRPreTrainedModel""",
       ]


if TYPE_CHECKING:
       from .configuration_trocr import TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP, TrOCRConfig
       from .processing_trocr import TrOCRProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_trocr import TROCR_PRETRAINED_MODEL_ARCHIVE_LIST, TrOCRForCausalLM, TrOCRPreTrainedModel

else:
       import sys

       lowerCAmelCase    :     Any					=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

