Skip to content

Conversation

@quic-amitraj
Copy link
Contributor

@quic-amitraj quic-amitraj commented Nov 4, 2025

Support for Diffusers Architecture in Efficient Transformers

Overview

This pull request introduces Diffusers architecture support to the Efficient Transformers framework, enabling seamless integration of diffusion models.

Key Highlights

  1. Support of model black-forest-labs/FLUX1-schnell
  2. Flexible Configuration
    • Supports JSON-based configuration files for easy compilation and execution.
  3. Performance Benchmarking
    • Implements a performance matrix for Diffusers models to enable benchmarking for each modules.
  4. Testing Framework
    • Includes initial test scripts for Diffusers (In progress).
  5. Support of onnx subfunction graph using flag use_onnx_function
  6. Support parallel compilation of modules using flag parallel_compile

@quic-amitraj quic-amitraj changed the title Flux support with custom config Diffusers support Nov 4, 2025
@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch 5 times, most recently from ffed450 to eb55c51 Compare November 13, 2025 08:47
@quic-amitraj quic-amitraj marked this pull request as ready for review November 13, 2025 08:48
@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch 2 times, most recently from 42cf8b6 to 1cf4b30 Compare November 13, 2025 09:07
@quic-amitraj quic-amitraj marked this pull request as draft November 13, 2025 09:25
@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch from 1cf4b30 to 0ee0b9f Compare November 13, 2025 09:29
@quic-amitraj quic-amitraj marked this pull request as ready for review November 13, 2025 09:30
@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch from 0ee0b9f to 1e0fbfd Compare November 13, 2025 10:08
@quic-amitraj quic-amitraj self-assigned this Nov 13, 2025
@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch 2 times, most recently from bb01d84 to 00f5286 Compare November 13, 2025 13:24
@quic-amitraj quic-amitraj added the Diffusers Use for PR related to diffusers in efficient-transformers. label Nov 13, 2025
@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch from 00f5286 to 0a26f1b Compare November 13, 2025 16:52
@quic-amitraj quic-amitraj requested a review from vbaddi November 14, 2025 04:40
@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch from ac6382a to 19e0ccd Compare November 14, 2025 10:24
Comment on lines +52 to +40
# text_encoder=custom_text_encoder, # Your custom CLIP text encoder
# transformer=custom_transformer, # Your custom transformer model
# tokenizer=custom_tokenizer, # Your custom tokenizer
Copy link
Contributor

Choose a reason for hiding this comment

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

this is nice.

@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch from 19e0ccd to 8d78ac9 Compare November 24, 2025 08:29
Signed-off-by: Amit Raj <amitraj@qti.qualcomm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcomm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcomm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Amit Raj added 9 commits November 27, 2025 09:36
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
…nd comments addressed

Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
… export 3. Hash getting changed after each export

Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch from 226e65a to 901d293 Compare November 27, 2025 09:37
def encode_prompt(
self,
prompt: Union[str, List[str]],
prompt_2: Optional[Union[str, List[str]]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit(suggestion): better to use prompt and secondary_prompt as variable names

Copy link
Contributor Author

@quic-amitraj quic-amitraj Nov 28, 2025

Choose a reason for hiding this comment

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

These are official names from diffusers, as we are alligned with diffusers pipeline, In my sugggestion we should keep the name same. Plaease refer this- Link

@@ -0,0 +1,95 @@

<div align="center">
Copy link
Contributor

Choose a reason for hiding this comment

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

move it to docs folder and create a new page for diffusers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure Rishin, Will put this in the docs as well as it will be helpful for the sphinx documentation. But keeping it here also make sense as it gives the proper idea about `How anyone can run diffusers supported model using Qefficient?"

@@ -0,0 +1,55 @@
# -----------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a readme file explaining the usage, follow the the contribution.md file in the example folder

parallel {
stage('Run Non-CLI Non-QAIC Tests') {
steps {
timeout(time: 25, unit: 'MINUTES') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a new tag and add tests as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, with the following PR we will add pytest as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added here- PR to add pytest

Please review.

Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
@quic-amitraj quic-amitraj force-pushed the config_support_diffusers branch from fc06ca3 to 901d293 Compare December 2, 2025 05:28
Amit Raj added 2 commits December 2, 2025 08:28
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
Comment on lines +58 to +70
try:
# 4. Execute the actual export
onnx_path = func(self, *args, **kwargs)

# 5. Save export metadata
_save_export_metadata(export_dir, filtered_hash_params)

return onnx_path

finally:
# 6. Always cleanup subfunctions if they were setup
if use_subfunctions:
_cleanup_onnx_subfunctions(self)
Copy link
Contributor

Choose a reason for hiding this comment

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

try/finally is not required. Let's not loop one try/except inside another.

**kwargs,
)

def export(self, export_dir: Optional[str] = None, use_onnx_subfunctions: bool = False) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to make this logic common for any diffusers model?
User only defines an ordered dictionary and uses the export method from base class?
user's job is to define a orderdict for modules and the get_onnx_config method for export params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With logic of having on more base class, this could be possible. In upcoming time will add support of QEffDiffusionPipeline as a base class, which will have all these logic common.

"""
for module_name, module_obj in tqdm(self.modules.items(), desc="Exporting modules", unit="module"):
# Get ONNX export configuration for this module
example_inputs, dynamic_axes, output_names = module_obj.get_onnx_config()
Copy link
Contributor

Choose a reason for hiding this comment

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

name the method better you are not returning a config here.

)

# Initialize QAIC inference session if not already created
if self.text_encoder_2.qpc_session is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we keeping session in memory?
This will hold the card occupied unless we explicitly del this or program execution terminates

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to keep it in the memory for genertating multple images sequentially in loop and not load the qpc again and again after each image generation.

from QEfficient.utils.logging_utils import logger


def calculate_compressed_latent_dimension(height: int, width: int, vae_scale_factor: int) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

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

is this method common to all diffusion models?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Diffusers Use for PR related to diffusers in efficient-transformers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants