

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase     :   Optional[Any]						     =  {
    'configuration_clap': [
        'CLAP_PRETRAINED_MODEL_ARCHIVE_LIST',
        'ClapAudioConfig',
        'ClapConfig',
        'ClapTextConfig',
    ],
    'processing_clap': ['ClapProcessor'],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase     :   Optional[int]						     =  [
        'CLAP_PRETRAINED_MODEL_ARCHIVE_LIST',
        'ClapModel',
        'ClapPreTrainedModel',
        'ClapTextModel',
        'ClapTextModelWithProjection',
        'ClapAudioModel',
        'ClapAudioModelWithProjection',
    ]
    lowerCAmelCase     :   int						     =  ['ClapFeatureExtractor']

if TYPE_CHECKING:
    from .configuration_clap import (
        CLAP_PRETRAINED_MODEL_ARCHIVE_LIST,
        ClapAudioConfig,
        ClapConfig,
        ClapTextConfig,
    )
    from .processing_clap import ClapProcessor

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .feature_extraction_clap import ClapFeatureExtractor
        from .modeling_clap import (
            CLAP_PRETRAINED_MODEL_ARCHIVE_LIST,
            ClapAudioModel,
            ClapAudioModelWithProjection,
            ClapModel,
            ClapPreTrainedModel,
            ClapTextModel,
            ClapTextModelWithProjection,
        )


else:
    import sys

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









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





        """simple docstring"""







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

        from datasets import load_dataset

        SCREAMING_SNAKE_CASE_				:  str           =     load_dataset('nielsr/rvlcdip-demo'					)

        SCREAMING_SNAKE_CASE_				:  List[Any]           =     dataset['train'][0]['image'].convert('RGB'					)

        SCREAMING_SNAKE_CASE_				:  List[Any]           =     image_processor(_SCREAMING_SNAKE_CASE ,					return_tensors='pt'					).to(_SCREAMING_SNAKE_CASE					)

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

        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     torch.Size((1, 16)					)
        self.assertEqual(logits.shape ,					_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  List[str]           =     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					)					)






