




from __future__ import annotations

import os
import tempfile
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import is_tensorflow_text_available, is_tf_available
from transformers.testing_utils import require_tensorflow_text, require_tf, slow

from ..test_modeling_tf_common import floats_tensor
from .test_framework_agnostic import GenerationIntegrationTestsMixin


if is_tf_available():
			import tensorflow as tf

			from transformers import (
			    AutoTokenizer,
			    TFAutoModelForCausalLM,
			    TFAutoModelForSeqaSeqLM,
			    TFAutoModelForSpeechSeqaSeq,
			    TFAutoModelForVisionaSeq,
			    TFBartForConditionalGeneration,
			    TFLogitsProcessorList,
			    TFMinLengthLogitsProcessor,
			    tf_top_k_top_p_filtering,
			)

if is_tensorflow_text_available():
			import tensorflow_text as text






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







				def     _A							(							self:   List[Any]		):
											SCREAMING_SNAKE_CASE_   	=    tf.convert_to_tensor(
											    [
											        [
											            8.2_22_09_91,  # 3rd highest value; idx. 0
											            -0.5_62_00_44,
											            5.23_22_97_52,
											            4.0_38_63_93,
											            -6.8_79_83_78,
											            -0.54_78_58_02,
											            -3.2_01_21_53,
											            2.92_77_71_76,
											            1.88_17_19_53,
											            7.35_34_12_76,  # 5th highest value; idx. 9
											            8.43_20_78_33,  # 2nd highest value; idx. 10
											            -9.85_71_18_36,
											            -5.96_20_92_36,
											            -1.13_03_91_61,
											            -7.1_11_52_94,
											            -0.8_36_96_33,
											            -5.3_18_64_08,
											            7.06_42_74_07,
											            0.81_36_93_44,
											            -0.82_02_38_17,
											            -5.9_17_97_96,
											            0.58_81_34_43,
											            -6.99_77_84_38,
											            4.71_55_11_89,
											            -0.18_77_16_37,
											            7.44_02_07_59,  # 4th highest value; idx. 25
											            9.38_45_09_87,  # 1st highest value; idx. 26
											            2.12_66_29_41,
											            -9.32_56_20_38,
											            2.35_65_25_22,
											        ],  # cummulative prob of 5 highest values <= 0.6
											        [
											            0.58_42_55_18,
											            4.53_13_92_38,
											            -5.57_51_04_64,
											            -6.28_03_06_99,
											            -7.19_52_95_03,
											            -4.02_12_25_51,
											            1.39_33_70_37,
											            -6.06_70_70_57,
											            1.59_48_05_17,
											            -9.64_31_19,
											            0.03_90_77_99,
											            0.67_23_17_62,
											            -8.88_20_67_26,
											            6.27_11_59_22,  # 4th highest value; idx. 13
											            2.28_52_07_23,
											            4.82_76_75_06,
											            4.30_42_13_68,
											            8.8_27_53_13,  # 2nd highest value; idx. 17
											            5.44_02_99_58,  # 5th highest value; idx. 18
											            -4.4_73_57_94,
											            7.38_57_95_36,  # 3rd highest value; idx. 20
											            -2.91_05_16_63,
											            2.61_94_60_77,
											            -2.5_67_47_62,
											            -9.48_95_93_02,
											            -4.02_92_26_45,
											            -1.35_41_69_18,
											            9.67_70_23_23,  # 1st highest value; idx. 27
											            -5.89_47_85_53,
											            1.85_37_04_67,
											        ],  # cummulative prob of 5 highest values <= 0.6
											    ]		,					dtype=tf.floataa		,					)

											SCREAMING_SNAKE_CASE_   	=    tf.convert_to_tensor(
											    [[0, 0], [0, 9], [0, 10], [0, 25], [0, 26], [1, 13], [1, 17], [1, 18], [1, 20], [1, 27]]		,					dtype=tf.intaa		,					)  # expected non filtered idx as noted above

											SCREAMING_SNAKE_CASE_   	=    tf.convert_to_tensor(
											    [8.22_20_99, 7.3_53_41_26, 8.43_20_78, 7.4_40_20_75, 9.3_84_51, 6.27_11_59, 8.82_75_31, 5.4_40_29_95, 7.3_85_79_56, 9.67_70_23]		,					dtype=tf.floataa		,					)  # expected non filtered values as noted above

											SCREAMING_SNAKE_CASE_   	=    tf_top_k_top_p_filtering(_lowerCamelCase		,					top_k=10		,					top_p=0.6		,					min_tokens_to_keep=4		)

											SCREAMING_SNAKE_CASE_   	=    output[output != -float('''inf'''		)]
											SCREAMING_SNAKE_CASE_   	=    tf.cast(
											    tf.where(tf.not_equal(_lowerCamelCase		,					tf.constant(-float('''inf'''		)		,					dtype=tf.floataa		)		)		)		,					dtype=tf.intaa		,					)

											tf.debugging.assert_near(_lowerCamelCase		,					_lowerCamelCase		,					rtol=1E-12		)
											tf.debugging.assert_equal(_lowerCamelCase		,					_lowerCamelCase		)






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







				if is_tf_available():
								SCREAMING_SNAKE_CASE__					:							Optional[int]	      =					{
								    "AutoModelForCausalLM": TFAutoModelForCausalLM,
								    "AutoModelForSpeechSeq2Seq": TFAutoModelForSpeechSeqaSeq,
								    "AutoModelForSeq2SeqLM": TFAutoModelForSeqaSeqLM,
								    "AutoModelForVision2Seq": TFAutoModelForVisionaSeq,
								    "LogitsProcessorList": TFLogitsProcessorList,
								    "MinLengthLogitsProcessor": TFMinLengthLogitsProcessor,
								    "create_tensor_fn": tf.convert_to_tensor,
								    "floats_tensor": floats_tensor,
								    "return_tensors": "tf",
								}


				@slow
				def     _A							(							self:   Optional[Any]		):
											# TF-only test: tf.saved_model export
											SCREAMING_SNAKE_CASE_   	=    TFAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''		)
											SCREAMING_SNAKE_CASE_   	=    2
											SCREAMING_SNAKE_CASE_   	=    2






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







															def __init__(							self:   Optional[Any]		,					_lowerCamelCase:   Union[str, Any]		):
																						super(_lowerCamelCase		,					self		).__init__()
																						SCREAMING_SNAKE_CASE_   	=    model





															@tf.function(
															    input_signature=(
															        tf.TensorSpec((None, input_length)		,					tf.intaa		,					name='''input_ids'''		),
															        tf.TensorSpec((None, input_length)		,					tf.intaa		,					name='''attention_mask'''		),
															    )		,					jit_compile=_lowerCamelCase		,					)
															def     _A							(							self:   Tuple		,					_lowerCamelCase:   int		,					_lowerCamelCase:   List[str]		):
																						SCREAMING_SNAKE_CASE_   	=    self.model.generate(
																						    input_ids=_lowerCamelCase		,					attention_mask=_lowerCamelCase		,					max_new_tokens=_lowerCamelCase		,					return_dict_in_generate=_lowerCamelCase		,					)
																						return {"sequences": outputs["sequences"]}






											SCREAMING_SNAKE_CASE_   	=    [[2, 0], [1_02, 1_03]]
											SCREAMING_SNAKE_CASE_   	=    [[1, 0], [1, 1]]
											SCREAMING_SNAKE_CASE_   	=    DummyModel(model=_lowerCamelCase		)
											with tempfile.TemporaryDirectory() as tmp_dir:
																		tf.saved_model.save(_lowerCamelCase		,					_lowerCamelCase		,					signatures={'''serving_default''': dummy_model.serving}		)
																		SCREAMING_SNAKE_CASE_   	=    tf.saved_model.load(_lowerCamelCase		).signatures['''serving_default''']
																		for batch_size in range(1		,					len(_lowerCamelCase		) + 1		):
																									SCREAMING_SNAKE_CASE_   	=    {
																									    '''input_ids''': tf.constant(dummy_input_ids[:batch_size]		),
																									    '''attention_mask''': tf.constant(dummy_attention_masks[:batch_size]		),
																									}
																									SCREAMING_SNAKE_CASE_   	=    serving_func(**_lowerCamelCase		)['''sequences''']
																									SCREAMING_SNAKE_CASE_   	=    test_model.generate(**_lowerCamelCase		,					max_new_tokens=_lowerCamelCase		)
																									tf.debugging.assert_equal(_lowerCamelCase		,					_lowerCamelCase		)


				@slow
				def     _A							(							self:   List[str]		):
											# TF-only test: tf.saved_model export
											SCREAMING_SNAKE_CASE_   	=    TFAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''		)
											SCREAMING_SNAKE_CASE_   	=    1
											SCREAMING_SNAKE_CASE_   	=    2






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







															def __init__(							self:   int		,					_lowerCamelCase:   str		):
																						super(_lowerCamelCase		,					self		).__init__()
																						SCREAMING_SNAKE_CASE_   	=    model





															@tf.function(
															    input_signature=(
															        tf.TensorSpec((batch_size, None)		,					tf.intaa		,					name='''input_ids'''		),
															        tf.TensorSpec((batch_size, None)		,					tf.intaa		,					name='''attention_mask'''		),
															    )		,					jit_compile=_lowerCamelCase		,					)
															def     _A							(							self:   List[Any]		,					_lowerCamelCase:   Dict		,					_lowerCamelCase:   Optional[Any]		):
																						SCREAMING_SNAKE_CASE_   	=    self.model.generate(
																						    input_ids=_lowerCamelCase		,					attention_mask=_lowerCamelCase		,					max_new_tokens=_lowerCamelCase		,					return_dict_in_generate=_lowerCamelCase		,					)
																						return {"sequences": outputs["sequences"]}






											SCREAMING_SNAKE_CASE_   	=    [[2], [1_02, 1_03]]
											SCREAMING_SNAKE_CASE_   	=    [[1], [1, 1]]
											SCREAMING_SNAKE_CASE_   	=    DummyModel(model=_lowerCamelCase		)
											with tempfile.TemporaryDirectory() as tmp_dir:
																		tf.saved_model.save(_lowerCamelCase		,					_lowerCamelCase		,					signatures={'''serving_default''': dummy_model.serving}		)
																		SCREAMING_SNAKE_CASE_   	=    tf.saved_model.load(_lowerCamelCase		).signatures['''serving_default''']
																		for input_row in range(len(_lowerCamelCase		)		):
																									SCREAMING_SNAKE_CASE_   	=    {
																									    '''input_ids''': tf.constant([dummy_input_ids[input_row]]		),
																									    '''attention_mask''': tf.constant([dummy_attention_masks[input_row]]		),
																									}
																									SCREAMING_SNAKE_CASE_   	=    serving_func(**_lowerCamelCase		)['''sequences''']
																									SCREAMING_SNAKE_CASE_   	=    test_model.generate(**_lowerCamelCase		,					max_new_tokens=_lowerCamelCase		)
																									tf.debugging.assert_equal(_lowerCamelCase		,					_lowerCamelCase		)


				@slow
				@require_tensorflow_text
				def     _A							(							self:   str		):
											# TF-only test: tf.saved_model export
											with tempfile.TemporaryDirectory() as tmp_dir:
																		# file needed to load the TF tokenizer
																		hf_hub_download(repo_id='''google/flan-t5-small'''		,					filename='''spiece.model'''		,					local_dir=_lowerCamelCase		)






																		class  __magic_name__						(  tf.keras.layers.Layer):
																						'''simple docstring'''







																						def __init__(							self:   List[Any]		):
																													super().__init__()
																													SCREAMING_SNAKE_CASE_   	=    text.SentencepieceTokenizer(
																													    model=tf.io.gfile.GFile(os.path.join(_lowerCamelCase		,					'''spiece.model'''		)		,					'''rb'''		).read()		)
																													SCREAMING_SNAKE_CASE_   	=    TFAutoModelForSeqaSeqLM.from_pretrained('''hf-internal-testing/tiny-random-t5'''		)





																						def     _A							(							self:   Optional[int]		,					_lowerCamelCase:   Optional[int]		,					*_lowerCamelCase:   Optional[int]		,					**_lowerCamelCase:   Optional[Any]		):
																													SCREAMING_SNAKE_CASE_   	=    self.tokenizer.tokenize(_lowerCamelCase		)
																													SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    text.pad_model_inputs(
																													    _lowerCamelCase		,					max_seq_length=64		,					pad_value=self.model.config.pad_token_id		)
																													SCREAMING_SNAKE_CASE_   	=    self.model.generate(input_ids=_lowerCamelCase		,					attention_mask=_lowerCamelCase		)
																													return self.tokenizer.detokenize(_lowerCamelCase		)






																		SCREAMING_SNAKE_CASE_   	=    CompleteSentenceTransformer()
																		SCREAMING_SNAKE_CASE_   	=    tf.keras.layers.Input(shape=(1,)		,					dtype=tf.string		,					name='''inputs'''		)
																		SCREAMING_SNAKE_CASE_   	=    complete_model(_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    tf.keras.Model(_lowerCamelCase		,					_lowerCamelCase		)
																		keras_model.save(_lowerCamelCase		)


				def     _A							(							self:   Union[str, Any]		):
											# Has PT equivalent: this test relies on random sampling
											SCREAMING_SNAKE_CASE_   	=    {
											    '''do_sample''': True,
											    '''num_beams''': 1,
											    '''top_p''': 0.7,
											    '''top_k''': 10,
											    '''temperature''': 0.7,
											}
											SCREAMING_SNAKE_CASE_   	=    14

											SCREAMING_SNAKE_CASE_   	=    AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''		)
											SCREAMING_SNAKE_CASE_   	=    '''Hello, my dog is cute and'''
											SCREAMING_SNAKE_CASE_   	=    tokenizer(_lowerCamelCase		,					return_tensors='''tf'''		)
											SCREAMING_SNAKE_CASE_   	=    TFAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''		)

											SCREAMING_SNAKE_CASE_   	=    6_38
											# forces the generation to happen on CPU, to avoid GPU-related quirks
											with tf.device(''':/CPU:0'''		):
																		tf.random.set_seed(0		)
																		SCREAMING_SNAKE_CASE_   	=    model.generate(**_lowerCamelCase		,					eos_token_id=_lowerCamelCase		,					**_lowerCamelCase		)
											self.assertTrue(expectation == len(generated_tokens[0]		)		)

											SCREAMING_SNAKE_CASE_   	=    [6_38, 1_98]
											with tf.device(''':/CPU:0'''		):
																		tf.random.set_seed(0		)
																		SCREAMING_SNAKE_CASE_   	=    model.generate(**_lowerCamelCase		,					eos_token_id=_lowerCamelCase		,					**_lowerCamelCase		)
											self.assertTrue(expectation == len(generated_tokens[0]		)		)





				def     _A							(							self:   Optional[int]		):
											# Has PT equivalent: ample use of framework-specific code
											SCREAMING_SNAKE_CASE_   	=    AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-bart'''		)
											SCREAMING_SNAKE_CASE_   	=    '''Hugging Face is a technology company based in New York and Paris.'''
											SCREAMING_SNAKE_CASE_   	=    bart_tokenizer(_lowerCamelCase		,					return_tensors='''tf'''		).input_ids
											SCREAMING_SNAKE_CASE_   	=    TFBartForConditionalGeneration.from_pretrained('''hf-internal-testing/tiny-random-bart'''		)
											SCREAMING_SNAKE_CASE_   	=    bart_model.generate(_lowerCamelCase		).numpy()






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







															def     _A							(							self:   Dict		,					_lowerCamelCase:   int		,					_lowerCamelCase:   Union[str, Any]=None		,					**_lowerCamelCase:   int		):
																						return super().call(_lowerCamelCase		,					**_lowerCamelCase		)






											SCREAMING_SNAKE_CASE_   	=    FakeBart.from_pretrained('''hf-internal-testing/tiny-random-bart'''		)
											SCREAMING_SNAKE_CASE_   	=    bart_model.generate(_lowerCamelCase		,					foo='''bar'''		).numpy()
											self.assertTrue(np.array_equal(_lowerCamelCase		,					_lowerCamelCase		)		)






											class  __magic_name__						(  bart_model.model.encoder.__class__):
															'''simple docstring'''







															def     _A							(							self:   Union[str, Any]		,					_lowerCamelCase:   Optional[Any]		,					**_lowerCamelCase:   Tuple		):
																						return super().call(_lowerCamelCase		,					**_lowerCamelCase		)






											SCREAMING_SNAKE_CASE_   	=    FakeEncoder(bart_model.config		,					bart_model.model.shared		)
											SCREAMING_SNAKE_CASE_   	=    fake_encoder

											# Normal generation still works (the output will be different because the encoder weights are different)
											SCREAMING_SNAKE_CASE_   	=    bart_model.generate(_lowerCamelCase		).numpy()
											with self.assertRaises(_lowerCamelCase		):
																		# FakeEncoder.call() accepts **kwargs -> no filtering -> value error due to unexpected input "foo"
																		bart_model.generate(_lowerCamelCase		,					foo='''bar'''		)








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'''],
											    )		,					)


