tlwu commited on
Commit
92d4faa
·
1 Parent(s): cd1da00

update doc

Browse files
Files changed (2) hide show
  1. ORT_CUDA/sdxl-turbo/engine/README.md +0 -103
  2. README.md +121 -1
ORT_CUDA/sdxl-turbo/engine/README.md DELETED
@@ -1,103 +0,0 @@
1
- ---
2
- license: openrail++
3
- base_model: stabilityai/sdxl-turbo
4
- language:
5
- - en
6
- tags:
7
- - stable-diffusion
8
- - sdxl
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 **SDXL Turbo** 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-Turbo](https://huggingface.co/stabilityai/sdxl-turbo) model 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 512x512 using NVIDIA A100-SXM4-80GB GPU:
37
-
38
- | Engine | Batch Size | Steps | PyTorch 2.1 | ONNX Runtime CUDA |
39
- |-------------|------------|------ | ----------------|-------------------|
40
- | Static | 1 | 1 | 109.4 ms | 43.9 ms |
41
- | Static | 4 | 1 | 247.0 ms | 121.1 ms |
42
- | Static | 1 | 4 | 171.1 ms | 97.5 ms |
43
- | Static | 4 | 4 | 390.5 ms | 248.0 ms |
44
-
45
-
46
- Static means the engine is built for the given batch size and image size combination, and CUDA graph is used to speed up.
47
-
48
- ## Usage Example
49
-
50
- 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:
51
-
52
- 0. Install nvidia-docker using these [instructions](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
53
-
54
- 1. Clone onnxruntime repository.
55
- ```shell
56
- git clone https://github.com/microsoft/onnxruntime
57
- cd onnxruntime
58
- ```
59
-
60
- 2. Download the SDXL ONNX files from this repo
61
- ```shell
62
- git lfs install
63
- git clone https://huggingface.co/tlwu/sdxl-turbo-onnxruntime
64
- ```
65
-
66
- 3. Launch the docker
67
- ```shell
68
- docker run --rm -it --gpus all -v $PWD:/workspace nvcr.io/nvidia/pytorch:23.10-py3 /bin/bash
69
- ```
70
-
71
- 4. Build ONNX Runtime from source
72
- ```shell
73
- export CUDACXX=/usr/local/cuda-12.2/bin/nvcc
74
- git config --global --add safe.directory '*'
75
- sh build.sh --config Release --build_shared_lib --parallel --use_cuda --cuda_version 12.2 \
76
- --cuda_home /usr/local/cuda-12.2 --cudnn_home /usr/lib/x86_64-linux-gnu/ --build_wheel --skip_tests \
77
- --use_tensorrt --tensorrt_home /usr/src/tensorrt \
78
- --cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF \
79
- --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES=80 \
80
- --allow_running_as_root
81
- python3 -m pip install build/Linux/Release/dist/onnxruntime_gpu-*-cp310-cp310-linux_x86_64.whl --force-reinstall
82
- ```
83
-
84
- If the GPU is not A100, change CMAKE_CUDA_ARCHITECTURES=80 in the command line according to the GPU compute capacity (like 89 for RTX 4090, or 86 for RTX 3090). If your machine has less than 64GB memory, replace --parallel by --parallel 4 --nvcc_threads 1 to avoid out of memory.
85
-
86
- 5. Install libraries and requirements
87
- ```shell
88
- python3 -m pip install --upgrade pip
89
- cd /workspace/onnxruntime/python/tools/transformers/models/stable_diffusion
90
- python3 -m pip install -r requirements-cuda12.txt
91
- python3 -m pip install --upgrade polygraphy onnx-graphsurgeon --extra-index-url https://pypi.ngc.nvidia.com
92
- ```
93
-
94
- 6. Perform ONNX Runtime optimized inference
95
- ```shell
96
- python3 demo_txt2img_xl.py \
97
- "starry night over Golden Gate Bridge by van gogh" \
98
- --version xl-turbo \
99
- --width 1024 \
100
- --height 1024 \
101
- --denoising-steps 8 \
102
- --work-dir /workspace/sdxl-turbo-onnxruntime
103
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -1,3 +1,123 @@
1
  ---
2
- license: creativeml-openrail-m
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: openrail++
3
+ base_model: stabilityai/sdxl-turbo
4
+ language:
5
+ - en
6
+ tags:
7
+ - stable-diffusion
8
+ - sdxl
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 **SDXL Turbo** 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-Turbo](https://huggingface.co/stabilityai/sdxl-turbo) model 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
+ The Canny control net is converted from [diffusers/controlnet-canny-sdxl-1.0](https://huggingface.co/diffusers/controlnet-canny-sdxl-1.0).
33
+
34
+ ## Performance Comparison
35
+
36
+ #### Latency for SDXL-Turbo
37
+
38
+ Below is average latency of generating an image of size 512x512 using NVIDIA A100-SXM4-80GB GPU:
39
+
40
+ | Engine | Batch Size | Steps | PyTorch 2.1 | ONNX Runtime CUDA |
41
+ |-------------|------------|------ | ----------------|-------------------|
42
+ | Static | 1 | 1 | 109.4 ms | 43.9 ms |
43
+ | Static | 4 | 1 | 247.0 ms | 121.1 ms |
44
+ | Static | 1 | 4 | 171.1 ms | 97.5 ms |
45
+ | Static | 4 | 4 | 390.5 ms | 248.0 ms |
46
+
47
+
48
+ Static means the engine is built for the given batch size and image size combination, and CUDA graph is used to speed up.
49
+
50
+
51
+ #### Latency for SDXL-Turbo with Canny Control Net
52
+
53
+ Below is average latency of generating an image of size 512x512 with canny control net using NVIDIA A100-SXM4-80GB GPU:
54
+
55
+ | Engine | Batch Size | Steps | PyTorch 2.1 | ONNX Runtime CUDA |
56
+ |-------------|------------|------ | ----------------|-------------------|
57
+ | Static | 1 | 1 | 160.0 ms | 49.3 ms |
58
+ | Static | 4 | 1 | 314.9 ms | 135.3 ms |
59
+ | Static | 1 | 4 | 251.9 ms | 123.3 ms |
60
+ | Static | 4 | 4 | 514.2 ms | 303.3 ms |
61
+
62
+
63
+ ## Usage Example
64
+
65
+ 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:
66
+
67
+ 0. Install nvidia-docker using these [instructions](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
68
+
69
+ 1. Clone onnxruntime repository.
70
+ ```shell
71
+ git clone https://github.com/microsoft/onnxruntime
72
+ cd onnxruntime
73
+ ```
74
+
75
+ If you want to try canny control net,
76
+ ```shell
77
+ git chehckout canny_control_net
78
+ ```
79
+
80
+ 2. Download the SDXL ONNX files from this repo
81
+ ```shell
82
+ git lfs install
83
+ git clone https://huggingface.co/tlwu/sdxl-turbo-onnxruntime
84
+ ```
85
+
86
+ 3. Launch the docker
87
+ ```shell
88
+ docker run --rm -it --gpus all -v $PWD:/workspace nvcr.io/nvidia/pytorch:23.10-py3 /bin/bash
89
+ ```
90
+
91
+ 4. Build ONNX Runtime from source
92
+ ```shell
93
+ export CUDACXX=/usr/local/cuda-12.2/bin/nvcc
94
+ git config --global --add safe.directory '*'
95
+ sh build.sh --config Release --build_shared_lib --parallel --use_cuda --cuda_version 12.2 \
96
+ --cuda_home /usr/local/cuda-12.2 --cudnn_home /usr/lib/x86_64-linux-gnu/ --build_wheel --skip_tests \
97
+ --use_tensorrt --tensorrt_home /usr/src/tensorrt \
98
+ --cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF \
99
+ --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES=80 \
100
+ --allow_running_as_root
101
+ python3 -m pip install build/Linux/Release/dist/onnxruntime_gpu-*-cp310-cp310-linux_x86_64.whl --force-reinstall
102
+ ```
103
+
104
+ If the GPU is not A100, change CMAKE_CUDA_ARCHITECTURES=80 in the command line according to the GPU compute capacity (like 89 for RTX 4090, or 86 for RTX 3090). If your machine has less than 64GB memory, replace --parallel by --parallel 4 --nvcc_threads 1 to avoid out of memory.
105
+
106
+ 5. Install libraries and requirements
107
+ ```shell
108
+ python3 -m pip install --upgrade pip
109
+ cd /workspace/onnxruntime/python/tools/transformers/models/stable_diffusion
110
+ python3 -m pip install -r requirements-cuda12.txt
111
+ python3 -m pip install --upgrade polygraphy onnx-graphsurgeon --extra-index-url https://pypi.ngc.nvidia.com
112
+ ```
113
+
114
+ 6. Perform ONNX Runtime optimized inference
115
+ ```shell
116
+ python3 demo_txt2img_xl.py \
117
+ "starry night over Golden Gate Bridge by van gogh" \
118
+ --version xl-turbo \
119
+ --width 1024 \
120
+ --height 1024 \
121
+ --denoising-steps 8 \
122
+ --work-dir /workspace/sdxl-turbo-onnxruntime
123
+ ```