



"""simple docstring"""

from typing import Callable, Optional

from .. import Features
from ..packaged_modules.generator.generator import Generator
from .abc import AbstractDatasetInputStream




class  _UpperCAmelCase (    __lowercase):

 def __init__(  self	: Optional[int]						,  lowercase_	: Optional[Any]						,  lowercase_	: List[str] = None						,  lowercase_	: Dict = None						,  lowercase_	: int = False						,  lowercase_	: Optional[Any] = False						,  lowercase_	: Optional[int] = None						,  lowercase_	: List[str] = None						,  **lowercase_	: Tuple						,  ):
     super().__init__(
         features=__A						,  cache_dir=__A						,  keep_in_memory=__A						,  streaming=__A						,  num_proc=__A						,  **__A						,  )
     snake_case_				:  List[Any]       =			Generator(
         cache_dir=__A						,  features=__A						,  generator=__A						,  gen_kwargs=__A						,  **__A						,  )






 def 		_snake_case      (  self	: str       ):
     # Build iterable dataset
     if self.streaming:
         snake_case_				:  str       =			self.builder.as_streaming_dataset(split='''train'''       )
     # Build regular (map-style) dataset
     else:
         snake_case_				:  Dict       =			None
         snake_case_				:  Any       =			None
         snake_case_				:  List[str]       =			None
         snake_case_				:  List[Any]       =			None

         self.builder.download_and_prepare(
             download_config=__A						,  download_mode=__A						,  verification_mode=__A						,  base_path=__A						,  num_proc=self.num_proc						,  )
         snake_case_				:  Union[str, Any]       =			self.builder.as_dataset(
             split='''train'''						,  verification_mode=__A						,  in_memory=self.keep_in_memory       )
     return dataset










"""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  _UpperCAmelCase (    unittest.TestCase):

 @slow
 def 		_snake_case      (  self	: List[Any]       ):
     snake_case_				:  List[Any]       =			AutoImageProcessor.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''       )
     snake_case_				:  List[Any]       =			AutoModelForImageClassification.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''       )
     model.to(lowercase_       )

     from datasets import load_dataset

     snake_case_				:  str       =			load_dataset('''nielsr/rvlcdip-demo'''       )

     snake_case_				:  Tuple       =			dataset['''train'''][0]['''image'''].convert('''RGB'''       )

     snake_case_				:  Union[str, Any]       =			image_processor(lowercase_						,  return_tensors='''pt'''       ).to(lowercase_       )

     # forward pass
     with torch.no_grad():
         snake_case_				:  List[Any]       =			model(**lowercase_       )
         snake_case_				:  int       =			outputs.logits

     snake_case_				:  Any       =			torch.Size((1, 16)       )
     self.assertEqual(logits.shape						,  lowercase_       )

     snake_case_				:  Any       =			torch.tensor(
         [-0.41_58, -0.40_92, -0.43_47]						,  device=lowercase_						,  dtype=torch.float						,  )
     self.assertTrue(torch.allclose(logits[0, :3]						,  lowercase_						,  atol=1E-4       )       )





