






'''simple docstring'''
import tempfile

import torch

from diffusers import (
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    DPMSolverSinglestepScheduler,
    UniPCMultistepScheduler,
)

from .test_schedulers import SchedulerCommonTest






class    __SCREAMING_SNAKE_CASE					(	A__ ):
 snake_case_     							=							(DEISMultistepScheduler,)
 snake_case_     							=							(("""num_inference_steps""", 25),)




 def    __magic_name__		(					self		:							Optional[int]    ,					**__lowercase		:							str					)		->  str:
       SCREAMING_SNAKE_CASE__   : str													={
           '''num_train_timesteps''': 10_00,
           '''beta_start''': 0.0001,
           '''beta_end''': 0.02,
           '''beta_schedule''': '''linear''',
           '''solver_order''': 2,
       }

       config.update(**_a					)
       return config




 def    __magic_name__		(					self		:							Union[str, Any]    ,					__lowercase		:							Optional[Any]=0    ,					**__lowercase		:							Any					)		->  Tuple:
       SCREAMING_SNAKE_CASE__   : int													=dict(self.forward_default_kwargs					)
       SCREAMING_SNAKE_CASE__   : int													=kwargs.pop('''num_inference_steps'''    ,					_a					)
       SCREAMING_SNAKE_CASE__   : Any													=self.dummy_sample
       SCREAMING_SNAKE_CASE__   : List[Any]													=0.1 * sample
       SCREAMING_SNAKE_CASE__   : str													=[residual + 0.2, residual + 0.15, residual + 0.10]

       for scheduler_class in self.scheduler_classes:
             SCREAMING_SNAKE_CASE__   : List[str]													=self.get_scheduler_config(**_a					)
             SCREAMING_SNAKE_CASE__   : int													=scheduler_class(**_a					)
             scheduler.set_timesteps(_a					)
             # copy over dummy past residuals
             SCREAMING_SNAKE_CASE__   : Union[str, Any]													=dummy_past_residuals[: scheduler.config.solver_order]

             with tempfile.TemporaryDirectory() as tmpdirname:
                   scheduler.save_config(_a					)
                   SCREAMING_SNAKE_CASE__   : str													=scheduler_class.from_pretrained(_a					)
                   new_scheduler.set_timesteps(_a					)
                   # copy over dummy past residuals
                   SCREAMING_SNAKE_CASE__   : Dict													=dummy_past_residuals[: new_scheduler.config.solver_order]

             SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__   : str													=sample, sample
             for t in range(_a    ,					time_step + scheduler.config.solver_order + 1					):
                   SCREAMING_SNAKE_CASE__   : Any													=scheduler.step(_a    ,					_a    ,					_a    ,					**_a					).prev_sample
                   SCREAMING_SNAKE_CASE__   : List[str]													=new_scheduler.step(_a    ,					_a    ,					_a    ,					**_a					).prev_sample

                   assert torch.sum(torch.abs(output - new_output					)					) < 1e-5, "Scheduler outputs are not identical"




 def    __magic_name__		(					self		:							Union[str, Any]					)		->  Any:
       pass




 def    __magic_name__		(					self		:							Optional[int]    ,					__lowercase		:							List[Any]=0    ,					**__lowercase		:							Optional[int]					)		->  List[str]:
       SCREAMING_SNAKE_CASE__   : List[str]													=dict(self.forward_default_kwargs					)
       SCREAMING_SNAKE_CASE__   : Dict													=kwargs.pop('''num_inference_steps'''    ,					_a					)
       SCREAMING_SNAKE_CASE__   : Dict													=self.dummy_sample
       SCREAMING_SNAKE_CASE__   : List[str]													=0.1 * sample
       SCREAMING_SNAKE_CASE__   : Any													=[residual + 0.2, residual + 0.15, residual + 0.10]

       for scheduler_class in self.scheduler_classes:
             SCREAMING_SNAKE_CASE__   : Optional[Any]													=self.get_scheduler_config()
             SCREAMING_SNAKE_CASE__   : Union[str, Any]													=scheduler_class(**_a					)
             scheduler.set_timesteps(_a					)

             # copy over dummy past residuals (must be after setting timesteps)
             SCREAMING_SNAKE_CASE__   : Tuple													=dummy_past_residuals[: scheduler.config.solver_order]

             with tempfile.TemporaryDirectory() as tmpdirname:
                   scheduler.save_config(_a					)
                   SCREAMING_SNAKE_CASE__   : int													=scheduler_class.from_pretrained(_a					)
                   # copy over dummy past residuals
                   new_scheduler.set_timesteps(_a					)

                   # copy over dummy past residual (must be after setting timesteps)
                   SCREAMING_SNAKE_CASE__   : List[Any]													=dummy_past_residuals[: new_scheduler.config.solver_order]

             SCREAMING_SNAKE_CASE__   : List[str]													=scheduler.step(_a    ,					_a    ,					_a    ,					**_a					).prev_sample
             SCREAMING_SNAKE_CASE__   : Tuple													=new_scheduler.step(_a    ,					_a    ,					_a    ,					**_a					).prev_sample

             assert torch.sum(torch.abs(output - new_output					)					) < 1e-5, "Scheduler outputs are not identical"




 def    __magic_name__		(					self		:							int    ,					__lowercase		:							Optional[Any]=None    ,					**__lowercase		:							Any					)		->  Optional[int]:






       if scheduler is None:
             SCREAMING_SNAKE_CASE__   : int													=self.scheduler_classes[0]
             SCREAMING_SNAKE_CASE__   : int													=self.get_scheduler_config(**_a					)
             SCREAMING_SNAKE_CASE__   : Any													=scheduler_class(**_a					)

       SCREAMING_SNAKE_CASE__   : List[str]													=self.scheduler_classes[0]
       SCREAMING_SNAKE_CASE__   : Optional[int]													=self.get_scheduler_config(**_a					)
       SCREAMING_SNAKE_CASE__   : Optional[Any]													=scheduler_class(**_a					)

       SCREAMING_SNAKE_CASE__   : Tuple													=10
       SCREAMING_SNAKE_CASE__   : Optional[Any]													=self.dummy_model()
       SCREAMING_SNAKE_CASE__   : str													=self.dummy_sample_deter
       scheduler.set_timesteps(_a					)

       for i, t in enumerate(scheduler.timesteps					):
             SCREAMING_SNAKE_CASE__   : List[Any]													=model(_a    ,					_a					)
             SCREAMING_SNAKE_CASE__   : List[str]													=scheduler.step(_a    ,					_a    ,					_a					).prev_sample

       return sample




 def    __magic_name__		(					self		:							Tuple					)		->  Dict:
       SCREAMING_SNAKE_CASE__   : int													=dict(self.forward_default_kwargs					)

       SCREAMING_SNAKE_CASE__   : Optional[Any]													=kwargs.pop('''num_inference_steps'''    ,					_a					)

       for scheduler_class in self.scheduler_classes:
             SCREAMING_SNAKE_CASE__   : Optional[int]													=self.get_scheduler_config()
             SCREAMING_SNAKE_CASE__   : Optional[int]													=scheduler_class(**_a					)

             SCREAMING_SNAKE_CASE__   : str													=self.dummy_sample
             SCREAMING_SNAKE_CASE__   : List[str]													=0.1 * sample

             if num_inference_steps is not None and hasattr(_a    ,					'''set_timesteps'''					):
                   scheduler.set_timesteps(_a					)
             elif num_inference_steps is not None and not hasattr(_a    ,					'''set_timesteps'''					):
                   SCREAMING_SNAKE_CASE__   : List[Any]													=num_inference_steps

             # copy over dummy past residuals (must be done after set_timesteps)
             SCREAMING_SNAKE_CASE__   : Optional[int]													=[residual + 0.2, residual + 0.15, residual + 0.10]
             SCREAMING_SNAKE_CASE__   : Optional[int]													=dummy_past_residuals[: scheduler.config.solver_order]

             SCREAMING_SNAKE_CASE__   : List[Any]													=scheduler.timesteps[5]
             SCREAMING_SNAKE_CASE__   : List[Any]													=scheduler.timesteps[6]

             SCREAMING_SNAKE_CASE__   : Tuple													=scheduler.step(_a    ,					_a    ,					_a    ,					**_a					).prev_sample
             SCREAMING_SNAKE_CASE__   : Any													=scheduler.step(_a    ,					_a    ,					_a    ,					**_a					).prev_sample

             self.assertEqual(output_a.shape    ,					sample.shape					)
             self.assertEqual(output_a.shape    ,					output_a.shape					)




 def    __magic_name__		(					self		:							Dict					)		->  str:
       SCREAMING_SNAKE_CASE__   : List[str]													=DEISMultistepScheduler(**self.get_scheduler_config()					)
       SCREAMING_SNAKE_CASE__   : Dict													=self.full_loop(scheduler=_a					)
       SCREAMING_SNAKE_CASE__   : Optional[Any]													=torch.mean(torch.abs(_a					)					)

       assert abs(result_mean.item() - 0.23916					) < 1e-3

       SCREAMING_SNAKE_CASE__   : List[Any]													=DPMSolverSinglestepScheduler.from_config(scheduler.config					)
       SCREAMING_SNAKE_CASE__   : Optional[Any]													=DPMSolverMultistepScheduler.from_config(scheduler.config					)
       SCREAMING_SNAKE_CASE__   : str													=UniPCMultistepScheduler.from_config(scheduler.config					)
       SCREAMING_SNAKE_CASE__   : Any													=DEISMultistepScheduler.from_config(scheduler.config					)

       SCREAMING_SNAKE_CASE__   : Any													=self.full_loop(scheduler=_a					)
       SCREAMING_SNAKE_CASE__   : Tuple													=torch.mean(torch.abs(_a					)					)

       assert abs(result_mean.item() - 0.23916					) < 1e-3




 def    __magic_name__		(					self		:							Tuple					)		->  Union[str, Any]:






       for timesteps in [25, 50, 1_00, 9_99, 10_00]:
             self.check_over_configs(num_train_timesteps=_a					)




 def    __magic_name__		(					self		:							Optional[int]					)		->  Dict:
       self.check_over_configs(thresholding=_a					)
       for order in [1, 2, 3]:
             for solver_type in ["logrho"]:
                   for threshold in [0.5, 1.0, 2.0]:
                         for prediction_type in ["epsilon", "sample"]:
                               self.check_over_configs(
                                   thresholding=_a    ,					prediction_type=_a    ,					sample_max_value=_a    ,					algorithm_type='''deis'''    ,					solver_order=_a    ,					solver_type=_a    ,					)




 def    __magic_name__		(					self		:							int					)		->  List[Any]:






       for prediction_type in ["epsilon", "v_prediction"]:
             self.check_over_configs(prediction_type=_a					)




 def    __magic_name__		(					self		:							List[Any]					)		->  Tuple:






       for algorithm_type in ["deis"]:
             for solver_type in ["logrho"]:
                   for order in [1, 2, 3]:
                         for prediction_type in ["epsilon", "sample"]:
                               self.check_over_configs(
                                   solver_order=_a    ,					solver_type=_a    ,					prediction_type=_a    ,					algorithm_type=_a    ,					)
                               SCREAMING_SNAKE_CASE__   : Optional[int]													=self.full_loop(
                                   solver_order=_a    ,					solver_type=_a    ,					prediction_type=_a    ,					algorithm_type=_a    ,					)
                               assert not torch.isnan(_a					).any(), "Samples have nan numbers"




 def    __magic_name__		(					self		:							Any					)		->  str:
       self.check_over_configs(lower_order_final=_a					)
       self.check_over_configs(lower_order_final=_a					)




 def    __magic_name__		(					self		:							List[str]					)		->  List[Any]:






       for num_inference_steps in [1, 2, 3, 5, 10, 50, 1_00, 9_99, 10_00]:
             self.check_over_forward(num_inference_steps=_a    ,					time_step=0					)




 def    __magic_name__		(					self		:							List[Any]					)		->  Dict:
       SCREAMING_SNAKE_CASE__   : Optional[Any]													=self.full_loop()
       SCREAMING_SNAKE_CASE__   : Union[str, Any]													=torch.mean(torch.abs(_a					)					)

       assert abs(result_mean.item() - 0.23916					) < 1e-3




 def    __magic_name__		(					self		:							Optional[Any]					)		->  Tuple:
       SCREAMING_SNAKE_CASE__   : Any													=self.full_loop(prediction_type='''v_prediction'''					)
       SCREAMING_SNAKE_CASE__   : Any													=torch.mean(torch.abs(_a					)					)

       assert abs(result_mean.item() - 0.091					) < 1e-3




 def    __magic_name__		(					self		:							Tuple					)		->  Dict:
       SCREAMING_SNAKE_CASE__   : Union[str, Any]													=self.scheduler_classes[0]
       SCREAMING_SNAKE_CASE__   : int													=self.get_scheduler_config(thresholding=_a    ,					dynamic_thresholding_ratio=0					)
       SCREAMING_SNAKE_CASE__   : Optional[int]													=scheduler_class(**_a					)

       SCREAMING_SNAKE_CASE__   : str													=10
       SCREAMING_SNAKE_CASE__   : Optional[int]													=self.dummy_model()
       SCREAMING_SNAKE_CASE__   : str													=self.dummy_sample_deter.half()
       scheduler.set_timesteps(_a					)

       for i, t in enumerate(scheduler.timesteps					):
             SCREAMING_SNAKE_CASE__   : List[Any]													=model(_a    ,					_a					)
             SCREAMING_SNAKE_CASE__   : int													=scheduler.step(_a    ,					_a    ,					_a					).prev_sample

       assert sample.dtype == torch.floataa


'''simple docstring'''
import unittest

import numpy as np
import requests

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
     import torch

     from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
     lowerCamelCase :      int					 =     False

if is_vision_available():
     from PIL import Image

     from transformers import PixaStructImageProcessor







class 							A__    (       unittest.TestCase  ):





  def __init__(		self      :	List[str]							,					_a      :	List[Any]							,					_a      :	List[str]=7							,					_a      :	List[str]=3							,					_a      :	Tuple=18							,					_a      :	Tuple=30							,					_a      :	str=400							,					_a      :	Tuple=None							,					_a      :	Union[str, Any]=True							,					_a      :	List[str]=True							,					_a      :	Optional[int]=None							,					)	->    List[str]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =size if size is not None else {'height': 20, 'width': 20}
       _SCREAMING_SNAKE_CASE							    =parent
       _SCREAMING_SNAKE_CASE							    =batch_size
       _SCREAMING_SNAKE_CASE							    =num_channels
       _SCREAMING_SNAKE_CASE							    =image_size
       _SCREAMING_SNAKE_CASE							    =min_resolution
       _SCREAMING_SNAKE_CASE							    =max_resolution
       _SCREAMING_SNAKE_CASE							    =size
       _SCREAMING_SNAKE_CASE							    =do_normalize
       _SCREAMING_SNAKE_CASE							    =do_convert_rgb
       _SCREAMING_SNAKE_CASE							    =[512, 1024, 2048, 4096]
       _SCREAMING_SNAKE_CASE							    =patch_size if patch_size is not None else {'height': 16, 'width': 16}





  def 						A  (		self      :	Any )	->    List[str]:





       '''simple docstring'''






       return {"do_normalize": self.do_normalize, "do_convert_rgb": self.do_convert_rgb}





  def 						A  (		self      :	int )	->    str:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    ='https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/australia.jpg'
       _SCREAMING_SNAKE_CASE							    =Image.open(requests.get(_a							,					stream=_a ).raw ).convert('RGB' )
       return raw_image







@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11     ,   reason='`Pix2StructImageProcessor` requires `torch>=1.11.0`.'     ,   )
@require_torch
@require_vision
class 							A__    (       A__     ,   unittest.TestCase  ):
  A__		 =				PixaStructImageProcessor if is_vision_available() else None





  def 						A  (		self      :	Dict )	->    Tuple:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =PixaStructImageProcessingTester(self )





  @property
  def 						A  (		self      :	Optional[Any] )	->    int:





       '''simple docstring'''






       return self.image_processor_tester.prepare_image_processor_dict()





  def 						A  (		self      :	Any )	->    Tuple:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.image_processing_class(**self.image_processor_dict )
       self.assertTrue(hasattr(_a							,					'do_normalize' ) )
       self.assertTrue(hasattr(_a							,					'do_convert_rgb' ) )





  def 						A  (		self      :	Any )	->    List[str]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.image_processor_tester.prepare_dummy_image()

       _SCREAMING_SNAKE_CASE							    =self.image_processing_class(**self.image_processor_dict )
       _SCREAMING_SNAKE_CASE							    =2048

       _SCREAMING_SNAKE_CASE							    =image_processor(_a							,					return_tensors='pt'							,					max_patches=_a )
       self.assertTrue(torch.allclose(inputs.flattened_patches.mean()							,					torch.tensor(0.06_06 )							,					atol=1e-3							,					rtol=1e-3 ) )





  def 						A  (		self      :	Any )	->    Any:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.image_processing_class(**self.image_processor_dict )
       # create random PIL images
       _SCREAMING_SNAKE_CASE							    =prepare_image_inputs(self.image_processor_tester							,					equal_resolution=_a )
       for image in image_inputs:
            self.assertIsInstance(_a							,					Image.Image )

       # Test not batched input
       _SCREAMING_SNAKE_CASE							    =(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * self.image_processor_tester.num_channels
       ) + 2

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            _SCREAMING_SNAKE_CASE							    =image_processor(
                image_inputs[0]							,					return_tensors='pt'							,					max_patches=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(1, max_patch, expected_hidden_dim)							,					)

            # Test batched
            _SCREAMING_SNAKE_CASE							    =image_processor(
                _a							,					return_tensors='pt'							,					max_patches=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)							,					)





  def 						A  (		self      :	List[str] )	->    Optional[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.image_processing_class(**self.image_processor_dict )
       # create random PIL images
       _SCREAMING_SNAKE_CASE							    =prepare_image_inputs(self.image_processor_tester							,					equal_resolution=_a )
       for image in image_inputs:
            self.assertIsInstance(_a							,					Image.Image )

       # Test not batched input
       _SCREAMING_SNAKE_CASE							    =(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * self.image_processor_tester.num_channels
       ) + 2

       _SCREAMING_SNAKE_CASE							    =True

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            with self.assertRaises(_a ):
                 _SCREAMING_SNAKE_CASE							    =image_processor(
                     image_inputs[0]							,					return_tensors='pt'							,					max_patches=_a ).flattened_patches

            _SCREAMING_SNAKE_CASE							    ='Hello'

            _SCREAMING_SNAKE_CASE							    =image_processor(
                image_inputs[0]							,					return_tensors='pt'							,					max_patches=_a							,					header_text=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(1, max_patch, expected_hidden_dim)							,					)

            # Test batched
            _SCREAMING_SNAKE_CASE							    =image_processor(
                _a							,					return_tensors='pt'							,					max_patches=_a							,					header_text=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)							,					)





  def 						A  (		self      :	List[Any] )	->    Any:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.image_processing_class(**self.image_processor_dict )
       # create random numpy tensors
       _SCREAMING_SNAKE_CASE							    =prepare_image_inputs(self.image_processor_tester							,					equal_resolution=_a							,					numpify=_a )
       for image in image_inputs:
            self.assertIsInstance(_a							,					np.ndarray )

       _SCREAMING_SNAKE_CASE							    =(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * self.image_processor_tester.num_channels
       ) + 2

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            _SCREAMING_SNAKE_CASE							    =image_processor(
                image_inputs[0]							,					return_tensors='pt'							,					max_patches=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(1, max_patch, expected_hidden_dim)							,					)

            # Test batched
            _SCREAMING_SNAKE_CASE							    =image_processor(
                _a							,					return_tensors='pt'							,					max_patches=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)							,					)





  def 						A  (		self      :	Union[str, Any] )	->    Tuple:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.image_processing_class(**self.image_processor_dict )
       # create random PyTorch tensors
       _SCREAMING_SNAKE_CASE							    =prepare_image_inputs(self.image_processor_tester							,					equal_resolution=_a							,					torchify=_a )
       for image in image_inputs:
            self.assertIsInstance(_a							,					torch.Tensor )

       # Test not batched input
       _SCREAMING_SNAKE_CASE							    =(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * self.image_processor_tester.num_channels
       ) + 2

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            _SCREAMING_SNAKE_CASE							    =image_processor(
                image_inputs[0]							,					return_tensors='pt'							,					max_patches=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(1, max_patch, expected_hidden_dim)							,					)

            # Test batched
            _SCREAMING_SNAKE_CASE							    =image_processor(
                _a							,					return_tensors='pt'							,					max_patches=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)							,					)







