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

Make stable diffusion pipelines compatible with compel #581

Merged
merged 7 commits into from
Apr 30, 2024

Conversation

JingyaHuang
Copy link
Collaborator

@JingyaHuang JingyaHuang commented Apr 25, 2024

What does this PR do?

  • Make NeuronStableDiffusionXLPipeline compel compatible
  • Make NeuronStableDiffusionPipeline compel compatible
  • Tests
  • Fix the neuron config wrongly reconstructed for sdxl's text encoder 2

Fixes #357

@neo @Suprhimp

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@dacorvo dacorvo 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 ! And my deepest apologies for the wrongly formatted TGI test from my last pull-request you had to fix (looks like style-check is not triggered on TGI changes).

Copy link
Contributor

@neo neo left a comment

Choose a reason for hiding this comment

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

Thank you for inviting me to review! I left some minor comments, and I also tested it and it seemed like this would fix #371 as well 😆

optimum/exporters/neuron/__main__.py Outdated Show resolved Hide resolved
optimum/neuron/modeling_diffusion.py Outdated Show resolved Hide resolved
optimum/neuron/modeling_diffusion.py Outdated Show resolved Hide resolved
optimum/neuron/modeling_diffusion.py Outdated Show resolved Hide resolved
@Suprhimp
Copy link

I tested with my own model even with lora, and it works pretty well.

I compiled with output_hidden_states params true

And I tested with this example code 😃


from optimum.neuron import NeuronStableDiffusionXLPipeline
from compel import Compel, ReturnedEmbeddingsType

pipe = NeuronStableDiffusionXLPipeline.from_pretrained("sdxl_turbo_neuron/", data_parallel_mode="all")
prompt = "Self-portrait oil painting++++++++++, a beautiful cyborg with golden hair, 8k"
negative_prompt = "worst quality"

compel = Compel(
        tokenizer=[pipe.tokenizer, pipe.tokenizer_2],
        text_encoder=[pipe.text_encoder, pipe.text_encoder_2],
        returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
        requires_pooled=[False, True],
    )
prompt_embeds, pooled = compel(prompt)
neg_prompt_embeds, neg_pooled = compel(negative_prompt)

images = pipe(
        prompt_embeds=prompt_embeds,
        negative_prompt_embeds=neg_prompt_embeds,
        pooled_prompt_embeds=pooled,
        negative_pooled_prompt_embeds=neg_pooled, 
        guidance_scale=0.0, num_inference_steps=1).images

Thanks for the update!

JingyaHuang and others added 3 commits April 30, 2024 15:38
Co-authored-by: Wenchen Li <9028430+neo@users.noreply.github.com>
Co-authored-by: Wenchen Li <9028430+neo@users.noreply.github.com>
@JingyaHuang JingyaHuang requested a review from neo April 30, 2024 15:41
Copy link
Contributor

@neo neo left a comment

Choose a reason for hiding this comment

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

glad you like my suggestions! 😆

and thank you for making this happen ❤️

@JingyaHuang JingyaHuang merged commit 5643f94 into main Apr 30, 2024
12 of 14 checks passed
@JingyaHuang JingyaHuang deleted the lez-support-compel branch April 30, 2024 17:12
@JingyaHuang
Copy link
Collaborator Author

Thanks @neo and @Suprhimp for the help, the PR is merged. I will include it in our next release!

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.

SDXL with Compel: unexpected keyword argument output_hidden_states
5 participants