Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Stable Diffusion Inpainting model to FP16 with FP32 inputs #2147

Open
jdp8 opened this issue Jan 2, 2025 · 0 comments
Open

Convert Stable Diffusion Inpainting model to FP16 with FP32 inputs #2147

jdp8 opened this issue Jan 2, 2025 · 0 comments

Comments

@jdp8
Copy link

jdp8 commented Jan 2, 2025

Feature request

I've used this script to convert models to ONNX in FP16 format but maintaining the FP32 inputs. One of the models that I converted was Stable Diffusion 2 Inpainting to FP16 and tried to use it in ONNX Runtime and ONNX Runtime Web but it doesn't give me the expected results in either engine. I also converted the model with the Optimum conversion script to FP32 and this model gives me the expected result in ONNX Runtime. Results are shown below:

Input Image:
inpaint

Mask Image:
inpaint_mask

Correct Onnx Runtime Output (converted with Optimum script):
onnx_cat

Incorrect Onnx Runtime Output (converted with Stable-Diffusion-ONNX-FP16 script):
onnx_cat_discolored

Incorrect Onnx Runtime Web Output (converted with Stable-Diffusion-ONNX-FP16 script):
Colorful_cat_picture

I've also used the Optimum conversion script to convert the model to FP16 and this worked but the inputs are expected to be FP16. This datatype does not exist in JavaScript (specifically, Float16Array) and therefore cannot be used in ONNX Runtime Web.

With that being said, is it possible to convert a model to FP16 but leaving the inputs as FP32 in order for the UNET to be less than 2 GB?

Motivation

I would like to run Stable Diffusion Inpainting in ONNX Runtime Web and for the UNET to be less than 2GB. The FP16 model that I have at the moment gives me an output that is not as expected in ONNX Runtime and ONNX Runtime Web. So far, only the Optimum models give me a correct output in ONNX Runtime but I would like to use this in ONNX Runtime Web.

Your contribution

I am willing to contribute to this change given some guidance. Not sure how difficult it would be but I believe it would be similar to how it's implemented in the script mentioned beforehand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant