From fafc3523fc3ac0512dc7feaa1d785e0fcee24a84 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sun, 18 Dec 2022 21:46:24 -1000 Subject: [PATCH 01/23] add a doc page for each pipeline under api/pipelines/stable_diffusion add pipeline examples to docstrings updated stable_diffusion_2 page added descriptions for each stable diffusion pipeline --- docs/source/_toctree.yml | 17 ++++++++- docs/source/api/pipelines/alt_diffusion.mdx | 2 +- .../pipelines/stable_diffusion/depth2img.mdx | 32 ++++++++++++++++ .../stable_diffusion/image_variation.mdx | 30 +++++++++++++++ .../pipelines/stable_diffusion/img2img.mdx | 28 ++++++++++++++ .../pipelines/stable_diffusion/inpaint.mdx | 32 ++++++++++++++++ .../overview.mdx} | 11 ++++-- .../pipelines/stable_diffusion/text2img.mdx | 38 +++++++++++++++++++ .../pipelines/stable_diffusion/upscale.mdx | 31 +++++++++++++++ .../api/pipelines/stable_diffusion_2.mdx | 30 ++++++++------- .../api/pipelines/stable_diffusion_safe.mdx | 2 +- .../api/pipelines/versatile_diffusion.mdx | 2 +- docs/source/index.mdx | 6 +-- docs/source/quicktour.mdx | 2 +- .../alt_diffusion/pipeline_alt_diffusion.py | 12 ++++++ .../pipeline_alt_diffusion_img2img.py | 26 +++++++++++++ .../pipeline_stable_diffusion.py | 14 +++++++ .../pipeline_stable_diffusion_depth2img.py | 22 +++++++++++ .../pipeline_stable_diffusion_img2img.py | 28 ++++++++++++++ .../pipeline_stable_diffusion_inpaint.py | 29 ++++++++++++++ .../pipeline_stable_diffusion_upscale.py | 26 +++++++++++++ 21 files changed, 395 insertions(+), 25 deletions(-) create mode 100644 docs/source/api/pipelines/stable_diffusion/depth2img.mdx create mode 100644 docs/source/api/pipelines/stable_diffusion/image_variation.mdx create mode 100644 docs/source/api/pipelines/stable_diffusion/img2img.mdx create mode 100644 docs/source/api/pipelines/stable_diffusion/inpaint.mdx rename docs/source/api/pipelines/{stable_diffusion.mdx => stable_diffusion/overview.mdx} (79%) create mode 100644 docs/source/api/pipelines/stable_diffusion/text2img.mdx create mode 100644 docs/source/api/pipelines/stable_diffusion/upscale.mdx diff --git a/docs/source/_toctree.yml b/docs/source/_toctree.yml index 52ad170dc33a..698d30f3fab6 100644 --- a/docs/source/_toctree.yml +++ b/docs/source/_toctree.yml @@ -91,6 +91,7 @@ - local: api/outputs title: "Outputs" title: "Main Classes" + - sections: - local: api/pipelines/overview title: "Overview" @@ -112,7 +113,21 @@ title: "PNDM" - local: api/pipelines/score_sde_ve title: "Score SDE VE" - - local: api/pipelines/stable_diffusion + - sections: + - local: api/pipelines/stable_diffusion/overview + title: "Overview" + - local: api/pipelines/stable_diffusion/text2img + title: "Text-to-Image" + - local: api/pipelines/stable_diffusion/img2img + title: "Image-to-Image" + - local: api/pipelines/stable_diffusion/inpaint + title: "Inpaint" + - local: api/pipelines/stable_diffusion/depth2img + title: "Depth-to-Image" + - local: api/pipelines/stable_diffusion/image_variation + title: "Image-Variation" + - local: api/pipelines/stable_diffusion/upscale + title: "Super-Resolution" title: "Stable Diffusion" - local: api/pipelines/stable_diffusion_2 title: "Stable Diffusion 2" diff --git a/docs/source/api/pipelines/alt_diffusion.mdx b/docs/source/api/pipelines/alt_diffusion.mdx index 0f497a390a7c..95bc80b1365c 100644 --- a/docs/source/api/pipelines/alt_diffusion.mdx +++ b/docs/source/api/pipelines/alt_diffusion.mdx @@ -28,7 +28,7 @@ The abstract of the paper is the following: ## Tips -- AltDiffusion is conceptually exaclty the same as [Stable Diffusion](./api/pipelines/stable_diffusion). +- AltDiffusion is conceptually exaclty the same as [Stable Diffusion](./api/pipelines/stable_diffusion/overview). - *Run AltDiffusion* diff --git a/docs/source/api/pipelines/stable_diffusion/depth2img.mdx b/docs/source/api/pipelines/stable_diffusion/depth2img.mdx new file mode 100644 index 000000000000..47f02b5178b4 --- /dev/null +++ b/docs/source/api/pipelines/stable_diffusion/depth2img.mdx @@ -0,0 +1,32 @@ + + +# Depth-to-Image Generation + +## StableDiffusionDepth2ImgPipeline + +The depth-guided stable diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), and [LAION](https://laion.ai/), as part of Stable Diffusion 2.0. It uses [MiDas](https://github.com/isl-org/MiDaS) to infer depth based on an image. + +[`StableDiffusionDepth2ImgPipeline`] lets you pass a text prompt and an initial image to condition the generation of new images as well as a `depth_map` to preserve the images’ structure. + +The original codebase can be found here: +- *Stable Diffusion v2*: [Stability-AI/stablediffusion](https://github.com/Stability-AI/stablediffusion#depth-conditional-stable-diffusion) + +Available Checkpoints are: +- *stable-diffusion-2-depth*: [stabilityai/stable-diffusion-2-depth](https://huggingface.co/stabilityai/stable-diffusion-2-depth) + +[[autodoc]] StableDiffusionDepth2ImgPipeline + - __call__ + - enable_attention_slicing + - disable_attention_slicing + - enable_xformers_memory_efficient_attention + - disable_xformers_memory_efficient_attention \ No newline at end of file diff --git a/docs/source/api/pipelines/stable_diffusion/image_variation.mdx b/docs/source/api/pipelines/stable_diffusion/image_variation.mdx new file mode 100644 index 000000000000..63b8ceb2f89d --- /dev/null +++ b/docs/source/api/pipelines/stable_diffusion/image_variation.mdx @@ -0,0 +1,30 @@ + + +# Image Variation + +## StableDiffusionImageVariationPipeline + +[`StableDiffusionImageVariationPipeline`] lets you generate variations from an input image using Stable Diffusion. It uses a fine-tuned version of Stable Diffusion model, trained by [Justin Pinkney](https://www.justinpinkney.com/) (@Buntworthy) at [Lambda](https://lambdalabs.com/) + +The original codebase can be found here: +[Stable Diffusion Image Variations](https://github.com/LambdaLabsML/lambda-diffusers#stable-diffusion-image-variations) + +Available Checkpoints are: +- *sd-image-variations-diffusers*: [lambdalabs/sd-image-variations-diffusers](https://huggingface.co/lambdalabs/sd-image-variations-diffusers) + +[[autodoc]] StableDiffusionImageVariationPipeline + - __call__ + - enable_attention_slicing + - disable_attention_slicing + - enable_xformers_memory_efficient_attention + - disable_xformers_memory_efficient_attention \ No newline at end of file diff --git a/docs/source/api/pipelines/stable_diffusion/img2img.mdx b/docs/source/api/pipelines/stable_diffusion/img2img.mdx new file mode 100644 index 000000000000..b019eb9afb7d --- /dev/null +++ b/docs/source/api/pipelines/stable_diffusion/img2img.mdx @@ -0,0 +1,28 @@ + + +# Image-to-Image Generation + +## StableDiffusionImg2ImgPipeline + +The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), and [LAION](https://laion.ai/). The [`StableDiffusionImg2ImgPipeline`] lets you pass a text prompt and an initial image to condition the generation of new images using Stable Diffusion. + +The original codebase can be found here: [CampVis/stable-diffusion](https://github.com/CompVis/stable-diffusion/blob/main/scripts/img2img.py) + +[`StableDiffusionImg2ImgPipeline`] is compatible with all Stable Diffusion checkpoints for [Text-to-Image](./text2img) + +[[autodoc]] StableDiffusionImg2ImgPipeline + - __call__ + - enable_attention_slicing + - disable_attention_slicing + - enable_xformers_memory_efficient_attention + - disable_xformers_memory_efficient_attention \ No newline at end of file diff --git a/docs/source/api/pipelines/stable_diffusion/inpaint.mdx b/docs/source/api/pipelines/stable_diffusion/inpaint.mdx new file mode 100644 index 000000000000..e6b7cadcd937 --- /dev/null +++ b/docs/source/api/pipelines/stable_diffusion/inpaint.mdx @@ -0,0 +1,32 @@ + + +# Text-Guided Image Inpainting + +## StableDiffusionInpaintPipeline + +The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), and [LAION](https://laion.ai/). The [`StableDiffusionInpaintPipeline`] lets you edit specific parts of an image by providing a mask and a text prompt using Stable Diffusion. + +The original codebase can be found here: +- *Stable Diffusion V1*: [CampVis/stable-diffusion](https://github.com/runwayml/stable-diffusion#inpainting-with-stable-diffusion) +- *Stable Diffusion V2*: [Stability-AI/stablediffusion](https://github.com/Stability-AI/stablediffusion#image-inpainting-with-stable-diffusion) + +Available checkpoints are: +- *stable-diffusion-inpainting (512x512 resolution)*: [runwayml/stable-diffusion-inpainting](https://huggingface.co/runwayml/stable-diffusion-inpainting) +- *stable-diffusion-2-inpainting (512x512 resolution)*: [stabilityai/stable-diffusion-2-inpainting](https://huggingface.co/stabilityai/stable-diffusion-2-inpainting) + +[[autodoc]] StableDiffusionInpaintPipeline + - __call__ + - enable_attention_slicing + - disable_attention_slicing + - enable_xformers_memory_efficient_attention + - disable_xformers_memory_efficient_attention \ No newline at end of file diff --git a/docs/source/api/pipelines/stable_diffusion.mdx b/docs/source/api/pipelines/stable_diffusion/overview.mdx similarity index 79% rename from docs/source/api/pipelines/stable_diffusion.mdx rename to docs/source/api/pipelines/stable_diffusion/overview.mdx index fe28155600ce..d35389ecb080 100644 --- a/docs/source/api/pipelines/stable_diffusion.mdx +++ b/docs/source/api/pipelines/stable_diffusion/overview.mdx @@ -25,9 +25,14 @@ For more details about how Stable Diffusion works and how it differs from the ba | Pipeline | Tasks | Colab | Demo |---|---|:---:|:---:| -| [pipeline_stable_diffusion.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py) | *Text-to-Image Generation* | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/stable_diffusion.ipynb) | [🤗 Stable Diffusion](https://huggingface.co/spaces/stabilityai/stable-diffusion) -| [pipeline_stable_diffusion_img2img.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py) | *Image-to-Image Text-Guided Generation* | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/image_2_image_using_diffusers.ipynb) | [🤗 Diffuse the Rest](https://huggingface.co/spaces/huggingface/diffuse-the-rest) -| [pipeline_stable_diffusion_inpaint.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py) | **Experimental** – *Text-Guided Image Inpainting* | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb) | Coming soon +| [StableDiffusionPipeline](./text2img) | *Text-to-Image Generation* | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/stable_diffusion.ipynb) | [🤗 Stable Diffusion](https://huggingface.co/spaces/stabilityai/stable-diffusion) +| [StableDiffusionImg2ImgPipeline](./img2img) | *Image-to-Image Text-Guided Generation* | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/image_2_image_using_diffusers.ipynb) | [🤗 Diffuse the Rest](https://huggingface.co/spaces/huggingface/diffuse-the-rest) +| [StableDiffusionInpaintPipeline](./inpaint) | **Experimental** – *Text-Guided Image Inpainting* | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb) | Coming soon +| [StableDiffusionDepth2ImgPipeline](./depth2img) | **Experimental** – *Depth-to-Image Text-Guided Generation * | | Coming soon +| [StableDiffusionImageVariationPipeline](./image_variation) | **Experimental** – *Image Variation Generation * | | [🤗 Stable Diffusion Image Variations](https://huggingface.co/spaces/lambdalabs/stable-diffusion-image-variations) +| [StableDiffusionUpscalePipeline](./upscale) | **Experimental** – *Text-Guided Image Super-Resolution * | | Coming soon + + ## Tips diff --git a/docs/source/api/pipelines/stable_diffusion/text2img.mdx b/docs/source/api/pipelines/stable_diffusion/text2img.mdx new file mode 100644 index 000000000000..168f5d112e16 --- /dev/null +++ b/docs/source/api/pipelines/stable_diffusion/text2img.mdx @@ -0,0 +1,38 @@ + + +# Text-to-Image Generation + +## StableDiffusionPipeline + +The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), and [LAION](https://laion.ai/). The [`StableDiffusionPipeline`] is capable of generating photo-realistic images given any text input using Stable Diffusion. + +The original codebase can be found here: +- *Stable Diffusion V1*: [CampVis/stable-diffusion](https://github.com/CompVis/stable-diffusion) +- *Stable Diffusion v2*: [Stability-AI/stablediffusion](https://github.com/Stability-AI/stablediffusion) + +Available Checkpoints are: +- *stable-diffusion-v1-4 (512x512 resolution)* [CompVis/stable-diffusion-v1-4](https://huggingface.co/CompVis/stable-diffusion-v1-4) +- *stable-diffusion-v1-5 (512x512 resolution)* [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5) +- *stable-diffusion-2-base (512x512 resolution)*: [stabilityai/stable-diffusion-2-base](https://huggingface.co/stabilityai/stable-diffusion-2-base) +- *stable-diffusion-2 (768x768 resolution)*: [stabilityai/stable-diffusion-2](https://huggingface.co/stabilityai/stable-diffusion-2) +- *stable-diffusion-2-1-base (512x512 resolution)* [stabilityai/stable-diffusion-2-1-base](https://huggingface.co/stabilityai/stable-diffusion-2-1-base) +- *stable-diffusion-2-1 (768x768 resolution)*: [stabilityai/stable-diffusion-2-1](https://huggingface.co/stabilityai/stable-diffusion-2-1) + +[[autodoc]] StableDiffusionPipeline + - __call__ + - enable_attention_slicing + - disable_attention_slicing + - enable_vae_slicing + - disable_vae_slicing + - enable_xformers_memory_efficient_attention + - disable_xformers_memory_efficient_attention \ No newline at end of file diff --git a/docs/source/api/pipelines/stable_diffusion/upscale.mdx b/docs/source/api/pipelines/stable_diffusion/upscale.mdx new file mode 100644 index 000000000000..bb9c545c787f --- /dev/null +++ b/docs/source/api/pipelines/stable_diffusion/upscale.mdx @@ -0,0 +1,31 @@ + + +# Super-Resolution + +## StableDiffusionUpscalePipeline + +The upscaler diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), and [LAION](https://laion.ai/), as part of Stable Diffusion 2.0. [`StableDiffusionUpscalePipeline`] can be used to enhance the resolution of input images by a factor of 4. + +The original codebase can be found here: +- *Stable Diffusion v2*: [Stability-AI/stablediffusion](https://github.com/Stability-AI/stablediffusion#image-upscaling-with-stable-diffusion) + +Available Checkpoints are: +- *stabilityai/stable-diffusion-x4-upscaler (x4 resolution resolution)*: [stable-diffusion-x4-upscaler](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler) + + +[[autodoc]] StableDiffusionUpscalePipeline + - __call__ + - enable_attention_slicing + - disable_attention_slicing + - enable_xformers_memory_efficient_attention + - disable_xformers_memory_efficient_attention \ No newline at end of file diff --git a/docs/source/api/pipelines/stable_diffusion_2.mdx b/docs/source/api/pipelines/stable_diffusion_2.mdx index 3dce6da4f429..67cb9c792059 100644 --- a/docs/source/api/pipelines/stable_diffusion_2.mdx +++ b/docs/source/api/pipelines/stable_diffusion_2.mdx @@ -24,17 +24,20 @@ For more details about how Stable Diffusion 2 works and how it differs from Stab ### Available checkpoints: -Note that the architecture is more or less identical to [Stable Diffusion 1](./api/pipelines/stable_diffusion) so please refer to [this page](./api/pipelines/stable_diffusion) for API documentation. +Note that the architecture is more or less identical to [Stable Diffusion 1](./stable_diffusion/overview) so please refer to [this page](./stable_diffusion/overview) for API documentation. - *Text-to-Image (512x512 resolution)*: [stabilityai/stable-diffusion-2-base](https://huggingface.co/stabilityai/stable-diffusion-2-base) with [`StableDiffusionPipeline`] - *Text-to-Image (768x768 resolution)*: [stabilityai/stable-diffusion-2](https://huggingface.co/stabilityai/stable-diffusion-2) with [`StableDiffusionPipeline`] - *Image Inpainting (512x512 resolution)*: [stabilityai/stable-diffusion-2-inpainting](https://huggingface.co/stabilityai/stable-diffusion-2-inpainting) with [`StableDiffusionInpaintPipeline`] -- *Image Upscaling (x4 resolution resolution)*: [stable-diffusion-x4-upscaler](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler) [`StableDiffusionUpscalePipeline`] +- *Super-Resolution (x4 resolution resolution)*: [stable-diffusion-x4-upscaler](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler) [`StableDiffusionUpscalePipeline`] - *Depth-to-Image (512x512 resolution)*: [stabilityai/stable-diffusion-2-depth](https://huggingface.co/stabilityai/stable-diffusion-2-depth) with [`StableDiffusionDepth2ImagePipeline`] We recommend using the [`DPMSolverMultistepScheduler`] as it's currently the fastest scheduler there is. -- *Text-to-Image (512x512 resolution)*: + +### Text-to-Image + +- *Text-to-Image (512x512 resolution)*: [stabilityai/stable-diffusion-2-base](https://huggingface.co/stabilityai/stable-diffusion-2-base) with [`StableDiffusionPipeline`] ```python from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler @@ -51,7 +54,7 @@ image = pipe(prompt, num_inference_steps=25).images[0] image.save("astronaut.png") ``` -- *Text-to-Image (768x768 resolution)*: +- *Text-to-Image (768x768 resolution)*: [stabilityai/stable-diffusion-2](https://huggingface.co/stabilityai/stable-diffusion-2) with [`StableDiffusionPipeline`] ```python from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler @@ -68,7 +71,9 @@ image = pipe(prompt, guidance_scale=9, num_inference_steps=25).images[0] image.save("astronaut.png") ``` -- *Image Inpainting (512x512 resolution)*: +### Image Inpainting + +- *Image Inpainting (512x512 resolution)*: [stabilityai/stable-diffusion-2-inpainting](https://huggingface.co/stabilityai/stable-diffusion-2-inpainting) with [`StableDiffusionInpaintPipeline`] ```python import PIL @@ -102,7 +107,10 @@ image = pipe(prompt=prompt, image=init_image, mask_image=mask_image, num_inferen image.save("yellow_cat.png") ``` -- *Image Upscaling (x4 resolution resolution)*: [stable-diffusion-x4-upscaler](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler) [`StableDiffusionUpscalePipeline`] +### Super-Resolution + +- *Image Upscaling (x4 resolution resolution)*: [stable-diffusion-x4-upscaler](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler) with [`StableDiffusionUpscalePipeline`] + ```python import requests @@ -126,16 +134,10 @@ upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0] upscaled_image.save("upsampled_cat.png") ``` -- *Depth-Guided Text-to-Image*: [stabilityai/stable-diffusion-2-depth](https://huggingface.co/stabilityai/stable-diffusion-2-depth) [`StableDiffusionDepth2ImagePipeline`] - -**Installation** +### Depth-to-Image -```bash -!pip install -U git+https://github.com/huggingface/transformers.git -!pip install diffusers[torch] -``` +- *Depth-Guided Text-to-Image*: [stabilityai/stable-diffusion-2-depth](https://huggingface.co/stabilityai/stable-diffusion-2-depth) [`StableDiffusionDepth2ImagePipeline`] -**Example** ```python import torch diff --git a/docs/source/api/pipelines/stable_diffusion_safe.mdx b/docs/source/api/pipelines/stable_diffusion_safe.mdx index c700b9c9f69e..be46907ff49f 100644 --- a/docs/source/api/pipelines/stable_diffusion_safe.mdx +++ b/docs/source/api/pipelines/stable_diffusion_safe.mdx @@ -28,7 +28,7 @@ The abstract of the paper is the following: ## Tips -- Safe Stable Diffusion may also be used with weights of [Stable Diffusion](./api/pipelines/stable_diffusion). +- Safe Stable Diffusion may also be used with weights of [Stable Diffusion](./api/pipelines/stable_diffusion/overview). ### Run Safe Stable Diffusion diff --git a/docs/source/api/pipelines/versatile_diffusion.mdx b/docs/source/api/pipelines/versatile_diffusion.mdx index 80da6768bfcf..6231ce6a1aa6 100644 --- a/docs/source/api/pipelines/versatile_diffusion.mdx +++ b/docs/source/api/pipelines/versatile_diffusion.mdx @@ -20,7 +20,7 @@ The abstract of the paper is the following: ## Tips -- VersatileDiffusion is conceptually very similar as [Stable Diffusion](./api/pipelines/stable_diffusion), but instead of providing just a image data stream conditioned on text, VersatileDiffusion provides both a image and text data stream and can be conditioned on both text and image. +- VersatileDiffusion is conceptually very similar as [Stable Diffusion](./api/pipelines/stable_diffusion/overview), but instead of providing just a image data stream conditioned on text, VersatileDiffusion provides both a image and text data stream and can be conditioned on both text and image. ### *Run VersatileDiffusion* diff --git a/docs/source/index.mdx b/docs/source/index.mdx index a532aa099ec3..148ee53f411f 100644 --- a/docs/source/index.mdx +++ b/docs/source/index.mdx @@ -47,9 +47,9 @@ available a colab notebook to directly try them out. | [pndm](./api/pipelines/pndm) | [**Pseudo Numerical Methods for Diffusion Models on Manifolds**](https://arxiv.org/abs/2202.09778) | Unconditional Image Generation | | [score_sde_ve](./api/pipelines/score_sde_ve) | [**Score-Based Generative Modeling through Stochastic Differential Equations**](https://openreview.net/forum?id=PxTIG12RRHS) | Unconditional Image Generation | | [score_sde_vp](./api/pipelines/score_sde_vp) | [**Score-Based Generative Modeling through Stochastic Differential Equations**](https://openreview.net/forum?id=PxTIG12RRHS) | Unconditional Image Generation | -| [stable_diffusion](./api/pipelines/stable_diffusion) | [**Stable Diffusion**](https://stability.ai/blog/stable-diffusion-public-release) | Text-to-Image Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/training_example.ipynb) -| [stable_diffusion](./api/pipelines/stable_diffusion) | [**Stable Diffusion**](https://stability.ai/blog/stable-diffusion-public-release) | Image-to-Image Text-Guided Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/image_2_image_using_diffusers.ipynb) -| [stable_diffusion](./api/pipelines/stable_diffusion) | [**Stable Diffusion**](https://stability.ai/blog/stable-diffusion-public-release) | Text-Guided Image Inpainting | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb) +| [stable_diffusion](./api/pipelines/stable_diffusion/text2img) | [**Stable Diffusion**](https://stability.ai/blog/stable-diffusion-public-release) | Text-to-Image Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/training_example.ipynb) +| [stable_diffusion](./api/pipelines/stable_diffusion/img2img) | [**Stable Diffusion**](https://stability.ai/blog/stable-diffusion-public-release) | Image-to-Image Text-Guided Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/image_2_image_using_diffusers.ipynb) +| [stable_diffusion](./api/pipelines/stable_diffusion/inpaint) | [**Stable Diffusion**](https://stability.ai/blog/stable-diffusion-public-release) | Text-Guided Image Inpainting | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb) | [stable_diffusion_2](./api/pipelines/stable_diffusion_2) | [**Stable Diffusion 2**](https://stability.ai/blog/stable-diffusion-v2-release) | Text-to-Image Generation | | [stable_diffusion_2](./api/pipelines/stable_diffusion_2) | [**Stable Diffusion 2**](https://stability.ai/blog/stable-diffusion-v2-release) | Text-Guided Image Inpainting | | [stable_diffusion_2](./api/pipelines/stable_diffusion_2) | [**Stable Diffusion 2**](https://stability.ai/blog/stable-diffusion-v2-release) | Text-Guided Super Resolution Image-to-Image | diff --git a/docs/source/quicktour.mdx b/docs/source/quicktour.mdx index 05bf12127344..e9a95d3c74cb 100644 --- a/docs/source/quicktour.mdx +++ b/docs/source/quicktour.mdx @@ -22,7 +22,7 @@ pip install --upgrade diffusers accelerate transformers ``` - [`accelerate`](https://huggingface.co/docs/accelerate/index) speeds up model loading for inference and training -- [`transformers`](https://huggingface.co/docs/transformers/index) is required to run the most popular diffusion models, such as [Stable Diffusion](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion) +- [`transformers`](https://huggingface.co/docs/transformers/index) is required to run the most popular diffusion models, such as [Stable Diffusion](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/overview) ## DiffusionPipeline diff --git a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py index ab849c2f3991..4f91cb9d9708 100644 --- a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +++ b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py @@ -471,6 +471,18 @@ def __call__( The frequency at which the `callback` function will be called. If not specified, the callback will be called at every step. + Examples: + ```py + >>> import torch + >>> from diffusers import AltDiffusionPipeline + + >>> pipe = AltDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16) + >>> pipe = pipe.to("cuda") + + >>> prompt = "a photo of an astronaut riding a horse on mars" + >>> image = pipe(prompt).images[0] + ``` + Returns: [`~pipelines.stable_diffusion.AltDiffusionPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.AltDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple. diff --git a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py index c5579e4df456..43b472e1e063 100644 --- a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +++ b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py @@ -514,6 +514,32 @@ def __call__( callback_steps (`int`, *optional*, defaults to 1): The frequency at which the `callback` function will be called. If not specified, the callback will be called at every step. + Examples: + + ```py + >>> import requests + >>> import torch + >>> from PIL import Image + >>> from io import BytesIO + + >>> from diffusers import AltDiffusionImg2ImgPipeline + + >>> device = "cuda" + >>> model_id_or_path = "runwayml/stable-diffusion-v1-5" + >>> pipe = AltDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) + >>> pipe = pipe.to(device) + + >>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" + + >>> response = requests.get(url) + >>> init_image = Image.open(BytesIO(response.content)).convert("RGB") + >>> init_image = init_image.resize((768, 512)) + + >>> prompt = "A fantasy landscape, trending on artstation" + + >>> images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images + >>> images[0].save("fantasy_landscape.png") + ``` Returns: [`~pipelines.stable_diffusion.AltDiffusionPipelineOutput`] or `tuple`: diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py index b9b87e8f1425..c22147120288 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py @@ -470,6 +470,20 @@ def __call__( The frequency at which the `callback` function will be called. If not specified, the callback will be called at every step. + Examples: + ```py + >>> import torch + >>> from diffusers import StableDiffusionPipeline + + >>> pipe = StableDiffusionPipeline.from_pretrained( + ... "runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16 + ... ) + >>> pipe = pipe.to("cuda") + + >>> prompt = "a photo of an astronaut riding a horse on mars" + >>> image = pipe(prompt).images[0] + ``` + Returns: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple. diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py index e86f2d7226ba..3a6e0757d0a6 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py @@ -505,6 +505,28 @@ def __call__( The frequency at which the `callback` function will be called. If not specified, the callback will be called at every step. + Examples: + + ```py + >>> import torch + >>> import requests + >>> from PIL import Image + + >>> from diffusers import StableDiffusionDepth2ImgPipeline + + >>> pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( + ... "stabilityai/stable-diffusion-2-depth", + ... torch_dtype=torch.float16, + ... ).to("cuda") + + + >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg" + >>> init_image = Image.open(requests.get(url, stream=True).raw) + >>> prompt = "two tigers" + >>> n_propmt = "bad, deformed, ugly, bad anotomy" + >>> image = pipe(prompt=prompt, image=init_image, negative_prompt=n_propmt, strength=0.7).images[0] + ``` + Returns: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple. diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py index 0213a1a563de..90cbb4ae5fb0 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py @@ -519,6 +519,34 @@ def __call__( callback_steps (`int`, *optional*, defaults to 1): The frequency at which the `callback` function will be called. If not specified, the callback will be called at every step. + Examples: + + ```py + >>> import requests + >>> import torch + >>> from PIL import Image + >>> from io import BytesIO + + >>> from diffusers import StableDiffusionImg2ImgPipeline + + >>> device = "cuda" + >>> model_id_or_path = "runwayml/stable-diffusion-v1-5" + >>> pipe = StableDiffusionImg2ImgPipeline.from_pretrained( + ... model_id_or_path, torch_dtype=torch.float16 + ... ) + >>> pipe = pipe.to(device) + + >>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" + + >>> response = requests.get(url) + >>> init_image = Image.open(BytesIO(response.content)).convert("RGB") + >>> init_image = init_image.resize((768, 512)) + + >>> prompt = "A fantasy landscape, trending on artstation" + + >>> images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images + >>> images[0].save("fantasy_landscape.png") + ``` Returns: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`: diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py index 77e1df6e1d11..5ee43571d034 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py @@ -616,6 +616,35 @@ def __call__( The frequency at which the `callback` function will be called. If not specified, the callback will be called at every step. + Examples: + + ```py + >>> import PIL + >>> import requests + >>> import torch + >>> from io import BytesIO + + >>> from diffusers import StableDiffusionInpaintPipeline + + >>> def download_image(url): + >>> response = requests.get(url) + >>> return PIL.Image.open(BytesIO(response.content)).convert("RGB") + + >>> img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" + >>> mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" + + >>> init_image = download_image(img_url).resize((512, 512)) + >>> mask_image = download_image(mask_url).resize((512, 512)) + + >>> pipe = StableDiffusionInpaintPipeline.from_pretrained( + ... "runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16 + ... ) + >>> pipe = pipe.to("cuda") + + >>> prompt = "Face of a yellow cat, high resolution, sitting on a park bench" + >>> image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0] + ``` + Returns: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple. diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py index 236ecea59fa4..92a8cb5c9818 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py @@ -390,6 +390,32 @@ def __call__( The frequency at which the `callback` function will be called. If not specified, the callback will be called at every step. + Examples: + ```py + >>> import requests + >>> from PIL import Image + >>> from io import BytesIO + >>> from diffusers import StableDiffusionUpscalePipeline + >>> import torch + + >>> # load model and scheduler + >>> model_id = "stabilityai/stable-diffusion-x4-upscaler" + >>> pipeline = StableDiffusionUpscalePipeline.from_pretrained( + ... model_id, revision="fp16", torch_dtype=torch.float16 + ... ) + >>> pipeline = pipeline.to("cuda") + + >>> # let's download an image + >>> url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale/low_res_cat.png" + >>> response = requests.get(url) + >>> low_res_img = Image.open(BytesIO(response.content)).convert("RGB") + >>> low_res_img = low_res_img.resize((128, 128)) + >>> prompt = "a white cat" + >>> upscaled_image = pipeline( + ... prompt=prompt, image=low_res_img).images[0] + >>> upscaled_image.save("upsampled_cat.png") + ``` + Returns: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple. From ab8928c0a5833ae8e3a8c72e193aef4a3d324ffd Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sat, 31 Dec 2022 10:31:10 -1000 Subject: [PATCH 02/23] make style --- src/diffusers/models/embeddings_flax.py | 1 + .../stable_diffusion/pipeline_stable_diffusion.py | 4 +--- .../pipeline_stable_diffusion_depth2img.py | 4 ++-- .../stable_diffusion/pipeline_stable_diffusion_img2img.py | 4 +--- .../stable_diffusion/pipeline_stable_diffusion_inpaint.py | 8 +++++--- .../stable_diffusion/pipeline_stable_diffusion_upscale.py | 7 +++---- src/diffusers/training_utils.py | 1 + 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/diffusers/models/embeddings_flax.py b/src/diffusers/models/embeddings_flax.py index fbb1dbab3cb4..42d18cbac592 100644 --- a/src/diffusers/models/embeddings_flax.py +++ b/src/diffusers/models/embeddings_flax.py @@ -27,6 +27,7 @@ def get_sinusoidal_embeddings( scale: float = 1.0, ) -> jnp.ndarray: """Returns the positional encoding (same as Tensor2Tensor). + Args: timesteps: a 1-D Tensor of N indices, one per batch element. These may be fractional. diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py index c22147120288..9f3b672fa4bb 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py @@ -475,9 +475,7 @@ def __call__( >>> import torch >>> from diffusers import StableDiffusionPipeline - >>> pipe = StableDiffusionPipeline.from_pretrained( - ... "runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16 - ... ) + >>> pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16) >>> pipe = pipe.to("cuda") >>> prompt = "a photo of an astronaut riding a horse on mars" diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py index 3a6e0757d0a6..c1c873d3113b 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py @@ -515,8 +515,8 @@ def __call__( >>> from diffusers import StableDiffusionDepth2ImgPipeline >>> pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( - ... "stabilityai/stable-diffusion-2-depth", - ... torch_dtype=torch.float16, + ... "stabilityai/stable-diffusion-2-depth", + ... torch_dtype=torch.float16, ... ).to("cuda") diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py index 90cbb4ae5fb0..533a8ed30d77 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py @@ -531,9 +531,7 @@ def __call__( >>> device = "cuda" >>> model_id_or_path = "runwayml/stable-diffusion-v1-5" - >>> pipe = StableDiffusionImg2ImgPipeline.from_pretrained( - ... model_id_or_path, torch_dtype=torch.float16 - ... ) + >>> pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) >>> pipe = pipe.to(device) >>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py index 5ee43571d034..e56a22b24edb 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py @@ -626,9 +626,11 @@ def __call__( >>> from diffusers import StableDiffusionInpaintPipeline + >>> def download_image(url): - >>> response = requests.get(url) - >>> return PIL.Image.open(BytesIO(response.content)).convert("RGB") + ... response = requests.get(url) + ... return PIL.Image.open(BytesIO(response.content)).convert("RGB") + >>> img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" >>> mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" @@ -637,7 +639,7 @@ def __call__( >>> mask_image = download_image(mask_url).resize((512, 512)) >>> pipe = StableDiffusionInpaintPipeline.from_pretrained( - ... "runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16 + ... "runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16 ... ) >>> pipe = pipe.to("cuda") diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py index 92a8cb5c9818..dd9382b0718a 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py @@ -401,8 +401,8 @@ def __call__( >>> # load model and scheduler >>> model_id = "stabilityai/stable-diffusion-x4-upscaler" >>> pipeline = StableDiffusionUpscalePipeline.from_pretrained( - ... model_id, revision="fp16", torch_dtype=torch.float16 - ... ) + ... model_id, revision="fp16", torch_dtype=torch.float16 + ... ) >>> pipeline = pipeline.to("cuda") >>> # let's download an image @@ -411,8 +411,7 @@ def __call__( >>> low_res_img = Image.open(BytesIO(response.content)).convert("RGB") >>> low_res_img = low_res_img.resize((128, 128)) >>> prompt = "a white cat" - >>> upscaled_image = pipeline( - ... prompt=prompt, image=low_res_img).images[0] + >>> upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0] >>> upscaled_image.save("upsampled_cat.png") ``` diff --git a/src/diffusers/training_utils.py b/src/diffusers/training_utils.py index fa1694161fc5..fefc490c1f01 100644 --- a/src/diffusers/training_utils.py +++ b/src/diffusers/training_utils.py @@ -60,6 +60,7 @@ def __init__( to train for a million or more steps (reaches decay factor 0.999 at 31.6K steps, 0.9999 at 1M steps), gamma=1, power=3/4 for models you plan to train for less (reaches decay factor 0.999 at 10K steps, 0.9999 at 215.4k steps). + Args: inv_gamma (float): Inverse multiplicative factor of EMA warmup. Default: 1. power (float): Exponential factor of EMA warmup. Default: 2/3. From 897c7db99765194ec997ac4170b2f7b7f78c8cc2 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sun, 1 Jan 2023 17:32:28 -1000 Subject: [PATCH 03/23] updated default markdown syntax to list methods based on https://github.com/huggingface/diffusers/pull/1870 --- docs/README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/docs/README.md b/docs/README.md index 23b96fa82a85..87bbfbe22a61 100644 --- a/docs/README.md +++ b/docs/README.md @@ -126,23 +126,18 @@ When adding a new pipeline: - Paper abstract - Tips and tricks and how to use it best - Possible an end-to-end example of how to use it -- Add all the pipeline classes that should be linked in the diffusion model. These classes should be added using our Markdown syntax. Usually as follows: - -``` -## XXXPipeline - -[[autodoc]] XXXPipeline -``` - -This will include every public method of the pipeline that is documented. You can specify which methods should be in the docs: +- Add all the pipeline classes that should be linked in the diffusion model. These classes should be added using our Markdown syntax. By default as follows: ``` ## XXXPipeline [[autodoc]] XXXPipeline + - all - __call__ ``` +This will include every public method of the pipeline that is documented, as well as the magic method like `__call__` are not documented by default. If you just want to add another method that is not documented, you can put the list of methods to add in a list that contains `all`. + You can follow the same process to create a new scheduler under the `docs/source/api/schedulers` folder ### Writing source documentation From b8a51f7044ea6606298aedd40b4c18b38c360de9 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sun, 1 Jan 2023 18:53:52 -1000 Subject: [PATCH 04/23] edit --- docs/README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 87bbfbe22a61..8ae0aafe08cb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -136,7 +136,17 @@ When adding a new pipeline: - __call__ ``` -This will include every public method of the pipeline that is documented, as well as the magic method like `__call__` are not documented by default. If you just want to add another method that is not documented, you can put the list of methods to add in a list that contains `all`. +This will include every public method of the pipeline that is documented, as well as the `__call__` method that is not documented by default. If you just want to add additional methods that are not documented, you can put the list of all methods to add in a list that contains `all`. + +``` +[[autodoc]] XXXPipeline + - all + - __call__ + - enable_attention_slicing + - disable_attention_slicing + - enable_xformers_memory_efficient_attention + - disable_xformers_memory_efficient_attention +``` You can follow the same process to create a new scheduler under the `docs/source/api/schedulers` folder From 63b3ad6d56f7786e5ab20cf2ffda58b48b9462fe Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:01:27 -1000 Subject: [PATCH 05/23] Update docs/source/api/pipelines/stable_diffusion/depth2img.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion/depth2img.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/api/pipelines/stable_diffusion/depth2img.mdx b/docs/source/api/pipelines/stable_diffusion/depth2img.mdx index 47f02b5178b4..7902042cf00a 100644 --- a/docs/source/api/pipelines/stable_diffusion/depth2img.mdx +++ b/docs/source/api/pipelines/stable_diffusion/depth2img.mdx @@ -25,6 +25,7 @@ Available Checkpoints are: - *stable-diffusion-2-depth*: [stabilityai/stable-diffusion-2-depth](https://huggingface.co/stabilityai/stable-diffusion-2-depth) [[autodoc]] StableDiffusionDepth2ImgPipeline + - all - __call__ - enable_attention_slicing - disable_attention_slicing From a08fe867bacceb8be11f2ba0157cb92171b2649f Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:01:55 -1000 Subject: [PATCH 06/23] Update docs/source/api/pipelines/stable_diffusion/image_variation.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion/image_variation.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/api/pipelines/stable_diffusion/image_variation.mdx b/docs/source/api/pipelines/stable_diffusion/image_variation.mdx index 63b8ceb2f89d..cc4dcd43d310 100644 --- a/docs/source/api/pipelines/stable_diffusion/image_variation.mdx +++ b/docs/source/api/pipelines/stable_diffusion/image_variation.mdx @@ -23,6 +23,7 @@ Available Checkpoints are: - *sd-image-variations-diffusers*: [lambdalabs/sd-image-variations-diffusers](https://huggingface.co/lambdalabs/sd-image-variations-diffusers) [[autodoc]] StableDiffusionImageVariationPipeline + - all - __call__ - enable_attention_slicing - disable_attention_slicing From 851b82816bd10935d6b49b8889be31edfb5f3d59 Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:02:12 -1000 Subject: [PATCH 07/23] Update docs/source/api/pipelines/stable_diffusion/img2img.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion/img2img.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/api/pipelines/stable_diffusion/img2img.mdx b/docs/source/api/pipelines/stable_diffusion/img2img.mdx index b019eb9afb7d..c57dde164c79 100644 --- a/docs/source/api/pipelines/stable_diffusion/img2img.mdx +++ b/docs/source/api/pipelines/stable_diffusion/img2img.mdx @@ -21,6 +21,7 @@ The original codebase can be found here: [CampVis/stable-diffusion](https://gith [`StableDiffusionImg2ImgPipeline`] is compatible with all Stable Diffusion checkpoints for [Text-to-Image](./text2img) [[autodoc]] StableDiffusionImg2ImgPipeline + - all - __call__ - enable_attention_slicing - disable_attention_slicing From 268fca0d48973868f88c506277168765bcbeeebd Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:02:32 -1000 Subject: [PATCH 08/23] Update docs/source/api/pipelines/stable_diffusion/inpaint.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion/inpaint.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/api/pipelines/stable_diffusion/inpaint.mdx b/docs/source/api/pipelines/stable_diffusion/inpaint.mdx index e6b7cadcd937..731e7f04fae6 100644 --- a/docs/source/api/pipelines/stable_diffusion/inpaint.mdx +++ b/docs/source/api/pipelines/stable_diffusion/inpaint.mdx @@ -25,6 +25,7 @@ Available checkpoints are: - *stable-diffusion-2-inpainting (512x512 resolution)*: [stabilityai/stable-diffusion-2-inpainting](https://huggingface.co/stabilityai/stable-diffusion-2-inpainting) [[autodoc]] StableDiffusionInpaintPipeline + - all - __call__ - enable_attention_slicing - disable_attention_slicing From fd133b8d5ec80234f7c7c9db75ca1ecd040a2e1a Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:04:17 -1000 Subject: [PATCH 09/23] Update docs/source/api/pipelines/stable_diffusion/text2img.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion/text2img.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/api/pipelines/stable_diffusion/text2img.mdx b/docs/source/api/pipelines/stable_diffusion/text2img.mdx index 168f5d112e16..977253cc5c2f 100644 --- a/docs/source/api/pipelines/stable_diffusion/text2img.mdx +++ b/docs/source/api/pipelines/stable_diffusion/text2img.mdx @@ -14,7 +14,7 @@ specific language governing permissions and limitations under the License. ## StableDiffusionPipeline -The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), and [LAION](https://laion.ai/). The [`StableDiffusionPipeline`] is capable of generating photo-realistic images given any text input using Stable Diffusion. +The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), [runway](https://github.com/runwayml), and [LAION](https://laion.ai/). The [`StableDiffusionPipeline`] is capable of generating photo-realistic images given any text input using Stable Diffusion. The original codebase can be found here: - *Stable Diffusion V1*: [CampVis/stable-diffusion](https://github.com/CompVis/stable-diffusion) From 39cc898ab8135ddbbf485482d3c77e0e46ccf770 Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:04:42 -1000 Subject: [PATCH 10/23] Update docs/source/api/pipelines/stable_diffusion/upscale.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion/upscale.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/api/pipelines/stable_diffusion/upscale.mdx b/docs/source/api/pipelines/stable_diffusion/upscale.mdx index bb9c545c787f..5185903edc09 100644 --- a/docs/source/api/pipelines/stable_diffusion/upscale.mdx +++ b/docs/source/api/pipelines/stable_diffusion/upscale.mdx @@ -24,6 +24,7 @@ Available Checkpoints are: [[autodoc]] StableDiffusionUpscalePipeline + - all - __call__ - enable_attention_slicing - disable_attention_slicing From 51509e44455fc87a5a57aa6d19271acd9dde92c4 Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:05:09 -1000 Subject: [PATCH 11/23] Update docs/source/api/pipelines/stable_diffusion/text2img.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion/text2img.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/api/pipelines/stable_diffusion/text2img.mdx b/docs/source/api/pipelines/stable_diffusion/text2img.mdx index 977253cc5c2f..952ad24808b8 100644 --- a/docs/source/api/pipelines/stable_diffusion/text2img.mdx +++ b/docs/source/api/pipelines/stable_diffusion/text2img.mdx @@ -29,6 +29,7 @@ Available Checkpoints are: - *stable-diffusion-2-1 (768x768 resolution)*: [stabilityai/stable-diffusion-2-1](https://huggingface.co/stabilityai/stable-diffusion-2-1) [[autodoc]] StableDiffusionPipeline + - all - __call__ - enable_attention_slicing - disable_attention_slicing From 0cfa4acaf73a910997ea765aa1eafe02656f0672 Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:05:31 -1000 Subject: [PATCH 12/23] Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py Co-authored-by: Patrick von Platen --- .../stable_diffusion/pipeline_stable_diffusion_upscale.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py index dd9382b0718a..5d2620c7e408 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py @@ -411,6 +411,7 @@ def __call__( >>> low_res_img = Image.open(BytesIO(response.content)).convert("RGB") >>> low_res_img = low_res_img.resize((128, 128)) >>> prompt = "a white cat" + >>> upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0] >>> upscaled_image.save("upsampled_cat.png") ``` From d3f9c395c227806a63e8bf2b6f196f219b76aed5 Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:05:49 -1000 Subject: [PATCH 13/23] Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py Co-authored-by: Patrick von Platen --- .../stable_diffusion/pipeline_stable_diffusion_depth2img.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py index c1c873d3113b..b5ec8fe3918b 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py @@ -517,7 +517,8 @@ def __call__( >>> pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( ... "stabilityai/stable-diffusion-2-depth", ... torch_dtype=torch.float16, - ... ).to("cuda") + ... ) + >>> pipe.to("cuda") >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg" From be35fdac9ad1f3216e79a0c1e36c3b94b33f144b Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:06:26 -1000 Subject: [PATCH 14/23] Update src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py Co-authored-by: Patrick von Platen --- .../pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py index 43b472e1e063..4f2d922463fc 100644 --- a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +++ b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py @@ -525,7 +525,7 @@ def __call__( >>> from diffusers import AltDiffusionImg2ImgPipeline >>> device = "cuda" - >>> model_id_or_path = "runwayml/stable-diffusion-v1-5" + >>> model_id_or_path = "BAAI/AltDiffusion-m9" >>> pipe = AltDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) >>> pipe = pipe.to(device) From 18f1056f8a7bf03c6dced5e220574d642ae75bd9 Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:07:02 -1000 Subject: [PATCH 15/23] Update src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py Co-authored-by: Patrick von Platen --- .../pipelines/alt_diffusion/pipeline_alt_diffusion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py index 4f91cb9d9708..2069d39b01fe 100644 --- a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +++ b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py @@ -479,7 +479,8 @@ def __call__( >>> pipe = AltDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16) >>> pipe = pipe.to("cuda") - >>> prompt = "a photo of an astronaut riding a horse on mars" + >>> # "dark elf princess, highly detailed, d & d, fantasy, highly detailed, digital painting, trending on artstation, concept art, sharp focus, illustration, art by artgerm and greg rutkowski and fuji choko and viktoria gavrilenko and hoang lap" + >>> prompt = "黑暗精灵公主,非常详细,幻想,非常详细,数字绘画,概念艺术,敏锐的焦点,插图" >>> image = pipe(prompt).images[0] ``` From b5cb05e102fe12dd653df081464529a1fd58eadc Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:07:09 -1000 Subject: [PATCH 16/23] Update src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py Co-authored-by: Patrick von Platen --- src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py index 2069d39b01fe..2f857300d1fd 100644 --- a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +++ b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py @@ -476,7 +476,7 @@ def __call__( >>> import torch >>> from diffusers import AltDiffusionPipeline - >>> pipe = AltDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16) + >>> pipe = AltDiffusionPipeline.from_pretrained("BAAI/AltDiffusion-m9", torch_dtype=torch.float16) >>> pipe = pipe.to("cuda") >>> # "dark elf princess, highly detailed, d & d, fantasy, highly detailed, digital painting, trending on artstation, concept art, sharp focus, illustration, art by artgerm and greg rutkowski and fuji choko and viktoria gavrilenko and hoang lap" From c36684d491001d273f8f32f99d388aaf7e019f74 Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:07:41 -1000 Subject: [PATCH 17/23] Update docs/source/api/pipelines/stable_diffusion_safe.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion_safe.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/api/pipelines/stable_diffusion_safe.mdx b/docs/source/api/pipelines/stable_diffusion_safe.mdx index be46907ff49f..d2ae319a78e6 100644 --- a/docs/source/api/pipelines/stable_diffusion_safe.mdx +++ b/docs/source/api/pipelines/stable_diffusion_safe.mdx @@ -28,7 +28,7 @@ The abstract of the paper is the following: ## Tips -- Safe Stable Diffusion may also be used with weights of [Stable Diffusion](./api/pipelines/stable_diffusion/overview). +- Safe Stable Diffusion may also be used with weights of [Stable Diffusion](./api/pipelines/stable_diffusion/text2img). ### Run Safe Stable Diffusion From 0aa62e08bae0b5aa3cbde53a11a0103a2090e4e2 Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:07:57 -1000 Subject: [PATCH 18/23] Update docs/source/api/pipelines/stable_diffusion/inpaint.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion/inpaint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/api/pipelines/stable_diffusion/inpaint.mdx b/docs/source/api/pipelines/stable_diffusion/inpaint.mdx index 731e7f04fae6..312bd33d23ba 100644 --- a/docs/source/api/pipelines/stable_diffusion/inpaint.mdx +++ b/docs/source/api/pipelines/stable_diffusion/inpaint.mdx @@ -14,7 +14,7 @@ specific language governing permissions and limitations under the License. ## StableDiffusionInpaintPipeline -The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), and [LAION](https://laion.ai/). The [`StableDiffusionInpaintPipeline`] lets you edit specific parts of an image by providing a mask and a text prompt using Stable Diffusion. +The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), [runway](https://github.com/runwayml), and [LAION](https://laion.ai/). The [`StableDiffusionInpaintPipeline`] lets you edit specific parts of an image by providing a mask and a text prompt using Stable Diffusion. The original codebase can be found here: - *Stable Diffusion V1*: [CampVis/stable-diffusion](https://github.com/runwayml/stable-diffusion#inpainting-with-stable-diffusion) From fcb860ab2fd546c6b0138f7e622b0261448261a9 Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Sun, 1 Jan 2023 19:09:40 -1000 Subject: [PATCH 19/23] Update docs/source/api/pipelines/stable_diffusion/img2img.mdx Co-authored-by: Patrick von Platen --- docs/source/api/pipelines/stable_diffusion/img2img.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/api/pipelines/stable_diffusion/img2img.mdx b/docs/source/api/pipelines/stable_diffusion/img2img.mdx index c57dde164c79..9385174db021 100644 --- a/docs/source/api/pipelines/stable_diffusion/img2img.mdx +++ b/docs/source/api/pipelines/stable_diffusion/img2img.mdx @@ -14,7 +14,7 @@ specific language governing permissions and limitations under the License. ## StableDiffusionImg2ImgPipeline -The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), and [LAION](https://laion.ai/). The [`StableDiffusionImg2ImgPipeline`] lets you pass a text prompt and an initial image to condition the generation of new images using Stable Diffusion. +The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), https://github.com/runwayml, and [LAION](https://laion.ai/). The [`StableDiffusionImg2ImgPipeline`] lets you pass a text prompt and an initial image to condition the generation of new images using Stable Diffusion. The original codebase can be found here: [CampVis/stable-diffusion](https://github.com/CompVis/stable-diffusion/blob/main/scripts/img2img.py) From c0cbc97b49410c3a3c845846b911fa4e3c876f57 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sun, 1 Jan 2023 20:24:46 -1000 Subject: [PATCH 20/23] fix --- docs/source/api/pipelines/stable_diffusion/img2img.mdx | 2 +- .../alt_diffusion/pipeline_alt_diffusion_img2img.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/source/api/pipelines/stable_diffusion/img2img.mdx b/docs/source/api/pipelines/stable_diffusion/img2img.mdx index 9385174db021..5ece114f9267 100644 --- a/docs/source/api/pipelines/stable_diffusion/img2img.mdx +++ b/docs/source/api/pipelines/stable_diffusion/img2img.mdx @@ -14,7 +14,7 @@ specific language governing permissions and limitations under the License. ## StableDiffusionImg2ImgPipeline -The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), https://github.com/runwayml, and [LAION](https://laion.ai/). The [`StableDiffusionImg2ImgPipeline`] lets you pass a text prompt and an initial image to condition the generation of new images using Stable Diffusion. +The Stable Diffusion model was created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), [runway](https://github.com/runwayml), and [LAION](https://laion.ai/). The [`StableDiffusionImg2ImgPipeline`] lets you pass a text prompt and an initial image to condition the generation of new images using Stable Diffusion. The original codebase can be found here: [CampVis/stable-diffusion](https://github.com/CompVis/stable-diffusion/blob/main/scripts/img2img.py) diff --git a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py index 4f2d922463fc..f72cd79d9243 100644 --- a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +++ b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py @@ -534,8 +534,9 @@ def __call__( >>> response = requests.get(url) >>> init_image = Image.open(BytesIO(response.content)).convert("RGB") >>> init_image = init_image.resize((768, 512)) - - >>> prompt = "A fantasy landscape, trending on artstation" + + >>> # "A fantasy landscape, trending on artstation" + >>> prompt = "幻想风景, artstation" >>> images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images >>> images[0].save("fantasy_landscape.png") From 89c59db4c8da5010359c6f49faa93cc0b9785e58 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 2 Jan 2023 16:44:04 +0100 Subject: [PATCH 21/23] add function decorator --- .../alt_diffusion/pipeline_alt_diffusion.py | 29 ++++++++------ .../pipeline_alt_diffusion_img2img.py | 2 +- .../pipeline_stable_diffusion.py | 28 ++++++++------ .../pipeline_stable_diffusion_upscale.py | 2 +- src/diffusers/utils/__init__.py | 1 + src/diffusers/utils/doc_utils.py | 38 +++++++++++++++++++ 6 files changed, 74 insertions(+), 26 deletions(-) create mode 100644 src/diffusers/utils/doc_utils.py diff --git a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py index 2f857300d1fd..eb29bfff4e48 100644 --- a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +++ b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py @@ -31,7 +31,7 @@ LMSDiscreteScheduler, PNDMScheduler, ) -from ...utils import deprecate, logging +from ...utils import deprecate, logging, replace_example_docstring from ..pipeline_utils import DiffusionPipeline from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker from . import AltDiffusionPipelineOutput, RobertaSeriesModelWithTransformation @@ -39,6 +39,21 @@ logger = logging.get_logger(__name__) # pylint: disable=invalid-name +EXAMPLE_DOC_STRING = """ + Examples: + ```py + >>> import torch + >>> from diffusers import AltDiffusionPipeline + + >>> pipe = AltDiffusionPipeline.from_pretrained("BAAI/AltDiffusion-m9", torch_dtype=torch.float16) + >>> pipe = pipe.to("cuda") + + >>> # "dark elf princess, highly detailed, d & d, fantasy, highly detailed, digital painting, trending on artstation, concept art, sharp focus, illustration, art by artgerm and greg rutkowski and fuji choko and viktoria gavrilenko and hoang lap" + >>> prompt = "黑暗精灵公主,非常详细,幻想,非常详细,数字绘画,概念艺术,敏锐的焦点,插图" + >>> image = pipe(prompt).images[0] + ``` +""" + # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline with Stable->Alt, CLIPTextModel->RobertaSeriesModelWithTransformation, CLIPTokenizer->XLMRobertaTokenizer, AltDiffusionSafetyChecker->StableDiffusionSafetyChecker class AltDiffusionPipeline(DiffusionPipeline): @@ -407,6 +422,7 @@ def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype return latents @torch.no_grad() + @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Union[str, List[str]], @@ -472,17 +488,6 @@ def __call__( called at every step. Examples: - ```py - >>> import torch - >>> from diffusers import AltDiffusionPipeline - - >>> pipe = AltDiffusionPipeline.from_pretrained("BAAI/AltDiffusion-m9", torch_dtype=torch.float16) - >>> pipe = pipe.to("cuda") - - >>> # "dark elf princess, highly detailed, d & d, fantasy, highly detailed, digital painting, trending on artstation, concept art, sharp focus, illustration, art by artgerm and greg rutkowski and fuji choko and viktoria gavrilenko and hoang lap" - >>> prompt = "黑暗精灵公主,非常详细,幻想,非常详细,数字绘画,概念艺术,敏锐的焦点,插图" - >>> image = pipe(prompt).images[0] - ``` Returns: [`~pipelines.stable_diffusion.AltDiffusionPipelineOutput`] or `tuple`: diff --git a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py index f72cd79d9243..04375439a190 100644 --- a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +++ b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py @@ -534,7 +534,7 @@ def __call__( >>> response = requests.get(url) >>> init_image = Image.open(BytesIO(response.content)).convert("RGB") >>> init_image = init_image.resize((768, 512)) - + >>> # "A fantasy landscape, trending on artstation" >>> prompt = "幻想风景, artstation" diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py index 9f3b672fa4bb..edfc8eaf7a52 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py @@ -17,7 +17,6 @@ import torch -from diffusers.utils import is_accelerate_available from packaging import version from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer @@ -31,7 +30,7 @@ LMSDiscreteScheduler, PNDMScheduler, ) -from ...utils import deprecate, logging +from ...utils import deprecate, is_accelerate_available, logging, replace_example_docstring from ..pipeline_utils import DiffusionPipeline from . import StableDiffusionPipelineOutput from .safety_checker import StableDiffusionSafetyChecker @@ -39,6 +38,20 @@ logger = logging.get_logger(__name__) # pylint: disable=invalid-name +EXAMPLE_DOC_STRING = """ + Examples: + ```py + >>> import torch + >>> from diffusers import StableDiffusionPipeline + + >>> pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16) + >>> pipe = pipe.to("cuda") + + >>> prompt = "a photo of an astronaut riding a horse on mars" + >>> image = pipe(prompt).images[0] + ``` +""" + class StableDiffusionPipeline(DiffusionPipeline): r""" @@ -406,6 +419,7 @@ def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype return latents @torch.no_grad() + @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Union[str, List[str]], @@ -471,16 +485,6 @@ def __call__( called at every step. Examples: - ```py - >>> import torch - >>> from diffusers import StableDiffusionPipeline - - >>> pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16) - >>> pipe = pipe.to("cuda") - - >>> prompt = "a photo of an astronaut riding a horse on mars" - >>> image = pipe(prompt).images[0] - ``` Returns: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`: diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py index 5d2620c7e408..8490e199e023 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py @@ -411,7 +411,7 @@ def __call__( >>> low_res_img = Image.open(BytesIO(response.content)).convert("RGB") >>> low_res_img = low_res_img.resize((128, 128)) >>> prompt = "a white cat" - + >>> upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0] >>> upscaled_image.save("upsampled_cat.png") ``` diff --git a/src/diffusers/utils/__init__.py b/src/diffusers/utils/__init__.py index 332a9917010c..160282b46351 100644 --- a/src/diffusers/utils/__init__.py +++ b/src/diffusers/utils/__init__.py @@ -32,6 +32,7 @@ WEIGHTS_NAME, ) from .deprecation_utils import deprecate +from .doc_utils import replace_example_docstring from .dynamic_modules_utils import get_class_from_dynamic_module from .hub_utils import HF_HUB_OFFLINE, http_user_agent from .import_utils import ( diff --git a/src/diffusers/utils/doc_utils.py b/src/diffusers/utils/doc_utils.py new file mode 100644 index 000000000000..ba79175c14bc --- /dev/null +++ b/src/diffusers/utils/doc_utils.py @@ -0,0 +1,38 @@ +# Copyright 2022 The HuggingFace Team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Doc utilities: Utilities related to documentation +""" +import re + + +def replace_example_docstring(example_docstring): + def docstring_decorator(fn): + func_doc = fn.__doc__ + lines = func_doc.split("\n") + i = 0 + while i < len(lines) and re.search(r"^\s*Examples?:\s*$", lines[i]) is None: + i += 1 + if i < len(lines): + lines[i] = example_docstring + func_doc = "\n".join(lines) + else: + raise ValueError( + f"The function {fn} should have an empty 'Examples:' in its docstring as placeholder, " + f"current docstring is:\n{func_doc}" + ) + fn.__doc__ = func_doc + return fn + + return docstring_decorator From 963ea639449cbb5e554d5d852c67b0af51549e9c Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Mon, 2 Jan 2023 11:10:56 -1000 Subject: [PATCH 22/23] use replace_example_docstring --- .../pipeline_alt_diffusion_img2img.py | 58 ++++++++++--------- .../pipeline_stable_diffusion_img2img.py | 57 +++++++++--------- 2 files changed, 61 insertions(+), 54 deletions(-) diff --git a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py index 04375439a190..ca3491ae5127 100644 --- a/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +++ b/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py @@ -33,7 +33,7 @@ LMSDiscreteScheduler, PNDMScheduler, ) -from ...utils import PIL_INTERPOLATION, deprecate, logging +from ...utils import PIL_INTERPOLATION, deprecate, logging, replace_example_docstring from ..pipeline_utils import DiffusionPipeline from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker from . import AltDiffusionPipelineOutput, RobertaSeriesModelWithTransformation @@ -41,6 +41,35 @@ logger = logging.get_logger(__name__) # pylint: disable=invalid-name +EXAMPLE_DOC_STRING = """ + Examples: + ```py + >>> import requests + >>> import torch + >>> from PIL import Image + >>> from io import BytesIO + + >>> from diffusers import AltDiffusionImg2ImgPipeline + + >>> device = "cuda" + >>> model_id_or_path = "BAAI/AltDiffusion-m9" + >>> pipe = AltDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) + >>> pipe = pipe.to(device) + + >>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" + + >>> response = requests.get(url) + >>> init_image = Image.open(BytesIO(response.content)).convert("RGB") + >>> init_image = init_image.resize((768, 512)) + + >>> # "A fantasy landscape, trending on artstation" + >>> prompt = "幻想风景, artstation" + + >>> images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images + >>> images[0].save("幻想风景.png") + ``` +""" + # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.preprocess def preprocess(image): @@ -450,6 +479,7 @@ def prepare_latents(self, image, timestep, batch_size, num_images_per_prompt, dt return latents @torch.no_grad() + @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Union[str, List[str]], @@ -516,32 +546,6 @@ def __call__( called at every step. Examples: - ```py - >>> import requests - >>> import torch - >>> from PIL import Image - >>> from io import BytesIO - - >>> from diffusers import AltDiffusionImg2ImgPipeline - - >>> device = "cuda" - >>> model_id_or_path = "BAAI/AltDiffusion-m9" - >>> pipe = AltDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) - >>> pipe = pipe.to(device) - - >>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" - - >>> response = requests.get(url) - >>> init_image = Image.open(BytesIO(response.content)).convert("RGB") - >>> init_image = init_image.resize((768, 512)) - - >>> # "A fantasy landscape, trending on artstation" - >>> prompt = "幻想风景, artstation" - - >>> images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images - >>> images[0].save("fantasy_landscape.png") - ``` - Returns: [`~pipelines.stable_diffusion.AltDiffusionPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.AltDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple. diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py index 533a8ed30d77..3fabb2a68f13 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py @@ -19,7 +19,6 @@ import torch import PIL -from diffusers.utils import is_accelerate_available from packaging import version from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer @@ -33,7 +32,7 @@ LMSDiscreteScheduler, PNDMScheduler, ) -from ...utils import PIL_INTERPOLATION, deprecate, logging +from ...utils import PIL_INTERPOLATION, is_accelerate_available, deprecate, logging, replace_example_docstring from ..pipeline_utils import DiffusionPipeline from . import StableDiffusionPipelineOutput from .safety_checker import StableDiffusionSafetyChecker @@ -41,6 +40,34 @@ logger = logging.get_logger(__name__) # pylint: disable=invalid-name +EXAMPLE_DOC_STRING = """ + Examples: + ```py + >>> import requests + >>> import torch + >>> from PIL import Image + >>> from io import BytesIO + + >>> from diffusers import StableDiffusionImg2ImgPipeline + + >>> device = "cuda" + >>> model_id_or_path = "runwayml/stable-diffusion-v1-5" + >>> pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) + >>> pipe = pipe.to(device) + + >>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" + + >>> response = requests.get(url) + >>> init_image = Image.open(BytesIO(response.content)).convert("RGB") + >>> init_image = init_image.resize((768, 512)) + + >>> prompt = "A fantasy landscape, trending on artstation" + + >>> images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images + >>> images[0].save("fantasy_landscape.png") + ``` +""" + def preprocess(image): if isinstance(image, torch.Tensor): @@ -455,6 +482,7 @@ def prepare_latents(self, image, timestep, batch_size, num_images_per_prompt, dt return latents @torch.no_grad() + @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Union[str, List[str]], @@ -521,31 +549,6 @@ def __call__( called at every step. Examples: - ```py - >>> import requests - >>> import torch - >>> from PIL import Image - >>> from io import BytesIO - - >>> from diffusers import StableDiffusionImg2ImgPipeline - - >>> device = "cuda" - >>> model_id_or_path = "runwayml/stable-diffusion-v1-5" - >>> pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) - >>> pipe = pipe.to(device) - - >>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" - - >>> response = requests.get(url) - >>> init_image = Image.open(BytesIO(response.content)).convert("RGB") - >>> init_image = init_image.resize((768, 512)) - - >>> prompt = "A fantasy landscape, trending on artstation" - - >>> images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images - >>> images[0].save("fantasy_landscape.png") - ``` - Returns: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple. From d397d985f7f61e16a3aca5a2704a98c7b14983d8 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Mon, 2 Jan 2023 11:15:51 -1000 Subject: [PATCH 23/23] make style --- .../stable_diffusion/pipeline_stable_diffusion_img2img.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py index 3fabb2a68f13..f2325fa50e20 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py @@ -32,7 +32,7 @@ LMSDiscreteScheduler, PNDMScheduler, ) -from ...utils import PIL_INTERPOLATION, is_accelerate_available, deprecate, logging, replace_example_docstring +from ...utils import PIL_INTERPOLATION, deprecate, is_accelerate_available, logging, replace_example_docstring from ..pipeline_utils import DiffusionPipeline from . import StableDiffusionPipelineOutput from .safety_checker import StableDiffusionSafetyChecker