[ONNX] Stable Diffusion exporter and pipeline#399
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
patil-suraj
left a comment
There was a problem hiding this comment.
Very cool addition! Let's also add tests for this no, maybe in future PR.
Just left some nits :)
patrickvonplaten
left a comment
There was a problem hiding this comment.
Looks very nice! More or less good to go for me - I like the design. Think we could:
- avoid one-liners a bit more
push_to_hubis maybe a bit too much for now- Mark the ONNX class as experimental
- Maybe add a test (ok without for me as well)
Co-authored-by: Suraj Patil <surajp815@gmail.com>
| logger = logging.get_logger(__name__) | ||
|
|
||
|
|
||
| class OnnxModel: |
There was a problem hiding this comment.
turbo nit: ONNX and ONNX Runtime are commonly confused as being the same thing (the former being a format, the latter a runtime)
it would be technically more correct to call this ORTModel or OnnxRuntimeModel since the __call__ method is passing the ONNX model through ONNX Runtime.
(no need to follow this advice, just noting it since the discussion also came up in optimum :))
There was a problem hiding this comment.
Makes sense to me to call it OnnxRuntimeModel -> your call though @anton-l :-)
There was a problem hiding this comment.
If we are going to change the name, I prefer OnnxRuntimeModel too (rather than ORTModel, even if people use ORT all the time).
There was a problem hiding this comment.
Opted for OnnxRuntimeModel!
|
Hi @anton-l, I did a quick try of this PR on DMLExecutionProvider. It works if the safetychecker is commented out as it fails for clip_input error, similar to the error on CPUExecutionProvider. There are few places where a provider is not passed, so I had to make minor changes to make this PR work.
If anyone wants to test this with DmlExecutionProvider on Windows (works on AMD/NVIDIA cards), here are the steps. conda create --name sd39 python=3.9 -y && conda activate sd39
pip install transformers ftfy scipy onnxruntime
cd diffusers/ && git checkout sd-onnx-pipeline && pip install -e .
# Download nightly onnxruntime-directml from the link below
# https://aiinfra.visualstudio.com/PublicPackages/_artifacts/feed/ORT-Nightly/PyPI/ort-nightly-directml/overview/1.13.0.dev20220908001
pip install ort_nightly_directml-1.13.0.dev20220830001-cp39-cp39-win_amd64.whl --force-reinstall |
pcuenca
left a comment
There was a problem hiding this comment.
Amazing work! I don't have much to contribute on top of what the others said. I'll test it in CUDA and CPU later if it helps.
|
Very cool - feel free to merge when you want 🥳 |
|
@pcuenca would be keen to know what inference speed numbers you get on GPU. |
|
cc @anton-l could you verify this real quick? |
|
@tdeboissiere to enable the GPU runtime, you'll need to install one more package on top: Then pipe = StableDiffusionOnnxPipeline.from_pretrained("./sd_onnx", provider="CUDAExecutionProvider") |
|
Yep, that's what I did. I also used this quick hack to ensure SD was executing on GPU I've also found that installing both |
|
Is someone planning on working on an onnx img2img pipeline? That would be awesome |
|
I'm also getting much slower inference speed with Onnx on a 3090. |
|
cc @anton-l |
* initial export and design * update imports * custom prover, import fixes * Update src/diffusers/onnx_utils.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/onnx_utils.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * remove push_to_hub * Update src/diffusers/onnx_utils.py Co-authored-by: Suraj Patil <surajp815@gmail.com> * remove torch_device * numpify the rest of the pipeline * torchify the safety checker * revert tensor * Code review suggestions + quality * fix tests * fix provider, add an end-to-end test * style Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: Suraj Patil <surajp815@gmail.com>
Usage:
pip install onnxruntimepython scripts/convert_stable_diffusion_checkpoint_to_onnx.py --model_path="CompVis/stable-diffusion-v1-4" --output_path="./sd_onnx"