-
Notifications
You must be signed in to change notification settings - Fork 63
Diffusers support #604
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
quic-amitraj
merged 55 commits into
quic:main
from
quic-amitraj:config_support_diffusers
Dec 9, 2025
Merged
Diffusers support #604
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
70321a4
Stage-1 export debug
quic-amitraj 15d34bb
Stage-2 Export inital working version done
quic-amitraj b9fba19
Stage-3 compilation work is under progress
quic-amitraj 966352c
Stage-4 Working pipeline with wrong output
quic-amitraj 2405b7b
Testing
quic-amitraj 2567b11
Testing
quic-amitraj b9e8400
Working sd3-turbo
quic-amitraj 49478f6
Working with cleaned code
quic-amitraj cf4c274
Working with cleaned code
quic-amitraj ccefb16
Working with vae_included
quic-amitraj 6ce1a91
Fix-1
quic-amitraj fcb6b11
Fix-2
quic-amitraj dea04f5
Fix-3
quic-amitraj 4b4263d
Added readme for diffusers
quic-amitraj 401c95d
Code cleanup
quic-amitraj bc3ae68
Code cleanup-2
quic-amitraj 51d8161
Minor fix
quic-amitraj 701a8f4
Added Support of flux
quic-amitraj e63e2a4
Updated seq_len of flux transformers
tv-karthikeya 1a2c3c3
Removing SD3, adding small fix for flux model hash
tv-karthikeya ce1142a
adding device id support for flux for all stages
tv-karthikeya 0648374
[WIP] Adding support for custom Height,width
tv-karthikeya 84dc2d8
Flux support with Custom config
quic-amitraj 5a9cae9
Added OnnxfunctionTransform and code cleanup while modifying compile …
quic-amitraj 359ab95
Compile fix
quic-amitraj 3e5baf4
Modification of Pipeline-1
d0897cd
Modification of Pipeline-2
4c5b209
Update readme for diffusers
77a37b7
Added support of output dataclass
36014cc
Replaced output dict with dataclass to make it more user friendly
b132412
Rebased with main and fixed some issues
5664e85
Code cleaning and removed redundant code
ce990e3
Code cleaning and removed redundant code-2
0f98242
Added tqdm for export and compile
c34a2be
Parallel compilation and onnx subfunction is added
77d4461
Height and widht now can be passed from compile and __call__ method a…
f5a2fd9
Removed redundant code
5847136
Minor fixes-1
686d671
addressed comments and fixes
50fa2db
Handled 1. Mutiple time export issue 2. Meta device error after first…
ab95e55
Code cleanup and fixes
6c2f172
Updated readme
5d5b172
Updated the class names
00e66ca
Addressed comments-2
6291c41
Addressed comments-3
5ea7766
Addressed comments-4
fbecc32
Working T5
de0a079
Minor fixes
41201b1
Comments addressed
26e8368
Adding pytest for flux (#18)
tv-karthikeya e822679
Comments addressed-2
4ae608b
Hash fix
0b28841
Hash fix-2 for CI
f011ded
Hash fix-3 for CI
119245a
Increasaed stage time
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
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,95 @@ | ||
|
|
||
| <div align="center"> | ||
|
|
||
|
|
||
| # **Diffusion Models on Qualcomm Cloud AI 100** | ||
|
|
||
|
|
||
| <div align="center"> | ||
|
|
||
| ### 🎨 **Experience the Future of AI Image Generation** | ||
|
|
||
| * Optimized for Qualcomm Cloud AI 100* | ||
|
|
||
| <img src="../../docs/image/girl_laughing.png" alt="Sample Output" width="400"> | ||
|
|
||
| **Generated with**: `black-forest-labs/FLUX.1-schnell` • `"A girl laughing"` • 4 steps • 0.0 guidance scale • ⚡ | ||
|
|
||
|
|
||
|
|
||
| </div> | ||
|
|
||
|
|
||
|
|
||
| [](https://github.com/huggingface/diffusers) | ||
| </div> | ||
|
|
||
| --- | ||
|
|
||
| ## ✨ Overview | ||
|
|
||
| QEfficient Diffusers brings the power of state-of-the-art diffusion models to Qualcomm Cloud AI 100 hardware for text-to-image generation. Built on top of the popular HuggingFace Diffusers library, our optimized pipeline provides seamless inference on Qualcomm Cloud AI 100 hardware. | ||
|
|
||
| ## 🛠️ Installation | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| Ensure you have Python 3.8+ and the required dependencies: | ||
|
|
||
| ```bash | ||
| # Create Python virtual environment (Recommended Python 3.10) | ||
| sudo apt install python3.10-venv | ||
| python3.10 -m venv qeff_env | ||
| source qeff_env/bin/activate | ||
| pip install -U pip | ||
| ``` | ||
|
|
||
| ### Install QEfficient | ||
|
|
||
| ```bash | ||
| # Install from GitHub (includes diffusers support) | ||
| pip install git+https://github.com/quic/efficient-transformers | ||
|
|
||
| # Or build from source | ||
| git clone https://github.com/quic/efficient-transformers.git | ||
| cd efficient-transformers | ||
| pip install build wheel | ||
| python -m build --wheel --outdir dist | ||
| pip install dist/qefficient-0.0.1.dev0-py3-none-any.whl | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🎯 Supported Models | ||
| - ✅ [`black-forest-labs/FLUX.1-schnell`](https://huggingface.co/black-forest-labs/FLUX.1-schnell) | ||
|
|
||
| --- | ||
|
|
||
|
|
||
| ## 📚 Examples | ||
|
|
||
| Check out our comprehensive examples in the [`examples/diffusers/`](../../examples/diffusers/) directory: | ||
|
|
||
| --- | ||
|
|
||
| ## 🤝 Contributing | ||
|
|
||
| We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for details. | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
| ## 🙏 Acknowledgments | ||
|
|
||
| - **HuggingFace Diffusers**: For the excellent foundation library | ||
| - **Stability AI**: For the amazing Stable Diffusion models | ||
| --- | ||
|
|
||
| ## 📞 Support | ||
|
|
||
| - 📖 **Documentation**: [https://quic.github.io/efficient-transformers/](https://quic.github.io/efficient-transformers/) | ||
| - 🐛 **Issues**: [GitHub Issues](https://github.com/quic/efficient-transformers/issues) | ||
|
|
||
| --- | ||
|
|
||
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,6 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # | ||
| # ---------------------------------------------------------------------------- |
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,6 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # | ||
| # ---------------------------------------------------------------------------- |
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,40 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # | ||
| # ---------------------------------------------------------------------------- | ||
| from typing import Optional, Tuple | ||
|
|
||
| import torch | ||
| from diffusers.models.normalization import AdaLayerNormContinuous, AdaLayerNormZero, AdaLayerNormZeroSingle | ||
|
|
||
|
|
||
| class QEffAdaLayerNormZero(AdaLayerNormZero): | ||
| def forward( | ||
| self, | ||
| x: torch.Tensor, | ||
| shift_msa: Optional[torch.Tensor] = None, | ||
| scale_msa: Optional[torch.Tensor] = None, | ||
| ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]: | ||
quic-amitraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| x = self.norm(x) * (1 + scale_msa[:, None]) + shift_msa[:, None] | ||
| return x | ||
|
|
||
|
|
||
| class QEffAdaLayerNormZeroSingle(AdaLayerNormZeroSingle): | ||
| def forward( | ||
| self, | ||
| x: torch.Tensor, | ||
| scale_msa: Optional[torch.Tensor] = None, | ||
| shift_msa: Optional[torch.Tensor] = None, | ||
| ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]: | ||
| x = self.norm(x) * (1 + scale_msa[:, None]) + shift_msa[:, None] | ||
| return x | ||
|
|
||
|
|
||
| class QEffAdaLayerNormContinuous(AdaLayerNormContinuous): | ||
| def forward(self, x: torch.Tensor, conditioning_embedding: torch.Tensor) -> torch.Tensor: | ||
| emb = conditioning_embedding | ||
| scale, shift = torch.chunk(emb, 2, dim=1) | ||
| x = self.norm(x) * (1 + scale)[:, None, :] + shift[:, None, :] | ||
| return x | ||
quic-amitraj marked this conversation as resolved.
Show resolved
Hide resolved
|
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,56 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| from diffusers.models.normalization import AdaLayerNormContinuous, AdaLayerNormZero, AdaLayerNormZeroSingle, RMSNorm | ||
| from diffusers.models.transformers.transformer_flux import ( | ||
| FluxAttention, | ||
| FluxAttnProcessor, | ||
| FluxSingleTransformerBlock, | ||
| FluxTransformer2DModel, | ||
| FluxTransformerBlock, | ||
| ) | ||
| from torch import nn | ||
|
|
||
| from QEfficient.base.pytorch_transforms import ModuleMappingTransform | ||
| from QEfficient.customop.rms_norm import CustomRMSNormAIC | ||
| from QEfficient.diffusers.models.normalization import ( | ||
| QEffAdaLayerNormContinuous, | ||
| QEffAdaLayerNormZero, | ||
| QEffAdaLayerNormZeroSingle, | ||
| ) | ||
| from QEfficient.diffusers.models.transformers.transformer_flux import ( | ||
| QEffFluxAttention, | ||
| QEffFluxAttnProcessor, | ||
| QEffFluxSingleTransformerBlock, | ||
| QEffFluxTransformer2DModel, | ||
| QEffFluxTransformerBlock, | ||
| ) | ||
|
|
||
|
|
||
| class CustomOpsTransform(ModuleMappingTransform): | ||
| _module_mapping = { | ||
| RMSNorm: CustomRMSNormAIC, | ||
| nn.RMSNorm: CustomRMSNormAIC, # for torch.nn.RMSNorm | ||
| } | ||
|
|
||
|
|
||
| class AttentionTransform(ModuleMappingTransform): | ||
| _module_mapping = { | ||
| FluxSingleTransformerBlock: QEffFluxSingleTransformerBlock, | ||
| FluxTransformerBlock: QEffFluxTransformerBlock, | ||
| FluxTransformer2DModel: QEffFluxTransformer2DModel, | ||
| FluxAttention: QEffFluxAttention, | ||
| FluxAttnProcessor: QEffFluxAttnProcessor, | ||
| } | ||
|
|
||
|
|
||
| class NormalizationTransform(ModuleMappingTransform): | ||
| _module_mapping = { | ||
| AdaLayerNormZero: QEffAdaLayerNormZero, | ||
| AdaLayerNormZeroSingle: QEffAdaLayerNormZeroSingle, | ||
| AdaLayerNormContinuous: QEffAdaLayerNormContinuous, | ||
| } |
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,6 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # | ||
| # ---------------------------------------------------------------------------- |
Oops, something went wrong.
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.