


'''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 	a       (       unittest.TestCase    ):
 @slow
 def 							__UpperCAmelCase						(	self  )   ->							Tuple:
      _a      =							AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'  )
      _a      =							AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'  )
      model.to(lowerCAmelCase_  )

      from datasets import load_dataset

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

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

      _a      =							image_processor(lowerCAmelCase_ ,			return_tensors='pt'  ).to(lowerCAmelCase_  )

      # forward pass
      with torch.no_grad():
           _a      =							model(**lowerCAmelCase_  )
           _a      =							outputs.logits

      _a      =							torch.Size((1, 16)  )
      self.assertEqual(logits.shape ,			lowerCAmelCase_  )

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





'''simple docstring'''






import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline






@pytest.mark.integration
def 		_A			()				->					Optional[Any]:




     '''simple docstring'''



     with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT						):
          with pytest.raises(lowerCAmelCase__						):
               requests.request('GET'			,  'https://huggingface.co'						)
          with pytest.raises(requests.exceptions.ConnectTimeout						):
               requests.request('GET'			,  'https://huggingface.co'			,  timeout=1.0						)






@pytest.mark.integration
def 		_A			()				->					Any:




     '''simple docstring'''



     with offline(OfflineSimulationMode.CONNECTION_FAILS						):
          with pytest.raises(requests.exceptions.ConnectionError						):
               requests.request('GET'			,  'https://huggingface.co'						)






def 		_A			()				->					Dict:




     '''simple docstring'''



     with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1						):
          with pytest.raises(lowerCAmelCase__						):
               http_head('https://huggingface.co'						)

