






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




							@slow
							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														lowerCamelCase__      :			str 						= AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""  )
														lowerCamelCase__      :			Optional[Any] 						= AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""  )
														model.to(UpperCamelCase__  )

														from datasets import load_dataset

														lowerCamelCase__      :			Dict 						= load_dataset("""nielsr/rvlcdip-demo"""  )

														lowerCamelCase__      :			List[str] 						= dataset["""train"""][0]["""image"""].convert("""RGB"""  )

														lowerCamelCase__      :			Dict 						= image_processor(UpperCamelCase__    ,							return_tensors="""pt"""  ).to(UpperCamelCase__  )

														# forward pass
														with torch.no_grad():
																					lowerCamelCase__      :			Optional[Any] 						= model(**UpperCamelCase__  )
																					lowerCamelCase__      :			Any 						= outputs.logits

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

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









'''simple docstring'''







_A			:    List[str]					  ='''0.21.0'''

from .accelerator import Accelerator
from .big_modeling import (
    cpu_offload,
    cpu_offload_with_hook,
    disk_offload,
    dispatch_model,
    init_empty_weights,
    init_on_device,
    load_checkpoint_and_dispatch,
)
from .data_loader import skip_first_batches
from .launchers import debug_launcher, notebook_launcher
from .state import PartialState
from .utils import (
    DeepSpeedPlugin,
    DistributedDataParallelKwargs,
    DistributedType,
    FullyShardedDataParallelPlugin,
    GradScalerKwargs,
    InitProcessGroupKwargs,
    find_executable_batch_size,
    infer_auto_device_map,
    is_rich_available,
    load_checkpoint_in_model,
    synchronize_rng_states,
)


if is_rich_available():
			from .utils import rich

