





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







					'''simple docstring'''




					@slow
					def  _lowerCamelCase		(						self     ):
									__a :						Any			       =  AutoImageProcessor.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''     )
									__a :						str			       =  AutoModelForImageClassification.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''     )
									model.to(_UpperCAmelCase     )

									from datasets import load_dataset

									__a :						int			       =  load_dataset('''nielsr/rvlcdip-demo'''     )

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

									__a :						Optional[int]			       =  image_processor(_UpperCAmelCase	,			return_tensors='''pt'''     ).to(_UpperCAmelCase     )

									# forward pass
									with torch.no_grad():
													__a :						Optional[Any]			       =  model(**_UpperCAmelCase     )
													__a :						List[str]			       =  outputs.logits

									__a :						Any			       =  torch.Size((1, 16)     )
									self.assertEqual(logits.shape	,			_UpperCAmelCase     )

									__a :						str			       =  torch.tensor(
									    [-0.4_1_5_8, -0.4_0_9_2, -0.4_3_4_7]	,			device=_UpperCAmelCase	,			dtype=torch.float	,			)
									self.assertTrue(torch.allclose(logits[0, :3]	,			_UpperCAmelCase	,			atol=1e-4     )     )






"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A 			=  {
    '''configuration_jukebox''': [
        '''JUKEBOX_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''JukeboxConfig''',
        '''JukeboxPriorConfig''',
        '''JukeboxVQVAEConfig''',
    ],
    '''tokenization_jukebox''': ['''JukeboxTokenizer'''],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		A 			=  [
		    '''JUKEBOX_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''JukeboxModel''',
		    '''JukeboxPreTrainedModel''',
		    '''JukeboxVQVAE''',
		    '''JukeboxPrior''',
		]

if TYPE_CHECKING:
		from .configuration_jukebox import (
		    JUKEBOX_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    JukeboxConfig,
		    JukeboxPriorConfig,
		    JukeboxVQVAEConfig,
		)
		from .tokenization_jukebox import JukeboxTokenizer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_jukebox import (
				    JUKEBOX_PRETRAINED_MODEL_ARCHIVE_LIST,
				    JukeboxModel,
				    JukeboxPreTrainedModel,
				    JukeboxPrior,
				    JukeboxVQVAE,
				)

else:
		import sys

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