




import gc
import importlib.metadata
import tempfile
import unittest

from packaging import version

from transformers import (
    AutoModel,
    AutoModelForCausalLM,
    AutoModelForSeqaSeqLM,
    AutoModelForSequenceClassification,
    AutoTokenizer,
    BitsAndBytesConfig,
    pipeline,
)
from transformers.testing_utils import (
    is_torch_available,
    require_accelerate,
    require_bitsandbytes,
    require_torch,
    require_torch_gpu,
    require_torch_multi_gpu,
    slow,
)

def 			a   (_lowerCAmelCase     ):
							if model.config.model_type == "gpt2":
														return model.transformer.h[0].mlp.c_fc
							return model.transformer.h[0].mlp.dense_ah_to_h


if is_torch_available():
			import torch
			import torch.nn as nn






			class  __magic_name__						(  nn.Module):
							'''simple docstring'''







							def __init__(							self:   List[str]		,					_lowerCamelCase:   Optional[int]		,					_lowerCamelCase:   Tuple		):
														super().__init__()
														SCREAMING_SNAKE_CASE_   	=    module
														SCREAMING_SNAKE_CASE_   	=    nn.Sequential(
														    nn.Linear(module.in_features		,					_lowerCamelCase		,					bias=_lowerCamelCase		)		,					nn.Linear(_lowerCamelCase		,					module.out_features		,					bias=_lowerCamelCase		)		,					)
														SCREAMING_SNAKE_CASE_   	=    (2.0 / (5 * min(module.in_features		,					module.out_features		))) ** 0.5
														nn.init.normal_(self.adapter[0].weight		,					std=_lowerCamelCase		)
														nn.init.zeros_(self.adapter[1].weight		)
														self.adapter.to(module.weight.device		)





							def     _A							(							self:   Union[str, Any]		,					_lowerCamelCase:   str		,					*_lowerCamelCase:   Optional[int]		,					**_lowerCamelCase:   List[str]		):
														return self.module(_lowerCamelCase		,					*_lowerCamelCase		,					**_lowerCamelCase		) + self.adapter(_lowerCamelCase		)






