import importlib.metadata
import warnings
from copy import deepcopy

from packaging import version

from ..utils import logging
from .import_utils import is_accelerate_available, is_bitsandbytes_available


if is_bitsandbytes_available():
      import bitsandbytes as bnb
      import torch
      import torch.nn as nn

      from ..pytorch_utils import ConvaD

if is_accelerate_available():
      from accelerate import init_empty_weights
      from accelerate.utils import find_tied_parameters

SCREAMING_SNAKE_CASE__		:					List[str]						=					logging.get_logger(__name__)







def     _a				(      lowercase__  :			List[Any]     ,  lowercase__  :			Any     ,  lowercase__  :			Union[str, Any]     ,  lowercase__  :			int=None     ,  lowercase__  :			int=None ):







     '''simple docstring'''


     if "." in tensor_name:
          SCREAMING_SNAKE_CASE__				:				Tuple			=		tensor_name.split('.' )
          for split in splits[:-1]:
               SCREAMING_SNAKE_CASE__				:				List[str]			=		getattr(lowercase__     ,  lowercase__ )
               if new_module is None:
                    raise ValueError(f'''{module} has no attribute {split}.''' )
               SCREAMING_SNAKE_CASE__				:				List[Any]			=		new_module
          SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		splits[-1]

     if tensor_name not in module._parameters and tensor_name not in module._buffers:
          raise ValueError(f'''{module} does not have a parameter or a buffer named {tensor_name}.''' )
     SCREAMING_SNAKE_CASE__				:				Optional[int]			=		tensor_name in module._buffers
     SCREAMING_SNAKE_CASE__				:				Tuple			=		getattr(lowercase__     ,  lowercase__ )

     if old_value.device == torch.device('meta' ) and device not in ["meta", torch.device('meta' )] and value is None:
          raise ValueError(f'''{tensor_name} is on the meta device, we need a `value` to put in on {device}.''' )

     SCREAMING_SNAKE_CASE__				:				List[str]			=		False
     SCREAMING_SNAKE_CASE__				:				Dict			=		False
     if is_buffer or not is_bitsandbytes_available():
          SCREAMING_SNAKE_CASE__				:				str			=		False
          SCREAMING_SNAKE_CASE__				:				Optional[int]			=		False
     else:
          SCREAMING_SNAKE_CASE__				:				Any			=		hasattr(bnb.nn     ,  'Params4bit' ) and isinstance(module._parameters[tensor_name]     ,  bnb.nn.Paramsabit )
          SCREAMING_SNAKE_CASE__				:				str			=		isinstance(module._parameters[tensor_name]     ,  bnb.nn.IntaParams )

     if is_abit or is_abit:
          SCREAMING_SNAKE_CASE__				:				str			=		module._parameters[tensor_name]
          if param.device.type != "cuda":
               if value is None:
                    SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		old_value.to(lowercase__ )
               elif isinstance(lowercase__     ,  torch.Tensor ):
                    SCREAMING_SNAKE_CASE__				:				List[Any]			=		value.to('cpu' )
                    if value.dtype == torch.inta:
                         SCREAMING_SNAKE_CASE__				:				str			=		version.parse(importlib.metadata.version('bitsandbytes' ) ) > version.parse(
                             '0.37.2' )
                         if not is_abit_serializable:
                              raise ValueError(
                                  'Detected int8 weights but the version of bitsandbytes is not compatible with int8 serialization. '
                                  'Make sure to download the latest `bitsandbytes` version. `pip install --upgrade bitsandbytes`.' )
               else:
                    SCREAMING_SNAKE_CASE__				:				Optional[int]			=		torch.tensor(lowercase__     ,  device='cpu' )

               # Support models using `Conv1D` in place of `nn.Linear` (e.g. gpt2) by transposing the weight matrix prior to quantization.
               # Since weights are saved in the correct "orientation", we skip transposing when loading.
               if issubclass(module.source_cls     ,  lowercase__ ) and fpaa_statistics is None:
                    SCREAMING_SNAKE_CASE__				:				int			=		new_value.T

               SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		old_value.__dict__
               if is_abit:
                    SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		bnb.nn.IntaParams(lowercase__     ,  requires_grad=lowercase__     ,  **lowercase__ ).to(lowercase__ )
               elif is_abit:
                    SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		bnb.nn.Paramsabit(lowercase__     ,  requires_grad=lowercase__     ,  **lowercase__ ).to(lowercase__ )

               SCREAMING_SNAKE_CASE__				:				Dict			=		new_value
               if fpaa_statistics is not None:
                    setattr(module.weight     ,  'SCB'     ,  fpaa_statistics.to(lowercase__ ) )

     else:
          if value is None:
               SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		old_value.to(lowercase__ )
          elif isinstance(lowercase__     ,  torch.Tensor ):
               SCREAMING_SNAKE_CASE__				:				Any			=		value.to(lowercase__ )
          else:
               SCREAMING_SNAKE_CASE__				:				List[str]			=		torch.tensor(lowercase__     ,  device=lowercase__ )

          if is_buffer:
               SCREAMING_SNAKE_CASE__				:				Any			=		new_value
          else:
               SCREAMING_SNAKE_CASE__				:				Tuple			=		nn.Parameter(lowercase__     ,  requires_grad=old_value.requires_grad )
               SCREAMING_SNAKE_CASE__				:				List[str]			=		new_value







def     _a				(      lowercase__  :			str     ,  lowercase__  :			List[str]=None     ,  lowercase__  :			str=None     ,  lowercase__  :			Optional[Any]=None     ,  lowercase__  :			Union[str, Any]=False ):







     '''simple docstring'''


     for name, module in model.named_children():
          if current_key_name is None:
               SCREAMING_SNAKE_CASE__				:				List[Any]			=		[]
          current_key_name.append(lowercase__ )

          if (isinstance(lowercase__     ,  nn.Linear ) or isinstance(lowercase__     ,  lowercase__ )) and name not in modules_to_not_convert:
               # Check if the current key is not in the `modules_to_not_convert`
               if not any(key in '.'.join(lowercase__ ) for key in modules_to_not_convert ):
                    with init_empty_weights():
                         if isinstance(lowercase__     ,  lowercase__ ):
                              SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__				:				Dict			=		module.weight.shape
                         else:
                              SCREAMING_SNAKE_CASE__				:				Any			=		module.in_features
                              SCREAMING_SNAKE_CASE__				:				int			=		module.out_features

                         if quantization_config.quantization_method() == "llm_int8":
                              SCREAMING_SNAKE_CASE__				:				str			=		bnb.nn.LinearabitLt(
                                  lowercase__     ,  lowercase__     ,  module.bias is not None     ,  has_fpaa_weights=quantization_config.llm_inta_has_fpaa_weight     ,  threshold=quantization_config.llm_inta_threshold     ,  )
                              SCREAMING_SNAKE_CASE__				:				Optional[int]			=		True
                         else:
                              if (
                                  quantization_config.llm_inta_skip_modules is not None
                                  and name in quantization_config.llm_inta_skip_modules
                              ):
                                   pass
                              else:
                                   SCREAMING_SNAKE_CASE__				:				List[Any]			=		bnb.nn.Linearabit(
                                       lowercase__     ,  lowercase__     ,  module.bias is not None     ,  quantization_config.bnb_abit_compute_dtype     ,  compress_statistics=quantization_config.bnb_abit_use_double_quant     ,  quant_type=quantization_config.bnb_abit_quant_type     ,  )
                                   SCREAMING_SNAKE_CASE__				:				List[str]			=		True
                    # Store the module class in case we need to transpose the weight later
                         SCREAMING_SNAKE_CASE__				:				str			=		type(lowercase__ )
                         # Force requires grad to False to avoid unexpected errors
                         model._modules[name].requires_grad_(lowercase__ )
          if len(list(module.children() ) ) > 0:
               SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__				:				int			=		_replace_with_bnb_linear(
                   lowercase__     ,  lowercase__     ,  lowercase__     ,  lowercase__     ,  has_been_replaced=lowercase__     ,  )
          # Remove the last key for recursion
          current_key_name.pop(-1 )
     return model, has_been_replaced







def     _a				(      lowercase__  :			Dict     ,  lowercase__  :			List[str]=None     ,  lowercase__  :			Tuple=None     ,  lowercase__  :			Any=None ):







     '''simple docstring'''


     SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		['lm_head'] if modules_to_not_convert is None else modules_to_not_convert
     SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__				:				int			=		_replace_with_bnb_linear(
         lowercase__     ,  lowercase__     ,  lowercase__     ,  lowercase__ )

     if not has_been_replaced:
          logger.warning(
              'You are loading your model in 8bit or 4bit but no linear modules were found in your model.'
              ' Please double check your model architecture, or submit an issue on github if you think this is'
              ' a bug.' )

     return model







