


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




					@slow
					def 				snake_case__						(      self):
								UpperCAmelCase__  :					str        =     AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip""")
								UpperCAmelCase__  :					List[str]        =     AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip""")
								model.to(_lowerCamelCase)

								from datasets import load_dataset

								UpperCAmelCase__  :					Any        =     load_dataset("""nielsr/rvlcdip-demo""")

								UpperCAmelCase__  :					Dict        =     dataset["""train"""][0]["""image"""].convert("""RGB""")

								UpperCAmelCase__  :					List[Any]        =     image_processor(_lowerCamelCase							,							return_tensors="""pt""").to(_lowerCamelCase)

								# forward pass
								with torch.no_grad():
											UpperCAmelCase__  :					Dict        =     model(**_lowerCamelCase)
											UpperCAmelCase__  :					Dict        =     outputs.logits

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

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



'''simple docstring'''



from typing import TYPE_CHECKING

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


__A	={
    'configuration_encodec': [
        'ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'EncodecConfig',
    ],
    'feature_extraction_encodec': ['EncodecFeatureExtractor'],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__A	=[
		    'ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'EncodecModel',
		    'EncodecPreTrainedModel',
		]

if TYPE_CHECKING:
		from .configuration_encodec import (
		    ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    EncodecConfig,
		)
		from .feature_extraction_encodec import EncodecFeatureExtractor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_encodec import (
				    ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST,
				    EncodecModel,
				    EncodecPreTrainedModel,
				)

else:
		import sys

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