class_docstr: Pipeline for text-to-image generation using Stable Diffusion and conditioning the results using feedback images.
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
  implemented for all pipelines (downloading, saving, running on a particular device, etc.).
  
  Args:
      vae ([`AutoencoderKL`]):
          Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
      text_encoder ([`~transformers.CLIPTextModel`]):
          Frozen text-encoder ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)).
      tokenizer ([`~transformers.CLIPTokenizer`]):
          A `CLIPTokenizer` to tokenize text.
      unet ([`UNet2DConditionModel`]):
          A `UNet2DConditionModel` to denoise the encoded image latents.
      scheduler ([`EulerAncestralDiscreteScheduler`]):
          A scheduler to be used in combination with `unet` to denoise the encoded image latents. Can be one of
          [`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
      safety_checker ([`StableDiffusionSafetyChecker`]):
          Classification module that estimates whether generated images could be considered offensive or harmful.
          Please refer to the [model card](https://huggingface.co/runwayml/stable-diffusion-v1-5) for more details
          about a model's potential harms.
code: def unet_forward_with_cached_hidden_states(
      self,
      z_all,
      t,
      prompt_embd,
      cached_pos_hiddens: Optional[List[torch.Tensor]] = None,
      cached_neg_hiddens: Optional[List[torch.Tensor]] = None,
      pos_weights=(0.8, 0.8),
      neg_weights=(0.5, 0.5),
  ):
      if cached_pos_hiddens is None and cached_neg_hiddens is None:
          return self.unet(z_all, t, encoder_hidden_states=prompt_embd)
  
      local_pos_weights = torch.linspace(
          *pos_weights, steps=len(self.unet.down_blocks) + 1
      )[:-1].tolist()
      local_neg_weights = torch.linspace(
          *neg_weights, steps=len(self.unet.down_blocks) + 1
      )[:-1].tolist()
      for block, pos_weight, neg_weight in zip(
          self.unet.down_blocks
          + [self.unet.mid_block]
          + self.unet.up_blocks,
          local_pos_weights
          + [pos_weights[1]]
          + local_pos_weights[::-1],
          local_neg_weights
          + [neg_weights[1]]
          + local_neg_weights[::-1],
      ):
          for module in block.modules():
              if isinstance(module, BasicTransformerBlock):
  
                  def new_forward(
                      self,
                      hidden_states,
                      pos_weight=pos_weight,
                      neg_weight=neg_weight,
                      **kwargs,
                  ):
                      (
                          cond_hiddens,
                          uncond_hiddens,
                      ) = hidden_states.chunk(2, dim=0)
                      batch_size, d_model = cond_hiddens.shape[:2]
                      device, dtype = (
                          hidden_states.device,
                          hidden_states.dtype,
                      )
  
                      weights = torch.ones(
                          batch_size,
                          d_model,
                          device=device,
                          dtype=dtype,
                      )
                      out_pos = self.old_forward(hidden_states)
                      out_neg = self.old_forward(hidden_states)
  
                      if cached_pos_hiddens is not None:
                          cached_pos_hs = cached_pos_hiddens.pop(0).to(
                              hidden_states.device
                          )
                          cond_pos_hs = torch.cat(
                              [cond_hiddens, cached_pos_hs], dim=1
                          )
                          pos_weights = weights.clone().repeat(
                              1, 1 + cached_pos_hs.shape[1] // d_model
                          )
                          pos_weights[:, d_model:] = pos_weight
                          attn_with_weights = FabricCrossAttnProcessor()
                          out_pos = attn_with_weights(
                              self,
                              cond_hiddens,
                              encoder_hidden_states=cond_pos_hs,
                              weights=pos_weights,
                          )
                      else:
                          out_pos = self.old_forward(cond_hiddens)
  
                      if cached_neg_hiddens is not None:
                          cached_neg_hs = cached_neg_hiddens.pop(0).to(
                              hidden_states.device
                          )
                          uncond_neg_hs = torch.cat(
                              [uncond_hiddens, cached_neg_hs], dim=1
                          )
                          neg_weights = weights.clone().repeat(
                              1, 1 + cached_neg_hs.shape[1] // d_model
                          )
                          neg_weights[:, d_model:] = neg_weight
                          attn_with_weights = FabricCrossAttnProcessor()
                          out_neg = attn_with_weights(
                              self,
                              uncond_hiddens,
                              encoder_hidden_states=uncond_neg_hs,
                              weights=neg_weights,
                          )
                      else:
                          out_neg = self.old_forward(uncond_hiddens)
  
                      out = torch.cat([out_pos, out_neg], dim=0)
                      return out
  
                  module.attn1.old_forward = module.attn1.forward
                  module.attn1.forward = new_forward.__get__(
                      module.attn1
                  )
  
      out = self.unet(z_all, t, encoder_hidden_states=prompt_embd)
  
      # restore original forward pass
      for module in self.unet.modules():
          if isinstance(module, BasicTransformerBlock):
              module.attn1.forward = module.attn1.old_forward
              del module.attn1.old_forward
  
      return out
  
imports: from typing import List, Optional, Union
  import torch
  from packaging import version
  from PIL import Image
  from transformers import CLIPTextModel, CLIPTokenizer
  from diffusers import AutoencoderKL, UNet2DConditionModel
  from diffusers.configuration_utils import FrozenDict
  from diffusers.image_processor import VaeImageProcessor
  from diffusers.loaders import LoraLoaderMixin, TextualInversionLoaderMixin
  from diffusers.models.attention import BasicTransformerBlock
  from diffusers.models.attention_processor import LoRAAttnProcessor
  from diffusers.pipelines.pipeline_utils import DiffusionPipeline
  from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
  from diffusers.schedulers import EulerAncestralDiscreteScheduler, KarrasDiffusionSchedulers
  from diffusers.utils import deprecate, logging, replace_example_docstring
  from diffusers.utils.torch_utils import randn_tensor
label_desc: Use image node_id 4 for calling the FabricPipeline obj's underlying member method code with example usage: obj.unet_forward_with_cached_hidden_states(z_all, t, prompt_embd, cached_pos_hiddens, cached_neg_hiddens, pos_weights, neg_weights) and returns: out, self, out