class_docstr: Pipeline for text-to-image generation using Stable Diffusion on IPEX.
  
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
  library implements for all the pipelines (such as downloading or 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 ([`CLIPTextModel`]):
          Frozen text-encoder. Stable Diffusion uses the text portion of
          [CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel), specifically
          the [clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14) variant.
      tokenizer (`CLIPTokenizer`):
          Tokenizer of class
          [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer).
      unet ([`UNet2DConditionModel`]): Conditional U-Net architecture to denoise the encoded image latents.
      scheduler ([`SchedulerMixin`]):
          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 details.
      feature_extractor ([`CLIPFeatureExtractor`]):
          Model that extracts features from generated images to be used as inputs for the `safety_checker`.
class_docstr_tok: ["Pipeline","for","text-to-image","generation","using","Stable","Diffusion","on","IPEX",".","This","model","inherits","from","[","`","DiffusionPipeline","`","]",".","Check","the","superclass","documentation","for","the","generic","methods","the","library","implements","for","all","the","pipelines","(","such","as","downloading","or","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","(","[","`","CLIPTextModel","`","]",")",":","Frozen","text-encoder",".","Stable","Diffusion","uses","the","text","portion","of","[","CLIP","]","(","https",":","\/\/huggingface.co\/docs\/transformers\/model_doc\/clip","#","transformers.CLIPTextModel",")",",","specifically","the","[","clip-vit-large-patch14","]","(","https",":","\/\/huggingface.co\/openai\/clip-vit-large-patch14",")","variant",".","tokenizer","(","`","CLIPTokenizer","`",")",":","Tokenizer","of","class","[","CLIPTokenizer","]","(","https",":","\/\/huggingface.co\/docs\/transformers\/v4.21.0\/en\/model_doc\/clip","#","transformers.CLIPTokenizer",")",".","unet","(","[","`","UNet2DConditionModel","`","]",")",":","Conditional","U-Net","architecture","to","denoise","the","encoded","image","latents",".","scheduler","(","[","`","SchedulerMixin","`","]",")",":","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","details",".","feature_extractor","(","[","`","CLIPFeatureExtractor","`","]",")",":","Model","that","extracts","features","from","generated","images","to","be","used","as","inputs","for","the","`","safety_checker","`","."]
code: def prepare_for_ipex(
      self,
      promt,
      dtype=torch.float32,
      height=None,
      width=None,
      guidance_scale=7.5,
  ):
      self.unet = self.unet.to(memory_format=torch.channels_last)
      self.vae.decoder = self.vae.decoder.to(
          memory_format=torch.channels_last
      )
      self.text_encoder = self.text_encoder.to(
          memory_format=torch.channels_last
      )
      if self.safety_checker is not None:
          self.safety_checker = self.safety_checker.to(
              memory_format=torch.channels_last
          )
  
      (
          unet_input_example,
          vae_decoder_input_example,
      ) = self.get_input_example(promt, height, width, guidance_scale)
  
      # optimize with ipex
      if dtype == torch.bfloat16:
          self.unet = ipex.optimize(
              self.unet.eval(),
              dtype=torch.bfloat16,
              inplace=True,
              sample_input=unet_input_example,
          )
          self.vae.decoder = ipex.optimize(
              self.vae.decoder.eval(),
              dtype=torch.bfloat16,
              inplace=True,
          )
          self.text_encoder = ipex.optimize(
              self.text_encoder.eval(),
              dtype=torch.bfloat16,
              inplace=True,
          )
          if self.safety_checker is not None:
              self.safety_checker = ipex.optimize(
                  self.safety_checker.eval(),
                  dtype=torch.bfloat16,
                  inplace=True,
              )
      elif dtype == torch.float32:
          self.unet = ipex.optimize(
              self.unet.eval(),
              dtype=torch.float32,
              inplace=True,
              sample_input=unet_input_example,
              level="O1",
              weights_prepack=True,
              auto_kernel_selection=False,
          )
          self.vae.decoder = ipex.optimize(
              self.vae.decoder.eval(),
              dtype=torch.float32,
              inplace=True,
              level="O1",
              weights_prepack=True,
              auto_kernel_selection=False,
          )
          self.text_encoder = ipex.optimize(
              self.text_encoder.eval(),
              dtype=torch.float32,
              inplace=True,
              level="O1",
              weights_prepack=True,
              auto_kernel_selection=False,
          )
          if self.safety_checker is not None:
              self.safety_checker = ipex.optimize(
                  self.safety_checker.eval(),
                  dtype=torch.float32,
                  inplace=True,
                  level="O1",
                  weights_prepack=True,
                  auto_kernel_selection=False,
              )
      else:
          raise ValueError(
              " The value of 'dtype' should be 'torch.bfloat16' or 'torch.float32' !"
          )
  
      # trace unet model to get better performance on IPEX
      with torch.cpu.amp.autocast(
          enabled=dtype == torch.bfloat16
      ), torch.no_grad():
          unet_trace_model = torch.jit.trace(
              self.unet,
              unet_input_example,
              check_trace=False,
              strict=False,
          )
          unet_trace_model = torch.jit.freeze(unet_trace_model)
      self.unet.forward = unet_trace_model.forward
  
      # trace vae.decoder model to get better performance on IPEX
      with torch.cpu.amp.autocast(
          enabled=dtype == torch.bfloat16
      ), torch.no_grad():
          ave_decoder_trace_model = torch.jit.trace(
              self.vae.decoder,
              vae_decoder_input_example,
              check_trace=False,
              strict=False,
          )
          ave_decoder_trace_model = torch.jit.freeze(
              ave_decoder_trace_model
          )
      self.vae.decoder.forward = ave_decoder_trace_model.forward
  
imports: import inspect
  from typing import Any, Callable, Dict, List, Optional, Union
  import intel_extension_for_pytorch
  import torch
  from packaging import version
  from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer
  from diffusers.configuration_utils import FrozenDict
  from diffusers.models import AutoencoderKL, UNet2DConditionModel
  from diffusers.pipeline_utils import DiffusionPipeline
  from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
  from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import deprecate, is_accelerate_available, is_accelerate_version, logging, replace_example_docstring
  from diffusers.utils.torch_utils import randn_tensor
label_desc: Use image node_id 3 for calling the StableDiffusionIPEXPipeline obj's underlying member method code with example usage: obj.prepare_for_ipex(promt, dtype, height, width, guidance_scale) without return types