


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






      @slow
      def __UpperCAmelCase       ( self			:str	)       ->					Tuple:




             '''simple docstring'''
             _a    : List[Any]     					=AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""	)
             _a    : Any     					=AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""	)
             model.to(SCREAMING_SNAKE_CASE	)

             from datasets import load_dataset

             _a    : int     					=load_dataset("""nielsr/rvlcdip-demo"""	)

             _a    : Optional[Any]     					=dataset["""train"""][0]["""image"""].convert("""RGB"""	)

             _a    : List[str]     					=image_processor(SCREAMING_SNAKE_CASE     ,						return_tensors="""pt"""	).to(SCREAMING_SNAKE_CASE	)

             # forward pass
             with torch.no_grad():
                    _a    : Dict     					=model(**SCREAMING_SNAKE_CASE	)
                    _a    : Optional[int]     					=outputs.logits

             _a    : List[Any]     					=torch.Size((1, 1_6)	)
             self.assertEqual(logits.shape     ,						SCREAMING_SNAKE_CASE	)

             _a    : int     					=torch.tensor(
                 [-0.4_158, -0.4_092, -0.4_347]     ,						device=SCREAMING_SNAKE_CASE     ,						dtype=torch.float     ,						)
             self.assertTrue(torch.allclose(logits[0, :3]     ,						SCREAMING_SNAKE_CASE     ,						atol=1e-4	)	)






'''simple docstring'''







from typing import TYPE_CHECKING

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


A__:    List[str]					    =       {
    '''configuration_chinese_clip''': [
        '''CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''ChineseCLIPConfig''',
        '''ChineseCLIPOnnxConfig''',
        '''ChineseCLIPTextConfig''',
        '''ChineseCLIPVisionConfig''',
    ],
    '''processing_chinese_clip''': ['''ChineseCLIPProcessor'''],
}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A__:    Optional[int]					    =       ['''ChineseCLIPFeatureExtractor''']
   A__:    Any					    =       ['''ChineseCLIPImageProcessor''']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A__:    Dict					    =       [
       '''CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''ChineseCLIPModel''',
       '''ChineseCLIPPreTrainedModel''',
       '''ChineseCLIPTextModel''',
       '''ChineseCLIPVisionModel''',
   ]

if TYPE_CHECKING:
   from .configuration_chinese_clip import (
       CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
       ChineseCLIPConfig,
       ChineseCLIPOnnxConfig,
       ChineseCLIPTextConfig,
       ChineseCLIPVisionConfig,
   )
   from .processing_chinese_clip import ChineseCLIPProcessor

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_chinese_clip import ChineseCLIPFeatureExtractor, ChineseCLIPImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_chinese_clip import (
          CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
          ChineseCLIPModel,
          ChineseCLIPPreTrainedModel,
          ChineseCLIPTextModel,
          ChineseCLIPVisionModel,
      )

else:
   import sys

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


