





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 SCREAMING_SNAKE_CASE_  :






						def __init__( self : Any						,				_A : str						,				_A : Tuple=13						,				_A : List[str]=7						,				_A : Dict=True						,				_A : List[str]=True						,				_A : Tuple=False						,				_A : str=True						,				_A : Optional[Any]=99						,				_A : Optional[int]=32						,				_A : Dict=5						,				_A : Union[str, Any]=4						,				_A : Union[str, Any]=37						,				_A : List[str]="gelu"						,				_A : Tuple=0.1						,				_A : str=0.1						,				_A : Optional[Any]=512						,				_A : List[Any]=16						,				_A : Union[str, Any]=2						,				_A : List[str]=0.0_2						,				_A : str=3						,				_A : Any=4						,				_A : Dict=None						,				)							->      Optional[Any]:







							"""simple docstring"""


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






						def UpperCAmelCase_			( self : Any		)							->      int:







							"""simple docstring"""


							snake_case_						:     Dict     =		ids_tensor([self.batch_size, self.seq_length]						,				self.vocab_size		)

							snake_case_						:     Optional[int]     =		None
							if self.use_input_mask:
								snake_case_						:     Any     =		random_attention_mask([self.batch_size, self.seq_length]		)

							snake_case_						:     Tuple     =		None
							if self.use_token_type_ids:
								snake_case_						:     Union[str, Any]     =		ids_tensor([self.batch_size, self.seq_length]						,				self.type_vocab_size		)

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

							snake_case_						:     int     =		self.get_config()

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






						def UpperCAmelCase_			( self : int		)							->      List[Any]:







							"""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=_A						,				initializer_range=self.initializer_range						,				use_stable_embedding=_A						,				)






						def UpperCAmelCase_			( self : Optional[Any]						,				_A : List[str]						,				_A : Optional[int]						,				_A : Dict						,				_A : Optional[int]						,				_A : Union[str, Any]						,				_A : int						,				_A : Dict		)							->      Optional[Any]:







							"""simple docstring"""


							snake_case_						:     int     =		OpenLlamaModel(config=_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     List[Any]     =		model(_A						,				attention_mask=_A		)
							snake_case_						:     int     =		model(_A		)
							self.parent.assertEqual(result.last_hidden_state.shape						,				(self.batch_size, self.seq_length, self.hidden_size)		)






						def UpperCAmelCase_			( self : int						,				_A : str						,				_A : int						,				_A : Optional[int]						,				_A : Optional[Any]						,				_A : int						,				_A : int						,				_A : str						,				_A : Optional[int]						,				_A : Any						,				)							->      Optional[Any]:







							"""simple docstring"""


							snake_case_						:     str     =		True
							snake_case_						:     Any     =		OpenLlamaModel(_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     Dict     =		model(
							    _A						,				attention_mask=_A						,				encoder_hidden_states=_A						,				encoder_attention_mask=_A						,				)
							snake_case_						:     List[str]     =		model(
							    _A						,				attention_mask=_A						,				encoder_hidden_states=_A						,				)
							snake_case_						:     List[str]     =		model(_A						,				attention_mask=_A		)
							self.parent.assertEqual(result.last_hidden_state.shape						,				(self.batch_size, self.seq_length, self.hidden_size)		)






						def UpperCAmelCase_			( self : str						,				_A : Tuple						,				_A : Dict						,				_A : Optional[int]						,				_A : Tuple						,				_A : Optional[Any]						,				_A : Union[str, Any]						,				_A : Tuple						,				_A : str						,				_A : List[str]						,				)							->      Union[str, Any]:







							"""simple docstring"""


							snake_case_						:     Dict     =		OpenLlamaForCausalLM(config=_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     int     =		model(_A						,				attention_mask=_A						,				labels=_A		)
							self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.seq_length, self.vocab_size)		)






						def UpperCAmelCase_			( self : int						,				_A : str						,				_A : Dict						,				_A : str						,				_A : Optional[Any]						,				_A : str						,				_A : Tuple						,				_A : str						,				_A : List[str]						,				_A : Optional[Any]						,				)							->      List[Any]:







							"""simple docstring"""


							snake_case_						:     str     =		True
							snake_case_						:     Tuple     =		True
							snake_case_						:     List[str]     =		OpenLlamaForCausalLM(config=_A		)
							model.to(_A		)
							model.eval()

							# first forward pass
							snake_case_						:     Tuple     =		model(
							    _A						,				attention_mask=_A						,				encoder_hidden_states=_A						,				encoder_attention_mask=_A						,				use_cache=_A						,				)
							snake_case_						:     Dict     =		outputs.past_key_values

							# create hypothetical multiple next token and extent to next_input_ids
							snake_case_						:     Union[str, Any]     =		ids_tensor((self.batch_size, 3)						,				config.vocab_size		)
							snake_case_						:     int     =		ids_tensor((self.batch_size, 3)						,				vocab_size=2		)

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

							snake_case_						:     Any     =		model(
							    _A						,				attention_mask=_A						,				encoder_hidden_states=_A						,				encoder_attention_mask=_A						,				output_hidden_states=_A						,				)['hidden_states'][0]
							snake_case_						:     Optional[Any]     =		model(
							    _A						,				attention_mask=_A						,				encoder_hidden_states=_A						,				encoder_attention_mask=_A						,				past_key_values=_A						,				output_hidden_states=_A						,				)['hidden_states'][0]

							# select random slice
							snake_case_						:     str     =		ids_tensor((1,)						,				output_from_past.shape[-1]		).item()
							snake_case_						:     str     =		output_from_no_past[:, -3:, random_slice_idx].detach()
							snake_case_						:     Optional[int]     =		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(_A						,				_A						,				atol=1E-3		)		)






						def UpperCAmelCase_			( self : Union[str, Any]		)							->      Any:







							"""simple docstring"""


							snake_case_						:     int     =		self.prepare_config_and_inputs()
							(
							    (
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,
							)						:     int     =		config_and_inputs
							snake_case_						:     Optional[Any]     =		{'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict
@require_torch
class SCREAMING_SNAKE_CASE_  (   snake_case_    ,			snake_case_    ,			snake_case_    ,			unittest.TestCase   ):
						__magic_name__:     List[Any]	 =    (
						    (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
						)
						__magic_name__:     Dict	 =    (OpenLlamaForCausalLM,) if is_torch_available() else ()
						__magic_name__:     Dict	 =    (
						    {
						        "feature-extraction": OpenLlamaModel,
						        "text-classification": OpenLlamaForSequenceClassification,
						        "text-generation": OpenLlamaForCausalLM,
						        "zero-shot": OpenLlamaForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						__magic_name__:     Dict	 =    False
						__magic_name__:     str	 =    False






						def UpperCAmelCase_			( self : Optional[int]		)							->      List[Any]:







							"""simple docstring"""


							snake_case_						:     Tuple     =		OpenLlamaModelTester(self		)
							snake_case_						:     str     =		ConfigTester(self						,				config_class=_A						,				hidden_size=37		)






						def UpperCAmelCase_			( self : Tuple		)							->      str:







							"""simple docstring"""


							self.config_tester.run_common_tests()






						def UpperCAmelCase_			( self : Optional[Any]		)							->      Optional[int]:







							"""simple docstring"""


							snake_case_						:     int     =		self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_A		)






						def UpperCAmelCase_			( self : Any		)							->      Optional[int]:







							"""simple docstring"""


							snake_case_						:     Optional[int]     =		self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
								snake_case_						:     Any     =		type
								self.model_tester.create_and_check_model(*_A		)






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







							"""simple docstring"""


							snake_case_  ,snake_case_						:     Tuple     =		self.model_tester.prepare_config_and_inputs_for_common()
							snake_case_						:     List[Any]     =		3
							snake_case_						:     List[str]     =		input_dict['input_ids']
							snake_case_						:     List[str]     =		input_ids.ne(1		).to(_A		)
							snake_case_						:     Optional[Any]     =		ids_tensor([self.model_tester.batch_size]						,				self.model_tester.type_sequence_label_size		)
							snake_case_						:     str     =		OpenLlamaForSequenceClassification(_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     Optional[Any]     =		model(_A						,				attention_mask=_A						,				labels=_A		)
							self.assertEqual(result.logits.shape						,				(self.model_tester.batch_size, self.model_tester.num_labels)		)






						def UpperCAmelCase_			( self : Any		)							->      Tuple:







							"""simple docstring"""


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






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







							"""simple docstring"""


							snake_case_  ,snake_case_						:     List[str]     =		self.model_tester.prepare_config_and_inputs_for_common()
							snake_case_						:     Optional[int]     =		3
							snake_case_						:     List[Any]     =		'multi_label_classification'
							snake_case_						:     Union[str, Any]     =		input_dict['input_ids']
							snake_case_						:     List[str]     =		input_ids.ne(1		).to(_A		)
							snake_case_						:     str     =		ids_tensor(
							    [self.model_tester.batch_size, config.num_labels]						,				self.model_tester.type_sequence_label_size		).to(torch.float		)
							snake_case_						:     Union[str, Any]     =		OpenLlamaForSequenceClassification(_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     Union[str, Any]     =		model(_A						,				attention_mask=_A						,				labels=_A		)
							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 UpperCAmelCase_			( self : List[str]		)							->      Optional[Any]:







							"""simple docstring"""


							pass






						@parameterized.expand([('linear',), ('dynamic',)]		)
						def UpperCAmelCase_			( self : Optional[Any]						,				_A : Tuple		)							->      Optional[Any]:







							"""simple docstring"""


							snake_case_  ,snake_case_						:     Dict     =		self.model_tester.prepare_config_and_inputs_for_common()
							snake_case_						:     str     =		ids_tensor([1, 10]						,				config.vocab_size		)
							snake_case_						:     Optional[Any]     =		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
							snake_case_						:     List[Any]     =		OpenLlamaModel(_A		)
							original_model.to(_A		)
							original_model.eval()
							snake_case_						:     str     =		original_model(_A		).last_hidden_state
							snake_case_						:     List[Any]     =		original_model(_A		).last_hidden_state

							set_seed(42		)  # Fixed seed at init time so the two models get the same random weights
							snake_case_						:     Optional[Any]     =		{'type': scaling_type, 'factor': 1_0.0}
							snake_case_						:     Dict     =		OpenLlamaModel(_A		)
							scaled_model.to(_A		)
							scaled_model.eval()
							snake_case_						:     Dict     =		scaled_model(_A		).last_hidden_state
							snake_case_						:     str     =		scaled_model(_A		).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(_A						,				_A						,				atol=1E-5		)		)
							else:
								self.assertFalse(torch.allclose(_A						,				_A						,				atol=1E-5		)		)

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








import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, XLMRobertaTokenizer

from diffusers import AltDiffusionPipeline, AutoencoderKL, DDIMScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.alt_diffusion.modeling_roberta_series import (
    RobertaSeriesConfig,
    RobertaSeriesModelWithTransformation,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

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


enable_full_determinism()
class SCREAMING_SNAKE_CASE_  (   snake_case_    ,			snake_case_    ,			snake_case_    ,			unittest.TestCase   ):
						__magic_name__:     int	 =    AltDiffusionPipeline
						__magic_name__:     Any	 =    TEXT_TO_IMAGE_PARAMS
						__magic_name__:     Any	 =    TEXT_TO_IMAGE_BATCH_PARAMS
						__magic_name__:     Any	 =    TEXT_TO_IMAGE_IMAGE_PARAMS
						__magic_name__:     Union[str, Any]	 =    TEXT_TO_IMAGE_IMAGE_PARAMS






						def UpperCAmelCase_			( self : List[Any]		)							->      int:







							"""simple docstring"""


							torch.manual_seed(0		)
							snake_case_						:     List[str]     =		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						,				)
							snake_case_						:     Optional[Any]     =		DDIMScheduler(
							    beta_start=0.0_0_0_8_5						,				beta_end=0.0_1_2						,				beta_schedule='scaled_linear'						,				clip_sample=_A						,				set_alpha_to_one=_A						,				)
							torch.manual_seed(0		)
							snake_case_						:     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						,				)

							# TODO: address the non-deterministic text encoder (fails for save-load tests)
							# torch.manual_seed(0)
							# text_encoder_config = RobertaSeriesConfig(
							#     hidden_size=32,
							#     project_dim=32,
							#     intermediate_size=37,
							#     layer_norm_eps=1e-05,
							#     num_attention_heads=4,
							#     num_hidden_layers=5,
							#     vocab_size=5002,
							# )
							# text_encoder = RobertaSeriesModelWithTransformation(text_encoder_config)

							torch.manual_seed(0		)
							snake_case_						:     Optional[Any]     =		CLIPTextConfig(
							    bos_token_id=0						,				eos_token_id=2						,				hidden_size=32						,				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=5002						,				)
							snake_case_						:     Any     =		CLIPTextModel(_A		)

							snake_case_						:     Any     =		XLMRobertaTokenizer.from_pretrained('hf-internal-testing/tiny-xlm-roberta'		)
							snake_case_						:     Dict     =		77

							snake_case_						:     List[Any]     =		{
							    'unet': unet,
							    'scheduler': scheduler,
							    'vae': vae,
							    'text_encoder': text_encoder,
							    'tokenizer': tokenizer,
							    'safety_checker': None,
							    'feature_extractor': None,
							}
							return components






						def UpperCAmelCase_			( self : int						,				_A : Optional[int]						,				_A : int=0		)							->      Dict:







							"""simple docstring"""


							if str(_A		).startswith('mps'		):
								snake_case_						:     Union[str, Any]     =		torch.manual_seed(_A		)
							else:
								snake_case_						:     Union[str, Any]     =		torch.Generator(device=_A		).manual_seed(_A		)
							snake_case_						:     Any     =		{
							    'prompt': 'A painting of a squirrel eating a burger',
							    'generator': generator,
							    'num_inference_steps': 2,
							    'guidance_scale': 6.0,
							    'output_type': 'numpy',
							}
							return inputs






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







							"""simple docstring"""


							super().test_attention_slicing_forward_pass(expected_max_diff=3E-3		)






						def UpperCAmelCase_			( self : List[Any]		)							->      Dict:







							"""simple docstring"""


							super().test_inference_batch_single_identical(expected_max_diff=3E-3		)






						def UpperCAmelCase_			( self : Dict		)							->      Any:







							"""simple docstring"""


							snake_case_						:     Tuple     =		'cpu'  # ensure determinism for the device-dependent torch.Generator

							snake_case_						:     Any     =		self.get_dummy_components()
							torch.manual_seed(0		)
							snake_case_						:     Any     =		RobertaSeriesConfig(
							    hidden_size=32						,				project_dim=32						,				intermediate_size=37						,				layer_norm_eps=1E-05						,				num_attention_heads=4						,				num_hidden_layers=5						,				vocab_size=5002						,				)
							# TODO: remove after fixing the non-deterministic text encoder
							snake_case_						:     Optional[Any]     =		RobertaSeriesModelWithTransformation(_A		)
							snake_case_						:     Optional[Any]     =		text_encoder

							snake_case_						:     Optional[Any]     =		AltDiffusionPipeline(**_A		)
							snake_case_						:     List[Any]     =		alt_pipe.to(_A		)
							alt_pipe.set_progress_bar_config(disable=_A		)

							snake_case_						:     Optional[Any]     =		self.get_dummy_inputs(_A		)
							snake_case_						:     int     =		'A photo of an astronaut'
							snake_case_						:     Tuple     =		alt_pipe(**_A		)
							snake_case_						:     Any     =		output.images
							snake_case_						:     Optional[int]     =		image[0, -3:, -3:, -1]

							assert image.shape == (1, 64, 64, 3)
							snake_case_						:     Any     =		np.array(
							    [0.5_7_4_8_1_6_2, 0.6_0_4_4_7_1_4_5, 0.4_8_8_2_1_2_1_7, 0.5_0_1_0_0_6_3_6, 0.5_4_3_1_1_8_5, 0.4_5_7_6_3_6_8_3, 0.4_9_6_5_7_6_9_6, 0.4_8_1_3_2_7_3_3, 0.4_7_5_7_3_0_9_3]		)

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






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







							"""simple docstring"""


							snake_case_						:     Optional[Any]     =		'cpu'  # ensure determinism for the device-dependent torch.Generator

							snake_case_						:     Any     =		self.get_dummy_components()
							snake_case_						:     List[str]     =		PNDMScheduler(skip_prk_steps=_A		)
							torch.manual_seed(0		)
							snake_case_						:     Optional[int]     =		RobertaSeriesConfig(
							    hidden_size=32						,				project_dim=32						,				intermediate_size=37						,				layer_norm_eps=1E-05						,				num_attention_heads=4						,				num_hidden_layers=5						,				vocab_size=5002						,				)
							# TODO: remove after fixing the non-deterministic text encoder
							snake_case_						:     Tuple     =		RobertaSeriesModelWithTransformation(_A		)
							snake_case_						:     Any     =		text_encoder
							snake_case_						:     Tuple     =		AltDiffusionPipeline(**_A		)
							snake_case_						:     Dict     =		alt_pipe.to(_A		)
							alt_pipe.set_progress_bar_config(disable=_A		)

							snake_case_						:     Dict     =		self.get_dummy_inputs(_A		)
							snake_case_						:     Tuple     =		alt_pipe(**_A		)
							snake_case_						:     int     =		output.images
							snake_case_						:     List[Any]     =		image[0, -3:, -3:, -1]

							assert image.shape == (1, 64, 64, 3)
							snake_case_						:     Optional[int]     =		np.array(
							    [0.5_1_6_0_5_0_9_3, 0.5_7_0_7_2_4_1, 0.4_7_3_6_5_5_0_7, 0.5_0_5_7_8_8_8_6, 0.5_6_3_3_8_7_7, 0.4_6_4_2_5_0_3, 0.5_1_8_2_0_8_1, 0.4_8_7_6_3_4_8_4, 0.4_9_0_8_4_2_3_7]		)

							assert np.abs(image_slice.flatten() - expected_slice		).max() < 1E-2
@slow
@require_torch_gpu
class SCREAMING_SNAKE_CASE_  (   unittest.TestCase   ):






						def UpperCAmelCase_			( self : List[Any]		)							->      Tuple:







							"""simple docstring"""


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






						def UpperCAmelCase_			( self : int		)							->      List[str]:







							"""simple docstring"""


							snake_case_						:     Optional[int]     =		AltDiffusionPipeline.from_pretrained('BAAI/AltDiffusion'						,				safety_checker=_A		)
							snake_case_						:     Optional[int]     =		alt_pipe.to(_A		)
							alt_pipe.set_progress_bar_config(disable=_A		)

							snake_case_						:     str     =		'A painting of a squirrel eating a burger'
							snake_case_						:     Tuple     =		torch.manual_seed(0		)
							snake_case_						:     str     =		alt_pipe([prompt]						,				generator=_A						,				guidance_scale=6.0						,				num_inference_steps=20						,				output_type='np'		)

							snake_case_						:     Any     =		output.images

							snake_case_						:     List[Any]     =		image[0, -3:, -3:, -1]

							assert image.shape == (1, 512, 512, 3)
							snake_case_						:     Union[str, Any]     =		np.array([0.1_0_1_0, 0.0_8_0_0, 0.0_7_9_4, 0.0_8_8_5, 0.0_8_4_3, 0.0_7_6_2, 0.0_7_6_9, 0.0_7_2_9, 0.0_5_8_6]		)

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






						def UpperCAmelCase_			( self : Optional[int]		)							->      Union[str, Any]:







							"""simple docstring"""


							snake_case_						:     Optional[Any]     =		DDIMScheduler.from_pretrained('BAAI/AltDiffusion'						,				subfolder='scheduler'		)

							snake_case_						:     Union[str, Any]     =		AltDiffusionPipeline.from_pretrained('BAAI/AltDiffusion'						,				scheduler=_A						,				safety_checker=_A		)
							snake_case_						:     List[str]     =		alt_pipe.to(_A		)
							alt_pipe.set_progress_bar_config(disable=_A		)

							snake_case_						:     List[Any]     =		'A painting of a squirrel eating a burger'
							snake_case_						:     int     =		torch.manual_seed(0		)

							snake_case_						:     List[Any]     =		alt_pipe([prompt]						,				generator=_A						,				num_inference_steps=2						,				output_type='numpy'		)
							snake_case_						:     Any     =		output.images

							snake_case_						:     Dict     =		image[0, -3:, -3:, -1]

							assert image.shape == (1, 512, 512, 3)
							snake_case_						:     List[Any]     =		np.array([0.4_0_1_9, 0.4_0_5_2, 0.3_8_1_0, 0.4_1_1_9, 0.3_9_1_6, 0.3_9_8_2, 0.4_6_5_1, 0.4_1_9_5, 0.5_3_2_3]		)

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

