



import torch
from torch import nn
from torch.nn import CrossEntropyLoss, MSELoss

from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
from transformers.models.bert.modeling_bert import (
    BERT_INPUTS_DOCSTRING,
    BERT_START_DOCSTRING,
    BertEmbeddings,
    BertLayer,
    BertPooler,
    BertPreTrainedModel,
)





def 		a__			(		_UpperCamelCase			: Any							):
   __lowerCamelCase													=    torch.exp(_UpperCamelCase							)
   __lowerCamelCase													=    torch.sum(_UpperCamelCase ,dim=1							)  # sum of exp(x_i)
   __lowerCamelCase													=    torch.sum(x * exp_x ,dim=1							)  # sum of x_i * exp(x_i)
   return torch.log(_UpperCamelCase							) - B / A



class  __lowerCAmelCase     (	nn.Module   ):




 def __init__(						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    super().__init__()
    __lowerCamelCase													=    config.output_attentions
    __lowerCamelCase													=    config.output_hidden_states
    __lowerCamelCase													=    nn.ModuleList([BertLayer(__UpperCAmelCase				) for _ in range(config.num_hidden_layers				)]				)
    __lowerCamelCase													=    nn.ModuleList([BertHighway(__UpperCAmelCase				) for _ in range(config.num_hidden_layers				)]				)

    __lowerCamelCase													=    [-1 for _ in range(config.num_hidden_layers				)]




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    if (type(__UpperCAmelCase				) is float) or (type(__UpperCAmelCase				) is int):
       for i in range(len(self.early_exit_entropy				)				):
          __lowerCamelCase													=    x
    else:
       __lowerCamelCase													=    x




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    pooler.state_dict()
    for highway in self.highway:
       for name, param in highway.pooler.state_dict().items():
          param.copy_(loaded_model[name]				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				):



    '''simple docstring'''
    __lowerCamelCase													=    ()
    __lowerCamelCase													=    ()
    __lowerCamelCase													=    ()
    for i, layer_module in enumerate(self.layer				):
       if self.output_hidden_states:
          __lowerCamelCase													=    all_hidden_states + (hidden_states,)

       __lowerCamelCase													=    layer_module(
           __UpperCAmelCase	,				__UpperCAmelCase	,				head_mask[i]	,				__UpperCAmelCase	,				__UpperCAmelCase				)
       __lowerCamelCase													=    layer_outputs[0]

       if self.output_attentions:
          __lowerCamelCase													=    all_attentions + (layer_outputs[1],)

       __lowerCamelCase													=    (hidden_states,)
       if self.output_hidden_states:
          __lowerCamelCase													=    current_outputs + (all_hidden_states,)
       if self.output_attentions:
          __lowerCamelCase													=    current_outputs + (all_attentions,)

       __lowerCamelCase													=    self.highway[i](__UpperCAmelCase				)
       # logits, pooled_output

       if not self.training:
          __lowerCamelCase													=    highway_exit[0]
          __lowerCamelCase													=    entropy(__UpperCAmelCase				)
          __lowerCamelCase													=    highway_exit + (highway_entropy,)  # logits, hidden_states(?), entropy
          __lowerCamelCase													=    all_highway_exits + (highway_exit,)

          if highway_entropy < self.early_exit_entropy[i]:
             __lowerCamelCase													=    (highway_logits,) + current_outputs[1:] + (all_highway_exits,)
             raise HighwayException(__UpperCAmelCase	,				i + 1				)
       else:
          __lowerCamelCase													=    all_highway_exits + (highway_exit,)

        # Add last layer
    if self.output_hidden_states:
       __lowerCamelCase													=    all_hidden_states + (hidden_states,)

    __lowerCamelCase													=    (hidden_states,)
    if self.output_hidden_states:
       __lowerCamelCase													=    outputs + (all_hidden_states,)
    if self.output_attentions:
       __lowerCamelCase													=    outputs + (all_attentions,)

    __lowerCamelCase													=    outputs + (all_highway_exits,)
    return outputs  # last-layer hidden state, (all hidden states), (all attentions), all highway exits



@add_start_docstrings(
    """The Bert Model transformer with early exiting (DeeBERT). """  ,	lowerCAmelCase__  ,	)
class  __lowerCAmelCase     (	lowerCAmelCase__   ):




 def __init__(						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    super().__init__(__UpperCAmelCase				)
    __lowerCamelCase													=    config

    __lowerCamelCase													=    BertEmbeddings(__UpperCAmelCase				)
    __lowerCamelCase													=    DeeBertEncoder(__UpperCAmelCase				)
    __lowerCamelCase													=    BertPooler(__UpperCAmelCase				)

    self.init_weights()




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    self.encoder.init_highway_pooler(self.pooler				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    return self.embeddings.word_embeddings




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    value




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    for layer, heads in heads_to_prune.items():
       self.encoder.layer[layer].attention.prune_heads(__UpperCAmelCase				)




 @add_start_docstrings_to_model_forward(__UpperCAmelCase				)
 def        lowerCamelCase      (						self	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				):



    '''simple docstring'''
    if input_ids is not None and inputs_embeds is not None:
       raise ValueError('''You cannot specify both input_ids and inputs_embeds at the same time'''				)
    elif input_ids is not None:
       __lowerCamelCase													=    input_ids.size()
    elif inputs_embeds is not None:
       __lowerCamelCase													=    inputs_embeds.size()[:-1]
    else:
       raise ValueError('''You have to specify either input_ids or inputs_embeds'''				)

    __lowerCamelCase													=    input_ids.device if input_ids is not None else inputs_embeds.device

    if attention_mask is None:
       __lowerCamelCase													=    torch.ones(__UpperCAmelCase	,				device=__UpperCAmelCase				)
    if encoder_attention_mask is None:
       __lowerCamelCase													=    torch.ones(__UpperCAmelCase	,				device=__UpperCAmelCase				)
    if token_type_ids is None:
       __lowerCamelCase													=    torch.zeros(__UpperCAmelCase	,				dtype=torch.long	,				device=__UpperCAmelCase				)

    # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
    # ourselves in which case we just need to make it broadcastable to all heads.
    __lowerCamelCase													=    self.get_extended_attention_mask(__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				)

    # If a 2D ou 3D attention mask is provided for the cross-attention
    # we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length]
    if encoder_attention_mask.dim() == 3:
       __lowerCamelCase													=    encoder_attention_mask[:, None, :, :]
    if encoder_attention_mask.dim() == 2:
       __lowerCamelCase													=    encoder_attention_mask[:, None, None, :]

    __lowerCamelCase													=    encoder_extended_attention_mask.to(
        dtype=next(self.parameters()				).dtype				)  # fp16 compatibility
    __lowerCamelCase													=    (1.0 - encoder_extended_attention_mask) * -10000.0

    # Prepare head mask if needed
    # 1.0 in head_mask indicate we keep the head
    # attention_probs has shape bsz x n_heads x N x N
    # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads]
    # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length]
    __lowerCamelCase													=    self.get_head_mask(__UpperCAmelCase	,				self.config.num_hidden_layers				)

    __lowerCamelCase													=    self.embeddings(
        input_ids=__UpperCAmelCase	,				position_ids=__UpperCAmelCase	,				token_type_ids=__UpperCAmelCase	,				inputs_embeds=__UpperCAmelCase				)
    __lowerCamelCase													=    self.encoder(
        __UpperCAmelCase	,				attention_mask=__UpperCAmelCase	,				head_mask=__UpperCAmelCase	,				encoder_hidden_states=__UpperCAmelCase	,				encoder_attention_mask=__UpperCAmelCase	,				)
    __lowerCamelCase													=    encoder_outputs[0]
    __lowerCamelCase													=    self.pooler(__UpperCAmelCase				)

    __lowerCamelCase													=    (
        sequence_output,
        pooled_output,
    ) + encoder_outputs[
        1:
    ]  # add hidden_states and attentions if they are here
    return outputs  # sequence_output, pooled_output, (hidden_states), (attentions), highway exits



class  __lowerCAmelCase     (	lowerCAmelCase__   ):




 def __init__(						self	,				__UpperCAmelCase	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    message
    __lowerCamelCase													=    exit_layer  # start from 1!



class  __lowerCAmelCase     (	nn.Module   ):




 def __init__(						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    super().__init__()
    __lowerCamelCase													=    BertPooler(__UpperCAmelCase				)
    __lowerCamelCase													=    nn.Dropout(config.hidden_dropout_prob				)
    __lowerCamelCase													=    nn.Linear(config.hidden_size	,				config.num_labels				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    encoder_outputs[0]
    __lowerCamelCase													=    self.pooler(__UpperCAmelCase				)
    # "return" pooler_output

    # BertModel
    __lowerCamelCase													=    (pooler_input, pooler_output) + encoder_outputs[1:]
    # "return" bmodel_output

    # Dropout and classification
    __lowerCamelCase													=    bmodel_output[1]

    __lowerCamelCase													=    self.dropout(__UpperCAmelCase				)
    __lowerCamelCase													=    self.classifier(__UpperCAmelCase				)

    return logits, pooled_output



@add_start_docstrings(
    """Bert Model (with early exiting - DeeBERT) with a classifier on top,
    also takes care of multi-layer training. """  ,	lowerCAmelCase__  ,	)
class  __lowerCAmelCase     (	lowerCAmelCase__   ):




 def __init__(						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    super().__init__(__UpperCAmelCase				)
    __lowerCamelCase													=    config.num_labels
    __lowerCamelCase													=    config.num_hidden_layers

    __lowerCamelCase													=    DeeBertModel(__UpperCAmelCase				)
    __lowerCamelCase													=    nn.Dropout(config.hidden_dropout_prob				)
    __lowerCamelCase													=    nn.Linear(config.hidden_size	,				self.config.num_labels				)

    self.init_weights()




 @add_start_docstrings_to_model_forward(__UpperCAmelCase				)
 def        lowerCamelCase      (						self	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=None	,				__UpperCAmelCase=-1	,				__UpperCAmelCase=False	,				):



    '''simple docstring'''
    __lowerCamelCase													=    self.num_layers
    try:
       __lowerCamelCase													=    self.bert(
           __UpperCAmelCase	,				attention_mask=__UpperCAmelCase	,				token_type_ids=__UpperCAmelCase	,				position_ids=__UpperCAmelCase	,				head_mask=__UpperCAmelCase	,				inputs_embeds=__UpperCAmelCase	,				)
       # sequence_output, pooled_output, (hidden_states), (attentions), highway exits

       __lowerCamelCase													=    outputs[1]

       __lowerCamelCase													=    self.dropout(__UpperCAmelCase				)
       __lowerCamelCase													=    self.classifier(__UpperCAmelCase				)
       __lowerCamelCase													=    (logits,) + outputs[2:]  # add hidden states and attention if they are here
    except HighwayException as e:
       __lowerCamelCase													=    e.message
       __lowerCamelCase													=    e.exit_layer
       __lowerCamelCase													=    outputs[0]

    if not self.training:
       __lowerCamelCase													=    entropy(__UpperCAmelCase				)
       __lowerCamelCase													=    []
       __lowerCamelCase													=    []
    if labels is not None:
       if self.num_labels == 1:
          #  We are doing regression
          __lowerCamelCase													=    MSELoss()
          __lowerCamelCase													=    loss_fct(logits.view(-1				)	,				labels.view(-1				)				)
       else:
          __lowerCamelCase													=    CrossEntropyLoss()
          __lowerCamelCase													=    loss_fct(logits.view(-1	,				self.num_labels				)	,				labels.view(-1				)				)

       # work with highway exits
       __lowerCamelCase													=    []
       for highway_exit in outputs[-1]:
          __lowerCamelCase													=    highway_exit[0]
          if not self.training:
             highway_logits_all.append(__UpperCAmelCase				)
             highway_entropy.append(highway_exit[2]				)
          if self.num_labels == 1:
             #  We are doing regression
             __lowerCamelCase													=    MSELoss()
             __lowerCamelCase													=    loss_fct(highway_logits.view(-1				)	,				labels.view(-1				)				)
          else:
             __lowerCamelCase													=    CrossEntropyLoss()
             __lowerCamelCase													=    loss_fct(highway_logits.view(-1	,				self.num_labels				)	,				labels.view(-1				)				)
          highway_losses.append(__UpperCAmelCase				)

       if train_highway:
          __lowerCamelCase													=    (sum(highway_losses[:-1]				),) + outputs
          # exclude the final highway, of course
       else:
          __lowerCamelCase													=    (loss,) + outputs
    if not self.training:
       __lowerCamelCase													=    outputs + ((original_entropy, highway_entropy), exit_layer)
       if output_layer >= 0:
          __lowerCamelCase													=    (
              (outputs[0],) + (highway_logits_all[output_layer],) + outputs[2:]
          )  # use the highway of the last layer

    return outputs  # (loss), logits, (hidden_states), (attentions), (highway_exits)











import gc
import random
import unittest

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

from diffusers import (
    AutoencoderKL,
    DiffusionPipeline,
    EulerDiscreteScheduler,
    StableDiffusionXLImgaImgPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import floats_tensor, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import (
    IMAGE_TO_IMAGE_IMAGE_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()



class  __lowerCAmelCase     (	lowerCAmelCase__  ,	lowerCAmelCase__  ,	unittest.TestCase   ):
 lowerCAmelCase__       					=  StableDiffusionXLImgaImgPipeline
 lowerCAmelCase__       					=  TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""height""", """width"""}
 lowerCAmelCase__       					=  PipelineTesterMixin.required_optional_params - {"""latents"""}
 lowerCAmelCase__       					=  TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
 lowerCAmelCase__       					=  IMAGE_TO_IMAGE_IMAGE_PARAMS
 lowerCAmelCase__       					=  IMAGE_TO_IMAGE_IMAGE_PARAMS




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    torch.manual_seed(0				)
    __lowerCamelCase													=    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''')	,				attention_head_dim=(2, 4)	,				use_linear_projection=__UpperCAmelCase	,				addition_embed_type='''text_time'''	,				addition_time_embed_dim=8	,				transformer_layers_per_block=(1, 2)	,				projection_class_embeddings_input_dim=80	,				cross_attention_dim=64	,				)
    __lowerCamelCase													=    EulerDiscreteScheduler(
        beta_start=0.00_085	,				beta_end=0.012	,				steps_offset=1	,				beta_schedule='''scaled_linear'''	,				timestep_spacing='''leading'''	,				)
    torch.manual_seed(0				)
    __lowerCamelCase													=    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	,				sample_size=128	,				)
    torch.manual_seed(0				)
    __lowerCamelCase													=    CLIPTextConfig(
        bos_token_id=0	,				eos_token_id=2	,				hidden_size=32	,				intermediate_size=37	,				layer_norm_eps=1E-0_5	,				num_attention_heads=4	,				num_hidden_layers=5	,				pad_token_id=1	,				vocab_size=1000	,				hidden_act='''gelu'''	,				projection_dim=32	,				)
    __lowerCamelCase													=    CLIPTextModel(__UpperCAmelCase				)
    __lowerCamelCase													=    CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''	,				local_files_only=__UpperCAmelCase				)

    __lowerCamelCase													=    CLIPTextModelWithProjection(__UpperCAmelCase				)
    __lowerCamelCase													=    CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''	,				local_files_only=__UpperCAmelCase				)

    __lowerCamelCase													=    {
        '''unet''': unet,
        '''scheduler''': scheduler,
        '''vae''': vae,
        '''text_encoder''': text_encoder,
        '''tokenizer''': tokenizer,
        '''text_encoder_2''': text_encoder_a,
        '''tokenizer_2''': tokenizer_a,
        # "safety_checker": None,
        # "feature_extractor": None,
    }
    return components




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase=0				):



    '''simple docstring'''
    __lowerCamelCase													=    floats_tensor((1, 3, 32, 32)	,				rng=random.Random(__UpperCAmelCase				)				).to(__UpperCAmelCase				)
    __lowerCamelCase													=    image / 2 + 0.5
    if str(__UpperCAmelCase				).startswith('''mps'''				):
       __lowerCamelCase													=    torch.manual_seed(__UpperCAmelCase				)
    else:
       __lowerCamelCase													=    torch.Generator(device=__UpperCAmelCase				).manual_seed(__UpperCAmelCase				)
    __lowerCamelCase													=    {
        '''prompt''': '''A painting of a squirrel eating a burger''',
        '''image''': image,
        '''generator''': generator,
        '''num_inference_steps''': 2,
        '''guidance_scale''': 5.0,
        '''output_type''': '''numpy''',
        '''strength''': 0.75,
    }
    return inputs




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    '''cpu'''  # ensure determinism for the device-dependent torch.Generator
    __lowerCamelCase													=    self.get_dummy_components()
    __lowerCamelCase													=    StableDiffusionXLImgaImgPipeline(**__UpperCAmelCase				)
    __lowerCamelCase													=    sd_pipe.to(__UpperCAmelCase				)
    sd_pipe.set_progress_bar_config(disable=__UpperCAmelCase				)

    __lowerCamelCase													=    self.get_dummy_inputs(__UpperCAmelCase				)
    __lowerCamelCase													=    sd_pipe(**__UpperCAmelCase				).images
    __lowerCamelCase													=    image[0, -3:, -3:, -1]

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

    __lowerCamelCase													=    np.array([0.4_656, 0.4_840, 0.4_439, 0.6_698, 0.5_574, 0.4_524, 0.5_799, 0.5_943, 0.5_165]				)

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




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    super().test_attention_slicing_forward_pass(expected_max_diff=3E-3				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    super().test_inference_batch_single_identical(expected_max_diff=3E-3				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    pass




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.get_dummy_components()
    __lowerCamelCase													=    StableDiffusionXLImgaImgPipeline(**__UpperCAmelCase				)
    __lowerCamelCase													=    sd_pipe.to(__UpperCAmelCase				)
    __lowerCamelCase													=    sd_pipe.to(__UpperCAmelCase				)
    sd_pipe.set_progress_bar_config(disable=__UpperCAmelCase				)

    # forward without prompt embeds
    __lowerCamelCase													=    self.get_dummy_inputs(__UpperCAmelCase				)
    __lowerCamelCase													=    3 * ['''this is a negative prompt''']
    __lowerCamelCase													=    negative_prompt
    __lowerCamelCase													=    3 * [inputs['''prompt''']]

    __lowerCamelCase													=    sd_pipe(**__UpperCAmelCase				)
    __lowerCamelCase													=    output.images[0, -3:, -3:, -1]

    # forward with prompt embeds
    __lowerCamelCase													=    self.get_dummy_inputs(__UpperCAmelCase				)
    __lowerCamelCase													=    3 * ['''this is a negative prompt''']
    __lowerCamelCase													=    3 * [inputs.pop('''prompt'''				)]

    (
        (
        __lowerCamelCase
    )							,(
        __lowerCamelCase
    )							,(
        __lowerCamelCase
    )							,(
        __lowerCamelCase
    )							,
    )													=    sd_pipe.encode_prompt(__UpperCAmelCase	,				negative_prompt=__UpperCAmelCase				)

    __lowerCamelCase													=    sd_pipe(
        **__UpperCAmelCase	,				prompt_embeds=__UpperCAmelCase	,				negative_prompt_embeds=__UpperCAmelCase	,				pooled_prompt_embeds=__UpperCAmelCase	,				negative_pooled_prompt_embeds=__UpperCAmelCase	,				)
    __lowerCamelCase													=    output.images[0, -3:, -3:, -1]

    # make sure that it's equal
    assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()				).max() < 1E-4



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




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    super().tearDown()
    gc.collect()
    torch.cuda.empty_cache()




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase="cpu"	,				__UpperCAmelCase=torch.floataa	,				__UpperCAmelCase=0				):



    '''simple docstring'''
    __lowerCamelCase													=    torch.Generator(device=__UpperCAmelCase				).manual_seed(__UpperCAmelCase				)
    __lowerCamelCase													=    np.random.RandomState(__UpperCAmelCase				).standard_normal((1, 4, 64, 64)				)
    __lowerCamelCase													=    torch.from_numpy(__UpperCAmelCase				).to(device=__UpperCAmelCase	,				dtype=__UpperCAmelCase				)
    __lowerCamelCase													=    {
        '''prompt''': '''a photograph of an astronaut riding a horse''',
        '''latents''': latents,
        '''generator''': generator,
        '''num_inference_steps''': 3,
        '''guidance_scale''': 7.5,
        '''output_type''': '''numpy''',
    }
    return inputs




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    DiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-base'''				)
    pipe.to(__UpperCAmelCase				)
    pipe.set_progress_bar_config(disable=__UpperCAmelCase				)

    __lowerCamelCase													=    self.get_inputs(__UpperCAmelCase				)
    __lowerCamelCase													=    pipe(**__UpperCAmelCase				).images
    __lowerCamelCase													=    image[0, -3:, -3:, -1].flatten()

    assert image.shape == (1, 512, 512, 3)
    __lowerCamelCase													=    np.array([0.49_493, 0.47_896, 0.40_798, 0.54_214, 0.53_212, 0.48_202, 0.47_656, 0.46_329, 0.48_506]				)
    assert np.abs(image_slice - expected_slice				).max() < 7E-3






