


import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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 (
			    MODEL_FOR_PRETRAINING_MAPPING,
			    MobileBertForMaskedLM,
			    MobileBertForMultipleChoice,
			    MobileBertForNextSentencePrediction,
			    MobileBertForPreTraining,
			    MobileBertForQuestionAnswering,
			    MobileBertForSequenceClassification,
			    MobileBertForTokenClassification,
			    MobileBertModel,
			)

class        a	:




							"""simple docstring"""


							def __init__(							self :						Optional[int]					,			lowerCamelCase :						Any					,			lowerCamelCase :						int=13					,			lowerCamelCase :						Any=7					,			lowerCamelCase :						Optional[Any]=True					,			lowerCamelCase :						int=True					,			lowerCamelCase :						int=True					,			lowerCamelCase :						Union[str, Any]=True					,			lowerCamelCase :						str=99					,			lowerCamelCase :						int=64					,			lowerCamelCase :						int=32					,			lowerCamelCase :						int=5					,			lowerCamelCase :						List[str]=4					,			lowerCamelCase :						Tuple=37					,			lowerCamelCase :						Optional[int]="gelu"					,			lowerCamelCase :						Optional[Any]=0.1					,			lowerCamelCase :						List[Any]=0.1					,			lowerCamelCase :						List[Any]=512					,			lowerCamelCase :						Optional[int]=16					,			lowerCamelCase :						Any=2					,			lowerCamelCase :						List[Any]=0.02					,			lowerCamelCase :						Optional[int]=3					,			lowerCamelCase :						Dict=4					,			lowerCamelCase :						Any=None					,			)			->					Union[str, Any]:
														__snake_case	:    Optional[Any]											=     parent
														__snake_case	:    str											=     batch_size
														__snake_case	:    List[str]											=     seq_length
														__snake_case	:    Any											=     is_training
														__snake_case	:    Dict											=     use_input_mask
														__snake_case	:    Dict											=     use_token_type_ids
														__snake_case	:    Optional[Any]											=     use_labels
														__snake_case	:    str											=     vocab_size
														__snake_case	:    Union[str, Any]											=     hidden_size
														__snake_case	:    int											=     embedding_size
														__snake_case	:    List[str]											=     num_hidden_layers
														__snake_case	:    Optional[Any]											=     num_attention_heads
														__snake_case	:    Optional[int]											=     intermediate_size
														__snake_case	:    List[Any]											=     hidden_act
														__snake_case	:    Tuple											=     hidden_dropout_prob
														__snake_case	:    Union[str, Any]											=     attention_probs_dropout_prob
														__snake_case	:    Union[str, Any]											=     max_position_embeddings
														__snake_case	:    Optional[int]											=     type_vocab_size
														__snake_case	:    List[Any]											=     type_sequence_label_size
														__snake_case	:    Union[str, Any]											=     initializer_range
														__snake_case	:    Dict											=     num_labels
														__snake_case	:    Any											=     num_choices
														__snake_case	:    Any											=     scope

							def 					__snake_case      (							self :						Tuple       )			->					List[Any]:
														__snake_case	:    Any											=     ids_tensor([self.batch_size, self.seq_length]					,			self.vocab_size       )

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

														__snake_case	:    Optional[int]											=     None
														if self.use_token_type_ids:
																					__snake_case	:    Any											=     ids_tensor([self.batch_size, self.seq_length]					,			self.type_vocab_size       )

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

														__snake_case	:    Optional[Any]											=     self.get_config()

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

							def 					__snake_case      (							self :						Union[str, Any]       )			->					Dict:
														return MobileBertConfig(
														    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					,			embedding_size=self.embedding_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=lowerCamelCase					,			initializer_range=self.initializer_range					,			)

							def 					__snake_case      (							self :						Union[str, Any]					,			lowerCamelCase :						Tuple					,			lowerCamelCase :						Any					,			lowerCamelCase :						int					,			lowerCamelCase :						Tuple					,			lowerCamelCase :						int					,			lowerCamelCase :						Dict					,			lowerCamelCase :						Any       )			->					Dict:
														__snake_case	:    Optional[Any]											=     MobileBertModel(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    Any											=     model(lowerCamelCase					,			attention_mask=lowerCamelCase					,			token_type_ids=lowerCamelCase       )
														__snake_case	:    Tuple											=     model(lowerCamelCase					,			token_type_ids=lowerCamelCase       )
														__snake_case	:    Dict											=     model(lowerCamelCase       )

														self.parent.assertEqual(result.last_hidden_state.shape					,			(self.batch_size, self.seq_length, self.hidden_size)       )
														self.parent.assertEqual(result.pooler_output.shape					,			(self.batch_size, self.hidden_size)       )

							def 					__snake_case      (							self :						Optional[Any]					,			lowerCamelCase :						str					,			lowerCamelCase :						int					,			lowerCamelCase :						str					,			lowerCamelCase :						Any					,			lowerCamelCase :						Union[str, Any]					,			lowerCamelCase :						Tuple					,			lowerCamelCase :						Optional[Any]       )			->					Dict:
														__snake_case	:    int											=     MobileBertForMaskedLM(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    Dict											=     model(lowerCamelCase					,			attention_mask=lowerCamelCase					,			token_type_ids=lowerCamelCase					,			labels=lowerCamelCase       )
														self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.seq_length, self.vocab_size)       )

							def 					__snake_case      (							self :						Optional[Any]					,			lowerCamelCase :						Any					,			lowerCamelCase :						Dict					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						int					,			lowerCamelCase :						int					,			lowerCamelCase :						Optional[Any]					,			lowerCamelCase :						Dict       )			->					List[str]:
														__snake_case	:    Optional[Any]											=     MobileBertForNextSentencePrediction(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    Dict											=     model(
														    lowerCamelCase					,			attention_mask=lowerCamelCase					,			token_type_ids=lowerCamelCase					,			labels=lowerCamelCase					,			)
														self.parent.assertEqual(result.logits.shape					,			(self.batch_size, 2)       )

							def 					__snake_case      (							self :						Tuple					,			lowerCamelCase :						List[str]					,			lowerCamelCase :						Optional[Any]					,			lowerCamelCase :						int					,			lowerCamelCase :						str					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						Dict					,			lowerCamelCase :						List[Any]       )			->					Optional[Any]:
														__snake_case	:    Tuple											=     MobileBertForPreTraining(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    List[str]											=     model(
														    lowerCamelCase					,			attention_mask=lowerCamelCase					,			token_type_ids=lowerCamelCase					,			labels=lowerCamelCase					,			next_sentence_label=lowerCamelCase					,			)
														self.parent.assertEqual(result.prediction_logits.shape					,			(self.batch_size, self.seq_length, self.vocab_size)       )
														self.parent.assertEqual(result.seq_relationship_logits.shape					,			(self.batch_size, 2)       )

							def 					__snake_case      (							self :						Optional[int]					,			lowerCamelCase :						Any					,			lowerCamelCase :						Any					,			lowerCamelCase :						int					,			lowerCamelCase :						Any					,			lowerCamelCase :						Any					,			lowerCamelCase :						Union[str, Any]					,			lowerCamelCase :						Optional[Any]       )			->					Any:
														__snake_case	:    Optional[Any]											=     MobileBertForQuestionAnswering(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    List[str]											=     model(
														    lowerCamelCase					,			attention_mask=lowerCamelCase					,			token_type_ids=lowerCamelCase					,			start_positions=lowerCamelCase					,			end_positions=lowerCamelCase					,			)
														self.parent.assertEqual(result.start_logits.shape					,			(self.batch_size, self.seq_length)       )
														self.parent.assertEqual(result.end_logits.shape					,			(self.batch_size, self.seq_length)       )

							def 					__snake_case      (							self :						Optional[Any]					,			lowerCamelCase :						Optional[Any]					,			lowerCamelCase :						Dict					,			lowerCamelCase :						List[str]					,			lowerCamelCase :						Union[str, Any]					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						Optional[int]					,			lowerCamelCase :						str       )			->					Optional[Any]:
														__snake_case	:    str											=     self.num_labels
														__snake_case	:    Optional[Any]											=     MobileBertForSequenceClassification(lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    List[Any]											=     model(lowerCamelCase					,			attention_mask=lowerCamelCase					,			token_type_ids=lowerCamelCase					,			labels=lowerCamelCase       )
														self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.num_labels)       )

							def 					__snake_case      (							self :						List[str]					,			lowerCamelCase :						List[str]					,			lowerCamelCase :						Dict					,			lowerCamelCase :						int					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						int					,			lowerCamelCase :						Optional[int]					,			lowerCamelCase :						str       )			->					Tuple:
														__snake_case	:    List[Any]											=     self.num_labels
														__snake_case	:    Dict											=     MobileBertForTokenClassification(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    str											=     model(lowerCamelCase					,			attention_mask=lowerCamelCase					,			token_type_ids=lowerCamelCase					,			labels=lowerCamelCase       )
														self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.seq_length, self.num_labels)       )

							def 					__snake_case      (							self :						Union[str, Any]					,			lowerCamelCase :						Optional[int]					,			lowerCamelCase :						str					,			lowerCamelCase :						Tuple					,			lowerCamelCase :						Any					,			lowerCamelCase :						int					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						Dict       )			->					Optional[Any]:
														__snake_case	:    str											=     self.num_choices
														__snake_case	:    int											=     MobileBertForMultipleChoice(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    Any											=     input_ids.unsqueeze(1       ).expand(-1					,			self.num_choices					,			-1       ).contiguous()
														__snake_case	:    List[str]											=     token_type_ids.unsqueeze(1       ).expand(-1					,			self.num_choices					,			-1       ).contiguous()
														__snake_case	:    Optional[Any]											=     input_mask.unsqueeze(1       ).expand(-1					,			self.num_choices					,			-1       ).contiguous()
														__snake_case	:    List[str]											=     model(
														    lowerCamelCase					,			attention_mask=lowerCamelCase					,			token_type_ids=lowerCamelCase					,			labels=lowerCamelCase					,			)
														self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.num_choices)       )






							def 					__snake_case      (							self :						Dict       )			->					str:
														__snake_case	:    Union[str, Any]											=     self.prepare_config_and_inputs()
														(
														    (
														    __snake_case
														)				,    (
														    __snake_case
														)				,    (
														    __snake_case
														)				,    (
														    __snake_case
														)				,    (
														    __snake_case
														)				,    (
														    __snake_case
														)				,    (
														    __snake_case
														)				,    
														)	:    Tuple											=     config_and_inputs
														__snake_case	:    List[str]											=     {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
														return config, inputs_dict

@require_torch
class        a	(_lowerCAmelCase  ,       _lowerCAmelCase  ,       unittest.TestCase   ):




							"""simple docstring"""


							__UpperCAmelCase					:							Optional[int]  						=						(
							    (
							        MobileBertModel,
							        MobileBertForMaskedLM,
							        MobileBertForMultipleChoice,
							        MobileBertForNextSentencePrediction,
							        MobileBertForPreTraining,
							        MobileBertForQuestionAnswering,
							        MobileBertForSequenceClassification,
							        MobileBertForTokenClassification,
							    )
							    if is_torch_available()
							    else ()
							)
							__UpperCAmelCase					:							List[Any]  						=						(
							    {
							        "feature-extraction": MobileBertModel,
							        "fill-mask": MobileBertForMaskedLM,
							        "question-answering": MobileBertForQuestionAnswering,
							        "text-classification": MobileBertForSequenceClassification,
							        "token-classification": MobileBertForTokenClassification,
							        "zero-shot": MobileBertForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							__UpperCAmelCase					:							Optional[Any]  						=						True

							def 					__snake_case      (							self :						List[str]					,			lowerCamelCase :						int					,			lowerCamelCase :						Optional[Any]					,			lowerCamelCase :						Any=False       )			->					List[str]:
														__snake_case	:    Dict											=     super()._prepare_for_class(lowerCamelCase					,			lowerCamelCase					,			return_labels=lowerCamelCase       )

														if return_labels:
																					if model_class in get_values(lowerCamelCase       ):
																												__snake_case	:    Any											=     torch.zeros(
																												    (self.model_tester.batch_size, self.model_tester.seq_length)					,			dtype=torch.long					,			device=lowerCamelCase       )
																												__snake_case	:    Union[str, Any]											=     torch.zeros(
																												    self.model_tester.batch_size					,			dtype=torch.long					,			device=lowerCamelCase       )
														return inputs_dict

							def 					__snake_case      (							self :						Union[str, Any]       )			->					List[str]:
														__snake_case	:    Optional[int]											=     MobileBertModelTester(self       )
														__snake_case	:    Dict											=     ConfigTester(self					,			config_class=lowerCamelCase					,			hidden_size=37       )

							def 					__snake_case      (							self :						Any       )			->					List[Any]:
														self.config_tester.run_common_tests()

							def 					__snake_case      (							self :						Optional[int]       )			->					List[Any]:
														__snake_case	:    Optional[int]											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_model(*lowerCamelCase       )

							def 					__snake_case      (							self :						List[Any]       )			->					int:
														__snake_case	:    Union[str, Any]											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_masked_lm(*lowerCamelCase       )

							def 					__snake_case      (							self :						Tuple       )			->					Dict:
														__snake_case	:    str											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_multiple_choice(*lowerCamelCase       )

							def 					__snake_case      (							self :						int       )			->					Optional[int]:
														__snake_case	:    Any											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*lowerCamelCase       )

							def 					__snake_case      (							self :						int       )			->					Dict:
														__snake_case	:    str											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_pretraining(*lowerCamelCase       )

							def 					__snake_case      (							self :						Union[str, Any]       )			->					List[str]:
														__snake_case	:    str											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_question_answering(*lowerCamelCase       )

							def 					__snake_case      (							self :						Optional[Any]       )			->					Union[str, Any]:
														__snake_case	:    Optional[Any]											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_sequence_classification(*lowerCamelCase       )






							def 					__snake_case      (							self :						Optional[Any]       )			->					Optional[int]:
														__snake_case	:    Any											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_token_classification(*lowerCamelCase       )







def        lowerCAmelCase_  (      __lowerCamelCase			):
							return torch.tensor(
							    __lowerCamelCase							,			dtype=torch.long							,			device=__lowerCamelCase							,			)


_snake_case  :	Union[str, Any]			      =       1E-3

@require_torch
@require_sentencepiece
@require_tokenizers
class        a	(unittest.TestCase   ):




							"""simple docstring"""


							@slow
							def 					__snake_case      (							self :						str       )			->					str:
														__snake_case	:    Dict											=     MobileBertModel.from_pretrained("google/mobilebert-uncased"       ).to(lowerCamelCase       )
														__snake_case	:    int											=     _long_tensor([[101, 7110, 1005, 1056, 2023, 11333, 17413, 1029, 102]]       )
														with torch.no_grad():
																					__snake_case	:    Optional[int]											=     model(lowerCamelCase       )[0]
														__snake_case	:    Dict											=     torch.Size((1, 9, 512)       )
														self.assertEqual(output.shape					,			lowerCamelCase       )
														__snake_case	:    str											=     torch.tensor(
														    [
														        [
														            [-2.4736526E07, 8.2691656E04, 1.6521838E05],
														            [-5.7541704E-01, 3.9056022E00, 4.4011507E00],
														            [2.6047359E00, 1.5677652E00, -1.7324188E-01],
														        ]
														    ]					,			device=lowerCamelCase					,			)

														# MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
														# ~1 difference, it's therefore not a good idea to measure using addition.
														# Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
														# result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
														__snake_case	:    str											=     torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE       )
														__snake_case	:    Any											=     torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE       )

														self.assertTrue(lower_bound and upper_bound       )





import gc
import unittest

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

from diffusers import AutoencoderKL, DDIMScheduler, LDMTextToImagePipeline, UNetaDConditionModel
from diffusers.utils.testing_utils import (
    enable_full_determinism,
    load_numpy,
    nightly,
    require_torch_gpu,
    slow,
    torch_device,
)

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()

class        a	(_lowerCAmelCase  ,       unittest.TestCase   ):




							"""simple docstring"""


							__UpperCAmelCase					:							Optional[Any]  						=						LDMTextToImagePipeline
							__UpperCAmelCase					:							List[Any]  						=						TEXT_TO_IMAGE_PARAMS - {
							    "negative_prompt",
							    "negative_prompt_embeds",
							    "cross_attention_kwargs",
							    "prompt_embeds",
							}
							__UpperCAmelCase					:							int  						=						PipelineTesterMixin.required_optional_params - {
							    "num_images_per_prompt",
							    "callback",
							    "callback_steps",
							}
							__UpperCAmelCase					:							Any  						=						TEXT_TO_IMAGE_BATCH_PARAMS
							__UpperCAmelCase					:							int  						=						False

							def 					__snake_case      (							self :						Union[str, Any]       )			->					str:
														torch.manual_seed(0       )
														__snake_case	:    List[Any]											=     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	:    Any											=     DDIMScheduler(
														    beta_start=0.0_00_85					,			beta_end=0.0_12					,			beta_schedule="scaled_linear"					,			clip_sample=lowerCamelCase					,			set_alpha_to_one=lowerCamelCase					,			)
														torch.manual_seed(0       )
														__snake_case	:    Dict											=     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					,			)
														torch.manual_seed(0       )
														__snake_case	:    Any											=     CLIPTextConfig(
														    bos_token_id=0					,			eos_token_id=2					,			hidden_size=32					,			intermediate_size=37					,			layer_norm_eps=1E-05					,			num_attention_heads=4					,			num_hidden_layers=5					,			pad_token_id=1					,			vocab_size=1000					,			)
														__snake_case	:    Any											=     CLIPTextModel(lowerCamelCase       )
														__snake_case	:    Dict											=     CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"       )

														__snake_case	:    List[str]											=     {
														    "unet": unet,
														    "scheduler": scheduler,
														    "vqvae": vae,
														    "bert": text_encoder,
														    "tokenizer": tokenizer,
														}
														return components

							def 					__snake_case      (							self :						List[Any]					,			lowerCamelCase :						str					,			lowerCamelCase :						Any=0       )			->					str:
														if str(lowerCamelCase       ).startswith("mps"       ):
																					__snake_case	:    Union[str, Any]											=     torch.manual_seed(lowerCamelCase       )
														else:
																					__snake_case	:    str											=     torch.Generator(device=lowerCamelCase       ).manual_seed(lowerCamelCase       )
														__snake_case	:    Dict											=     {
														    "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 					__snake_case      (							self :						Dict       )			->					Optional[Any]:
														__snake_case	:    List[Any]											=     "cpu"  # ensure determinism for the device-dependent torch.Generator

														__snake_case	:    Union[str, Any]											=     self.get_dummy_components()
														__snake_case	:    int											=     LDMTextToImagePipeline(**lowerCamelCase       )
														pipe.to(lowerCamelCase       )
														pipe.set_progress_bar_config(disable=lowerCamelCase       )

														__snake_case	:    Optional[Any]											=     self.get_dummy_inputs(lowerCamelCase       )
														__snake_case	:    Optional[Any]											=     pipe(**lowerCamelCase       ).images
														__snake_case	:    Optional[int]											=     image[0, -3:, -3:, -1]

														assert image.shape == (1, 16, 16, 3)
														__snake_case	:    int											=     np.array([0.61_01, 0.61_56, 0.56_22, 0.48_95, 0.66_61, 0.38_04, 0.57_48, 0.61_36, 0.50_14]       )

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

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




							"""simple docstring"""


							def 					__snake_case      (							self :						int       )			->					str:
														super().tearDown()
														gc.collect()
														torch.cuda.empty_cache()

							def 					__snake_case      (							self :						Optional[int]					,			lowerCamelCase :						Dict					,			lowerCamelCase :						Any=torch.floataa					,			lowerCamelCase :						List[Any]=0       )			->					Dict:
														__snake_case	:    List[Any]											=     torch.manual_seed(lowerCamelCase       )
														__snake_case	:    Tuple											=     np.random.RandomState(lowerCamelCase       ).standard_normal((1, 4, 32, 32)       )
														__snake_case	:    int											=     torch.from_numpy(lowerCamelCase       ).to(device=lowerCamelCase					,			dtype=lowerCamelCase       )
														__snake_case	:    List[str]											=     {
														    "prompt": "A painting of a squirrel eating a burger",
														    "latents": latents,
														    "generator": generator,
														    "num_inference_steps": 3,
														    "guidance_scale": 6.0,
														    "output_type": "numpy",
														}
														return inputs






							def 					__snake_case      (							self :						Tuple       )			->					Optional[Any]:
														__snake_case	:    str											=     LDMTextToImagePipeline.from_pretrained("CompVis/ldm-text2im-large-256"       ).to(lowerCamelCase       )
														pipe.set_progress_bar_config(disable=lowerCamelCase       )

														__snake_case	:    List[str]											=     self.get_inputs(lowerCamelCase       )
														__snake_case	:    str											=     pipe(**lowerCamelCase       ).images
														__snake_case	:    Dict											=     image[0, -3:, -3:, -1].flatten()

														assert image.shape == (1, 256, 256, 3)
														__snake_case	:    int											=     np.array([0.5_18_25, 0.5_28_50, 0.5_25_43, 0.5_42_58, 0.5_23_04, 0.5_25_69, 0.5_43_63, 0.5_52_76, 0.5_68_78]       )
														__snake_case	:    List[str]											=     np.abs(expected_slice - image_slice       ).max()
														assert max_diff < 1E-3

@nightly
@require_torch_gpu
class        a	(unittest.TestCase   ):




							"""simple docstring"""


							def 					__snake_case      (							self :						List[Any]       )			->					List[Any]:
														super().tearDown()
														gc.collect()
														torch.cuda.empty_cache()

							def 					__snake_case      (							self :						Any					,			lowerCamelCase :						Dict					,			lowerCamelCase :						Any=torch.floataa					,			lowerCamelCase :						List[Any]=0       )			->					Optional[Any]:
														__snake_case	:    int											=     torch.manual_seed(lowerCamelCase       )
														__snake_case	:    Tuple											=     np.random.RandomState(lowerCamelCase       ).standard_normal((1, 4, 32, 32)       )
														__snake_case	:    Optional[Any]											=     torch.from_numpy(lowerCamelCase       ).to(device=lowerCamelCase					,			dtype=lowerCamelCase       )
														__snake_case	:    List[Any]											=     {
														    "prompt": "A painting of a squirrel eating a burger",
														    "latents": latents,
														    "generator": generator,
														    "num_inference_steps": 50,
														    "guidance_scale": 6.0,
														    "output_type": "numpy",
														}
														return inputs






							def 					__snake_case      (							self :						List[str]       )			->					int:
														__snake_case	:    Union[str, Any]											=     LDMTextToImagePipeline.from_pretrained("CompVis/ldm-text2im-large-256"       ).to(lowerCamelCase       )
														pipe.set_progress_bar_config(disable=lowerCamelCase       )

														__snake_case	:    Optional[Any]											=     self.get_inputs(lowerCamelCase       )
														__snake_case	:    str											=     pipe(**lowerCamelCase       ).images[0]

														__snake_case	:    Tuple											=     load_numpy(
														    "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/ldm_text2img/ldm_large_256_ddim.npy"       )
														__snake_case	:    str											=     np.abs(expected_image - image       ).max()
														assert max_diff < 1E-3