@require_bitsandbytes
@require_accelerate
@require_torch
@require_torch_gpu
@slow
class  __magic_name__						(  unittest.TestCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Any	      =					'bigscience/bloom-1b7'

				# Constant values
				SCREAMING_SNAKE_CASE__					:							Union[str, Any]	      =					2.109659552692574

				SCREAMING_SNAKE_CASE__					:							List[Any]	      =					'Hello my name is'
				SCREAMING_SNAKE_CASE__					:							List[str]	      =					set()
				EXPECTED_OUTPUTS.add("Hello my name is John and I am a professional photographer. I")
				EXPECTED_OUTPUTS.add("Hello my name is John.\nI am a friend of your father.\n")
				EXPECTED_OUTPUTS.add("Hello my name is John Doe, I am a student at the University")
				SCREAMING_SNAKE_CASE__					:							Any	      =					10


				def     _A							(							self:   int		):
											# Models and tokenizer
											SCREAMING_SNAKE_CASE_   	=    AutoTokenizer.from_pretrained(self.model_name		)






class  __magic_name__						(  lowercase__):
				'''simple docstring'''







				def     _A							(							self:   Any		):
											super().setUp()

											# Models and tokenizer
											SCREAMING_SNAKE_CASE_   	=    AutoModelForCausalLM.from_pretrained(
											    self.model_name		,					torch_dtype=torch.floataa		,					device_map='''auto'''		)
											SCREAMING_SNAKE_CASE_   	=    AutoModelForCausalLM.from_pretrained(self.model_name		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)


				def     _A							(							self:   Tuple		):
											del self.model_fpaa
											del self.model_abit

											gc.collect()
											torch.cuda.empty_cache()


				def     _A							(							self:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    self.model_abit.config

											self.assertTrue(hasattr(_lowerCamelCase		,					'''quantization_config'''		)		)

											SCREAMING_SNAKE_CASE_   	=    config.to_dict()
											SCREAMING_SNAKE_CASE_   	=    config.to_diff_dict()

											SCREAMING_SNAKE_CASE_   	=    config.to_json_string()


				def     _A							(							self:   List[Any]		):
											from bitsandbytes.nn import Paramsabit

											SCREAMING_SNAKE_CASE_   	=    self.model_fpaa.get_memory_footprint()
											SCREAMING_SNAKE_CASE_   	=    self.model_abit.get_memory_footprint()

											self.assertAlmostEqual(mem_fpaa / mem_abit		,					self.EXPECTED_RELATIVE_DIFFERENCE		)
											SCREAMING_SNAKE_CASE_   	=    get_some_linear_layer(self.model_abit		)
											self.assertTrue(linear.weight.__class__ == Paramsabit		)


				def     _A							(							self:   Tuple		):
											from transformers import TaPreTrainedModel

											self.model_fpaa.get_memory_footprint()
											self.model_abit.get_memory_footprint()

											for name, module in self.model_abit.named_modules():
																		if isinstance(_lowerCamelCase		,					torch.nn.Linear		):
																									if name not in ["lm_head"] + TaPreTrainedModel._keep_in_fpaa_modules:
																																# 4-bit parameters are packed in uint8 variables
																																self.assertTrue(module.weight.dtype == torch.uinta		)


				def     _A							(							self:   Optional[int]		):
											SCREAMING_SNAKE_CASE_   	=    self.tokenizer(self.input_text		,					return_tensors='''pt'''		)
											SCREAMING_SNAKE_CASE_   	=    self.model_abit.generate(input_ids=encoded_input['''input_ids'''].to(0		)		,					max_new_tokens=10		)

											self.assertIn(self.tokenizer.decode(output_sequences[0]		,					skip_special_tokens=_lowerCamelCase		)		,					self.EXPECTED_OUTPUTS		)


				def     _A							(							self:   int		):
											SCREAMING_SNAKE_CASE_   	=    BitsAndBytesConfig()
											SCREAMING_SNAKE_CASE_   	=    True

											SCREAMING_SNAKE_CASE_   	=    AutoModelForCausalLM.from_pretrained(
											    self.model_name		,					quantization_config=_lowerCamelCase		,					device_map='''auto'''		)

											SCREAMING_SNAKE_CASE_   	=    self.tokenizer(self.input_text		,					return_tensors='''pt'''		)
											SCREAMING_SNAKE_CASE_   	=    model_abit_from_config.generate(
											    input_ids=encoded_input['''input_ids'''].to(0		)		,					max_new_tokens=10		)

											self.assertIn(self.tokenizer.decode(output_sequences[0]		,					skip_special_tokens=_lowerCamelCase		)		,					self.EXPECTED_OUTPUTS		)


				def     _A							(							self:   int		):
											with self.assertRaises(_lowerCamelCase		), tempfile.TemporaryDirectory() as tmpdirname:
																		self.model_abit.save_pretrained(_lowerCamelCase		)


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    BitsAndBytesConfig()

											with self.assertRaises(_lowerCamelCase		):
																		SCREAMING_SNAKE_CASE_   	=    AutoModelForCausalLM.from_pretrained(
																		    self.model_name		,					quantization_config=_lowerCamelCase		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		,					bnb_abit_quant_type='''nf4'''		,					)


				def     _A							(							self:   List[Any]		):
											with self.assertRaises(_lowerCamelCase		):
																		# Tries with `str`
																		self.model_abit.to('''cpu'''		)

											with self.assertRaises(_lowerCamelCase		):
																		# Tries with a `dtype``
																		self.model_abit.to(torch.floataa		)

											with self.assertRaises(_lowerCamelCase		):
																		# Tries with a `device`
																		self.model_abit.to(torch.device('''cuda:0'''		)		)

											with self.assertRaises(_lowerCamelCase		):
																		# Tries with a `device`
																		self.model_abit.float()

											with self.assertRaises(_lowerCamelCase		):
																		# Tries with a `device`
																		self.model_abit.half()

											# Test if we did not break anything
											SCREAMING_SNAKE_CASE_   	=    self.tokenizer(self.input_text		,					return_tensors='''pt'''		)

											SCREAMING_SNAKE_CASE_   	=    self.model_fpaa.to(torch.floataa		)
											SCREAMING_SNAKE_CASE_   	=    self.model_fpaa.generate(input_ids=encoded_input['''input_ids'''].to(0		)		,					max_new_tokens=10		)

											# Check this does not throw an error
											SCREAMING_SNAKE_CASE_   	=    self.model_fpaa.to('''cpu'''		)

											# Check this does not throw an error
											SCREAMING_SNAKE_CASE_   	=    self.model_fpaa.half()

											# Check this does not throw an error
											SCREAMING_SNAKE_CASE_   	=    self.model_fpaa.float()





				def     _A							(							self:   str		):
											SCREAMING_SNAKE_CASE_   	=    AutoModelForSeqaSeqLM.from_pretrained('''t5-small'''		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)
											self.assertTrue(model.decoder.block[0].layer[2].DenseReluDense.wo.weight.dtype == torch.floataa		)






@require_bitsandbytes
@require_accelerate
@require_torch
@require_torch_gpu
@slow
class  __magic_name__						(  unittest.TestCase):
				'''simple docstring'''







				@classmethod
				def     _A							(							cls:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    '''t5-small'''
											SCREAMING_SNAKE_CASE_   	=    '''google/flan-t5-small'''  # flan-t5 uses dense-act instead of dense-relu-dense
											SCREAMING_SNAKE_CASE_   	=    AutoTokenizer.from_pretrained(cls.model_name		)
											SCREAMING_SNAKE_CASE_   	=    '''Translate in German: Hello, my dog is cute'''


				def     _A							(							self:   List[str]		):
											gc.collect()
											torch.cuda.empty_cache()


				def     _A							(							self:   Optional[int]		):
											from transformers import TaForConditionalGeneration

											SCREAMING_SNAKE_CASE_   	=    TaForConditionalGeneration._keep_in_fpaa_modules
											SCREAMING_SNAKE_CASE_   	=    None

											# test with `t5-small`
											SCREAMING_SNAKE_CASE_   	=    TaForConditionalGeneration.from_pretrained(self.model_name		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)
											SCREAMING_SNAKE_CASE_   	=    self.tokenizer(self.input_text		,					return_tensors='''pt'''		).to(0		)
											SCREAMING_SNAKE_CASE_   	=    model.generate(**_lowerCamelCase		)

											# test with `flan-t5-small`
											SCREAMING_SNAKE_CASE_   	=    TaForConditionalGeneration.from_pretrained(
											    self.dense_act_model_name		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)
											SCREAMING_SNAKE_CASE_   	=    self.tokenizer(self.input_text		,					return_tensors='''pt'''		).to(0		)
											SCREAMING_SNAKE_CASE_   	=    model.generate(**_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    modules





				def     _A							(							self:   int		):
											import bitsandbytes as bnb

											from transformers import TaForConditionalGeneration

											# test with `t5-small`
											SCREAMING_SNAKE_CASE_   	=    TaForConditionalGeneration.from_pretrained(self.model_name		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)

											# there was a bug with decoders - this test checks that it is fixed
											self.assertTrue(isinstance(model.decoder.block[0].layer[0].SelfAttention.q		,					bnb.nn.Linearabit		)		)

											SCREAMING_SNAKE_CASE_   	=    self.tokenizer(self.input_text		,					return_tensors='''pt'''		).to(0		)
											SCREAMING_SNAKE_CASE_   	=    model.generate(**_lowerCamelCase		)

											# test with `flan-t5-small`
											SCREAMING_SNAKE_CASE_   	=    TaForConditionalGeneration.from_pretrained(
											    self.dense_act_model_name		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)
											SCREAMING_SNAKE_CASE_   	=    self.tokenizer(self.input_text		,					return_tensors='''pt'''		).to(0		)
											SCREAMING_SNAKE_CASE_   	=    model.generate(**_lowerCamelCase		)






class  __magic_name__						(  lowercase__):
				'''simple docstring'''







				def     _A							(							self:   Tuple		):
											super().setUp()
											# model_name
											SCREAMING_SNAKE_CASE_   	=    '''bigscience/bloom-560m'''
											SCREAMING_SNAKE_CASE_   	=    '''t5-small'''

											# Different types of model

											SCREAMING_SNAKE_CASE_   	=    AutoModel.from_pretrained(self.model_name		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)
											# Sequence classification model
											SCREAMING_SNAKE_CASE_   	=    AutoModelForSequenceClassification.from_pretrained(
											    self.model_name		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)
											# CausalLM model
											SCREAMING_SNAKE_CASE_   	=    AutoModelForCausalLM.from_pretrained(self.model_name		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)
											# Seq2seq model
											SCREAMING_SNAKE_CASE_   	=    AutoModelForSeqaSeqLM.from_pretrained(
											    self.seq_to_seq_name		,					load_in_abit=_lowerCamelCase		,					device_map='''auto'''		)


				def     _A							(							self:   int		):
											del self.base_model
											del self.sequence_model
											del self.model_abit
											del self.seq_to_seq_model

											gc.collect()
											torch.cuda.empty_cache()





				def     _A							(							self:   List[Any]		):
											from bitsandbytes.nn import Paramsabit

											self.assertTrue(self.base_model.h[-1].mlp.dense_ah_to_h.weight.__class__ == Paramsabit		)

											# Other heads should be nn.Parameter
											self.assertTrue(self.model_abit.lm_head.weight.__class__ == torch.nn.Parameter		)
											self.assertTrue(self.sequence_model.score.weight.__class__ == torch.nn.Parameter		)
											self.assertTrue(self.seq_to_seq_model.lm_head.weight.__class__ == torch.nn.Parameter		)






class  __magic_name__						(  lowercase__):
				'''simple docstring'''







				def     _A							(							self:   Optional[int]		):
											super().setUp()


				def     _A							(							self:   Optional[int]		):
											del self.pipe

											gc.collect()
											torch.cuda.empty_cache()





				def     _A							(							self:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    pipeline(
											    '''text-generation'''		,					model=self.model_name		,					model_kwargs={'''device_map''': '''auto''', '''load_in_4bit''': True, '''torch_dtype''': torch.floataa}		,					max_new_tokens=self.MAX_NEW_TOKENS		,					)

											# Real second forward pass
											SCREAMING_SNAKE_CASE_   	=    self.pipe(self.input_text		)
											self.assertIn(pipeline_output[0]['''generated_text''']		,					self.EXPECTED_OUTPUTS		)






@require_torch_multi_gpu
class  __magic_name__						(  lowercase__):
				'''simple docstring'''







				def     _A							(							self:   List[Any]		):
											super().setUp()





				def     _A							(							self:   int		):
											SCREAMING_SNAKE_CASE_   	=    AutoModelForCausalLM.from_pretrained(
											    self.model_name		,					load_in_abit=_lowerCamelCase		,					device_map='''balanced'''		)

											# Check correct device map
											self.assertEqual(set(model_parallel.hf_device_map.values()		)		,					{0, 1}		)

											# Check that inference pass works on the model
											SCREAMING_SNAKE_CASE_   	=    self.tokenizer(self.input_text		,					return_tensors='''pt'''		)

											# Second real batch
											SCREAMING_SNAKE_CASE_   	=    model_parallel.generate(input_ids=encoded_input['''input_ids'''].to(0		)		,					max_new_tokens=10		)
											self.assertIn(self.tokenizer.decode(output_parallel[0]		,					skip_special_tokens=_lowerCamelCase		)		,					self.EXPECTED_OUTPUTS		)






class  __magic_name__						(  lowercase__):
				'''simple docstring'''







				def     _A							(							self:   Dict		):
											SCREAMING_SNAKE_CASE_   	=    '''facebook/opt-350m'''
											super().setUp()





				def     _A							(							self:   Dict		):
											if version.parse(importlib.metadata.version('''bitsandbytes'''		)		) < version.parse('''0.37.0'''		):
																		return

											# Step 1: freeze all parameters
											SCREAMING_SNAKE_CASE_   	=    AutoModelForCausalLM.from_pretrained(self.model_name		,					load_in_abit=_lowerCamelCase		)

											self.assertEqual(set(model.hf_device_map.values()		)		,					{torch.cuda.current_device()}		)

											for param in model.parameters():
																		SCREAMING_SNAKE_CASE_   	=    False  # freeze the model - train adapters later
																		if param.ndim == 1:
																									# cast the small parameters (e.g. layernorm) to fp32 for stability
																									SCREAMING_SNAKE_CASE_   	=    param.data.to(torch.floataa		)

        # Step 2: add adapters
											for _, module in model.named_modules():
																		if "OPTAttention" in repr(type(_lowerCamelCase		)		):
																									SCREAMING_SNAKE_CASE_   	=    LoRALayer(module.q_proj		,					rank=16		)
																									SCREAMING_SNAKE_CASE_   	=    LoRALayer(module.k_proj		,					rank=16		)
																									SCREAMING_SNAKE_CASE_   	=    LoRALayer(module.v_proj		,					rank=16		)

        # Step 3: dummy batch
											SCREAMING_SNAKE_CASE_   	=    self.tokenizer('''Test batch '''		,					return_tensors='''pt'''		).to(0		)

											# Step 4: Check if the gradient is not None
											with torch.cuda.amp.autocast():
																		SCREAMING_SNAKE_CASE_   	=    model.forward(**_lowerCamelCase		)
																		out.logits.norm().backward()

											for module in model.modules():
																		if isinstance(_lowerCamelCase		,					_lowerCamelCase		):
																									self.assertTrue(module.adapter[1].weight.grad is not None		)
																									self.assertTrue(module.adapter[1].weight.grad.norm().item() > 0		)
																		elif isinstance(_lowerCamelCase		,					nn.Embedding		):
																									self.assertTrue(module.weight.grad is None		)






class  __magic_name__						(  lowercase__):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Dict	      =					'gpt2-xl'
				SCREAMING_SNAKE_CASE__					:							int	      =					3.3191854854152187








import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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

if is_vision_available():
			from PIL import Image

			from transformers import DonutImageProcessor






class  __magic_name__						(  unittest.TestCase):
				'''simple docstring'''







				def __init__(							self:   Union[str, Any]		,					_lowerCamelCase:   List[str]		,					_lowerCamelCase:   Union[str, Any]=7		,					_lowerCamelCase:   int=3		,					_lowerCamelCase:   Optional[int]=18		,					_lowerCamelCase:   Optional[Any]=30		,					_lowerCamelCase:   Any=4_00		,					_lowerCamelCase:   List[str]=True		,					_lowerCamelCase:   str=None		,					_lowerCamelCase:   Union[str, Any]=True		,					_lowerCamelCase:   Union[str, Any]=False		,					_lowerCamelCase:   int=True		,					_lowerCamelCase:   Any=True		,					_lowerCamelCase:   List[str]=[0.5, 0.5, 0.5]		,					_lowerCamelCase:   Dict=[0.5, 0.5, 0.5]		,					):
											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_   	=    do_resize
											SCREAMING_SNAKE_CASE_   	=    size if size is not None else {'''height''': 18, '''width''': 20}
											SCREAMING_SNAKE_CASE_   	=    do_thumbnail
											SCREAMING_SNAKE_CASE_   	=    do_align_axis
											SCREAMING_SNAKE_CASE_   	=    do_pad
											SCREAMING_SNAKE_CASE_   	=    do_normalize
											SCREAMING_SNAKE_CASE_   	=    image_mean
											SCREAMING_SNAKE_CASE_   	=    image_std





				def     _A							(							self:   str		):
											return {
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "do_thumbnail": self.do_thumbnail,
											    "do_align_long_axis": self.do_align_axis,
											    "do_pad": self.do_pad,
											    "do_normalize": self.do_normalize,
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											}






@require_torch
@require_vision
class  __magic_name__						(  __UpperCAmelCase    ,  unittest.TestCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Dict	      =					DonutImageProcessor if is_vision_available() else None


				def     _A							(							self:   Optional[int]		):
											SCREAMING_SNAKE_CASE_   	=    DonutImageProcessingTester(self		)


				@property
				def     _A							(							self:   List[str]		):
											return self.image_processor_tester.prepare_image_processor_dict()


				def     _A							(							self:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class(**self.image_processor_dict		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_resize'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''size'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_thumbnail'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_align_long_axis'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_pad'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_normalize'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''image_mean'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''image_std'''		)		)


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class.from_dict(self.image_processor_dict		)
											self.assertEqual(image_processor.size		,					{'''height''': 18, '''width''': 20}		)

											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class.from_dict(self.image_processor_dict		,					size=42		)
											self.assertEqual(image_processor.size		,					{'''height''': 42, '''width''': 42}		)

											# Previous config had dimensions in (width, height) order
											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class.from_dict(self.image_processor_dict		,					size=(42, 84)		)
											self.assertEqual(image_processor.size		,					{'''height''': 84, '''width''': 42}		)


				def     _A							(							self:   List[Any]		):
											pass


				@is_flaky()
				def     _A							(							self:   int		):
											# Initialize image_processing
											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=_lowerCamelCase		)
											for image in image_inputs:
																		self.assertIsInstance(_lowerCamelCase		,					Image.Image		)

											# Test not batched input
											SCREAMING_SNAKE_CASE_   	=    image_processing(image_inputs[0]		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)

											# Test batched
											SCREAMING_SNAKE_CASE_   	=    image_processing(_lowerCamelCase		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)


				@is_flaky()
				def     _A							(							self:   Optional[Any]		):
											# Initialize image_processing
											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=_lowerCamelCase		,					numpify=_lowerCamelCase		)
											for image in image_inputs:
																		self.assertIsInstance(_lowerCamelCase		,					np.ndarray		)

											# Test not batched input
											SCREAMING_SNAKE_CASE_   	=    image_processing(image_inputs[0]		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)

											# Test batched
											SCREAMING_SNAKE_CASE_   	=    image_processing(_lowerCamelCase		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)





				@is_flaky()
				def     _A							(							self:   List[str]		):
											# Initialize image_processing
											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=_lowerCamelCase		,					torchify=_lowerCamelCase		)
											for image in image_inputs:
																		self.assertIsInstance(_lowerCamelCase		,					torch.Tensor		)

											# Test not batched input
											SCREAMING_SNAKE_CASE_   	=    image_processing(image_inputs[0]		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)

											# Test batched
											SCREAMING_SNAKE_CASE_   	=    image_processing(_lowerCamelCase		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)


