cassiebreviu / StableDiffusion

Inference Stable Diffusion with C# and ONNX Runtime
MIT License
218 stars 49 forks source link

Add ddim scheduler #10

Closed ZTMIDGO closed 1 year ago

ZTMIDGO commented 1 year ago

The current LMS scheduler has poor quality for quantized UINT8 model generation.

Hopefully, DDIM and DPMS schedulers can be added, and DDIM and DPMS schedulers can improve build quality

jdluzen commented 1 year ago

I've been attempting to port the DDIM scheduler, but no luck so far. This is where I got stuck on my own implementation of SD for C#. What are you using for UINT8 quantization? My current goal is to get it running as fast as it can on the CPU.

ZTMIDGO commented 1 year ago

@jdluzen I use this code for uint8 quantization https://github.com/LowinLi/stable-diffusion-streamlit/blob/main/src/stable-diffusion-streamlit/pages/model/quantization.py, Currently I'm trying to run sd on a mobile device using onnxruntime-android but it's very slow, on a Qualcomm 855 CPU it takes 5 seconds to run a step, I don't know how to make it run faster on an arm CPU at the moment, Nnapi doesn't do anything

jdluzen commented 1 year ago

Thanks, that's what I was doing as well. I'll keep trying to chip away at porting and see what happens. Do you know if LMS doesn't like INT8 in general? Or maybe we can make it INT8 aware?

ZTMIDGO commented 1 year ago

@jdluzen lms is not suitable for unt8, you need to use eulerA or dpm solvent, you can refer to Python to write eulerA and dpm solvent

https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py

jdluzen commented 1 year ago

Well, EulerA is ported. It doesn't work, but it compiles and runs incorrectly 😅 I need to push it to a fork and then PR it to get some more eyes on it. I've got a ton of changes locally to sift through first.

jdluzen commented 1 year ago

Draft PR is available: https://github.com/cassiebreviu/StableDiffusion/pull/12

cassiebreviu commented 1 year ago

PR 12 is now working. The EulerA scheduler will be in the main branch soon!