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

SD3 and Flux support #2073

Merged
merged 32 commits into from
Nov 19, 2024
Merged

SD3 and Flux support #2073

merged 32 commits into from
Nov 19, 2024

Conversation

IlyasMoutawwakil
Copy link
Member

@IlyasMoutawwakil IlyasMoutawwakil commented Oct 21, 2024

What does this PR do?

In this PR we add support of SD3 and Flux Diffusion Pipelines, for onnx export and onnxruntime inference.

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?

Who can review?

@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.

@IlyasMoutawwakil IlyasMoutawwakil marked this pull request as ready for review October 23, 2024 15:33
@IlyasMoutawwakil IlyasMoutawwakil changed the title SD3 support SD3 and Flux support Oct 24, 2024
Copy link
Contributor

@JingyaHuang JingyaHuang left a comment

Choose a reason for hiding this comment

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

LGTM as far as we get the CIs green. Thanks for adding the support @IlyasMoutawwakil !

@kahmed10
Copy link

kahmed10 commented Nov 1, 2024

How would this work with stabilityai/stable-diffusion-3-medium on huggingface?

Even after specifying the framework as pytorch, it's not able infer the correct library for the models:

optimum-cli export onnx --model stabilityai/stable-diffusion-3-medium --framework pt  models/sd3-onnx
  File "/home/kahmed10/.local/bin/optimum-cli", line 8, in <module>
    sys.exit(main())
  File "/home/kahmed10/.local/lib/python3.10/site-packages/optimum/commands/optimum_cli.py", line 208, in main
    service.run()
  File "/home/kahmed10/.local/lib/python3.10/site-packages/optimum/commands/export/onnx.py", line 265, in run
    main_export(
  File "/home/kahmed10/.local/lib/python3.10/site-packages/optimum/exporters/onnx/__main__.py", line 258, in main_export
    task = TasksManager.infer_task_from_model(model_name_or_path)
  File "/home/kahmed10/.local/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 1764, in infer_task_from_model
    inferred_task_name = cls._infer_task_from_model_name_or_path(
  File "/home/kahmed10/.local/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 1678, in _infer_task_from_model_name_or_path
    library_name = cls.infer_library_from_model(
  File "/home/kahmed10/.local/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 1918, in infer_library_from_model
    library_name = cls._infer_library_from_model_name_or_path(
  File "/home/kahmed10/.local/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 1880, in _infer_library_from_model_name_or_path
    raise ValueError(
ValueError: The library name could not be automatically inferred. If using the command-line, please provide the argument --library {transformers,diffusers,timm,sentence_transformers}. Example: `--library diffusers`.

@IlyasMoutawwakil
Copy link
Member Author

IlyasMoutawwakil commented Nov 2, 2024

hi @kahmed10, the pipeline should be loadable with diffusers first, stability has a diffusers-compatible pipeline in stabilityai/stable-diffusion-3-medium-diffusers

@kahmed10
Copy link

kahmed10 commented Nov 4, 2024

hi @kahmed10, the pipeline should be loadable with diffusers first, stability has a diffusers-compatible pipeline in stabilityai/stable-diffusion-3-medium-diffusers

This worked, thanks!!!

optimum-cli export onnx --model stabilityai/stable-diffusion-3-medium-diffusers  models/sd3-onnx

@kahmed10
Copy link

kahmed10 commented Nov 9, 2024

@IlyasMoutawwakil is this planning to be merged in soon? I see in CI there are some tests failing.

@IlyasMoutawwakil
Copy link
Member Author

@kahmed10 it should be merged today, the failing tests are unrelated (because tests saturating the memory).

@IlyasMoutawwakil
Copy link
Member Author

tests are passing except for macos-13 (due to known issue handled in #2085)

Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

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

Looks great thanks @IlyasMoutawwakil

optimum/utils/input_generators.py Outdated Show resolved Hide resolved
optimum/exporters/onnx/model_configs.py Outdated Show resolved Hide resolved
optimum/exporters/onnx/model_configs.py Show resolved Hide resolved
@IlyasMoutawwakil
Copy link
Member Author

will merge once all ci is finished !

@IlyasMoutawwakil
Copy link
Member Author

IlyasMoutawwakil commented Nov 18, 2024

with the merged #2085, I added some checks based on transformers and diffusers versions.

@IlyasMoutawwakil IlyasMoutawwakil force-pushed the diffusers-transformer-export branch from a21148f to 2183fb7 Compare November 19, 2024 10:07
@IlyasMoutawwakil IlyasMoutawwakil merged commit a7a807c into main Nov 19, 2024
41 checks passed
@IlyasMoutawwakil IlyasMoutawwakil deleted the diffusers-transformer-export branch November 19, 2024 12:11
@xhcao
Copy link

xhcao commented Nov 25, 2024

Hi, @IlyasMoutawwakil Did this patch support to export the series of SD3 to onnx models, include SD3.5 large, SD3.5 Large Turbo, SD3.5 Medium and SD3.0-medium?

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.

6 participants