





import unittest

from parameterized import parameterized

from transformers import OpenLlamaConfig, is_torch_available, set_seed
from transformers.testing_utils import require_torch, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import OpenLlamaForCausalLM, OpenLlamaForSequenceClassification, OpenLlamaModel
class     UpperCamelCase__					:






		'''simple docstring'''






		def __init__(							self,   snake_case__,   snake_case__=13,   snake_case__=7,   snake_case__=True,   snake_case__=True,   snake_case__=False,   snake_case__=True,   snake_case__=99,   snake_case__=32,   snake_case__=5,   snake_case__=4,   snake_case__=37,   snake_case__="gelu",   snake_case__=0.1,   snake_case__=0.1,   snake_case__=5_12,   snake_case__=16,   snake_case__=2,   snake_case__=0.02,   snake_case__=3,   snake_case__=4,   snake_case__=None,   )       -> Optional[Any]:






									"""simple docstring"""
									lowercase_	:   List[Any]  				=     parent
									lowercase_	:   Optional[int]  				=     batch_size
									lowercase_	:   Tuple  				=     seq_length
									lowercase_	:   Dict  				=     is_training
									lowercase_	:   Dict  				=     use_input_mask
									lowercase_	:   Union[str, Any]  				=     use_token_type_ids
									lowercase_	:   Optional[Any]  				=     use_labels
									lowercase_	:   str  				=     vocab_size
									lowercase_	:   List[Any]  				=     hidden_size
									lowercase_	:   List[Any]  				=     num_hidden_layers
									lowercase_	:   int  				=     num_attention_heads
									lowercase_	:   int  				=     intermediate_size
									lowercase_	:   Dict  				=     hidden_act
									lowercase_	:   Optional[int]  				=     hidden_dropout_prob
									lowercase_	:   Tuple  				=     attention_probs_dropout_prob
									lowercase_	:   Optional[Any]  				=     max_position_embeddings
									lowercase_	:   Tuple  				=     type_vocab_size
									lowercase_	:   Tuple  				=     type_sequence_label_size
									lowercase_	:   Union[str, Any]  				=     initializer_range
									lowercase_	:   Optional[int]  				=     num_labels
									lowercase_	:   Tuple  				=     num_choices
									lowercase_	:   str  				=     scope






		def 						snake_case__				(							self  )       -> Optional[Any]:






									"""simple docstring"""
									lowercase_	:   Any  				=     ids_tensor([self.batch_size, self.seq_length],   self.vocab_size  )

									lowercase_	:   Tuple  				=     None
									if self.use_input_mask:
																lowercase_	:   List[Any]  				=     random_attention_mask([self.batch_size, self.seq_length]  )

									lowercase_	:   Tuple  				=     None
									if self.use_token_type_ids:
																lowercase_	:   List[str]  				=     ids_tensor([self.batch_size, self.seq_length],   self.type_vocab_size  )

									lowercase_	:   Optional[int]  				=     None
									lowercase_	:   int  				=     None
									lowercase_	:   int  				=     None
									if self.use_labels:
																lowercase_	:   Tuple  				=     ids_tensor([self.batch_size],   self.type_sequence_label_size  )
																lowercase_	:   Optional[Any]  				=     ids_tensor([self.batch_size, self.seq_length],   self.num_labels  )
																lowercase_	:   Union[str, Any]  				=     ids_tensor([self.batch_size],   self.num_choices  )

									lowercase_	:   Any  				=     self.get_config()

									return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






		def 						snake_case__				(							self  )       -> Dict:






									"""simple docstring"""
									return OpenLlamaConfig(
									    vocab_size=self.vocab_size,   hidden_size=self.hidden_size,   num_hidden_layers=self.num_hidden_layers,   num_attention_heads=self.num_attention_heads,   intermediate_size=self.intermediate_size,   hidden_act=self.hidden_act,   hidden_dropout_prob=self.hidden_dropout_prob,   attention_probs_dropout_prob=self.attention_probs_dropout_prob,   max_position_embeddings=self.max_position_embeddings,   type_vocab_size=self.type_vocab_size,   is_decoder=snake_case__,   initializer_range=self.initializer_range,   use_stable_embedding=snake_case__,   )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__  )       -> Optional[Any]:






									"""simple docstring"""
									lowercase_	:   Union[str, Any]  				=     OpenLlamaModel(config=snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   str  				=     model(snake_case__,   attention_mask=snake_case__  )
									lowercase_	:   int  				=     model(snake_case__  )
									self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.hidden_size)  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   )       -> List[str]:






									"""simple docstring"""
									lowercase_	:   Optional[Any]  				=     True
									lowercase_	:   Optional[int]  				=     OpenLlamaModel(snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   Dict  				=     model(
									    snake_case__,   attention_mask=snake_case__,   encoder_hidden_states=snake_case__,   encoder_attention_mask=snake_case__,   )
									lowercase_	:   str  				=     model(
									    snake_case__,   attention_mask=snake_case__,   encoder_hidden_states=snake_case__,   )
									lowercase_	:   List[Any]  				=     model(snake_case__,   attention_mask=snake_case__  )
									self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.hidden_size)  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   )       -> Optional[int]:






									"""simple docstring"""
									lowercase_	:   Dict  				=     OpenLlamaForCausalLM(config=snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   Optional[int]  				=     model(snake_case__,   attention_mask=snake_case__,   labels=snake_case__  )
									self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.vocab_size)  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   )       -> Optional[int]:






									"""simple docstring"""
									lowercase_	:   int  				=     True
									lowercase_	:   List[str]  				=     True
									lowercase_	:   Optional[Any]  				=     OpenLlamaForCausalLM(config=snake_case__  )
									model.to(snake_case__  )
									model.eval()

									# first forward pass
									lowercase_	:   List[str]  				=     model(
									    snake_case__,   attention_mask=snake_case__,   encoder_hidden_states=snake_case__,   encoder_attention_mask=snake_case__,   use_cache=snake_case__,   )
									lowercase_	:   str  				=     outputs.past_key_values

									# create hypothetical multiple next token and extent to next_input_ids
									lowercase_	:   List[str]  				=     ids_tensor((self.batch_size, 3),   config.vocab_size  )
									lowercase_	:   Dict  				=     ids_tensor((self.batch_size, 3),   vocab_size=2  )

									# append to next input_ids and
									lowercase_	:   Dict  				=     torch.cat([input_ids, next_tokens],   dim=-1  )
									lowercase_	:   int  				=     torch.cat([input_mask, next_mask],   dim=-1  )

									lowercase_	:   str  				=     model(
									    snake_case__,   attention_mask=snake_case__,   encoder_hidden_states=snake_case__,   encoder_attention_mask=snake_case__,   output_hidden_states=snake_case__,   )["""hidden_states"""][0]
									lowercase_	:   Union[str, Any]  				=     model(
									    snake_case__,   attention_mask=snake_case__,   encoder_hidden_states=snake_case__,   encoder_attention_mask=snake_case__,   past_key_values=snake_case__,   output_hidden_states=snake_case__,   )["""hidden_states"""][0]

									# select random slice
									lowercase_	:   List[str]  				=     ids_tensor((1,),   output_from_past.shape[-1]  ).item()
									lowercase_	:   Optional[int]  				=     output_from_no_past[:, -3:, random_slice_idx].detach()
									lowercase_	:   Union[str, Any]  				=     output_from_past[:, :, random_slice_idx].detach()

									self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]  )

									# test that outputs are equal for slice
									self.parent.assertTrue(torch.allclose(snake_case__,   snake_case__,   atol=1E-3  )  )






		def 						snake_case__				(							self  )       -> Any:






									"""simple docstring"""
									lowercase_	:   Union[str, Any]  				=     self.prepare_config_and_inputs()
									(
									    (
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		
									)	:   str  				=     config_and_inputs
									lowercase_	:   List[Any]  				=     {"""input_ids""": input_ids, """attention_mask""": input_mask}
									return config, inputs_dict




@require_torch
class     UpperCamelCase__					(     lowerCamelCase__				, lowerCamelCase__				, lowerCamelCase__				, unittest.TestCase				):






		'''simple docstring'''






		__a       :       Dict       =	(
		    (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
		)
		__a       :       Optional[int]       =	(OpenLlamaForCausalLM,) if is_torch_available() else ()
		__a       :       Optional[Any]       =	(
		    {
		        """feature-extraction""": OpenLlamaModel,
		        """text-classification""": OpenLlamaForSequenceClassification,
		        """text-generation""": OpenLlamaForCausalLM,
		        """zero-shot""": OpenLlamaForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		__a       :       List[str]       =	False
		__a       :       Tuple       =	False






		def 						snake_case__				(							self  )       -> List[Any]:






									"""simple docstring"""
									lowercase_	:   Tuple  				=     OpenLlamaModelTester(self  )
									lowercase_	:   Optional[int]  				=     ConfigTester(self,   config_class=snake_case__,   hidden_size=37  )






		def 						snake_case__				(							self  )       -> str:






									"""simple docstring"""
									self.config_tester.run_common_tests()






		def 						snake_case__				(							self  )       -> Optional[int]:






									"""simple docstring"""
									lowercase_	:   int  				=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*snake_case__  )






		def 						snake_case__				(							self  )       -> List[str]:






									"""simple docstring"""
									lowercase_	:   List[str]  				=     self.model_tester.prepare_config_and_inputs()
									for type in ["absolute", "relative_key", "relative_key_query"]:
																lowercase_	:   List[str]  				=     type
																self.model_tester.create_and_check_model(*snake_case__  )






		def 						snake_case__				(							self  )       -> str:






									"""simple docstring"""
									lowercase_				,		lowercase_	:   Optional[Any]  				=     self.model_tester.prepare_config_and_inputs_for_common()
									lowercase_	:   Tuple  				=     3
									lowercase_	:   Dict  				=     input_dict["""input_ids"""]
									lowercase_	:   List[Any]  				=     input_ids.ne(1  ).to(snake_case__  )
									lowercase_	:   int  				=     ids_tensor([self.model_tester.batch_size],   self.model_tester.type_sequence_label_size  )
									lowercase_	:   Dict  				=     OpenLlamaForSequenceClassification(snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   int  				=     model(snake_case__,   attention_mask=snake_case__,   labels=snake_case__  )
									self.assertEqual(result.logits.shape,   (self.model_tester.batch_size, self.model_tester.num_labels)  )






		def 						snake_case__				(							self  )       -> Dict:






									"""simple docstring"""
									lowercase_				,		lowercase_	:   Tuple  				=     self.model_tester.prepare_config_and_inputs_for_common()
									lowercase_	:   Any  				=     3
									lowercase_	:   Dict  				=     """single_label_classification"""
									lowercase_	:   Any  				=     input_dict["""input_ids"""]
									lowercase_	:   int  				=     input_ids.ne(1  ).to(snake_case__  )
									lowercase_	:   Union[str, Any]  				=     ids_tensor([self.model_tester.batch_size],   self.model_tester.type_sequence_label_size  )
									lowercase_	:   List[str]  				=     OpenLlamaForSequenceClassification(snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   List[Any]  				=     model(snake_case__,   attention_mask=snake_case__,   labels=snake_case__  )
									self.assertEqual(result.logits.shape,   (self.model_tester.batch_size, self.model_tester.num_labels)  )






		def 						snake_case__				(							self  )       -> Any:






									"""simple docstring"""
									lowercase_				,		lowercase_	:   List[Any]  				=     self.model_tester.prepare_config_and_inputs_for_common()
									lowercase_	:   Union[str, Any]  				=     3
									lowercase_	:   List[str]  				=     """multi_label_classification"""
									lowercase_	:   str  				=     input_dict["""input_ids"""]
									lowercase_	:   Optional[int]  				=     input_ids.ne(1  ).to(snake_case__  )
									lowercase_	:   List[str]  				=     ids_tensor(
									    [self.model_tester.batch_size, config.num_labels],   self.model_tester.type_sequence_label_size  ).to(torch.float  )
									lowercase_	:   Dict  				=     OpenLlamaForSequenceClassification(snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   Union[str, Any]  				=     model(snake_case__,   attention_mask=snake_case__,   labels=snake_case__  )
									self.assertEqual(result.logits.shape,   (self.model_tester.batch_size, self.model_tester.num_labels)  )






		@unittest.skip("""Open-Llama buffers include complex numbers, which breaks this test"""  )
		def 						snake_case__				(							self  )       -> str:






									"""simple docstring"""
									pass






		@parameterized.expand([("""linear""",), ("""dynamic""",)]  )
		def 						snake_case__				(							self,   snake_case__  )       -> Dict:






									"""simple docstring"""
									lowercase_				,		lowercase_	:   str  				=     self.model_tester.prepare_config_and_inputs_for_common()
									lowercase_	:   List[str]  				=     ids_tensor([1, 10],   config.vocab_size  )
									lowercase_	:   str  				=     ids_tensor([1, int(config.max_position_embeddings * 1.5  )],   config.vocab_size  )

									set_seed(42  )  # Fixed seed at init time so the two models get the same random weights
									lowercase_	:   List[str]  				=     OpenLlamaModel(snake_case__  )
									original_model.to(snake_case__  )
									original_model.eval()
									lowercase_	:   Union[str, Any]  				=     original_model(snake_case__  ).last_hidden_state
									lowercase_	:   Dict  				=     original_model(snake_case__  ).last_hidden_state

									set_seed(42  )  # Fixed seed at init time so the two models get the same random weights
									lowercase_	:   str  				=     {"""type""": scaling_type, """factor""": 10.0}
									lowercase_	:   Tuple  				=     OpenLlamaModel(snake_case__  )
									scaled_model.to(snake_case__  )
									scaled_model.eval()
									lowercase_	:   Optional[Any]  				=     scaled_model(snake_case__  ).last_hidden_state
									lowercase_	:   List[Any]  				=     scaled_model(snake_case__  ).last_hidden_state

									# Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
									# maximum sequence length, so the outputs for the short input should match.
									if scaling_type == "dynamic":
																self.assertTrue(torch.allclose(snake_case__,   snake_case__,   atol=1E-5  )  )
									else:
																self.assertFalse(torch.allclose(snake_case__,   snake_case__,   atol=1E-5  )  )

									# The output should be different for long inputs
									self.assertFalse(torch.allclose(snake_case__,   snake_case__,   atol=1E-5  )  )






import gc
import unittest

import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DDPMScheduler,
    PriorTransformer,
    StableUnCLIPPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion.stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
from diffusers.utils.testing_utils import enable_full_determinism, load_numpy, require_torch_gpu, slow, torch_device

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import (
    PipelineKarrasSchedulerTesterMixin,
    PipelineLatentTesterMixin,
    PipelineTesterMixin,
    assert_mean_pixel_difference,
)


enable_full_determinism()
class     UpperCamelCase__					(     lowerCamelCase__				, lowerCamelCase__				, lowerCamelCase__				, unittest.TestCase				):






		'''simple docstring'''






		__a       :       Optional[int]       =	StableUnCLIPPipeline
		__a       :       int       =	TEXT_TO_IMAGE_PARAMS
		__a       :       Optional[Any]       =	TEXT_TO_IMAGE_BATCH_PARAMS
		__a       :       Tuple       =	TEXT_TO_IMAGE_IMAGE_PARAMS
		__a       :       Optional[int]       =	TEXT_TO_IMAGE_IMAGE_PARAMS

		# TODO(will) Expected attn_bias.stride(1) == 0 to be true, but got false
		__a       :       Tuple       =	False






		def 						snake_case__				(							self  )       -> Optional[Any]:






									"""simple docstring"""
									lowercase_	:   int  				=     32
									lowercase_	:   Tuple  				=     embedder_hidden_size

									# prior components

									torch.manual_seed(0  )
									lowercase_	:   Optional[Any]  				=     CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""  )

									torch.manual_seed(0  )
									lowercase_	:   Dict  				=     CLIPTextModelWithProjection(
									    CLIPTextConfig(
									        bos_token_id=0,   eos_token_id=2,   hidden_size=snake_case__,   projection_dim=snake_case__,   intermediate_size=37,   layer_norm_eps=1E-05,   num_attention_heads=4,   num_hidden_layers=5,   pad_token_id=1,   vocab_size=10_00,   )  )

									torch.manual_seed(0  )
									lowercase_	:   Tuple  				=     PriorTransformer(
									    num_attention_heads=2,   attention_head_dim=12,   embedding_dim=snake_case__,   num_layers=1,   )

									torch.manual_seed(0  )
									lowercase_	:   Optional[Any]  				=     DDPMScheduler(
									    variance_type="""fixed_small_log""",   prediction_type="""sample""",   num_train_timesteps=10_00,   clip_sample=snake_case__,   clip_sample_range=5.0,   beta_schedule="""squaredcos_cap_v2""",   )

									# regular denoising components

									torch.manual_seed(0  )
									lowercase_	:   Union[str, Any]  				=     StableUnCLIPImageNormalizer(embedding_dim=snake_case__  )
									lowercase_	:   str  				=     DDPMScheduler(beta_schedule="""squaredcos_cap_v2"""  )

									torch.manual_seed(0  )
									lowercase_	:   str  				=     CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""  )

									torch.manual_seed(0  )
									lowercase_	:   List[Any]  				=     CLIPTextModel(
									    CLIPTextConfig(
									        bos_token_id=0,   eos_token_id=2,   hidden_size=snake_case__,   projection_dim=32,   intermediate_size=37,   layer_norm_eps=1E-05,   num_attention_heads=4,   num_hidden_layers=5,   pad_token_id=1,   vocab_size=10_00,   )  )

									torch.manual_seed(0  )
									lowercase_	:   Optional[int]  				=     UNetaDConditionModel(
									    sample_size=32,   in_channels=4,   out_channels=4,   down_block_types=("""CrossAttnDownBlock2D""", """DownBlock2D"""),   up_block_types=("""UpBlock2D""", """CrossAttnUpBlock2D"""),   block_out_channels=(32, 64),   attention_head_dim=(2, 4),   class_embed_type="""projection""",   projection_class_embeddings_input_dim=embedder_projection_dim * 2,   cross_attention_dim=snake_case__,   layers_per_block=1,   upcast_attention=snake_case__,   use_linear_projection=snake_case__,   )

									torch.manual_seed(0  )
									lowercase_	:   Dict  				=     DDIMScheduler(
									    beta_schedule="""scaled_linear""",   beta_start=0.00085,   beta_end=0.012,   prediction_type="""v_prediction""",   set_alpha_to_one=snake_case__,   steps_offset=1,   )

									torch.manual_seed(0  )
									lowercase_	:   str  				=     AutoencoderKL()

									lowercase_	:   str  				=     {
									    # prior components
									    """prior_tokenizer""": prior_tokenizer,
									    """prior_text_encoder""": prior_text_encoder,
									    """prior""": prior,
									    """prior_scheduler""": prior_scheduler,
									    # image noising components
									    """image_normalizer""": image_normalizer,
									    """image_noising_scheduler""": image_noising_scheduler,
									    # regular denoising components
									    """tokenizer""": tokenizer,
									    """text_encoder""": text_encoder,
									    """unet""": unet,
									    """scheduler""": scheduler,
									    """vae""": vae,
									}

									return components






		def 						snake_case__				(							self,   snake_case__,   snake_case__=0  )       -> str:






									"""simple docstring"""
									if str(snake_case__  ).startswith("""mps"""  ):
																lowercase_	:   Tuple  				=     torch.manual_seed(snake_case__  )
									else:
																lowercase_	:   int  				=     torch.Generator(device=snake_case__  ).manual_seed(snake_case__  )
									lowercase_	:   Dict  				=     {
									    """prompt""": """A painting of a squirrel eating a burger""",
									    """generator""": generator,
									    """num_inference_steps""": 2,
									    """prior_num_inference_steps""": 2,
									    """output_type""": """numpy""",
									}
									return inputs






		def 						snake_case__				(							self  )       -> List[Any]:






									"""simple docstring"""
									lowercase_	:   int  				=     torch_device == """cpu"""

									self._test_attention_slicing_forward_pass(test_max_difference=snake_case__  )






		def 						snake_case__				(							self  )       -> Any:






									"""simple docstring"""
									lowercase_	:   List[str]  				=     torch_device in ["""cpu""", """mps"""]

									self._test_inference_batch_single_identical(test_max_difference=snake_case__  )




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






		'''simple docstring'''






		def 						snake_case__				(							self  )       -> Any:






									"""simple docstring"""
									# clean up the VRAM after each test
									super().tearDown()
									gc.collect()
									torch.cuda.empty_cache()






		def 						snake_case__				(							self  )       -> List[str]:






									"""simple docstring"""
									lowercase_	:   Union[str, Any]  				=     load_numpy(
									    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/stable_unclip_2_1_l_anime_turtle_fp16.npy"""  )

									lowercase_	:   List[Any]  				=     StableUnCLIPPipeline.from_pretrained("""fusing/stable-unclip-2-1-l""",   torch_dtype=torch.floataa  )
									pipe.to(snake_case__  )
									pipe.set_progress_bar_config(disable=snake_case__  )
									# stable unclip will oom when integration tests are run on a V100,
									# so turn on memory savings
									pipe.enable_attention_slicing()
									pipe.enable_sequential_cpu_offload()

									lowercase_	:   Any  				=     torch.Generator(device="""cpu"""  ).manual_seed(0  )
									lowercase_	:   Dict  				=     pipe("""anime turle""",   generator=snake_case__,   output_type="""np"""  )

									lowercase_	:   str  				=     output.images[0]

									assert image.shape == (7_68, 7_68, 3)

									assert_mean_pixel_difference(snake_case__,   snake_case__  )






		def 						snake_case__				(							self  )       -> Dict:






									"""simple docstring"""
									torch.cuda.empty_cache()
									torch.cuda.reset_max_memory_allocated()
									torch.cuda.reset_peak_memory_stats()

									lowercase_	:   str  				=     StableUnCLIPPipeline.from_pretrained("""fusing/stable-unclip-2-1-l""",   torch_dtype=torch.floataa  )
									lowercase_	:   Optional[int]  				=     pipe.to(snake_case__  )
									pipe.set_progress_bar_config(disable=snake_case__  )
									pipe.enable_attention_slicing()
									pipe.enable_sequential_cpu_offload()

									lowercase_	:   List[Any]  				=     pipe(
									    """anime turtle""",   prior_num_inference_steps=2,   num_inference_steps=2,   output_type="""np""",   )

									lowercase_	:   Optional[int]  				=     torch.cuda.max_memory_allocated()
									# make sure that less than 7 GB is allocated
									assert mem_bytes < 7 * 10**9