






"""simple docstring"""



import tempfile
import unittest
from pathlib import Path
from shutil import copyfile

from transformers import BatchEncoding, MarianTokenizer
from transformers.testing_utils import get_tests_dir, require_sentencepiece, slow
from transformers.utils import is_sentencepiece_available, is_tf_available, is_torch_available


if is_sentencepiece_available():
						from transformers.models.marian.tokenization_marian import VOCAB_FILES_NAMES, save_json

from ...test_tokenization_common import TokenizerTesterMixin


A__	:    List[str]			 = get_tests_dir('fixtures/test_sentencepiece.model')

A__	:    Optional[int]			 = {'target_lang': 'fi', 'source_lang': 'en'}
A__	:    Optional[int]			 = '>>zh<<'
A__	:    Any			 = 'Helsinki-NLP/'

if is_torch_available():
						A__	:    str			 = 'pt'
elif is_tf_available():
						A__	:    List[str]			 = 'tf'
else:
						A__	:    List[str]			 = 'jax'







@require_sentencepiece
class        lowercase__      (							snake_case__,       unittest.TestCase       ):
			_UpperCAmelCase		:Optional[Any]             =			MarianTokenizer
			_UpperCAmelCase		:Dict             =			False
			_UpperCAmelCase		:Tuple             =			True


			def      UpperCAmelCase__						(				self					:  List[str] ):
										super().setUp()
										lowerCamelCase_	:							List[str]									=["</s>", "<unk>", "▁This", "▁is", "▁a", "▁t", "est", "\u0120", "<pad>"]
										lowerCamelCase_	:							Optional[Any]									=dict(zip(snake_case__       ,	range(len(snake_case__ ) ) ) )
										lowerCamelCase_	:							Optional[int]									=Path(self.tmpdirname )
										save_json(snake_case__       ,	save_dir / VOCAB_FILES_NAMES["vocab"] )
										save_json(snake_case__       ,	save_dir / VOCAB_FILES_NAMES["tokenizer_config_file"] )
										if not (save_dir / VOCAB_FILES_NAMES["source_spm"]).exists():
																	copyfile(snake_case__       ,	save_dir / VOCAB_FILES_NAMES["source_spm"] )
																	copyfile(snake_case__       ,	save_dir / VOCAB_FILES_NAMES["target_spm"] )

										lowerCamelCase_	:							str									=MarianTokenizer.from_pretrained(self.tmpdirname )
										tokenizer.save_pretrained(self.tmpdirname )


			def      UpperCAmelCase__						(				self					:  Union[str, Any]       ,	**snake_case__					:  int ):
										return MarianTokenizer.from_pretrained(self.tmpdirname       ,	**snake_case__ )


			def      UpperCAmelCase__						(				self					:  Tuple       ,	snake_case__					:  Optional[int] ):
										return (
										    "This is a test",
										    "This is a test",
										)


			def      UpperCAmelCase__						(				self					:  str ):
										lowerCamelCase_	:							Union[str, Any]									="</s>"
										lowerCamelCase_	:							List[Any]									=0

										self.assertEqual(self.get_tokenizer()._convert_token_to_id(snake_case__ )       ,	snake_case__ )
										self.assertEqual(self.get_tokenizer()._convert_id_to_token(snake_case__ )       ,	snake_case__ )


			def      UpperCAmelCase__						(				self					:  Union[str, Any] ):
										lowerCamelCase_	:							Tuple									=list(self.get_tokenizer().get_vocab().keys() )

										self.assertEqual(vocab_keys[0]       ,	"</s>" )
										self.assertEqual(vocab_keys[1]       ,	"<unk>" )
										self.assertEqual(vocab_keys[-1]       ,	"<pad>" )
										self.assertEqual(len(snake_case__ )       ,	9 )


			def      UpperCAmelCase__						(				self					:  Any ):
										self.assertEqual(self.get_tokenizer().vocab_size       ,	9 )


			def      UpperCAmelCase__						(				self					:  Union[str, Any] ):
										lowerCamelCase_	:							Union[str, Any]									=MarianTokenizer.from_pretrained(F"""{ORG_NAME}opus-mt-en-de""" )
										lowerCamelCase_	:							Optional[Any]									=en_de_tokenizer(["I am a small frog"]       ,	return_tensors=snake_case__ )
										self.assertIsInstance(snake_case__       ,	snake_case__ )
										lowerCamelCase_	:							Tuple									=[38, 121, 14, 697, 3_8848, 0]
										self.assertListEqual(snake_case__       ,	batch.input_ids[0] )

										lowerCamelCase_	:							Dict									=tempfile.mkdtemp()
										en_de_tokenizer.save_pretrained(snake_case__ )
										lowerCamelCase_	:							Optional[Any]									=[x.name for x in Path(snake_case__ ).glob("*" )]
										self.assertIn("source.spm"       ,	snake_case__ )
										MarianTokenizer.from_pretrained(snake_case__ )


			def      UpperCAmelCase__						(				self					:  List[Any] ):
										lowerCamelCase_	:							Any									=self.get_tokenizer()

										lowerCamelCase_	:							Optional[int]									=tok(
										    ["I am a small frog" * 1000, "I am a small frog"]       ,	padding=snake_case__       ,	truncation=snake_case__       ,	return_tensors=snake_case__ )
										self.assertIsInstance(snake_case__       ,	snake_case__ )
										self.assertEqual(batch.input_ids.shape       ,	(2, 512) )


			def      UpperCAmelCase__						(				self					:  int ):
										lowerCamelCase_	:							Dict									=self.get_tokenizer()
										lowerCamelCase_	:							Optional[int]									=tok(["I am a tiny frog", "I am a small frog"]       ,	padding=snake_case__       ,	return_tensors=snake_case__ )
										self.assertIsInstance(snake_case__       ,	snake_case__ )
										self.assertEqual(batch_smaller.input_ids.shape       ,	(2, 10) )


			@slow
			def      UpperCAmelCase__						(				self					:  Tuple ):
										# fmt: off
										lowerCamelCase_	:							List[str]									={"input_ids": [[4_3495, 462, 20, 4_2164, 1369, 52, 464, 132, 1703, 492, 13, 7491, 3_8999, 6, 8, 464, 132, 1703, 492, 13, 4669, 3_7867, 13, 7525, 27, 1593, 988, 13, 3_3972, 7029, 6, 20, 8251, 383, 2, 270, 5866, 3788, 2, 2353, 8251, 1_2338, 2, 1_3958, 387, 2, 3629, 6953, 188, 2900, 2, 1_3958, 8011, 1_1501, 23, 8460, 4073, 3_4009, 20, 435, 1_1439, 27, 8, 8460, 4073, 6004, 20, 9988, 375, 27, 33, 266, 1945, 1076, 1350, 3_7867, 3288, 5, 577, 1076, 4374, 8, 5082, 5, 2_6453, 257, 556, 403, 2, 242, 132, 383, 316, 492, 8, 1_0767, 6, 316, 304, 4239, 3, 0], [148, 1_5722, 19, 1839, 12, 1350, 13, 2_2327, 5082, 5418, 4_7567, 3_5938, 59, 318, 1_9552, 108, 2183, 54, 1_4976, 4835, 32, 547, 1114, 8, 315, 2417, 5, 92, 1_9088, 3, 0, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100], [36, 6395, 1_2570, 3_9147, 1_1597, 6, 266, 4, 4_5405, 7296, 3, 0, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100]], "attention_mask": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
										# fmt: on

										self.tokenizer_integration_test_util(
										    expected_encoding=snake_case__       ,	model_name="Helsinki-NLP/opus-mt-en-de"       ,	revision="1a8c2263da11e68e50938f97e10cd57820bd504c"       ,	decode_kwargs={"use_source_tokenizer": True}       ,	)


			def      UpperCAmelCase__						(				self					:  Optional[int] ):
										lowerCamelCase_	:							Tuple									=MarianTokenizer.from_pretrained("hf-internal-testing/test-marian-two-vocabs" )

										lowerCamelCase_	:							Union[str, Any]									="Tämä on testi"
										lowerCamelCase_	:							List[Any]									="This is a test"

										lowerCamelCase_	:							Any									=[76, 7, 2047, 2]
										lowerCamelCase_	:							List[Any]									=[69, 12, 11, 940, 2]

										lowerCamelCase_	:							Dict									=tokenizer(snake_case__ ).input_ids
										self.assertListEqual(snake_case__       ,	snake_case__ )

										lowerCamelCase_	:							List[str]									=tokenizer(text_target=snake_case__ ).input_ids
										self.assertListEqual(snake_case__       ,	snake_case__ )

										lowerCamelCase_	:							List[Any]									=tokenizer.decode(snake_case__       ,	skip_special_tokens=snake_case__ )
										self.assertEqual(snake_case__       ,	snake_case__ )











"""simple docstring"""



import gc
import random
import unittest

import numpy as np
import torch
from transformers import XLMRobertaTokenizer

from diffusers import (
    AltDiffusionImgaImgPipeline,
    AutoencoderKL,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.image_processor import VaeImageProcessor
from diffusers.pipelines.alt_diffusion.modeling_roberta_series import (
    RobertaSeriesConfig,
    RobertaSeriesModelWithTransformation,
)
from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()







class        lowercase__      (							unittest.TestCase       ):


			def      UpperCAmelCase__						(				self					:  Any ):
										# clean up the VRAM after each test
										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()


			@property
			def      UpperCAmelCase__						(				self					:  Dict ):
										lowerCamelCase_	:							Optional[Any]									=1
										lowerCamelCase_	:							Union[str, Any]									=3
										lowerCamelCase_	:							Dict									=(32, 32)

										lowerCamelCase_	:							List[Any]									=floats_tensor((batch_size, num_channels) + sizes       ,	rng=random.Random(0 ) ).to(snake_case__ )
										return image


			@property
			def      UpperCAmelCase__						(				self					:  Union[str, Any] ):
										torch.manual_seed(0 )
										lowerCamelCase_	:							Dict									=UNetaDConditionModel(
										    block_out_channels=(32, 64)       ,	layers_per_block=2       ,	sample_size=32       ,	in_channels=4       ,	out_channels=4       ,	down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")       ,	up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")       ,	cross_attention_dim=32       ,	)
										return model


			@property
			def      UpperCAmelCase__						(				self					:  List[Any] ):
										torch.manual_seed(0 )
										lowerCamelCase_	:							Union[str, Any]									=AutoencoderKL(
										    block_out_channels=[32, 64]       ,	in_channels=3       ,	out_channels=3       ,	down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]       ,	up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]       ,	latent_channels=4       ,	)
										return model


			@property
			def      UpperCAmelCase__						(				self					:  Optional[Any] ):
										torch.manual_seed(0 )
										lowerCamelCase_	:							Any									=RobertaSeriesConfig(
										    hidden_size=32       ,	project_dim=32       ,	intermediate_size=37       ,	layer_norm_eps=1E-05       ,	num_attention_heads=4       ,	num_hidden_layers=5       ,	pad_token_id=1       ,	vocab_size=5006       ,	)
										return RobertaSeriesModelWithTransformation(snake_case__ )


			@property
			def      UpperCAmelCase__						(				self					:  int ):
										def extract(*snake_case__					:  Dict       ,	**snake_case__					:  int ):







																	class        lowercase__      :


																				def __init__(				self					:  Optional[Any] ):
																											lowerCamelCase_	:							Union[str, Any]									=torch.ones([0] )


																				def      UpperCAmelCase__						(				self					:  List[Any]       ,	snake_case__					:  Any ):
																											self.pixel_values.to(snake_case__ )
																											return self


																	return Out()

										return extract


			def      UpperCAmelCase__						(				self					:  Optional[Any] ):
										lowerCamelCase_	:							Dict									="cpu"  # ensure determinism for the device-dependent torch.Generator
										lowerCamelCase_	:							Dict									=self.dummy_cond_unet
										lowerCamelCase_	:							List[str]									=PNDMScheduler(skip_prk_steps=snake_case__ )
										lowerCamelCase_	:							List[Any]									=self.dummy_vae
										lowerCamelCase_	:							Any									=self.dummy_text_encoder
										lowerCamelCase_	:							List[Any]									=XLMRobertaTokenizer.from_pretrained("hf-internal-testing/tiny-xlm-roberta" )
										lowerCamelCase_	:							List[str]									=77

										lowerCamelCase_	:							Optional[int]									=self.dummy_image.to(snake_case__ )
										lowerCamelCase_	:							Any									=init_image / 2 + 0.5

										# make sure here that pndm scheduler skips prk
										lowerCamelCase_	:							List[Any]									=AltDiffusionImgaImgPipeline(
										    unet=snake_case__       ,	scheduler=snake_case__       ,	vae=snake_case__       ,	text_encoder=snake_case__       ,	tokenizer=snake_case__       ,	safety_checker=snake_case__       ,	feature_extractor=self.dummy_extractor       ,	)
										lowerCamelCase_	:							int									=VaeImageProcessor(vae_scale_factor=alt_pipe.vae_scale_factor       ,	do_normalize=snake_case__ )
										lowerCamelCase_	:							Optional[int]									=alt_pipe.to(snake_case__ )
										alt_pipe.set_progress_bar_config(disable=snake_case__ )

										lowerCamelCase_	:							Any									="A painting of a squirrel eating a burger"
										lowerCamelCase_	:							Union[str, Any]									=torch.Generator(device=snake_case__ ).manual_seed(0 )
										lowerCamelCase_	:							str									=alt_pipe(
										    [prompt]       ,	generator=snake_case__       ,	guidance_scale=6.0       ,	num_inference_steps=2       ,	output_type="np"       ,	image=snake_case__       ,	)

										lowerCamelCase_	:							List[Any]									=output.images

										lowerCamelCase_	:							str									=torch.Generator(device=snake_case__ ).manual_seed(0 )
										lowerCamelCase_	:							Optional[Any]									=alt_pipe(
										    [prompt]       ,	generator=snake_case__       ,	guidance_scale=6.0       ,	num_inference_steps=2       ,	output_type="np"       ,	image=snake_case__       ,	return_dict=snake_case__       ,	)[0]

										lowerCamelCase_	:							Tuple									=image[0, -3:, -3:, -1]
										lowerCamelCase_	:							Union[str, Any]									=image_from_tuple[0, -3:, -3:, -1]

										assert image.shape == (1, 32, 32, 3)
										lowerCamelCase_	:							List[str]									=np.array([0.4_427, 0.3_731, 0.4_249, 0.4_941, 0.4_546, 0.4_148, 0.4_193, 0.4_666, 0.4_499] )

										assert np.abs(image_slice.flatten() - expected_slice ).max() < 5E-3
										assert np.abs(image_from_tuple_slice.flatten() - expected_slice ).max() < 5E-3


			@unittest.skipIf(torch_device != "cuda"       ,	"This test requires a GPU" )
			def      UpperCAmelCase__						(				self					:  Tuple ):
										lowerCamelCase_	:							Dict									=self.dummy_cond_unet
										lowerCamelCase_	:							Any									=PNDMScheduler(skip_prk_steps=snake_case__ )
										lowerCamelCase_	:							Tuple									=self.dummy_vae
										lowerCamelCase_	:							Union[str, Any]									=self.dummy_text_encoder
										lowerCamelCase_	:							Optional[Any]									=XLMRobertaTokenizer.from_pretrained("hf-internal-testing/tiny-xlm-roberta" )
										lowerCamelCase_	:							Tuple									=77

										lowerCamelCase_	:							str									=self.dummy_image.to(snake_case__ )

										# put models in fp16
										lowerCamelCase_	:							Optional[Any]									=unet.half()
										lowerCamelCase_	:							Dict									=vae.half()
										lowerCamelCase_	:							str									=bert.half()

										# make sure here that pndm scheduler skips prk
										lowerCamelCase_	:							Optional[int]									=AltDiffusionImgaImgPipeline(
										    unet=snake_case__       ,	scheduler=snake_case__       ,	vae=snake_case__       ,	text_encoder=snake_case__       ,	tokenizer=snake_case__       ,	safety_checker=snake_case__       ,	feature_extractor=self.dummy_extractor       ,	)
										lowerCamelCase_	:							List[Any]									=VaeImageProcessor(vae_scale_factor=alt_pipe.vae_scale_factor       ,	do_normalize=snake_case__ )
										lowerCamelCase_	:							int									=alt_pipe.to(snake_case__ )
										alt_pipe.set_progress_bar_config(disable=snake_case__ )

										lowerCamelCase_	:							Tuple									="A painting of a squirrel eating a burger"
										lowerCamelCase_	:							Tuple									=torch.manual_seed(0 )
										lowerCamelCase_	:							List[Any]									=alt_pipe(
										    [prompt]       ,	generator=snake_case__       ,	num_inference_steps=2       ,	output_type="np"       ,	image=snake_case__       ,	).images

										assert image.shape == (1, 32, 32, 3)


			@unittest.skipIf(torch_device != "cuda"       ,	"This test requires a GPU" )
			def      UpperCAmelCase__						(				self					:  Union[str, Any] ):
										lowerCamelCase_	:							int									=load_image(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
										    "/img2img/sketch-mountains-input.jpg" )
										# resize to resolution that is divisible by 8 but not 16 or 32
										lowerCamelCase_	:							Any									=init_image.resize((760, 504) )

										lowerCamelCase_	:							List[str]									="BAAI/AltDiffusion"
										lowerCamelCase_	:							List[str]									=AltDiffusionImgaImgPipeline.from_pretrained(
										    snake_case__       ,	safety_checker=snake_case__       ,	)
										pipe.to(snake_case__ )
										pipe.set_progress_bar_config(disable=snake_case__ )
										pipe.enable_attention_slicing()

										lowerCamelCase_	:							Optional[int]									="A fantasy landscape, trending on artstation"

										lowerCamelCase_	:							List[Any]									=torch.manual_seed(0 )
										lowerCamelCase_	:							Optional[int]									=pipe(
										    prompt=snake_case__       ,	image=snake_case__       ,	strength=0.75       ,	guidance_scale=7.5       ,	generator=snake_case__       ,	output_type="np"       ,	)
										lowerCamelCase_	:							Optional[int]									=output.images[0]

										lowerCamelCase_	:							Tuple									=image[255:258, 383:386, -1]

										assert image.shape == (504, 760, 3)
										lowerCamelCase_	:							Optional[int]									=np.array([0.9_358, 0.9_397, 0.9_599, 0.9_901, 1.0_000, 1.0_000, 0.9_882, 1.0_000, 1.0_000] )

										assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-2







