-
Notifications
You must be signed in to change notification settings - Fork 60
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
Open
quic-amitraj
wants to merge
37
commits into
quic:main
Choose a base branch
from
quic-amitraj:config_support_diffusers
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.
+3,086
−150
Open
Diffusers support #604
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
158f9b9
Stage-1 export debug
quic-amitraj 8690842
Stage-2 Export inital working version done
quic-amitraj 072be0e
Stage-3 compilation work is under progress
quic-amitraj 41503c2
Stage-4 Working pipeline with wrong output
quic-amitraj 597c936
Testing
quic-amitraj 565df68
Testing
quic-amitraj cb1591b
Working sd3-turbo
quic-amitraj 5f43d40
Working with cleaned code
quic-amitraj 9c77344
Working with cleaned code
quic-amitraj 5f17d61
Working with vae_included
quic-amitraj 7aed56f
Fix-1
quic-amitraj 39b53d0
Fix-2
quic-amitraj 83a2666
Fix-3
quic-amitraj e413646
Added readme for diffusers
quic-amitraj 060f4d0
Code cleanup
quic-amitraj 7cc9d28
Code cleanup-2
quic-amitraj b4aee48
Minor fix
quic-amitraj 80a1bbb
Added Support of flux
quic-amitraj 80ff141
Updated seq_len of flux transformers
tv-karthikeya 7947495
Removing SD3, adding small fix for flux model hash
tv-karthikeya 212be5d
adding device id support for flux for all stages
tv-karthikeya 4464fb7
[WIP] Adding support for custom Height,width
tv-karthikeya 12c3d3a
Flux support with Custom config
quic-amitraj 75842f7
Added OnnxfunctionTransform and code cleanup while modifying compile …
quic-amitraj 4ba0e9c
Compile fix
quic-amitraj 7f6aac1
Modification of Pipeline-1
1409315
Modification of Pipeline-2
42ef5cd
Update readme for diffusers
ddbf534
Added support of output dataclass
a36f598
Replaced output dict with dataclass to make it more user friendly
753ae8d
Rebased with main and fixed some issues
35a4bb3
Code cleaning and removed redundant code
f491971
Code cleaning and removed redundant code-2
fd31a58
Added tqdm for export and compile
b91e2c9
Parallel compilation and onnx subfunction is added
8d78ac9
Height and widht now can be passed from compile and __call__ method a…
fcec077
Removed redundant code
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,108 @@ | ||
|
|
||
| <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 | ||
| ``` | ||
|
|
||
| ### Install Diffusers Dependencies | ||
|
|
||
| ```bash | ||
| # Install diffusers optional dependencies | ||
| pip install "QEfficient[diffusers]" | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🎯 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. | ||
|
|
||
| ### Development Setup | ||
|
|
||
| ```bash | ||
| git clone https://github.com/quic/efficient-transformers.git | ||
| cd efficient-transformers | ||
| pip install -e ".[diffusers,test]" | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🙏 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,75 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # | ||
| # ---------------------------------------------------------------------------- | ||
|
|
||
| import torch | ||
| from diffusers.models.attention import JointTransformerBlock, _chunked_feed_forward | ||
|
|
||
|
|
||
| class QEffJointTransformerBlock(JointTransformerBlock): | ||
| def forward( | ||
| self, hidden_states: torch.FloatTensor, encoder_hidden_states: torch.FloatTensor, temb: torch.FloatTensor | ||
| ): | ||
| if self.use_dual_attention: | ||
| norm_hidden_states, gate_msa, shift_mlp, scale_mlp, gate_mlp, norm_hidden_states2, gate_msa2 = self.norm1( | ||
| hidden_states, emb=temb | ||
| ) | ||
| else: | ||
| norm_hidden_states, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.norm1(hidden_states, emb=temb) | ||
|
|
||
| if self.context_pre_only: | ||
| norm_encoder_hidden_states = self.norm1_context(encoder_hidden_states, temb) | ||
| else: | ||
| norm_encoder_hidden_states, c_gate_msa, c_shift_mlp, c_scale_mlp, c_gate_mlp = self.norm1_context( | ||
| encoder_hidden_states, emb=temb | ||
| ) | ||
|
|
||
| # Attention. | ||
| attn_output, context_attn_output = self.attn( | ||
| hidden_states=norm_hidden_states, encoder_hidden_states=norm_encoder_hidden_states | ||
| ) | ||
|
|
||
| # Process attention outputs for the `hidden_states`. | ||
| attn_output = gate_msa.unsqueeze(1) * attn_output | ||
| hidden_states = hidden_states + attn_output | ||
|
|
||
| if self.use_dual_attention: | ||
| attn_output2 = self.attn2(hidden_states=norm_hidden_states2) | ||
| attn_output2 = gate_msa2.unsqueeze(1) * attn_output2 | ||
| hidden_states = hidden_states + attn_output2 | ||
|
|
||
| norm_hidden_states = self.norm2(hidden_states) | ||
| norm_hidden_states = norm_hidden_states * (1 + scale_mlp[:, None]) + shift_mlp[:, None] | ||
| if self._chunk_size is not None: | ||
| # "feed_forward_chunk_size" can be used to save memory | ||
| ff_output = _chunked_feed_forward(self.ff, norm_hidden_states, self._chunk_dim, self._chunk_size) | ||
| else: | ||
| # ff_output = self.ff(norm_hidden_states) | ||
| ff_output = self.ff(norm_hidden_states, block_size=4096) | ||
| ff_output = gate_mlp.unsqueeze(1) * ff_output | ||
|
|
||
| hidden_states = hidden_states + ff_output | ||
|
|
||
| # Process attention outputs for the `encoder_hidden_states`. | ||
| if self.context_pre_only: | ||
| encoder_hidden_states = None | ||
| else: | ||
| context_attn_output = c_gate_msa.unsqueeze(1) * context_attn_output | ||
| encoder_hidden_states = encoder_hidden_states + context_attn_output | ||
|
|
||
| norm_encoder_hidden_states = self.norm2_context(encoder_hidden_states) | ||
| norm_encoder_hidden_states = norm_encoder_hidden_states * (1 + c_scale_mlp[:, None]) + c_shift_mlp[:, None] | ||
| if self._chunk_size is not None: | ||
| # "feed_forward_chunk_size" can be used to save memory | ||
| context_ff_output = _chunked_feed_forward( | ||
| self.ff_context, norm_encoder_hidden_states, self._chunk_dim, self._chunk_size | ||
| ) | ||
| else: | ||
| # context_ff_output = self.ff_context(norm_encoder_hidden_states) | ||
| context_ff_output = self.ff_context(norm_encoder_hidden_states, block_size=333) | ||
| encoder_hidden_states = encoder_hidden_states + c_gate_mlp.unsqueeze(1) * context_ff_output | ||
|
|
||
| return encoder_hidden_states, hidden_states |
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.