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

Enable Latent Consistency models ONNX export #1469

Merged
merged 23 commits into from
Oct 30, 2023
Merged

Conversation

echarlaix
Copy link
Collaborator

@echarlaix echarlaix commented Oct 19, 2023

Add Latent Consistency models (added in diffusers in huggingface/diffusers#5438 and huggingface/diffusers#5448 ) ONNX export and pipeline to enable ONNX Runtime inference for text-to-image

from optimum.onnxruntime import ORTLatentConsistencyModelPipeline

pipe = ORTLatentConsistencyModelPipeline.from_pretrained("SimianLuo/LCM_Dreamshaper_v7", export=True)
prompt = "sailing ship in storm by Leonardo da Vinci"
images = pipe(prompt=prompt, num_inference_steps=4, guidance_scale=8.0).images

Also enable ONNX export using the CLI :

optimum-cli export onnx --model SimianLuo/LCM_Dreamshaper_v7 lcm_onnx/

OpenVINO integration : huggingface/optimum-intel#463

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 24, 2023

The documentation is not available anymore as the PR was closed or merged.

@echarlaix echarlaix marked this pull request as ready for review October 25, 2023 09:05
@@ -435,7 +435,7 @@ def ordered_inputs(self, model: Union["PreTrainedModel", "TFPreTrainedModel"]) -
sig = inspect.signature(model.call)

for param in sig.parameters:
param_regex = re.compile(rf"{param}(\.\d*)?")
param_regex = re.compile(rf"{param}(\..*)?$")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this modification comes from timestep matching both timestep and timestep_cond previously (behavior that we don't want), we still want past_key_value to match past_key_values.0.key though

.github/workflows/test_onnxruntime.yml Outdated Show resolved Hide resolved
tests/onnxruntime/test_stable_diffusion_pipeline.py Outdated Show resolved Hide resolved
optimum/onnxruntime/modeling_diffusion.py Show resolved Hide resolved
optimum/utils/dummy_diffusers_objects.py Show resolved Hide resolved
Copy link
Member

@michaelbenayoun michaelbenayoun left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @echarlaix !


@parameterized.expand(SUPPORTED_ARCHITECTURES)
@require_diffusers
@unittest.skipIf(parse(_diffusers_version) <= Version("0.21.4"), "not supported with this diffusers version")
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would specify the minimal diffusers version needed in the skip message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point, will add it !

@echarlaix echarlaix merged commit 01dd5c3 into main Oct 30, 2023
64 of 68 checks passed
@echarlaix echarlaix deleted the latent-consistency branch October 30, 2023 14:52
@echarlaix echarlaix mentioned this pull request Oct 31, 2023
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