
'''simple docstring'''







import unittest

from transformers import MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING, AutoTokenizer, is_vision_available
from transformers.pipelines import pipeline
from transformers.pipelines.document_question_answering import apply_tesseract
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_detectrona,
    require_pytesseract,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
						from PIL import Image

						from transformers.image_utils import load_image
else:


						class 			lowerCAmelCase :




								@staticmethod
								def     lowercase       (				*UpperCamelCase					,						**UpperCamelCase      ):
														pass



						def 			_a		(	_SCREAMING_SNAKE_CASE		:   Tuple  ):
												return None


# This is a pinned image from a specific revision of a document question answering space, hosted by HuggingFace,
# so we can expect it to be available.
_snake_case				:   Tuple     =				(
    """https://huggingface.co/spaces/impira/docquery/resolve/2f6c96314dc84dfda62d40de9da55f2f5165d403/invoice.png"""
)


@is_pipeline_test
@require_torch
@require_vision
class 			lowerCAmelCase (				unittest.TestCase			):
		a							:					str       =					MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING




		@require_pytesseract
		@require_vision
		def     lowercase       (				self					,						UpperCamelCase					,						UpperCamelCase					,						UpperCamelCase      ):
								_SCREAMING_SNAKE_CASE				= pipeline(
								    "document-question-answering"					,						model=UpperCamelCase					,						tokenizer=UpperCamelCase					,						image_processor=UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= INVOICE_URL
								_SCREAMING_SNAKE_CASE				= list(zip(*apply_tesseract(load_image(UpperCamelCase      )					,						UpperCamelCase					,						""      )      )      )
								_SCREAMING_SNAKE_CASE				= "What is the placebo?"
								_SCREAMING_SNAKE_CASE				= [
								    {
								        "image": load_image(UpperCamelCase      ),
								        "question": question,
								    },
								    {
								        "image": image,
								        "question": question,
								    },
								    {
								        "image": image,
								        "question": question,
								        "word_boxes": word_boxes,
								    },
								]
								return dqa_pipeline, examples




		def     lowercase       (				self					,						UpperCamelCase					,						UpperCamelCase      ):
								_SCREAMING_SNAKE_CASE				= dqa_pipeline(UpperCamelCase					,						top_k=2      )
								self.assertEqual(
								    UpperCamelCase					,						[
								        [
								            {"score": ANY(UpperCamelCase      ), "answer": ANY(UpperCamelCase      ), "start": ANY(UpperCamelCase      ), "end": ANY(UpperCamelCase      )},
								            {"score": ANY(UpperCamelCase      ), "answer": ANY(UpperCamelCase      ), "start": ANY(UpperCamelCase      ), "end": ANY(UpperCamelCase      )},
								        ]
								    ]
								    * 3					,						)




		@require_torch
		@require_detectrona
		@require_pytesseract
		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= pipeline("document-question-answering"					,						model="hf-internal-testing/tiny-random-layoutlmv2"      )
								_SCREAMING_SNAKE_CASE				= INVOICE_URL
								_SCREAMING_SNAKE_CASE				= "How many cats are there?"

								_SCREAMING_SNAKE_CASE				= [
								    {"score": 0.00_01, "answer": "oy 2312/2019", "start": 38, "end": 39},
								    {"score": 0.00_01, "answer": "oy 2312/2019 DUE", "start": 38, "end": 40},
								]
								_SCREAMING_SNAKE_CASE				= dqa_pipeline(image=UpperCamelCase					,						question=UpperCamelCase					,						top_k=2      )
								self.assertEqual(nested_simplify(UpperCamelCase					,						decimals=4      )					,						UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= dqa_pipeline({"image": image, "question": question}					,						top_k=2      )
								self.assertEqual(nested_simplify(UpperCamelCase					,						decimals=4      )					,						UpperCamelCase      )

								# This image does not detect ANY text in it, meaning layoutlmv2 should fail.
								# Empty answer probably
								_SCREAMING_SNAKE_CASE				= "./tests/fixtures/tests_samples/COCO/000000039769.png"
								_SCREAMING_SNAKE_CASE				= dqa_pipeline(image=UpperCamelCase					,						question=UpperCamelCase					,						top_k=2      )
								self.assertEqual(UpperCamelCase					,						[]      )

								# We can optionnally pass directly the words and bounding boxes
								_SCREAMING_SNAKE_CASE				= "./tests/fixtures/tests_samples/COCO/000000039769.png"
								_SCREAMING_SNAKE_CASE				= []
								_SCREAMING_SNAKE_CASE				= []
								_SCREAMING_SNAKE_CASE				= dqa_pipeline(image=UpperCamelCase					,						question=UpperCamelCase					,						words=UpperCamelCase					,						boxes=UpperCamelCase					,						top_k=2      )
								self.assertEqual(UpperCamelCase					,						[]      )




		@slow
		@require_torch
		@require_detectrona
		@require_pytesseract
		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= pipeline(
								    "document-question-answering"					,						model="tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa"					,						revision="9977165"					,						)
								_SCREAMING_SNAKE_CASE				= INVOICE_URL
								_SCREAMING_SNAKE_CASE				= "What is the invoice number?"

								_SCREAMING_SNAKE_CASE				= dqa_pipeline(image=UpperCamelCase					,						question=UpperCamelCase					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        {"score": 0.99_44, "answer": "us-001", "start": 16, "end": 16},
								        {"score": 0.00_09, "answer": "us-001", "start": 16, "end": 16},
								    ]					,						)

								_SCREAMING_SNAKE_CASE				= dqa_pipeline({"image": image, "question": question}					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        {"score": 0.99_44, "answer": "us-001", "start": 16, "end": 16},
								        {"score": 0.00_09, "answer": "us-001", "start": 16, "end": 16},
								    ]					,						)

								_SCREAMING_SNAKE_CASE				= dqa_pipeline(
								    [{"image": image, "question": question}, {"image": image, "question": question}]					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        [
								            {"score": 0.99_44, "answer": "us-001", "start": 16, "end": 16},
								            {"score": 0.00_09, "answer": "us-001", "start": 16, "end": 16},
								        ],
								    ]
								    * 2					,						)




		@slow
		@require_torch
		@require_detectrona
		@require_pytesseract
		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= pipeline(
								    "document-question-answering"					,						model="tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa"					,						revision="9977165"					,						max_seq_len=50					,						)
								_SCREAMING_SNAKE_CASE				= INVOICE_URL
								_SCREAMING_SNAKE_CASE				= "What is the invoice number?"

								_SCREAMING_SNAKE_CASE				= dqa_pipeline(image=UpperCamelCase					,						question=UpperCamelCase					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        {"score": 0.99_74, "answer": "1110212019", "start": 23, "end": 23},
								        {"score": 0.99_48, "answer": "us-001", "start": 16, "end": 16},
								    ]					,						)

								_SCREAMING_SNAKE_CASE				= dqa_pipeline({"image": image, "question": question}					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        {"score": 0.99_74, "answer": "1110212019", "start": 23, "end": 23},
								        {"score": 0.99_48, "answer": "us-001", "start": 16, "end": 16},
								    ]					,						)

								_SCREAMING_SNAKE_CASE				= dqa_pipeline(
								    [{"image": image, "question": question}, {"image": image, "question": question}]					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        [
								            {"score": 0.99_74, "answer": "1110212019", "start": 23, "end": 23},
								            {"score": 0.99_48, "answer": "us-001", "start": 16, "end": 16},
								        ]
								    ]
								    * 2					,						)




		@slow
		@require_torch
		@require_pytesseract
		@require_vision
		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= AutoTokenizer.from_pretrained(
								    "impira/layoutlm-document-qa"					,						revision="3dc6de3"					,						add_prefix_space=UpperCamelCase      )
								_SCREAMING_SNAKE_CASE				= pipeline(
								    "document-question-answering"					,						model="impira/layoutlm-document-qa"					,						tokenizer=UpperCamelCase					,						revision="3dc6de3"					,						)
								_SCREAMING_SNAKE_CASE				= INVOICE_URL
								_SCREAMING_SNAKE_CASE				= "What is the invoice number?"

								_SCREAMING_SNAKE_CASE				= dqa_pipeline(image=UpperCamelCase					,						question=UpperCamelCase					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        {"score": 0.42_51, "answer": "us-001", "start": 16, "end": 16},
								        {"score": 0.08_19, "answer": "1110212019", "start": 23, "end": 23},
								    ]					,						)

								_SCREAMING_SNAKE_CASE				= dqa_pipeline({"image": image, "question": question}					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        {"score": 0.42_51, "answer": "us-001", "start": 16, "end": 16},
								        {"score": 0.08_19, "answer": "1110212019", "start": 23, "end": 23},
								    ]					,						)

								_SCREAMING_SNAKE_CASE				= dqa_pipeline(
								    [{"image": image, "question": question}, {"image": image, "question": question}]					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        [
								            {"score": 0.42_51, "answer": "us-001", "start": 16, "end": 16},
								            {"score": 0.08_19, "answer": "1110212019", "start": 23, "end": 23},
								        ]
								    ]
								    * 2					,						)

								_SCREAMING_SNAKE_CASE				= list(zip(*apply_tesseract(load_image(UpperCamelCase      )					,						UpperCamelCase					,						""      )      )      )

								# This model should also work if `image` is set to None
								_SCREAMING_SNAKE_CASE				= dqa_pipeline({"image": None, "word_boxes": word_boxes, "question": question}					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        {"score": 0.42_51, "answer": "us-001", "start": 16, "end": 16},
								        {"score": 0.08_19, "answer": "1110212019", "start": 23, "end": 23},
								    ]					,						)




		@slow
		@require_torch
		@require_pytesseract
		@require_vision
		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= AutoTokenizer.from_pretrained(
								    "impira/layoutlm-document-qa"					,						revision="3dc6de3"					,						add_prefix_space=UpperCamelCase      )
								_SCREAMING_SNAKE_CASE				= pipeline(
								    "document-question-answering"					,						model="impira/layoutlm-document-qa"					,						tokenizer=UpperCamelCase					,						revision="3dc6de3"					,						max_seq_len=50					,						)
								_SCREAMING_SNAKE_CASE				= INVOICE_URL
								_SCREAMING_SNAKE_CASE				= "What is the invoice number?"

								_SCREAMING_SNAKE_CASE				= dqa_pipeline(image=UpperCamelCase					,						question=UpperCamelCase					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        {"score": 0.99_99, "answer": "us-001", "start": 16, "end": 16},
								        {"score": 0.99_98, "answer": "us-001", "start": 16, "end": 16},
								    ]					,						)

								_SCREAMING_SNAKE_CASE				= dqa_pipeline(
								    [{"image": image, "question": question}, {"image": image, "question": question}]					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        [
								            {"score": 0.99_99, "answer": "us-001", "start": 16, "end": 16},
								            {"score": 0.99_98, "answer": "us-001", "start": 16, "end": 16},
								        ]
								    ]
								    * 2					,						)

								_SCREAMING_SNAKE_CASE				= list(zip(*apply_tesseract(load_image(UpperCamelCase      )					,						UpperCamelCase					,						""      )      )      )

								# This model should also work if `image` is set to None
								_SCREAMING_SNAKE_CASE				= dqa_pipeline({"image": None, "word_boxes": word_boxes, "question": question}					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        {"score": 0.99_99, "answer": "us-001", "start": 16, "end": 16},
								        {"score": 0.99_98, "answer": "us-001", "start": 16, "end": 16},
								    ]					,						)




		@slow
		@require_torch
		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= pipeline(
								    "document-question-answering"					,						model="naver-clova-ix/donut-base-finetuned-docvqa"					,						tokenizer=AutoTokenizer.from_pretrained("naver-clova-ix/donut-base-finetuned-docvqa"      )					,						feature_extractor="naver-clova-ix/donut-base-finetuned-docvqa"					,						)

								_SCREAMING_SNAKE_CASE				= INVOICE_URL
								_SCREAMING_SNAKE_CASE				= "What is the invoice number?"
								_SCREAMING_SNAKE_CASE				= dqa_pipeline(image=UpperCamelCase					,						question=UpperCamelCase					,						top_k=2      )
								self.assertEqual(nested_simplify(UpperCamelCase					,						decimals=4      )					,						[{"answer": "us-001"}]      )




		@require_tf
		@unittest.skip("Document question answering not implemented in TF"      )
		def     lowercase       (				self      ):
								pass

