tlwu commited on
Commit
2f4d024
1 Parent(s): 6bc9385

add sd-turbo onnx

Browse files
ORT_CUDA/sd-turbo/engine/clip.ort_cuda.fp16/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f1b1d827fb6013c67ac3f349b06d1a159373c2faf5253555e20b14ce2ebaacf
3
+ size 680852028
ORT_CUDA/sd-turbo/engine/unet.ort_cuda.fp16/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf77e0fc1a30bd77cbe86ddefccaadc30e2dc3a667c92418f3811f5417ce2af1
3
+ size 371766
ORT_CUDA/sd-turbo/engine/unet.ort_cuda.fp16/model.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:402069ca12429e3f7b810770a49f0121a3f0f025a38317ebfd4b956d7de1c41e
3
+ size 1732024320
ORT_CUDA/sd-turbo/engine/vae.ort_cuda.fp16/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a72b771027dde10c6bb0af1347c9e30b0df54f186f3ff7c688f2b89354bcc7a2
3
+ size 99070385
README.md CHANGED
@@ -1,3 +1,99 @@
1
  ---
2
- license: creativeml-openrail-m
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: openrail++
3
+ base_model: stabilityai/sd-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 Turbo for ONNX Runtime
16
+
17
+ ## Introduction
18
+
19
+ This repository hosts the optimized versions of **SD 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:** [STABILITY AI NON-COMMERCIAL RESEARCH COMMUNITY LICENSE](https://huggingface.co/stabilityai/sd-turbo/blob/main/LICENSE)
28
+ - **Model Description:** This is a conversion of the [SD-Turbo](https://huggingface.co/stabilityai/sd-turbo) model for [ONNX Runtime](https://github.com/microsoft/onnxruntime) inference with CUDA execution provider.
29
+
30
+ ## Performance Comparison
31
+
32
+ #### Latency
33
+
34
+ Below is average latency of generating an image of size 512x512 using NVIDIA A100-SXM4-80GB GPU:
35
+
36
+ | Engine | Batch Size | Steps | PyTorch 2.1 | ONNX Runtime CUDA |
37
+ |-------------|------------|------ | ----------------|-------------------|
38
+ | Static | 1 | 1 | 85.3 ms | 32.9 ms |
39
+ | Static | 4 | 1 | 213.8 ms | 97.5 ms |
40
+ | Static | 1 | 4 | 117.4 ms | 62.5 ms |
41
+ | Static | 4 | 4 | 294.3 ms | 168.3 ms |
42
+
43
+
44
+ Static means the engine is built for the given batch size and image size combination, and CUDA graph is used to speed up.
45
+
46
+
47
+ ## Usage Example
48
+
49
+ 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:
50
+
51
+ 0. Install nvidia-docker using these [instructions](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
52
+
53
+ 1. Clone onnxruntime repository.
54
+ ```shell
55
+ git clone https://github.com/microsoft/onnxruntime
56
+ cd onnxruntime
57
+ ```
58
+
59
+ 2. Download the SDXL ONNX files from this repo
60
+ ```shell
61
+ git lfs install
62
+ git clone https://huggingface.co/tlwu/sdxl-turbo-onnxruntime
63
+ ```
64
+
65
+ 3. Launch the docker
66
+ ```shell
67
+ docker run --rm -it --gpus all -v $PWD:/workspace nvcr.io/nvidia/pytorch:23.10-py3 /bin/bash
68
+ ```
69
+
70
+ 4. Build ONNX Runtime from source
71
+ ```shell
72
+ export CUDACXX=/usr/local/cuda-12.2/bin/nvcc
73
+ git config --global --add safe.directory '*'
74
+ sh build.sh --config Release --build_shared_lib --parallel --use_cuda --cuda_version 12.2 \
75
+ --cuda_home /usr/local/cuda-12.2 --cudnn_home /usr/lib/x86_64-linux-gnu/ --build_wheel --skip_tests \
76
+ --use_tensorrt --tensorrt_home /usr/src/tensorrt \
77
+ --cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF \
78
+ --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES=80 \
79
+ --allow_running_as_root
80
+ python3 -m pip install build/Linux/Release/dist/onnxruntime_gpu-*-cp310-cp310-linux_x86_64.whl --force-reinstall
81
+ ```
82
+
83
+ 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.
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.py \
96
+ "starry night over Golden Gate Bridge by van gogh" \
97
+ --version sd-turbo \
98
+ --work-dir /workspace/sd-turbo-onnxruntime
99
+ ```