ZTMIDGO / Android-Stable-diffusion-ONNX

使用Android手机的CPU推理stable diffusion
127 stars 26 forks source link

APK界面和编译 #3

Open yx-chan131 opened 1 year ago

yx-chan131 commented 1 year ago

你好,请问安装好的应用界面里分别是什么?我理解dropdown 192-512应该是生成图像大小,7.5和8分别是什么?

ZTMIDGO commented 1 year ago

第一个dropdown是宽度,第二个是高度,7.5是指导系数,8指步长

ZTMIDGO commented 1 year ago

可以通过 git clone https://huggingface.co/TIEMING/Chilloutmix 下载模型,然后把下载好的模型放到Path Manager类里的路径

yx-chan131 commented 1 year ago

@ZTMIDGO 感谢回复!想再请问这项目能支持其他任意ONNX版本的SD模型吗?

ZTMIDGO commented 1 year ago

支持,你可以使用 https://github.com/Amblyopius/Stable-Diffusion-ONNX-FP16 把pytorch转为onnx,然后使用 https://onnxruntime.ai/docs/performance/model-optimizations/ort-format-models.html 对模型进行量化,可以使用 https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/main 这里的模型测试转换

yx-chan131 commented 1 year ago

支持,你可以使用 https://github.com/Amblyopius/Stable-Diffusion-ONNX-FP16 把pytorch转为onnx,然后使用 https://onnxruntime.ai/docs/performance/model-optimizations/ort-format-models.html 对模型进行量化,可以使用 https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/main 这里的模型测试转换

@ZTMIDGO 你好,请问你能提供你转的chilloutmix pytorch模型huggingFace链接吗?我想尝试自己进行转换,再生成apk测试方法一致性。谢谢!

ZTMIDGO commented 1 year ago

支持,你可以使用 https://github.com/Amblyopius/Stable-Diffusion-ONNX-FP16 把pytorch转为onnx,然后使用 https://onnxruntime.ai/docs/performance/model-optimizations/ort-format-models.html 对模型进行量化,可以使用 https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/main 这里的模型测试转换

@ZTMIDGO 你好,请问你能提供你转的chilloutmix pytorch模型huggingFace链接吗?我想尝试自己进行转换,再生成apk测试方法一致性。谢谢!

这个模型是从Civitai上下载的, https://civitai.com/models/6424/chilloutmix, 你可以用 https://github.com/Amblyopius/Stable-Diffusion-ONNX-FP16 进行转化为onnx,不过要转为fp32,不可以使用fp16

yx-chan131 commented 1 year ago

支持,你可以使用 https://github.com/Amblyopius/Stable-Diffusion-ONNX-FP16 把pytorch转为onnx,然后使用 https://onnxruntime.ai/docs/performance/model-optimizations/ort-format-models.html 对模型进行量化,可以使用 https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/main 这里的模型测试转换

@ZTMIDGO 你好,请问你能提供你转的chilloutmix pytorch模型huggingFace链接吗?我想尝试自己进行转换,再生成apk测试方法一致性。谢谢!

这个模型是从Civitai上下载的, https://civitai.com/models/6424/chilloutmix, 你可以用 https://github.com/Amblyopius/Stable-Diffusion-ONNX-FP16 进行转化为onnx,不过要转为fp32,不可以使用fp16

@ZTMIDGO 请问是下载哪个版本的chilloutmix? image

可以说明一下为什么不能使用fp16的吗?

ZTMIDGO commented 1 year ago

用第一个fp32-fix,因为目前onnxruntime没办法对fp16的sd模型进行量化。

ZTMIDGO commented 1 year ago

如果对文本生成有所兴趣,你也可以去了解一下rwkv的Android版

https://github.com/ZTMIDGO/RWKV-Android

yx-chan131 commented 1 year ago

用第一个fp32-fix,因为目前onnxruntime没办法对fp16的sd模型进行量化。

@ZTMIDGO 我的转onnx指令: python conv_sd_to_onnx.py --model_path "D:\model_weights\stable_diffusion\chilloutmix\chilloutmix_NiPrunedFp32Fix.safetensors" --output_path "./model/chilloutmix"

模型转换过程报错了: bug

想请问你知道是什么原因吗?能否麻烦你提供完整转模型的指令?谢谢~

ZTMIDGO commented 1 year ago

conv_sd_to_onnx.txt 用这个文件转, 直接修改代码里的--model_path 和 --output_path,然后运行conv_sd_to_onnx

hubin858130 commented 1 year ago

感觉量化到Int8后效果非常不理想啊,每次都是丑八怪,有什么技巧吗?

ZTMIDGO commented 1 year ago

感觉量化到Int8后效果非常不理想啊,每次都是丑八怪,有什么技巧吗?

@hubin858130 可以自己转为用fp16的模型,但可能会比较慢。

yx-chan131 commented 1 year ago

conv_sd_to_onnx.txt 用这个文件转, 直接修改代码里的--model_path 和 --output_path,然后运行conv_sd_to_onnx

@ZTMIDGO v1-inference.yml可以顺便提供吗? image

ZTMIDGO commented 1 year ago

@yx-chan131 在 https://github.com/Amblyopius/Stable-Diffusion-ONNX-FP16 目录下有提供 v1-inference.yml

ZTMIDGO commented 1 year ago

@hubin858130 @yx-chan131 你可以试一下新的App https://huggingface.co/TIEMING/Chilloutmix/blob/main/app-release-int8.apk

不同的调度器生成的效果可能会有所不同,目前改为欧拉祖先采样,在超过8个步长上应该会比dpms好一些。

cap

fuerpy commented 1 year ago

现在还不能支持GPU加速吗?是有什么block点吗?我注意到最近tensorflow有准备合入group norm这个算子

ZTMIDGO commented 1 year ago

@fuerpy 我晚点会试一下,不过我刚刚看了TensorFlow的官方最新版本是3月份打包的,估计要手动编译最新的代码。

fuerpy commented 1 year ago

我看上一次 release 是5月30号,如果自己编译的话会更快一些。如果用GPU来加速的话,应该是使用FP16的模型对吧?

ZTMIDGO commented 1 year ago

@fuerpy 是,但FP16占用的内存太大,模型如果支持NNAPI,可以量化为int8,使用DSP或者NPU运行。

fuerpy commented 1 year ago

这个方法比较难实现,算子方面的支持,如果再NPU或者DSP上的话应该除了tensorflow还需要高通之类的芯片供应商的支持,以我现在的了解,他们还不打算支持