@slow
@require_torch_gpu
class        lowercase__      (							unittest.TestCase       ):


			def      UpperCAmelCase__						(				self					:  str ):
										# clean up the VRAM after each test
										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()


			def      UpperCAmelCase__						(				self					:  List[Any] ):
										lowerCamelCase_	:							str									=load_image(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
										    "/img2img/sketch-mountains-input.jpg" )
										lowerCamelCase_	:							Any									=init_image.resize((768, 512) )
										lowerCamelCase_	:							Optional[int]									=load_numpy(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/img2img/fantasy_landscape_alt.npy" )

										lowerCamelCase_	:							Dict									="BAAI/AltDiffusion"
										lowerCamelCase_	:							List[str]									=AltDiffusionImgaImgPipeline.from_pretrained(
										    snake_case__       ,	safety_checker=snake_case__       ,	)
										pipe.to(snake_case__ )
										pipe.set_progress_bar_config(disable=snake_case__ )
										pipe.enable_attention_slicing()

										lowerCamelCase_	:							Optional[Any]									="A fantasy landscape, trending on artstation"

										lowerCamelCase_	:							Dict									=torch.manual_seed(0 )
										lowerCamelCase_	:							int									=pipe(
										    prompt=snake_case__       ,	image=snake_case__       ,	strength=0.75       ,	guidance_scale=7.5       ,	generator=snake_case__       ,	output_type="np"       ,	)
										lowerCamelCase_	:							int									=output.images[0]

										assert image.shape == (512, 768, 3)
										# img2img is flaky across GPUs even in fp32, so using MAE here
										assert np.abs(expected_image - image ).max() < 1E-2



