tlwu commited on
Commit
7646089
·
1 Parent(s): d5cf786

update doc

Browse files
Files changed (1) hide show
  1. README.md +99 -1
README.md CHANGED
@@ -1,3 +1,101 @@
1
  ---
2
- license: creativeml-openrail-m
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: openrail++
3
+ base_model: stabilityai/stable-diffusion-xl-base-1.0
4
+ language:
5
+ - en
6
+ tags:
7
+ - stable-diffusion
8
+ - stable-diffusion-xl
9
+ - onnxruntime
10
+ - onnx
11
+ - text-to-image
12
  ---
13
+
14
+
15
+ # Stable Diffusion XL 1.0 for ONNX Runtime
16
+
17
+ ## Introduction
18
+
19
+ This repository hosts the optimized versions of **Stable Diffusion XL 1.0** to accelerate inference with ONNX Runtime CUDA execution provider.
20
+
21
+ See the [usage instructions](#usage-example) for how to run the SDXL pipeline with the ONNX files hosted in this repository.
22
+
23
+ ## Model Description
24
+
25
+ - **Developed by:** Stability AI
26
+ - **Model type:** Diffusion-based text-to-image generative model
27
+ - **License:** [CreativeML Open RAIL++-M License](https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/blob/main/LICENSE.md)
28
+ - **Model Description:** This is a conversion of the [SDXL base 1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) and [SDXL refiner 1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0) models for [ONNX Runtime](https://github.com/microsoft/onnxruntime) inference with CUDA execution provider.
29
+
30
+ The VAE decoder is converted from [sdxl-vae-fp16-fix](https://huggingface.co/madebyollin/sdxl-vae-fp16-fix). There are slight discrepancies between its output and that of the original VAE, but the decoded images should be [close enough for most purposes](https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/discussions/7#64c5c0f8e2e5c94bd04eaa80).
31
+
32
+ ## Performance Comparison
33
+
34
+ #### Latency for 30 steps base and 9 steps refiner
35
+
36
+ Below is average latency of generating an image of size 1024x1024 using NVIDIA A100-SXM4-80GB GPU:
37
+
38
+ | Engine | Batch Size | PyTorch 2.1 | ONNX Runtime CUDA |
39
+ |-------------|------------|----------------|-------------------|
40
+ | Static | 1 | N/A | 3389 ms |
41
+ | Static | 4 | N/A | 12264 ms |
42
+ | Dynamic | 1 | 3779 ms | 3458 ms |
43
+ | Dynamic | 4 | 13504 ms | 12347 ms |
44
+
45
+ Static means the engine is built for the given batch size and image size combination, and CUDA graph is used to speed up.
46
+
47
+ Dynamic means the engine is built to support dynamic batch size and image sizes.
48
+
49
+ ## Usage Example
50
+
51
+ Following the [demo instructions](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/python/tools/transformers/models/stable_diffusion/README.md#run-demo-with-docker). Example steps:
52
+
53
+ 0. Install nvidia-docker using these [instructions](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
54
+
55
+ 1. Clone onnxruntime repository.
56
+ ```shell
57
+ git clone https://github.com/microsoft/onnxruntime
58
+ cd onnxruntime
59
+ ```
60
+
61
+ 2. Download the SDXL ONNX files from this repo
62
+ ```shell
63
+ git lfs install
64
+ git clone https://huggingface.co/tlwu/stable-diffusion-xl-1.0-onnxruntime
65
+ ```
66
+
67
+ 3. Launch the docker
68
+ ```shell
69
+ docker run --rm -it --gpus all -v $PWD:/workspace nvcr.io/nvidia/pytorch:23.10-py3 /bin/bash
70
+ ```
71
+
72
+ 4. Build ONNX Runtime from source
73
+ ```shell
74
+ export CUDACXX=/usr/local/cuda-12.2/bin/nvcc
75
+ git config --global --add safe.directory '*'
76
+ sh build.sh --config Release --build_shared_lib --parallel --use_cuda --cuda_version 12.2 \
77
+ --cuda_home /usr/local/cuda-12.2 --cudnn_home /usr/lib/x86_64-linux-gnu/ --build_wheel --skip_tests \
78
+ --use_tensorrt --tensorrt_home /usr/src/tensorrt \
79
+ --cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF \
80
+ --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES=80 \
81
+ --allow_running_as_root
82
+ python3 -m pip install build/Linux/Release/dist/onnxruntime_gpu-*-cp310-cp310-linux_x86_64.whl --force-reinstall
83
+ ```
84
+
85
+ 5. Install libraries and requirements
86
+ ```shell
87
+ python3 -m pip install --upgrade pip
88
+ cd /workspace/onnxruntime/python/tools/transformers/models/stable_diffusion
89
+ python3 -m pip install -r requirements-cuda12.txt
90
+ python3 -m pip install --upgrade polygraphy onnx-graphsurgeon --extra-index-url https://pypi.ngc.nvidia.com
91
+ ```
92
+
93
+ 6. Perform ONNX Runtime optimized inference
94
+ ```shell
95
+ python3 demo_txt2img_xl.py \
96
+ "starry night over Golden Gate Bridge by van gogh" \
97
+ --width 1024 \
98
+ --height 1024 \
99
+ --denoising-steps 8 \
100
+ --work-dir /workspace/stable-diffusion-xl-1.0-onnxruntime
101
+ ```