Skip to content

Commit bb01d84

Browse files
author
Amit Raj
committed
Code cleaning and removed redundant code-2
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
1 parent d676aab commit bb01d84

File tree

7 files changed

+48
-20
lines changed

7 files changed

+48
-20
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -----------------------------------------------------------------------------
2+
#
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
#
6+
# ----------------------------------------------------------------------------

QEfficient/diffusers/pipelines/flux/pipeline_flux.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#
66
# ----------------------------------------------------------------------------
77

8-
import logging
98
import os
109
import time
1110
from typing import Any, Callable, Dict, List, Optional, Union
@@ -28,9 +27,7 @@
2827
set_module_device_ids,
2928
)
3029
from QEfficient.generation.cloud_infer import QAICInferenceSession
31-
32-
# Initialize logger for this module
33-
logger = logging.getLogger(__name__)
30+
from QEfficient.utils.logging_utils import logger
3431

3532

3633
class QEFFFluxPipeline(FluxPipeline):
@@ -224,18 +221,18 @@ def compile(self, compile_config: Optional[str] = None) -> None:
224221
# Compile each module with its specific configuration
225222
for module_name, module_obj in self.modules.items():
226223
module_config = self.custom_config["modules"]
227-
specializations = [module_config[module_name]["specializations"]]
224+
specializations = module_config[module_name]["specializations"]
228225
compile_kwargs = module_config[module_name]["compilation"]
229226

230227
# Set dynamic specialization values based on image dimensions
231228
if module_name == "transformer":
232-
specializations[0]["cl"] = self.cl
229+
specializations["cl"] = self.cl
233230
elif module_name == "vae_decoder":
234-
specializations[0]["latent_height"] = self.latent_height
235-
specializations[0]["latent_width"] = self.latent_width
231+
specializations["latent_height"] = self.latent_height
232+
specializations["latent_width"] = self.latent_width
236233

237234
# Compile the module to QPC format
238-
module_obj.compile(specializations=specializations, **compile_kwargs)
235+
module_obj.compile(specializations=[specializations], **compile_kwargs)
239236

240237
def _get_t5_prompt_embeds(
241238
self,

QEfficient/diffusers/pipelines/pipeline_module.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# ----------------------------------------------------------------------------
77

88
import copy
9-
import logging
109
from typing import Dict, List, Tuple
1110

1211
import torch
@@ -25,9 +24,6 @@
2524
)
2625
from QEfficient.utils import constants
2726

28-
# Initialize logger for this module
29-
logger = logging.getLogger(__name__)
30-
3127

3228
class QEffTextEncoder(QEFFBaseModel):
3329
"""

QEfficient/utils/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def create_model_params(qeff_model, **kwargs) -> Dict:
532532
"""
533533
model_params = copy.deepcopy(kwargs)
534534
model_params = {k: v for k, v in model_params.items() if k in KWARGS_INCLUSION_LIST}
535-
model_params["config"] = qeff_model.model.config
535+
model_params["config"] = qeff_model.model.config.to_diff_dict()
536536
model_params["peft_config"] = getattr(qeff_model.model, "active_peft_config", None)
537537
model_params["applied_transform_names"] = qeff_model._transform_names()
538538
return model_params

examples/diffusers/flux/flux_1_schnell.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,48 @@
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66
# -----------------------------------------------------------------------------
7+
8+
"""
9+
FLUX.1-schnell Image Generation Example
10+
11+
This example demonstrates how to use the QEFFFluxPipeline to generate images
12+
using the FLUX.1-schnell model from Black Forest Labs. FLUX.1-schnell is a
13+
fast, distilled version of the FLUX.1 text-to-image model optimized for
14+
speed with minimal quality loss.
15+
16+
Key Features:
17+
- Fast inference with only 4 steps
18+
- High-quality image generation from text prompts
19+
- Optimized for Qualcomm Cloud AI 100 using ONNX runtime
20+
- Deterministic output using fixed random seed
21+
22+
Output:
23+
- Generates an image based on the text prompt
24+
- Saves the image as 'cat_with_sign.png' in the current directory
25+
"""
26+
727
import torch
828

929
from QEfficient import QEFFFluxPipeline
1030

11-
pipeline = QEFFFluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", use_onnx_function=True)
31+
# Initialize the FLUX.1-schnell pipeline from pretrained weights
32+
# use_onnx_function=True enables ONNX-based optimizations for faster compilation
33+
pipeline = QEFFFluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", use_onnx_function=False)
1234

35+
# Generate an image from a text prompt
1336
output = pipeline(
1437
prompt="A cat holding a sign that says hello world",
1538
guidance_scale=0.0,
1639
num_inference_steps=4,
1740
max_sequence_length=256,
1841
generator=torch.manual_seed(42),
1942
)
43+
44+
# Extract the generated image from the output
2045
image = output.images[0]
46+
47+
# Save the generated image to disk
2148
image.save("cat_with_sign.png")
2249

50+
# Print the output object (contains perf info)
2351
print(output)

examples/diffusers/flux/flux_1_shnell_custom.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@
3737
# Option 1: Basic initialization with custom image dimensions
3838
pipeline = QEFFFluxPipeline.from_pretrained(
3939
"black-forest-labs/FLUX.1-schnell",
40-
height=256,
41-
width=256,
40+
height=512,
41+
width=512,
4242
)
4343

4444
# Option 2: Advanced initialization with custom modules
4545
# Uncomment and modify to use your own custom components:
4646
#
4747
# pipeline = QEFFFluxPipeline.from_pretrained(
4848
# "black-forest-labs/FLUX.1-schnell",
49-
# height=256,
50-
# width=256,
49+
# height=512,
50+
# width=512,
5151
# text_encoder=custom_text_encoder, # Your custom CLIP text encoder
5252
# transformer=custom_transformer, # Your custom transformer model
5353
# tokenizer=custom_tokenizer, # Your custom tokenizer

scripts/Jenkinsfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pipeline {
2222
. preflight_qeff/bin/activate &&
2323
pip install --upgrade pip setuptools &&
2424
pip install .[test] &&
25+
pip install .[diffusers] &&
2526
pip install junitparser pytest-xdist &&
2627
pip install librosa==0.10.2 soundfile==0.13.1 && #packages needed to load example for whisper testing
2728
pip install --extra-index-url https://download.pytorch.org/whl/cpu timm==1.0.14 torchvision==0.22.0+cpu einops==0.8.1 && #packages to load VLMs
@@ -34,7 +35,7 @@ pipeline {
3435
parallel {
3536
stage('Run Non-CLI Non-QAIC Tests') {
3637
steps {
37-
timeout(time: 25, unit: 'MINUTES') {
38+
timeout(time: 100, unit: 'MINUTES') {
3839
sh '''
3940
sudo docker exec ${BUILD_TAG} bash -c "
4041
cd /efficient-transformers &&

0 commit comments

Comments
 (0)