def     _a				(      *lowercase__  :			int     ,  **lowercase__  :			Union[str, Any] ):







     '''simple docstring'''


     warnings.warn(
         '`replace_8bit_linear` will be deprecated in a future version, please use `replace_with_bnb_linear` instead'     ,  lowercase__     ,  )
     return replace_with_bnb_linear(*lowercase__     ,  **lowercase__ )







def     _a				(      *lowercase__  :			Union[str, Any]     ,  **lowercase__  :			Union[str, Any] ):







     '''simple docstring'''


     warnings.warn(
         '`set_module_8bit_tensor_to_device` will be deprecated in a future version, please use `set_module_quantized_tensor_to_device` instead'     ,  lowercase__     ,  )
     return set_module_quantized_tensor_to_device(*lowercase__     ,  **lowercase__ )







def     _a				(      lowercase__  :			str ):







     '''simple docstring'''


     SCREAMING_SNAKE_CASE__				:				Any			=		deepcopy(lowercase__ )  # this has 0 cost since it is done inside `init_empty_weights` context manager`
     tied_model.tie_weights()

     SCREAMING_SNAKE_CASE__				:				Dict			=		find_tied_parameters(lowercase__ )
     # For compatibility with Accelerate < 0.18
     if isinstance(lowercase__     ,  lowercase__ ):
          SCREAMING_SNAKE_CASE__				:				Optional[int]			=		sum(list(tied_params.values() )     ,  [] ) + list(tied_params.keys() )
     else:
          SCREAMING_SNAKE_CASE__				:				Dict			=		sum(lowercase__     ,  [] )
     SCREAMING_SNAKE_CASE__				:				Any			=		len(lowercase__ ) > 0

     # Check if it is a base model
     SCREAMING_SNAKE_CASE__				:				str			=		not hasattr(lowercase__     ,  model.base_model_prefix )

     # Ignore this for base models (BertModel, GPT2Model, etc.)
     if (not has_tied_params) and is_base_model:
          return []

     # otherwise they have an attached head
     SCREAMING_SNAKE_CASE__				:				int			=		list(model.named_children() )
     SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		[list_modules[-1][0]]

     # add last module together with tied weights
     SCREAMING_SNAKE_CASE__				:				List[Any]			=		set(lowercase__ ) - set(lowercase__ )
     SCREAMING_SNAKE_CASE__				:				int			=		list(set(lowercase__ ) ) + list(lowercase__ )

     # remove ".weight" from the keys
     SCREAMING_SNAKE_CASE__				:				str			=		['.weight', '.bias']
     SCREAMING_SNAKE_CASE__				:				str			=		[]
     for name in list_untouched:
          for name_to_remove in names_to_remove:
               if name_to_remove in name:
                    SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		name.replace(lowercase__     ,  '' )
          filtered_module_names.append(lowercase__ )

     return filtered_module_names




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:
      SCREAMING_SNAKE_CASE__		:					Any						=					False

if is_vision_available():
      from PIL import Image

      from transformers import PixaStructImageProcessor