'''simple docstring'''







import tempfile

import numpy as np
import torch
from transformers import AutoTokenizer, TaEncoderModel

from diffusers import DDPMScheduler, UNetaDConditionModel
from diffusers.models.attention_processor import AttnAddedKVProcessor
from diffusers.pipelines.deepfloyd_if import IFWatermarker
from diffusers.utils.testing_utils import torch_device

from ..test_pipelines_common import to_np


class 			lowerCAmelCase :




		def     lowercase       (				self      ):
								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= TaEncoderModel.from_pretrained("hf-internal-testing/tiny-random-t5"      )

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5"      )

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= UNetaDConditionModel(
								    sample_size=32					,						layers_per_block=1					,						block_out_channels=[32, 64]					,						down_block_types=[
								        "ResnetDownsampleBlock2D",
								        "SimpleCrossAttnDownBlock2D",
								    ]					,						mid_block_type="UNetMidBlock2DSimpleCrossAttn"					,						up_block_types=["SimpleCrossAttnUpBlock2D", "ResnetUpsampleBlock2D"]					,						in_channels=3					,						out_channels=6					,						cross_attention_dim=32					,						encoder_hid_dim=32					,						attention_head_dim=8					,						addition_embed_type="text"					,						addition_embed_type_num_heads=2					,						cross_attention_norm="group_norm"					,						resnet_time_scale_shift="scale_shift"					,						act_fn="gelu"					,						)
								unet.set_attn_processor(AttnAddedKVProcessor()      )  # For reproducibility tests

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= DDPMScheduler(
								    num_train_timesteps=1_000					,						beta_schedule="squaredcos_cap_v2"					,						beta_start=0.00_01					,						beta_end=0.02					,						thresholding=UpperCamelCase					,						dynamic_thresholding_ratio=0.95					,						sample_max_value=1.0					,						prediction_type="epsilon"					,						variance_type="learned_range"					,						)

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= IFWatermarker()

								return {
								    "text_encoder": text_encoder,
								    "tokenizer": tokenizer,
								    "unet": unet,
								    "scheduler": scheduler,
								    "watermarker": watermarker,
								    "safety_checker": None,
								    "feature_extractor": None,
								}




		def     lowercase       (				self      ):
								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= TaEncoderModel.from_pretrained("hf-internal-testing/tiny-random-t5"      )

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5"      )

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= UNetaDConditionModel(
								    sample_size=32					,						layers_per_block=[1, 2]					,						block_out_channels=[32, 64]					,						down_block_types=[
								        "ResnetDownsampleBlock2D",
								        "SimpleCrossAttnDownBlock2D",
								    ]					,						mid_block_type="UNetMidBlock2DSimpleCrossAttn"					,						up_block_types=["SimpleCrossAttnUpBlock2D", "ResnetUpsampleBlock2D"]					,						in_channels=6					,						out_channels=6					,						cross_attention_dim=32					,						encoder_hid_dim=32					,						attention_head_dim=8					,						addition_embed_type="text"					,						addition_embed_type_num_heads=2					,						cross_attention_norm="group_norm"					,						resnet_time_scale_shift="scale_shift"					,						act_fn="gelu"					,						class_embed_type="timestep"					,						mid_block_scale_factor=1.4_14					,						time_embedding_act_fn="gelu"					,						time_embedding_dim=32					,						)
								unet.set_attn_processor(AttnAddedKVProcessor()      )  # For reproducibility tests

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= DDPMScheduler(
								    num_train_timesteps=1_000					,						beta_schedule="squaredcos_cap_v2"					,						beta_start=0.00_01					,						beta_end=0.02					,						thresholding=UpperCamelCase					,						dynamic_thresholding_ratio=0.95					,						sample_max_value=1.0					,						prediction_type="epsilon"					,						variance_type="learned_range"					,						)

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= DDPMScheduler(
								    num_train_timesteps=1_000					,						beta_schedule="squaredcos_cap_v2"					,						beta_start=0.00_01					,						beta_end=0.02					,						)

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= IFWatermarker()

								return {
								    "text_encoder": text_encoder,
								    "tokenizer": tokenizer,
								    "unet": unet,
								    "scheduler": scheduler,
								    "image_noising_scheduler": image_noising_scheduler,
								    "watermarker": watermarker,
								    "safety_checker": None,
								    "feature_extractor": None,
								}




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= self.get_dummy_components()
								_SCREAMING_SNAKE_CASE				= self.pipeline_class(**UpperCamelCase      )
								pipe.to(UpperCamelCase      )
								pipe.set_progress_bar_config(disable=UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= self.get_dummy_inputs(UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= inputs["prompt"]
								_SCREAMING_SNAKE_CASE				= inputs["generator"]
								_SCREAMING_SNAKE_CASE				= inputs["num_inference_steps"]
								_SCREAMING_SNAKE_CASE				= inputs["output_type"]

								if "image" in inputs:
														_SCREAMING_SNAKE_CASE				= inputs["image"]
								else:
														_SCREAMING_SNAKE_CASE				= None

								if "mask_image" in inputs:
														_SCREAMING_SNAKE_CASE				= inputs["mask_image"]
								else:
														_SCREAMING_SNAKE_CASE				= None

								if "original_image" in inputs:
														_SCREAMING_SNAKE_CASE				= inputs["original_image"]
								else:
														_SCREAMING_SNAKE_CASE				= None

								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= pipe.encode_prompt(UpperCamelCase      )

								# inputs with prompt converted to embeddings
								_SCREAMING_SNAKE_CASE				= {
								    "prompt_embeds": prompt_embeds,
								    "negative_prompt_embeds": negative_prompt_embeds,
								    "generator": generator,
								    "num_inference_steps": num_inference_steps,
								    "output_type": output_type,
								}

								if image is not None:
														_SCREAMING_SNAKE_CASE				= image

								if mask_image is not None:
														_SCREAMING_SNAKE_CASE				= mask_image

								if original_image is not None:
														_SCREAMING_SNAKE_CASE				= original_image

								# set all optional components to None
								for optional_component in pipe._optional_components:
														setattr(UpperCamelCase					,						UpperCamelCase					,						UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= pipe(**UpperCamelCase      )[0]

								with tempfile.TemporaryDirectory() as tmpdir:
														pipe.save_pretrained(UpperCamelCase      )
														_SCREAMING_SNAKE_CASE				= self.pipeline_class.from_pretrained(UpperCamelCase      )
														pipe_loaded.to(UpperCamelCase      )
														pipe_loaded.set_progress_bar_config(disable=UpperCamelCase      )

								pipe_loaded.unet.set_attn_processor(AttnAddedKVProcessor()      )  # For reproducibility tests

								for optional_component in pipe._optional_components:
														self.assertTrue(
														    getattr(UpperCamelCase					,						UpperCamelCase      ) is None					,						F'`{optional_component}` did not stay set to None after loading.'					,						)

								_SCREAMING_SNAKE_CASE				= self.get_dummy_inputs(UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= inputs["generator"]
								_SCREAMING_SNAKE_CASE				= inputs["num_inference_steps"]
								_SCREAMING_SNAKE_CASE				= inputs["output_type"]

								# inputs with prompt converted to embeddings
								_SCREAMING_SNAKE_CASE				= {
								    "prompt_embeds": prompt_embeds,
								    "negative_prompt_embeds": negative_prompt_embeds,
								    "generator": generator,
								    "num_inference_steps": num_inference_steps,
								    "output_type": output_type,
								}

								if image is not None:
														_SCREAMING_SNAKE_CASE				= image

								if mask_image is not None:
														_SCREAMING_SNAKE_CASE				= mask_image

								if original_image is not None:
														_SCREAMING_SNAKE_CASE				= original_image

								_SCREAMING_SNAKE_CASE				= pipe_loaded(**UpperCamelCase      )[0]

								_SCREAMING_SNAKE_CASE				= np.abs(to_np(UpperCamelCase      ) - to_np(UpperCamelCase      )      ).max()
								self.assertLess(UpperCamelCase					,						1e-4      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= self.get_dummy_components()
								_SCREAMING_SNAKE_CASE				= self.pipeline_class(**UpperCamelCase      )
								pipe.to(UpperCamelCase      )
								pipe.set_progress_bar_config(disable=UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= self.get_dummy_inputs(UpperCamelCase      )
								_SCREAMING_SNAKE_CASE				= pipe(**UpperCamelCase      )[0]

								with tempfile.TemporaryDirectory() as tmpdir:
														pipe.save_pretrained(UpperCamelCase      )
														_SCREAMING_SNAKE_CASE				= self.pipeline_class.from_pretrained(UpperCamelCase      )
														pipe_loaded.to(UpperCamelCase      )
														pipe_loaded.set_progress_bar_config(disable=UpperCamelCase      )

								pipe_loaded.unet.set_attn_processor(AttnAddedKVProcessor()      )  # For reproducibility tests

								_SCREAMING_SNAKE_CASE				= self.get_dummy_inputs(UpperCamelCase      )
								_SCREAMING_SNAKE_CASE				= pipe_loaded(**UpperCamelCase      )[0]

								_SCREAMING_SNAKE_CASE				= np.abs(to_np(UpperCamelCase      ) - to_np(UpperCamelCase      )      ).max()
								self.assertLess(UpperCamelCase					,						1e-4      )