SDXL? #403
Replies: 3 comments 3 replies
-
If SDXL has been converted to ONNX, then I definitely want to add support for it. I have the SDXL weights downloaded and set up for CUDA, but I haven't had a chance to dig into the ONNX side. Do you have that script handy? Getting the basic pipeline set up should not be too bad. It will take a little bit of work to get XL working with highres, because the current highres implementation runs txt2img followed by img2img in image space, where as XL is using latent space. That's something like I also want to allow passing numpy data between pipelines for other reasons and optimizations, so I'm curious how the results would look if we did SD v1.x highres in latent space instead, but I'll have to try that later. |
Beta Was this translation helpful? Give feedback.
-
I have a branch working with the SDXL base model and some custom txt2img models. I was able to generate 512x512 with a fully fp32 model and 1024x1024 after converting the Unet to fp16, using a 16GB card. Caveats: I haven't started testing on lower memory cards yet, I haven't tested the refiner or img2img yet, and I haven't tested any of this on the DirectML provider (Windows). The changes so far are on the https://github.com/ssube/onnx-web/tree/feat/00-sdxl branch. I've tested it under ORT 1.15 and PyTorch 2.0, with both the CUDA and ROCm providers, and the base model is working reliably. To convert SDXL models to ONNX from repositories on the HuggingFace hub: optimum-cli export onnx --model stabilityai/stable-diffusion-xl-base-1.0 --task stable-diffusion-xl ../models/diffusion-sd_xl_onnx/ To convert SDXL models from import torch
from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline
model = "/tmp/dreamshaper-xl"
pipe = StableDiffusionXLPipeline.from_single_file(f"{model}.safetensors", use_safetensors=True)
pipe.save_pretrained(model) followed by optimum-cli export onnx --model /tmp/dreamshaper-xl --task stable-diffusion-xl ../models/diffusion-dreamshaper-xl/ To optimize the Unet to fp16: import onnx
import torch
import onnxruntime
from onnx.shape_inference import infer_shapes_path
from onnxruntime.transformers.float16 import convert_float_to_float16
model = "/opt/onnx-web/models/diffusion-dreamshaper-xl"
infer_shapes_path(f"{model}/unet/model.onnx")
unet = onnx.load(f"{model}/unet/model.onnx")
opt_model = convert_float_to_float16(unet, disable_shape_infer=True, force_fp16_initializers=True, keep_io_types=True, op_block_list=["Attention", "MultiHeadAttention"])
onnx.save_model(opt_model, f"{model}/unet/model-fp16.onnx", save_as_external_data=True, all_tensors_to_one_file=True, location="weights.pb") A few examples: |
Beta Was this translation helpful? Give feedback.
-
I've merged the SDXL code for the existing pipelines (txt2img, img2img, and inpaint). Converting modules is still a manual process, I need to figure that out next. There are also a few bugs that have come up in the
|
Beta Was this translation helpful? Give feedback.
-
I saw SDXL to be ready to convert run on ONNX ,but with optimum, and with an script conversion for fp16 only working with CUDA, had someone already converted it? I would like to use it for a low mem AMD card....
Beta Was this translation helpful? Give feedback.
All reactions