class       snake_case					(      unittest.TestCase						):




  def __init__(      self     :	List[Any]     , a_     :	Optional[int]     , a_     :	Dict=7     , a_     :	Any=3     , a_     :	Any=18     , a_     :	int=30     , a_     :	int=400     , a_     :	List[Any]=None     , a_     :	int=True     , a_     :	int=True     , a_     :	Dict=None     , )->       Optional[int]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Dict			=		size if size is not None else {'height': 20, 'width': 20}
       SCREAMING_SNAKE_CASE__				:				str			=		parent
       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		batch_size
       SCREAMING_SNAKE_CASE__				:				Any			=		num_channels
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		image_size
       SCREAMING_SNAKE_CASE__				:				List[str]			=		min_resolution
       SCREAMING_SNAKE_CASE__				:				Dict			=		max_resolution
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		size
       SCREAMING_SNAKE_CASE__				:				Tuple			=		do_normalize
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		do_convert_rgb
       SCREAMING_SNAKE_CASE__				:				List[str]			=		[512, 1024, 2048, 4096]
       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		patch_size if patch_size is not None else {'height': 16, 'width': 16}




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




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




  def 	__lowercase(      self     :	Dict				)->       Dict:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/australia.jpg'
       SCREAMING_SNAKE_CASE__				:				str			=		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       snake_case					(      UpperCamelCase_   ,						unittest.TestCase						):
  lowercase_			=     PixaStructImageProcessor if is_vision_available() else None




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




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				int			=		PixaStructImageProcessingTester(self				)




  @property
  def 	__lowercase(      self     :	Dict				)->       Tuple:




       """simple docstring"""
       return self.image_processor_tester.prepare_image_processor_dict()




  def 	__lowercase(      self     :	Any				)->       Tuple:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		self.image_processing_class(**self.image_processor_dict				)
       self.assertTrue(hasattr(a_     , 'do_normalize'				)				)
       self.assertTrue(hasattr(a_     , 'do_convert_rgb'				)				)




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




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Dict			=		self.image_processor_tester.prepare_dummy_image()

       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		self.image_processing_class(**self.image_processor_dict				)
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		2048

       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		image_processor(a_     , return_tensors='pt'     , max_patches=a_				)
       self.assertTrue(torch.allclose(inputs.flattened_patches.mean()     , torch.tensor(0.0606				)     , atol=1e-3     , rtol=1e-3				)				)




  def 	__lowercase(      self     :	Any				)->       Tuple:




       """simple docstring"""
       # Initialize image_processor
       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		self.image_processing_class(**self.image_processor_dict				)
       # create random PIL images
       SCREAMING_SNAKE_CASE__				:				Dict			=		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__				:				str			=		(
           (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__				:				List[str]			=		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__				:				Tuple			=		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 	__lowercase(      self     :	Any				)->       Any:




       """simple docstring"""
       # Initialize image_processor
       SCREAMING_SNAKE_CASE__				:				Tuple			=		self.image_processing_class(**self.image_processor_dict				)
       # create random PIL images
       SCREAMING_SNAKE_CASE__				:				Dict			=		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__				:				str			=		(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * self.image_processor_tester.num_channels
       ) + 2

       SCREAMING_SNAKE_CASE__				:				int			=		True

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

            SCREAMING_SNAKE_CASE__				:				List[Any]			=		'Hello'

            SCREAMING_SNAKE_CASE__				:				List[Any]			=		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__				:				Any			=		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 	__lowercase(      self     :	List[Any]				)->       Dict:




       """simple docstring"""
       # Initialize image_processor
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		self.image_processing_class(**self.image_processor_dict				)
       # create random numpy tensors
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		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__				:				str			=		(
           (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__				:				str			=		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__				:				int			=		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 	__lowercase(      self     :	str				)->       Optional[Any]:




       """simple docstring"""
       # Initialize image_processor
       SCREAMING_SNAKE_CASE__				:				Any			=		self.image_processing_class(**self.image_processor_dict				)
       # create random PyTorch tensors
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		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__				:				Any			=		(
           (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__				:				Optional[Any]			=		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__				:				List[Any]			=		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       snake_case					(      UpperCamelCase_   ,						unittest.TestCase						):
  lowercase_			=     PixaStructImageProcessor if is_vision_available() else None




  def 	__lowercase(      self     :	Union[str, Any]				)->       Optional[Any]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				str			=		PixaStructImageProcessingTester(self     , num_channels=4				)
       SCREAMING_SNAKE_CASE__				:				Dict			=		3




  @property
  def 	__lowercase(      self     :	Any				)->       Any:




       """simple docstring"""
       return self.image_processor_tester.prepare_image_processor_dict()




  def 	__lowercase(      self     :	Dict				)->       Optional[int]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				int			=		self.image_processing_class(**self.image_processor_dict				)
       self.assertTrue(hasattr(a_     , 'do_normalize'				)				)
       self.assertTrue(hasattr(a_     , 'do_convert_rgb'				)				)




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




       """simple docstring"""
       # Initialize image_processor
       SCREAMING_SNAKE_CASE__				:				str			=		self.image_processing_class(**self.image_processor_dict				)
       # create random PIL images
       SCREAMING_SNAKE_CASE__				:				Tuple			=		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__				:				Dict			=		(
           (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__				:				Optional[int]			=		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__				:				Tuple			=		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)     , )



