Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
691cee3
add stable diffusion XL export
echarlaix Jul 6, 2023
b2b8d73
fix style
echarlaix Jul 6, 2023
86bd2aa
fix test model name
echarlaix Jul 6, 2023
9930adb
merge main in branch
echarlaix Jul 6, 2023
d98e859
Fix issues related to merging with main
echarlaix Jul 6, 2023
8f8f595
fix
echarlaix Jul 6, 2023
ef7d65b
fix style
echarlaix Jul 6, 2023
4d4eded
remove clip with projection from test
echarlaix Jul 7, 2023
d813195
change model name
echarlaix Jul 7, 2023
e3b81d0
fix style
echarlaix Jul 7, 2023
4905eab
remove need create pretrainedconfig
echarlaix Jul 7, 2023
a6a68d0
fix style
echarlaix Jul 7, 2023
10497b3
fix dummy input generation
echarlaix Jul 7, 2023
89eb71c
fix style
echarlaix Jul 7, 2023
99755f2
fix style
echarlaix Jul 7, 2023
1777870
add saving second tokenzier when exporting a SD XL model
echarlaix Jul 7, 2023
4aab693
fix style
echarlaix Jul 7, 2023
044a1fa
add SD XL pipeline
echarlaix Jul 10, 2023
99c9736
fix style
echarlaix Jul 10, 2023
45d94c1
add test
echarlaix Jul 10, 2023
ffb337d
add watermarker
echarlaix Jul 10, 2023
3ad4355
fix style
echarlaix Jul 10, 2023
b53e3c3
fix style
echarlaix Jul 10, 2023
cd437ff
fix style
echarlaix Jul 10, 2023
77aaebf
add watermark
echarlaix Jul 11, 2023
40a62e7
add test
echarlaix Jul 11, 2023
02e0304
set default height width stable diffusion pipeline
echarlaix Jul 11, 2023
46d9d1d
add img2img
echarlaix Jul 11, 2023
080f2ba
disable img2img until added
echarlaix Jul 11, 2023
b5c8909
remove img2img
echarlaix Jul 11, 2023
e5d0bb4
add img2img
echarlaix Jul 11, 2023
74457ee
remove redundant
echarlaix Jul 11, 2023
bac78eb
fix style
echarlaix Jul 11, 2023
00d26ba
fix style
echarlaix Jul 11, 2023
fc48e94
enable to only have the second tokenizer and text encoder
echarlaix Jul 11, 2023
6c12200
add test
echarlaix Jul 12, 2023
c522840
minor
echarlaix Jul 12, 2023
13bdbe3
fix cli export
echarlaix Jul 13, 2023
a0d5592
Merge branch 'main' into sd-XL
echarlaix Jul 13, 2023
0426fa4
test for batch size > 1
echarlaix Jul 17, 2023
4b62b78
add documentation export SD XL
echarlaix Jul 17, 2023
b45cf1b
Merge branch 'main' of github.com:huggingface/optimum into add-doc-sdxl
echarlaix Jul 17, 2023
869ade3
fix format
echarlaix Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/source/onnxruntime/package_reference/modeling_ort.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,12 @@ The following ORT classes are available for the following custom tasks.
#### ORTStableDiffusionInpaintPipeline

[[autodoc]] onnxruntime.ORTStableDiffusionInpaintPipeline


#### ORTStableDiffusionXLPipeline

[[autodoc]] onnxruntime.ORTStableDiffusionXLPipeline

#### ORTStableDiffusionXLImg2ImgPipeline

[[autodoc]] onnxruntime.ORTStableDiffusionXLImg2ImgPipeline
51 changes: 48 additions & 3 deletions docs/source/onnxruntime/usage_guides/models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ It is also possible, just as with regular [`~transformers.PreTrainedModel`]s, to
... )
```

## Export and inference of sequence-to-sequence models
## Sequence-to-sequence models

Sequence-to-sequence (Seq2Seq) models can also be used when running inference with ONNX Runtime. When Seq2Seq models
are exported to the ONNX format, they are decomposed into three parts that are later combined during inference:
Expand Down Expand Up @@ -92,7 +92,7 @@ Here is an example of how you can load a T5 model to the ONNX format and run inf
>>> # [{'translation_text': "Il n'est jamais sorti sans un livre sous son bras, et il est souvent revenu avec deux."}]
```

## Export and inference of Stable Diffusion models
## Stable Diffusion

Stable Diffusion models can also be used when running inference with ONNX Runtime. When Stable Diffusion models
are exported to the ONNX format, they are split into four components that are later combined during inference:
Expand All @@ -104,7 +104,7 @@ are exported to the ONNX format, they are split into four components that are la
Make sure you have 🤗 Diffusers installed.

To install `diffusers`:
```
```bash
pip install diffusers
```

Expand Down Expand Up @@ -183,3 +183,48 @@ mask_image = download_image(mask_url).resize((512, 512))
prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
image = pipeline(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
```


## Stable Diffusion XL

Before using `ORTStableDiffusionXLPipeline` make sure to have `diffusers` and `invisible_watermark` installed. You can install the libraries as follows:

```bash
pip install diffusers
pip install invisible-watermark>=2.0
```

### Text-to-Image

Here is an example of how you can load a PyTorch SD XL model, convert it to ONNX on-the-fly and run inference using ONNX Runtime:

```python
from optimum.onnxruntime import ORTStableDiffusionXLPipeline

model_id = "stabilityai/stable-diffusion-xl-base-0.9"
pipeline = ORTStableDiffusionXLPipeline.from_pretrained(model_id, export=True)
prompt = "sailing ship in storm by Leonardo da Vinci"
image = pipeline(prompt).images[0]

# Don't forget to save the ONNX model
save_directory = "a_local_path"
pipeline.save_pretrained(save_directory)

```

### Image-to-Image

The image can be refined by making use of a model like [stabilityai/stable-diffusion-xl-refiner-0.9](https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-0.9). In this case, you only have to output the latents from the base model.


```python
from optimum.onnxruntime import ORTStableDiffusionXLImg2ImgPipeline

use_refiner = True
model_id = "stabilityai/stable-diffusion-xl-refiner-0.9"
refiner = ORTStableDiffusionXLImg2ImgPipeline.from_pretrained(model_id, export=True)

image = pipeline(prompt=prompt, output_type="latent" if use_refiner else "pil").images[0]
image = refiner(prompt=prompt, image=image[None, :]).images[0]
image.save("sailing_ship.png")
```