Skip to content

Add SDXL example#44

Open
Abhishek-Varma wants to merge 3 commits into
iree-org:mainfrom
Abhishek-Varma:sdxl_example
Open

Add SDXL example#44
Abhishek-Varma wants to merge 3 commits into
iree-org:mainfrom
Abhishek-Varma:sdxl_example

Conversation

@Abhishek-Varma
Copy link
Copy Markdown
Contributor

Creates models/sdxl and adds scripts to run SDXL through the EP.

Creates models/sdxl and adds scripts to run SDXL through the EP.

Signed-off-by: Abhishek Varma <abhvarma@amd.com>
Comment thread models/sdxl/onnx_utils.py Outdated
Comment thread models/sdxl/export.py Outdated

MODEL_ID = "stabilityai/stable-diffusion-xl-base-1.0"

_INT8_UNET_AZURE_BASE = (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go for one approach and just put all onnx files (i8, f16) on azure and then download them. No need to include the files used to generate them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Can you check now?

Comment thread models/sdxl/run.py
Comment thread models/sdxl/export.py Outdated
continue
url = f"{_INT8_UNET_AZURE_BASE}/{fname}"
logger.info(" Downloading %s ...", fname)
urllib.request.urlretrieve(url, dest)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add timeout, retry and hash verification here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Can you check ?

Comment thread models/sdxl/run.py
Comment on lines +143 to +147
betas = np.linspace(0.00085**0.5, 0.012**0.5, 1000) ** 2
alphas_cumprod = np.cumprod(1.0 - betas)
sigmas = ((1 - alphas_cumprod) / alphas_cumprod) ** 0.5
step_ratio = 1000 // args.steps
timesteps = (np.arange(args.steps) * step_ratio)[::-1].copy()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude says we should be using karras sigmas instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the current linear schedule matches SDXL's default EulerDiscreteScheduler config (the default scheduler that ships with SDXL in HuggingFace diffusers (EulerDiscreteScheduler with use_karras_sigmas=False)).

I'd prefer keeping the default scheduler and matching the model's training config as is.

Comment thread models/sdxl/onnx_utils.py Outdated

torch-mlir's ONNX importer expects Slice parameters (starts, ends, axes,
steps) as ``onnx.Constant`` ops, not graph initializers.
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look at this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Abhishek-Varma could you post a reproducer for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @IanWood1 - seems like this was needed previously but we can now do away with this. I've anyway removed this file in the latest push. Can you check now ?

Comment thread models/sdxl/onnx_utils.py Outdated
Comment on lines +16 to +21
"""Patch Resize ops to 4-input format (X, roi, scales, sizes) for IREE.

The dynamo exporter produces ``Resize(X, "", scales)`` with an empty-string
roi input. The EP's MLIR generator skips empty-name inputs, producing only
2 inputs in MLIR. IREE needs all 4 positional inputs.
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a bug in the EP, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @IanWood1 - I've raised a patch fixing it : #46 - could you please take a look?

Signed-off-by: Abhishek Varma <abhvarma@amd.com>
Copy link
Copy Markdown
Collaborator

@Groverkss Groverkss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will have a look again, but on an initial look, looks very nice! Well done!

Signed-off-by: Abhishek Varma <abhvarma@amd.com>
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

Successfully merging this pull request may close these issues.

4 participants