-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add OmniGen #10148
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
Merged
Merged
Add OmniGen #10148
Changes from 29 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
36eee40
OmniGen model.py
staoxiao bbe2b98
update OmniGenTransformerModel
staoxiao b839590
omnigen pipeline
staoxiao 0d04194
omnigen pipeline
staoxiao 85abe5e
update omnigen_pipeline
staoxiao db92c69
test case for omnigen
staoxiao 308766c
update omnigenpipeline
staoxiao 4c5e8c5
update docs
staoxiao d9f80fc
update docs
staoxiao c78d1f4
offload_transformer
staoxiao 236f14b
enable_transformer_block_cpu_offload
staoxiao 6b52547
update docs
staoxiao 4fef9c8
reformat
staoxiao f2fc182
reformat
staoxiao 5f3148d
reformat
staoxiao cdd500e
Merge pull request #1 from huggingface/main
staoxiao 178d377
update docs
staoxiao 08c05f9
update docs
staoxiao 286990d
make style
staoxiao 3bb092b
make style
staoxiao 5925cb9
Update docs/source/en/api/models/omnigen_transformer.md
staoxiao 56aa821
Update docs/source/en/using-diffusers/omnigen.md
staoxiao 1e33ca8
Update docs/source/en/using-diffusers/omnigen.md
staoxiao c81a84d
update docs
staoxiao 3867830
revert changes to examples/
a-r-r-o-w c8b8173
Merge branch 'main' into main
a-r-r-o-w af0effa
update OmniGen2DModel
staoxiao a0cd392
make style
staoxiao 48fd390
update test cases
staoxiao 78431e1
Update docs/source/en/api/pipelines/omnigen.md
staoxiao d99a9f8
Update docs/source/en/using-diffusers/omnigen.md
staoxiao 61d802a
Update docs/source/en/using-diffusers/omnigen.md
staoxiao 8d6a35e
Update docs/source/en/using-diffusers/omnigen.md
staoxiao f8e645b
Update docs/source/en/using-diffusers/omnigen.md
staoxiao 85cdeb9
Update docs/source/en/using-diffusers/omnigen.md
staoxiao 3565837
update docs
staoxiao 0ccca15
typo
staoxiao d014f95
Update src/diffusers/models/embeddings.py
staoxiao 753daec
Update src/diffusers/models/attention.py
staoxiao 3d30a2a
Update src/diffusers/models/transformers/transformer_omnigen.py
staoxiao 9d1580a
Update src/diffusers/models/transformers/transformer_omnigen.py
staoxiao 6a58746
Update src/diffusers/models/transformers/transformer_omnigen.py
staoxiao 2b464c8
Update src/diffusers/pipelines/omnigen/pipeline_omnigen.py
staoxiao 7888119
Update src/diffusers/pipelines/omnigen/pipeline_omnigen.py
staoxiao 39148c3
Update src/diffusers/pipelines/omnigen/pipeline_omnigen.py
staoxiao 52a6f9e
Update tests/pipelines/omnigen/test_pipeline_omnigen.py
staoxiao aeea57a
Update tests/pipelines/omnigen/test_pipeline_omnigen.py
staoxiao 6b1177b
Update src/diffusers/pipelines/omnigen/pipeline_omnigen.py
staoxiao 7003a80
Update src/diffusers/pipelines/omnigen/pipeline_omnigen.py
staoxiao 792c3e6
Update src/diffusers/pipelines/omnigen/pipeline_omnigen.py
staoxiao b0c6267
Merge pull request #2 from huggingface/main
staoxiao f5e3f0b
consistent attention processor
staoxiao 3541ab8
updata
staoxiao 4e9850a
update
staoxiao f91cfcf
check_inputs
staoxiao 711dded
make style
staoxiao 565e51c
update testpipeline
staoxiao 29ad6ae
update testpipeline
staoxiao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!--Copyright 2024 The HuggingFace Team. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
--> | ||
|
||
# OmniGenTransformer2DModel | ||
|
||
A Transformer model that accepts multimodal instructions to generate images for [OmniGen](https://github.com/VectorSpaceLab/OmniGen/). | ||
|
||
## OmniGenTransformer2DModel | ||
|
||
[[autodoc]] OmniGenTransformer2DModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<!--Copyright 2024 The HuggingFace Team. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
--> | ||
|
||
# OmniGen | ||
|
||
[OmniGen: Unified Image Generation](https://arxiv.org/pdf/2409.11340) from BAAI, by Shitao Xiao, Yueze Wang, Junjie Zhou, Huaying Yuan, Xingrun Xing, Ruiran Yan, Chaofan Li, Shuting Wang, Tiejun Huang, Zheng Liu. | ||
|
||
The abstract from the paper is: | ||
|
||
*The emergence of Large Language Models (LLMs) has unified language | ||
generation tasks and revolutionized human-machine interaction. | ||
However, in the realm of image generation, a unified model capable of handling various tasks | ||
within a single framework remains largely unexplored. In | ||
this work, we introduce OmniGen, a new diffusion model | ||
for unified image generation. OmniGen is characterized | ||
by the following features: 1) Unification: OmniGen not | ||
only demonstrates text-to-image generation capabilities but | ||
also inherently supports various downstream tasks, such | ||
as image editing, subject-driven generation, and visual conditional generation. 2) Simplicity: The architecture of | ||
OmniGen is highly simplified, eliminating the need for additional plugins. Moreover, compared to existing diffusion | ||
models, it is more user-friendly and can complete complex | ||
tasks end-to-end through instructions without the need for | ||
extra intermediate steps, greatly simplifying the image generation workflow. 3) Knowledge Transfer: Benefit from | ||
learning in a unified format, OmniGen effectively transfers | ||
knowledge across different tasks, manages unseen tasks and | ||
domains, and exhibits novel capabilities. We also explore | ||
the model’s reasoning capabilities and potential applications of the chain-of-thought mechanism. | ||
This work represents the first attempt at a general-purpose image generation model, | ||
and we will release our resources at https: | ||
//github.com/VectorSpaceLab/OmniGen to foster future advancements.* | ||
|
||
<Tip> | ||
|
||
Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers.md) to learn how to explore the tradeoff between scheduler speed and quality, and see the [reuse components across pipelines](../../using-diffusers/loading.md#reuse-a-pipeline) section to learn how to efficiently load the same components into multiple pipelines. | ||
|
||
</Tip> | ||
|
||
This pipeline was contributed by [staoxiao](https://github.com/staoxiao). The original codebase can be found [here](https://github.com/VectorSpaceLab/OmniGen). The original weights can be found under [hf.co/shitao](https://huggingface.co/Shitao/OmniGen-v1). | ||
|
||
|
||
## Inference | ||
|
||
First, load the pipeline: | ||
|
||
```python | ||
import torch | ||
from diffusers import OmniGenPipeline | ||
pipe = OmniGenPipeline.from_pretrained( | ||
"Shitao/OmniGen-v1-diffusers", | ||
torch_dtype=torch.bfloat16 | ||
) | ||
pipe.to("cuda") | ||
``` | ||
|
||
For text-to-image, pass a text prompt. By default, OmniGen generates a 1024x1024 image. | ||
You can try setting the `height` and `width` parameters to generate images with different size. | ||
|
||
```py | ||
prompt = "Realistic photo. A young woman sits on a sofa, holding a book and facing the camera. She wears delicate silver hoop earrings adorned with tiny, sparkling diamonds that catch the light, with her long chestnut hair cascading over her shoulders. Her eyes are focused and gentle, framed by long, dark lashes. She is dressed in a cozy cream sweater, which complements her warm, inviting smile. Behind her, there is a table with a cup of water in a sleek, minimalist blue mug. The background is a serene indoor setting with soft natural light filtering through a window, adorned with tasteful art and flowers, creating a cozy and peaceful ambiance. 4K, HD." | ||
image = pipe( | ||
prompt=prompt, | ||
height=1024, | ||
width=1024, | ||
guidance_scale=3, | ||
generator=torch.Generator(device="cpu").manual_seed(111), | ||
).images[0] | ||
image | ||
``` | ||
|
||
OmniGen supports for multimodal inputs. | ||
When the input includes an image, you need to add a placeholder `<img><|image_1|></img>` in the text prompt to represent the image. | ||
It is recommended to enable 'use_input_image_size_as_output' to keep the edited image the same size as the original image. | ||
|
||
```py | ||
prompt="<img><|image_1|></img> Remove the woman's earrings. Replace the mug with a clear glass filled with sparkling iced cola." | ||
input_images=[load_image("https://raw.githubusercontent.com/VectorSpaceLab/OmniGen/main/imgs/docs_img/t2i_woman_with_book.png")] | ||
image = pipe( | ||
prompt=prompt, | ||
input_images=input_images, | ||
guidance_scale=2, | ||
img_guidance_scale=1.6, | ||
use_input_image_size_as_output=True, | ||
generator=torch.Generator(device="cpu").manual_seed(222)).images[0] | ||
image | ||
``` | ||
|
||
|
||
## OmniGenPipeline | ||
|
||
[[autodoc]] OmniGenPipeline | ||
- all | ||
- __call__ | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.