ONNX
How to use ONNX Runtime for inference
🌍 Optimum provides a Stable Diffusion pipeline compatible with ONNX Runtime.
Installation
Install 🌍 Optimum with the following command for ONNX Runtime support:
Copied
Stable Diffusion
Inference
To load an ONNX model and run inference with ONNX Runtime, you need to replace StableDiffusionPipeline with ORTStableDiffusionPipeline
. In case you want to load a PyTorch model and convert it to the ONNX format on-the-fly, you can set export=True
.
Copied
If you want to export the pipeline in the ONNX format offline and later use it for inference, you can use the optimum-cli export
command:
Copied
Then perform inference:
Copied
Notice that we didn’t have to specify export=True
above.
You can find more examples in optimum documentation.
Supported tasks
Task | Loading Class |
---|---|
|
|
|
|
|
|
Stable Diffusion XL
Export
To export your model to ONNX, you can use the Optimum CLI as follows :
Copied
Inference
Here is an example of how you can load a SDXL ONNX model from stabilityai/stable-diffusion-xl-base-1.0 and run inference with ONNX Runtime :
Copied
Supported tasks
Task | Loading Class |
---|---|
|
|
|
|
Known Issues
Generating multiple prompts in a batch seems to take too much memory. While we look into it, you may need to iterate instead of batching.
Last updated