thanks to stabilityai ❤
Browse files- .gitattributes +2 -0
- LICENSE.txt +29 -0
- README.md +130 -0
- mmdit.opt/22f546a0-2815-11ef-87dd-0242c0a80102 +3 -0
- mmdit.opt/model.onnx +3 -0
- mmdit_int8_v1.opt/871e89d8-287f-11ef-8a22-0242c0a80101 +3 -0
- mmdit_int8_v1.opt/model.onnx +3 -0
- vae_decoder.opt/model.onnx +3 -0
- vae_encoder.opt/model.onnx +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
mmdit.opt/22f546a0-2815-11ef-87dd-0242c0a80102 filter=lfs diff=lfs merge=lfs -text
|
37 |
+
mmdit_int8_v1.opt/871e89d8-287f-11ef-8a22-0242c0a80101 filter=lfs diff=lfs merge=lfs -text
|
LICENSE.txt
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
STABILITY AI NON-COMMERCIAL RESEARCH COMMUNITY LICENSE AGREEMENT
|
2 |
+
Dated: December 06, 2023
|
3 |
+
|
4 |
+
By using or distributing any portion or element of the Models, Software, Software Products or Derivative Works, you agree to be bound by this Agreement.
|
5 |
+
|
6 |
+
"Agreement" means this Stable Non-Commercial Research Community License Agreement.
|
7 |
+
|
8 |
+
“AUP” means the Stability AI Acceptable Use Policy available at https://stability.ai/use-policy, as may be updated from time to time.
|
9 |
+
"Derivative Work(s)” means (a) any derivative work of the Software Products as recognized by U.S. copyright laws and (b) any modifications to a Model, and any other model created which is based on or derived from the Model or the Model’s output. For clarity, Derivative Works do not include the output of any Model.
|
10 |
+
“Documentation” means any specifications, manuals, documentation, and other written information provided by Stability AI related to the Software.
|
11 |
+
"Licensee" or "you" means you, or your employer or any other person or entity (if you are entering into this Agreement on such person or entity's behalf), of the age required under applicable laws, rules or regulations to provide legal consent and that has legal authority to bind your employer or such other person or entity if you are entering in this Agreement on their behalf.
|
12 |
+
“Model(s)" means, collectively, Stability AI’s proprietary models and algorithms, including machine-learning models, trained model weights and other elements of the foregoing, made available under this Agreement.
|
13 |
+
“Non-Commercial Uses” means exercising any of the rights granted herein for the purpose of research or non-commercial purposes. Non-Commercial Uses does not include any production use of the Software Products or any Derivative Works.
|
14 |
+
"Stability AI" or "we" means Stability AI Ltd. and its affiliates.
|
15 |
+
"Software" means Stability AI’s proprietary software made available under this Agreement.
|
16 |
+
“Software Products” means the Models, Software and Documentation, individually or in any combination.
|
17 |
+
1. License Rights and Redistribution.
|
18 |
+
a. Subject to your compliance with this Agreement, the AUP (which is hereby incorporated herein by reference), and the Documentation, Stability AI grants you a non-exclusive, worldwide, non-transferable, non-sublicensable, revocable, royalty free and limited license under Stability AI’s intellectual property or other rights owned or controlled by Stability AI embodied in the Software Products to use, reproduce, distribute, and create Derivative Works of, the Software Products, in each case for Non-Commercial Uses only.
|
19 |
+
b. You may not use the Software Products or Derivative Works to enable third parties to use the Software Products or Derivative Works as part of your hosted service or via your APIs, whether you are adding substantial additional functionality thereto or not. Merely distributing the Software Products or Derivative Works for download online without offering any related service (ex. by distributing the Models on HuggingFace) is not a violation of this subsection. If you wish to use the Software Products or any Derivative Works for commercial or production use or you wish to make the Software Products or any Derivative Works available to third parties via your hosted service or your APIs, contact Stability AI at https://stability.ai/contact.
|
20 |
+
c. If you distribute or make the Software Products, or any Derivative Works thereof, available to a third party, the Software Products, Derivative Works, or any portion thereof, respectively, will remain subject to this Agreement and you must (i) provide a copy of this Agreement to such third party, and (ii) retain the following attribution notice within a "Notice" text file distributed as a part of such copies: "This Stability AI Model is licensed under the Stability AI Non-Commercial Research Community License, Copyright (c) Stability AI Ltd. All Rights Reserved.” If you create a Derivative Work of a Software Product, you may add your own attribution notices to the Notice file included with the Software Product, provided that you clearly indicate which attributions apply to the Software Product and you must state in the NOTICE file that you changed the Software Product and how it was modified.
|
21 |
+
2. Disclaimer of Warranty. UNLESS REQUIRED BY APPLICABLE LAW, THE SOFTWARE PRODUCTS AND ANY OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE SOFTWARE PRODUCTS, DERIVATIVE WORKS OR ANY OUTPUT OR RESULTS AND ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE SOFTWARE PRODUCTS, DERIVATIVE WORKS AND ANY OUTPUT AND RESULTS.
|
22 |
+
3. Limitation of Liability. IN NO EVENT WILL STABILITY AI OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING OUT OF THIS AGREEMENT, FOR ANY LOST PROFITS OR ANY DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, EVEN IF STABILITY AI OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF ANY OF THE FOREGOING.
|
23 |
+
4. Intellectual Property.
|
24 |
+
a. No trademark licenses are granted under this Agreement, and in connection with the Software Products or Derivative Works, neither Stability AI nor Licensee may use any name or mark owned by or associated with the other or any of its affiliates, except as required for reasonable and customary use in describing and redistributing the Software Products or Derivative Works.
|
25 |
+
b. Subject to Stability AI’s ownership of the Software Products and Derivative Works made by or for Stability AI, with respect to any Derivative Works that are made by you, as between you and Stability AI, you are and will be the owner of such Derivative Works
|
26 |
+
c. If you institute litigation or other proceedings against Stability AI (including a cross-claim or counterclaim in a lawsuit) alleging that the Software Products, Derivative Works or associated outputs or results, or any portion of any of the foregoing, constitutes infringement of intellectual property or other rights owned or licensable by you, then any licenses granted to you under this Agreement shall terminate as of the date such litigation or claim is filed or instituted. You will indemnify and hold harmless Stability AI from and against any claim by any third party arising out of or related to your use or distribution of the Software Products or Derivative Works in violation of this Agreement.
|
27 |
+
5. Term and Termination. The term of this Agreement will commence upon your acceptance of this Agreement or access to the Software Products and will continue in full force and effect until terminated in accordance with the terms and conditions herein. Stability AI may terminate this Agreement if you are in breach of any term or condition of this Agreement. Upon termination of this Agreement, you shall delete and cease use of any Software Products or Derivative Works. Sections 2-4 shall survive the termination of this Agreement.
|
28 |
+
6. Governing Law. This Agreement will be governed by and construed in accordance with the laws of the United States and the State of California without regard to choice of law
|
29 |
+
principles.
|
README.md
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
pipeline_tag: text-to-image
|
3 |
+
inference: false
|
4 |
+
license: other
|
5 |
+
license_name: stabilityai-nc-research-community
|
6 |
+
license_link: LICENSE
|
7 |
+
tags:
|
8 |
+
- tensorrt
|
9 |
+
- sd3
|
10 |
+
- sd3-medium
|
11 |
+
- text-to-image
|
12 |
+
- onnx
|
13 |
+
extra_gated_prompt: >-
|
14 |
+
By clicking "Agree", you agree to the [License
|
15 |
+
Agreement](https://huggingface.co/stabilityai/stable-diffusion-3-medium/blob/main/LICENSE)
|
16 |
+
and acknowledge Stability AI's [Privacy
|
17 |
+
Policy](https://stability.ai/privacy-policy).
|
18 |
+
extra_gated_fields:
|
19 |
+
Name: text
|
20 |
+
Email: text
|
21 |
+
Country: country
|
22 |
+
Organization or Affiliation: text
|
23 |
+
Receive email updates and promotions on Stability AI products, services, and research?:
|
24 |
+
type: select
|
25 |
+
options:
|
26 |
+
- 'Yes'
|
27 |
+
- 'No'
|
28 |
+
I acknowledge that this model is for non-commercial use only unless I acquire a separate license from Stability AI: checkbox
|
29 |
+
language:
|
30 |
+
- en
|
31 |
+
---
|
32 |
+
|
33 |
+
# Stable Diffusion 3 Medium TensorRT
|
34 |
+
## Introduction
|
35 |
+
|
36 |
+
This repository hosts the TensorRT version of **Stable Diffusion 3 Medium** created in collaboration with [NVIDIA](https://huggingface.co/nvidia). The optimized versions give substantial improvements in speed and efficiency.
|
37 |
+
|
38 |
+
Stable Diffusion 3 Medium is a fast generative text-to-image model with greatly improved performance in multi-subject prompts, image quality, and spelling abilities.
|
39 |
+
|
40 |
+
## Model Details
|
41 |
+
|
42 |
+
### Model Description
|
43 |
+
Stable Diffusion 3 Medium combines a diffusion transformer architecture and flow matching.
|
44 |
+
|
45 |
+
- **Developed by:** Stability AI
|
46 |
+
- **Model type:** MMDiT text-to-image model
|
47 |
+
- **Model Description:** This is a conversion of the [Stable Diffusion 3 Medium](https://huggingface.co/stabilityai/stable-diffusion-3-medium) model
|
48 |
+
|
49 |
+
|
50 |
+
## Performance using TensorRT 10.1
|
51 |
+
#### Timings for 50 steps at 1024x1024
|
52 |
+
|
53 |
+
| Accelerator | CLIP-G | CLIP-L | T5XXL | MMDiT | VAE Decoder | Total |
|
54 |
+
|-------------|-------------|--------------|---------------|-----------------------|---------------------|------------------------|
|
55 |
+
| A100 | 11.95 ms | 5.04 ms | 21.39 ms | 5468.17 ms | 72.25 ms | 5622.47 ms |
|
56 |
+
|
57 |
+
#### Timings for 30 steps at 1024x1024 with input image conditioning
|
58 |
+
|
59 |
+
| Accelerator | VAE Encoder | CLIP-G | CLIP-L | T5XXL | MMDiT | VAE Decoder | Total |
|
60 |
+
|-------------|----------------|-------------|--------------|---------------|-----------------------|---------------------|----------------|
|
61 |
+
| A100 | 37.04 ms | 12.07 ms | 5.07 ms | 21.49 ms | 3340.69 ms | 72.02 ms | 3531.49 ms |
|
62 |
+
|
63 |
+
|
64 |
+
## Int8 quantization with [TensorRT Model Optimizer](https://github.com/NVIDIA/TensorRT-Model-Optimizer)
|
65 |
+
The MMDiT in Stable Diffusion 3 Medium can be further optimized with INT8 quantization using TensorRT Model Optimizer. The estimated end-to-end speedup comparing TensorRT fp16 and TensorRT int8 is 1.2x~1.4x on various NVidia GPUs. The memory saving is about 2x for the int8 MMDiT engine compared with the fp16 counterpart. The image quality can be maintained with minimal to negligible degradation.
|
66 |
+
|
67 |
+
## Usage Example
|
68 |
+
<!-- Finalize the branch and namespace -->
|
69 |
+
1. Follow the [setup instructions](https://github.com/NVIDIA/TensorRT/blob/release/sd3/demo/Diffusion/README.md) on launching a TensorRT NGC container.
|
70 |
+
```shell
|
71 |
+
git clone https://github.com/NVIDIA/TensorRT.git
|
72 |
+
cd TensorRT
|
73 |
+
git checkout release/sd3
|
74 |
+
docker run --rm -it --gpus all -v $PWD:/workspace nvcr.io/nvidia/pytorch:24.05-py3 /bin/bash
|
75 |
+
```
|
76 |
+
|
77 |
+
2. Download the Stable Diffusion 3 Medium TensorRT files from this repo
|
78 |
+
```shell
|
79 |
+
git lfs install
|
80 |
+
git clone https://huggingface.co/stabilityai/stable-diffusion-3-medium-tensorrt
|
81 |
+
cd stable-diffusion-3-medium-tensorrt
|
82 |
+
git lfs pull
|
83 |
+
cd ..
|
84 |
+
```
|
85 |
+
|
86 |
+
3. Install libraries and requirements
|
87 |
+
```shell
|
88 |
+
cd demo/Diffusion
|
89 |
+
python3 -m pip install --upgrade pip
|
90 |
+
pip3 install -r requirements.txt
|
91 |
+
python3 -m pip install --pre --upgrade --extra-index-url https://pypi.nvidia.com tensorrt-cu12
|
92 |
+
```
|
93 |
+
|
94 |
+
|
95 |
+
4. Perform TensorRT optimized inference:
|
96 |
+
|
97 |
+
- **Stable Diffusion 3 Medium**
|
98 |
+
|
99 |
+
Works best for 1024x1024 images. The first invocation produces plan files in --engine-dir specific to the accelerator being run on and are reused for later invocations.
|
100 |
+
```
|
101 |
+
python3 demo_txt2img_sd3.py \
|
102 |
+
""Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"" \
|
103 |
+
--version=sd3 \
|
104 |
+
--onnx-dir /workspace/sd3-tensorrt/ \
|
105 |
+
--engine-dir /workspace/sd3-tensorrt/engine \
|
106 |
+
--seed 42 \
|
107 |
+
--width 1024 \
|
108 |
+
--height 1024 \
|
109 |
+
--build-static-batch \
|
110 |
+
--use-cuda-graph
|
111 |
+
```
|
112 |
+
|
113 |
+
- **Stable Diffusion 3 Medium with input image conditioning**
|
114 |
+
|
115 |
+
Provide an input image conditioning using below. Works best for 1024x1024 but may also work at 512x512.
|
116 |
+
```
|
117 |
+
wget https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png -O dog-on-bench.png
|
118 |
+
|
119 |
+
python3 demo_txt2img_sd3.py \
|
120 |
+
"""dog wearing a sweater and a blue collar""" \
|
121 |
+
--version=sd3 \
|
122 |
+
--onnx-dir /workspace/sd3-tensorrt/ \
|
123 |
+
--engine-dir /workspace/sd3-tensorrt/engine \
|
124 |
+
--seed 42 \
|
125 |
+
--width 1024 \
|
126 |
+
--height 1024 \
|
127 |
+
--input-image dog-on-bench.png \
|
128 |
+
--build-static-batch \
|
129 |
+
--use-cuda-graph
|
130 |
+
```
|
mmdit.opt/22f546a0-2815-11ef-87dd-0242c0a80102
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:575ba6fb3d7911ec253896420faff7c3add9a64a5e66c15f02860a87cd2bc1c4
|
3 |
+
size 4171081728
|
mmdit.opt/model.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:00fe83fb4bdd71886f7153cebb013a279ffcb6c28461f5876e1608fcb0a29425
|
3 |
+
size 1571410
|
mmdit_int8_v1.opt/871e89d8-287f-11ef-8a22-0242c0a80101
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3fec4fc692125a18b731fa5dd45ceb891e06de698e13849bc6bd8cceec31b90c
|
3 |
+
size 8192630784
|
mmdit_int8_v1.opt/model.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:932272f4cd94568af6cd6248be6d87b17a92aceff2aff91c4752bab996b25fe9
|
3 |
+
size 2584017
|
vae_decoder.opt/model.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b4191ca87594e109d18a89aff292f93d433cd9e4e36439c3d7c92ce9b71d87a1
|
3 |
+
size 99267298
|
vae_encoder.opt/model.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:48afed8c7eb5bba3772f798c702e3cd275cba3a2dbb74e29b4bd469de283dfd9
|
3 |
+
size 68683080
|