Skip to content

[DO NOT MERGE]Add tutorial for stable diffusion #1528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Stonepia
Copy link
Contributor

@Stonepia Stonepia commented Apr 1, 2025

This is a PR for Stable Diffusion tutorial.
Will put into the Dev Discuss, and it is for review only.

For the GitHub auto-rendered doc, please see https://github.com/intel/torch-xpu-ops/blob/tongsu/sd_tutorial/docs/tutorials/stable_diffusion.ipynb

Co-author: @gaopengff

@Stonepia Stonepia requested review from EikanWang and gaopengff April 1, 2025 08:55
@Stonepia
Copy link
Contributor Author

Stonepia commented Apr 2, 2025

BKC for reproducing the perf on PyTorch 2.6 vs PyTorch 2.7:

Copy and create the stable_diffusion.py from the last section of https://github.com/intel/torch-xpu-ops/blob/tongsu/sd_tutorial/docs/tutorials/stable_diffusion.ipynb
You could also use the one in the attachment and rename it to .py.

PT2.7:

conda create -n env_2.7 python=3.10
conda activate env_2.7
python -m pip install --pre torch==2.7.0.dev20250312+xpu --index-url https://download.pytorch.org/whl/nightly/xpu
pip install datasets accelerate einops torchmetrics transformers diffusers

# SD-v1-5 LCM
python -u stable_diffusion.py -m SimianLuo/LCM_Dreamshaper_v7 --precision fp16 --num_inference_steps 4 --gscale 8.0 --height 512 --width 512 --warmup_iter 1 --iteration 3

# SDXL
python -u stable_diffusion.py -m stabilityai/stable-diffusion-xl-base-1.0 --precision fp16 --num_inference_steps 20 --gscale 7.5 --height 512 --width 512 --warmup_iter 1 --iteration 3

# Additional Tests 
python -u stable_diffusion.py -m runwayml/stable-diffusion-v1-5 --precision fp16 --num_inference_steps 20 --height 512 --width 512 --warmup_iter 1 --iteration 3
python -u stable_diffusion.py -m CompVis/stable-diffusion-v1-4 --precision fp16 --num_inference_steps 20 --gscale 8.0 --height 512 --width 512 --warmup_iter 1 --iteration 3
python -u stable_diffusion.py -m stabilityai/stable-diffusion-xl-base-1.0 --precision fp16 --num_inference_steps 20 --gscale 7.5 --height 768 --width 768 --warmup_iter 1 --iteration 3
python -u stable_diffusion.py -m stabilityai/stable-diffusion-2-1 --precision fp16 --num_inference_steps 20 --gscale 8.0 --height 512 --width 512 --warmup_iter 1 --iteration 3

# Run img2img mode
python -u stable_diffusion.py -m SimianLuo/LCM_Dreamshaper_v7 --precision fp16 --num_inference_steps 4 --gscale 8.0 --height 512 --width 512 --warmup_iter 1 --iteration 3 --pipeline_mode img2img
python -u stable_diffusion.py -m stabilityai/stable-diffusion-xl-base-1.0 --precision fp16 --num_inference_steps 20 --gscale 7.5 --height 512 --width 512 --warmup_iter 1 --iteration 3 img2img

PT 2.6:

conda create -n env_2.6 python=3.10
conda activate env_2.6
pip install --pre torch==2.6.0 --index-url https://download.pytorch.org/whl/xpu
pip install datasets accelerate einops torchmetrics transformers diffusers

# SD-v1-5 LCM
python -u stable_diffusion.py -m SimianLuo/LCM_Dreamshaper_v7 --precision fp16 --num_inference_steps 4 --gscale 8.0 --height 512 --width 512 --warmup_iter 1 --iteration 3
# SDXL
python -u stable_diffusion.py -m stabilityai/stable-diffusion-xl-base-1.0 --precision fp16 --num_inference_steps 20 --gscale 7.5 --height 512 --width 512 --warmup_iter 1 --iteration 3

# Additional Tests 
python -u stable_diffusion.py -m runwayml/stable-diffusion-v1-5 --precision fp16 --num_inference_steps 20 --height 512 --width 512 --warmup_iter 1 --iteration 3
python -u stable_diffusion.py -m CompVis/stable-diffusion-v1-4 --precision fp16 --num_inference_steps 20 --gscale 8.0 --height 512 --width 512 --warmup_iter 1 --iteration 3
python -u stable_diffusion.py -m stabilityai/stable-diffusion-xl-base-1.0 --precision fp16 --num_inference_steps 20 --gscale 7.5 --height 768 --width 768 --warmup_iter 1 --iteration 3
python -u stable_diffusion.py -m stabilityai/stable-diffusion-2-1 --precision fp16 --num_inference_steps 20 --gscale 8.0 --height 512 --width 512 --warmup_iter 1 --iteration 3

# Run img2img mode
python -u stable_diffusion.py -m SimianLuo/LCM_Dreamshaper_v7 --precision fp16 --num_inference_steps 4 --gscale 8.0 --height 512 --width 512 --warmup_iter 1 --iteration 3 --pipeline_mode img2img
python -u stable_diffusion.py -m stabilityai/stable-diffusion-xl-base-1.0 --precision fp16 --num_inference_steps 20 --gscale 7.5 --height 512 --width 512 --warmup_iter 1 --iteration 3 img2img

You will find that the output.csv and all the results are in it.
stable_diffusion.txt

@Stonepia Stonepia requested a review from Copilot April 9, 2025 07:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant