forked from huggingface/diffusers
-
Notifications
You must be signed in to change notification settings - Fork 0
Mirage Pipeline #1
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
Open
DavidBert
wants to merge
39
commits into
main
Choose a base branch
from
mirage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
016316a
mirage pipeline first commit
4ac274b
use attention processors
904debc
use diffusers rmsnorm
122115a
use diffusers timestep embedding method
e3fe0e8
remove MirageParams
85ae87b
checkpoint conversion script
9a697d0
ruff formating
34fa9dd
remove dependencies to old checkpoints
5cc965a
remove old checkpoints dependency
d79cd8f
move default height and width in checkpoint config
f2759fd
add docstrings
394f725
if conditions and raised as ValueError instead of asserts
54fb063
small fix
c49fafb
nit remove try block at import
7e7df35
mirage pipeline doc
de03851
update doc
a69aa4b
rename model to photon
9e099a7
mirage pipeline first commit
6e10ed4
use attention processors
866c6de
use diffusers rmsnorm
4e8b647
use diffusers timestep embedding method
472ad97
remove MirageParams
97a231e
checkpoint conversion script
35d721f
ruff formating
775a115
remove dependencies to old checkpoints
1c6c25c
remove old checkpoints dependency
b0d965c
move default height and width in checkpoint config
235fe49
add docstrings
a6ff579
if conditions and raised as ValueError instead of asserts
3a91503
small fix
e200cf6
nit remove try block at import
2ea8976
mirage pipeline doc
26429a3
update doc
0abe136
rename model to photon
fe0e3d5
add text tower and vae in checkpoint
855b068
update doc
d2c6bdd
Merge branch 'mirage' of https://github.com/Photoroom/diffusers into …
89beae8
update photon doc
2df0e2f
ruff fixes
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| <!-- Copyright 2025 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. --> | ||
|
|
||
| # MiragePipeline | ||
|
|
||
| <div class="flex flex-wrap space-x-1"> | ||
| <img alt="LoRA" src="https://img.shields.io/badge/LoRA-d8b4fe?style=flat"/> | ||
| </div> | ||
|
|
||
| Mirage is a text-to-image diffusion model using a transformer-based architecture with flow matching for efficient high-quality image generation. The model uses T5Gemma as the text encoder and supports both Flux VAE (AutoencoderKL) and DC-AE (AutoencoderDC) for latent compression. | ||
|
|
||
| Key features: | ||
|
|
||
| - **Simplified MMDIT architecture**: Uses a simplified MMDIT architecture for image generation where text tokens are not updated through the transformer blocks | ||
| - **Flow Matching**: Employs flow matching with discrete scheduling for efficient sampling | ||
| - **Flexible VAE Support**: Compatible with both Flux VAE (8x compression, 16 latent channels) and DC-AE (32x compression, 32 latent channels) | ||
| - **T5Gemma Text Encoder**: Uses Google's T5Gemma-2B-2B-UL2 model for text encoding offering multiple language support | ||
| - **Efficient Architecture**: ~1.3B parameters in the transformer, enabling fast inference while maintaining quality | ||
|
|
||
|
|
||
| ## Loading the Pipeline | ||
|
|
||
| Mirage checkpoints only store the transformer and scheduler weights locally. The VAE and text encoder are automatically loaded from HuggingFace during pipeline initialization: | ||
|
|
||
| ```py | ||
| from diffusers import MiragePipeline | ||
|
|
||
| # Load pipeline - VAE and text encoder will be loaded from HuggingFace | ||
| pipe = MiragePipeline.from_pretrained("path/to/mirage_checkpoint") | ||
| pipe.to("cuda") | ||
|
|
||
| prompt = "A vibrant night sky filled with colorful fireworks, with one large firework burst forming the glowing text “Photon” in bright, sparkling light" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha, awesome! |
||
| image = pipe(prompt, num_inference_steps=28, guidance_scale=4.0).images[0] | ||
| image.save("mirage_output.png") | ||
| ``` | ||
|
|
||
| ### Manual Component Loading | ||
|
|
||
| You can also load components individually: | ||
|
|
||
| ```py | ||
| import torch | ||
| from diffusers import MiragePipeline | ||
| from diffusers.models import AutoencoderKL, AutoencoderDC | ||
| from diffusers.models.transformers.transformer_mirage import MirageTransformer2DModel | ||
| from diffusers.schedulers import FlowMatchEulerDiscreteScheduler | ||
| from transformers import T5GemmaModel, GemmaTokenizerFast | ||
|
|
||
| # Load transformer | ||
| transformer = MirageTransformer2DModel.from_pretrained( | ||
| "path/to/checkpoint", subfolder="transformer" | ||
| ) | ||
|
|
||
| # Load scheduler | ||
| scheduler = FlowMatchEulerDiscreteScheduler.from_pretrained( | ||
| "path/to/checkpoint", subfolder="scheduler" | ||
| ) | ||
|
|
||
| # Load T5Gemma text encoder | ||
| t5gemma_model = T5GemmaModel.from_pretrained("google/t5gemma-2b-2b-ul2") | ||
| text_encoder = t5gemma_model.encoder | ||
| tokenizer = GemmaTokenizerFast.from_pretrained("google/t5gemma-2b-2b-ul2") | ||
|
|
||
| # Load VAE - choose either Flux VAE or DC-AE | ||
| # Flux VAE (16 latent channels): | ||
| vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev", subfolder="vae") | ||
| # Or DC-AE (32 latent channels): | ||
| # vae = AutoencoderDC.from_pretrained("mit-han-lab/dc-ae-f32c32-sana-1.0-diffusers") | ||
|
|
||
| pipe = MiragePipeline( | ||
| transformer=transformer, | ||
| scheduler=scheduler, | ||
| text_encoder=text_encoder, | ||
| tokenizer=tokenizer, | ||
| vae=vae | ||
| ) | ||
| pipe.to("cuda") | ||
| ``` | ||
|
|
||
| ## VAE Variants | ||
|
|
||
| Mirage supports two VAE configurations: | ||
|
|
||
| ### Flux VAE (AutoencoderKL) | ||
| - **Compression**: 8x spatial compression | ||
| - **Latent channels**: 16 | ||
| - **Model**: `black-forest-labs/FLUX.1-dev` (subfolder: "vae") | ||
| - **Use case**: Balanced quality and speed | ||
|
|
||
| ### DC-AE (AutoencoderDC) | ||
| - **Compression**: 32x spatial compression | ||
| - **Latent channels**: 32 | ||
| - **Model**: `mit-han-lab/dc-ae-f32c32-sana-1.0-diffusers` | ||
| - **Use case**: Higher compression for faster processing | ||
|
|
||
| The VAE type is automatically determined from the checkpoint's `model_index.json` configuration. | ||
|
|
||
| ## Generation Parameters | ||
|
|
||
| Key parameters for image generation: | ||
|
|
||
| - **num_inference_steps**: Number of denoising steps (default: 28). More steps generally improve quality at the cost of speed. | ||
| - **guidance_scale**: Classifier-free guidance strength (default: 4.0). Higher values produce images more closely aligned with the prompt. | ||
| - **height/width**: Output image dimensions (default: 512x512). Can be customized in the checkpoint configuration. | ||
|
|
||
| ```py | ||
| # Example with custom parameters | ||
| image = pipe( | ||
| prompt="A vibrant night sky filled with colorful fireworks, with one large firework burst forming the glowing text “Photon” in bright, sparkling light", | ||
| num_inference_steps=28, | ||
| guidance_scale=4.0, | ||
| height=512, | ||
| width=512, | ||
| generator=torch.Generator("cuda").manual_seed(42) | ||
| ).images[0] | ||
| ``` | ||
|
|
||
| ## Memory Optimization | ||
|
|
||
| For memory-constrained environments: | ||
|
|
||
| ```py | ||
| import torch | ||
| from diffusers import MiragePipeline | ||
|
|
||
| pipe = MiragePipeline.from_pretrained("path/to/checkpoint", torch_dtype=torch.float16) | ||
| pipe.enable_model_cpu_offload() # Offload components to CPU when not in use | ||
|
|
||
| # Or use sequential CPU offload for even lower memory | ||
| pipe.enable_sequential_cpu_offload() | ||
| ``` | ||
|
|
||
| ## MiragePipeline | ||
|
|
||
| [[autodoc]] MiragePipeline | ||
| - all | ||
| - __call__ | ||
|
|
||
| ## MiragePipelineOutput | ||
|
|
||
| [[autodoc]] pipelines.mirage.pipeline_output.MiragePipelineOutput | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we'll be able to store the checkpoint on Hugging Face as well, right? If yes, we should not forget to update the paths here to the official one, to make this truly copy-paste and run.