Skip to content

Commit

Permalink
Add example for image generation using Consistency Models using Diffu…
Browse files Browse the repository at this point in the history
…sers (#490)

* add: example for LCM

* add: colab badges
  • Loading branch information
soumik12345 authored Dec 6, 2023
1 parent cc3bf73 commit 2ee0fd3
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
Binary file added colabs/diffusers/assets/diffusers-autolog-4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions colabs/diffusers/lcm-diffusers.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Image Generation with Consistency Models using 🤗 Diffusers\n",
"\n",
"[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/wandb/examples/blob/master/colabs/diffusers/lcm-diffusers.ipynb)\n",
"\n",
"This notebook demonstrates the following:\n",
"- Performing text-conditional image-generations with the [Consistency Models](https://huggingface.co/docs/diffusers/api/pipelines/consistency_models) using [🤗 Diffusers](https://huggingface.co/docs/diffusers).\n",
"- Manage image generation experiments using [Weights & Biases](http://wandb.ai/site).\n",
"- Log the prompts, generated images and experiment configs to [Weigts & Biases](http://wandb.ai/site) for visalization.\n",
"\n",
"![](./assets/diffusers-autolog-4.gif)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install diffusers transformers accelerate wandb > install.log"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"\n",
"import torch\n",
"from diffusers import DiffusionPipeline\n",
"\n",
"import wandb\n",
"from wandb.integration.diffusers import autolog"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Initialize the diffusion pipeline for latent consistency model\n",
"pipeline = DiffusionPipeline.from_pretrained(\"SimianLuo/LCM_Dreamshaper_v7\")\n",
"pipeline = pipeline.to(torch_device=\"cuda\", torch_dtype=torch.float32)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Define the prompts, negative prompts, and seed.\n",
"prompt = [\n",
" \"a photograph of an astronaut riding a horse\",\n",
" \"a photograph of a dragon\"\n",
"]\n",
"\n",
"# Make the experiment reproducible by controlling randomness.\n",
"# The seed would be automatically logged to WandB.\n",
"generator = torch.Generator(device=\"cpu\").manual_seed(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Call WandB Autolog for Diffusers. This would automatically log\n",
"# the prompts, generated images, pipeline architecture and all\n",
"# associated experiment configs to Weights & Biases, thus making your\n",
"# image generation experiments easy to reproduce, share and analyze.\n",
"autolog(init=dict(project=\"diffusers_logging\"))\n",
"\n",
"# call the pipeline to generate the images\n",
"images = pipeline(\n",
" prompt,\n",
" num_images_per_prompt=2,\n",
" generator=generator,\n",
" num_inference_steps=10,\n",
")\n",
"\n",
"# End the experiment\n",
"wandb.finish()"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 2 additions & 0 deletions colabs/diffusers/pixart-alpha-diffusers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"source": [
"# Image Generation with Pixart-α using 🤗 Diffusers\n",
"\n",
"[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/wandb/examples/blob/master/colabs/diffusers/pixart-alpha-diffusers.ipynb)\n",
"\n",
"This notebook demonstrates the following:\n",
"- Performing text-conditional image-generations with the [Pixart-α model](https://huggingface.co/docs/diffusers/v0.23.1/en/api/pipelines/pixart) using [🤗 Diffusers](https://huggingface.co/docs/diffusers).\n",
"- Manage image generation experiments using [Weights & Biases](http://wandb.ai/site).\n",
Expand Down

0 comments on commit 2ee0fd3

Please sign in to comment.