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







				@slow
				def 						UpperCAmelCase_    (       self     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'     )
											UpperCamelCase   			=     AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'     )
											model.to(A_     )

											from datasets import load_dataset

											UpperCamelCase   			=     load_dataset('nielsr/rvlcdip-demo'     )

											UpperCamelCase   			=     dataset['train'][0]['image'].convert('RGB'     )

											UpperCamelCase   			=     image_processor(A_						,				return_tensors='pt'     ).to(A_     )

											# forward pass
											with torch.no_grad():
																		UpperCamelCase   			=     model(**A_     )
																		UpperCamelCase   			=     outputs.logits

											UpperCamelCase   			=     torch.Size((1, 16)     )
											self.assertEqual(logits.shape						,				A_     )

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





'''simple docstring'''




def __lowerCAmelCase					(				UpperCamelCase__							)      ->       bool:
    if not isinstance(UpperCamelCase__							,    UpperCamelCase__							):
        raise ValueError('''Input series is not valid, valid series - [2, 4, 6]'''							)
    if len(UpperCamelCase__							) == 0:
        raise ValueError('''Input list must be a non empty list'''							)
    if len(UpperCamelCase__							) == 1:
        return True
    __lowerCamelCase            =    series[1] - series[0]
    for index in range(len(UpperCamelCase__							) - 1							):
        if series[index + 1] - series[index] != common_diff:
            return False
    return True






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       float:
    if not isinstance(UpperCamelCase__							,    UpperCamelCase__							):
        raise ValueError('''Input series is not valid, valid series - [2, 4, 6]'''							)
    if len(UpperCamelCase__							) == 0:
        raise ValueError('''Input list must be a non empty list'''							)
    __lowerCamelCase            =    0
    for val in series:
        answer += val
    return answer / len(UpperCamelCase__							)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
