text
stringlengths
0
5.54k
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.)
Pipeline for sampling actions from a diffusion model trained to predict sequences of states.
Original implementation inspired by this repository: https://github.com/jannerm/diffuser.
DDIM Denoising Diffusion Implicit Models (DDIM) by Jiaming Song, Chenlin Meng and Stefano Ermon. The abstract from the paper is: Denoising diffusion probabilistic models (DDPMs) have achieved high quality image generation without adversarial training, yet they require simulating a Markov chain for many steps to produce...
A UNet2DModel to denoise the encoded image latents. scheduler (SchedulerMixin) —
A scheduler to be used in combination with unet to denoise the encoded image. Can be one of
DDPMScheduler, or DDIMScheduler. Pipeline for image generation. 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.). __call__ < source > ( batch_size: int = 1 generator: Union = None eta: float = 0.0 num_inference_steps: int = 50 use_clipped_model_output: Optional = None output_type: Optional = 'pil' return_dict: bool = True ) → ImagePipelin...
The number of images to generate. generator (torch.Generator, optional) —
A torch.Generator to make
generation deterministic. eta (float, optional, defaults to 0.0) —
Corresponds to parameter eta (η) from the DDIM paper. Only applies
to the DDIMScheduler, and is ignored in other schedulers. A value of 0 corresponds to
DDIM and 1 corresponds to DDPM. num_inference_steps (int, optional, defaults to 50) —
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference. use_clipped_model_output (bool, optional, defaults to None) —
If True or False, see documentation for DDIMScheduler.step(). If None, nothing is passed
downstream to the scheduler (use None for schedulers which don’t support this argument). output_type (str, optional, defaults to "pil") —
The output format of the generated image. Choose between PIL.Image or np.array. return_dict (bool, optional, defaults to True) —
Whether or not to return a ImagePipelineOutput instead of a plain tuple. Returns
ImagePipelineOutput or tuple
If return_dict is True, ImagePipelineOutput is returned, otherwise a tuple is
returned where the first element is a list with the generated images
The call function to the pipeline for generation. Example: Copied >>> from diffusers import DDIMPipeline
>>> import PIL.Image
>>> import numpy as np
>>> # load model and scheduler
>>> pipe = DDIMPipeline.from_pretrained("fusing/ddim-lsun-bedroom")
>>> # run pipeline in inference (sample random noise and denoise)
>>> image = pipe(eta=0.0, num_inference_steps=50)
>>> # process image to PIL
>>> image_processed = image.cpu().permute(0, 2, 3, 1)
>>> image_processed = (image_processed + 1.0) * 127.5
>>> image_processed = image_processed.numpy().astype(np.uint8)
>>> image_pil = PIL.Image.fromarray(image_processed[0])
>>> # save image
>>> image_pil.save("test.png") ImagePipelineOutput class diffusers.ImagePipelineOutput < source > ( images: Union ) Parameters images (List[PIL.Image.Image] or np.ndarray) —
List of denoised PIL images of length batch_size or NumPy array of shape (batch_size, height, width, num_channels). Output class for image pipelines.
How to use Stable Diffusion on Habana Gaudi
🤗 Diffusers is compatible with Habana Gaudi through 🤗 Optimum Habana.
Requirements
Optimum Habana 1.5 or later, here is how to install it.
SynapseAI 1.9.
Inference Pipeline
To generate images with Stable Diffusion 1 and 2 on Gaudi, you need to instantiate two instances:
A pipeline with GaudiStableDiffusionPipeline. This pipeline supports text-to-image generation.
A scheduler with GaudiDDIMScheduler. This scheduler has been optimized for Habana Gaudi.
When initializing the pipeline, you have to specify use_habana=True to deploy it on HPUs.
Furthermore, in order to get the fastest possible generations you should enable HPU graphs with use_hpu_graphs=True.
Finally, you will need to specify a Gaudi configuration which can be downloaded from the Hugging Face Hub.
Copied
from optimum.habana import GaudiConfig
from optimum.habana.diffusers import GaudiDDIMScheduler, GaudiStableDiffusionPipeline
model_name = "stabilityai/stable-diffusion-2-base"
scheduler = GaudiDDIMScheduler.from_pretrained(model_name, subfolder="scheduler")
pipeline = GaudiStableDiffusionPipeline.from_pretrained(
model_name,
scheduler=scheduler,
use_habana=True,
use_hpu_graphs=True,
gaudi_config="Habana/stable-diffusion",
)
You can then call the pipeline to generate images by batches from one or several prompts:
Copied
outputs = pipeline(
prompt=[
"High quality photo of an astronaut riding a horse in space",
"Face of a yellow cat, high resolution, sitting on a park bench",
],
num_images_per_prompt=10,
batch_size=4,
)
For more information, check out Optimum Habana’s documentation and the example provided in the official Github repository.
Benchmark
Here are the latencies for Habana first-generation Gaudi and Gaudi2 with the Habana/stable-diffusion Gaudi configuration (mixed precision bf16/fp32):
Stable Diffusion v1.5 (512x512 resolution):
Latency (batch size = 1)
Throughput (batch size = 8)
first-generation Gaudi
4.22s
0.29 images/s