@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11     ,   reason='`Pix2StructImageProcessor` requires `torch>=1.11.0`.'     ,   )
@require_torch
@require_vision
class 							A__    (       A__     ,   unittest.TestCase  ):
  A__		 =				PixaStructImageProcessor if is_vision_available() else None





  def 						A  (		self      :	str )	->    Dict:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =PixaStructImageProcessingTester(self							,					num_channels=4 )
       _SCREAMING_SNAKE_CASE							    =3





  @property
  def 						A  (		self      :	List[str] )	->    Optional[Any]:





       '''simple docstring'''






       return self.image_processor_tester.prepare_image_processor_dict()





  def 						A  (		self      :	List[str] )	->    Tuple:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.image_processing_class(**self.image_processor_dict )
       self.assertTrue(hasattr(_a							,					'do_normalize' ) )
       self.assertTrue(hasattr(_a							,					'do_convert_rgb' ) )





  def 						A  (		self      :	Dict )	->    int:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.image_processing_class(**self.image_processor_dict )
       # create random PIL images
       _SCREAMING_SNAKE_CASE							    =prepare_image_inputs(self.image_processor_tester							,					equal_resolution=_a )
       for image in image_inputs:
            self.assertIsInstance(_a							,					Image.Image )

       # Test not batched input
       _SCREAMING_SNAKE_CASE							    =(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * (self.image_processor_tester.num_channels - 1)
       ) + 2

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            _SCREAMING_SNAKE_CASE							    =image_processor(
                image_inputs[0]							,					return_tensors='pt'							,					max_patches=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(1, max_patch, expected_hidden_dim)							,					)

            # Test batched
            _SCREAMING_SNAKE_CASE							    =image_processor(
                _a							,					return_tensors='pt'							,					max_patches=_a ).flattened_patches
            self.assertEqual(
                encoded_images.shape							,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)							,					)
