Skip to content

Added flux demo #3418

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
wants to merge 32 commits into
base: main
Choose a base branch
from
Open

Added flux demo #3418

wants to merge 32 commits into from

Conversation

cehongwang
Copy link
Collaborator

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant and/or add your own.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@github-actions github-actions bot added component: conversion Issues re: Conversion stage component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Feb 27, 2025
@cehongwang cehongwang marked this pull request as draft February 27, 2025 00:39
@github-actions github-actions bot requested a review from peri044 February 27, 2025 00:39
@narendasan
Copy link
Collaborator

Can the app display the inference time, might be nice to have some stats rendered live as you generate

@cehongwang cehongwang force-pushed the flux-demo branch 4 times, most recently from 48a7c94 to 5a528f1 Compare March 18, 2025 04:44
@github-actions github-actions bot added the component: tests Issues re: Tests label Mar 18, 2025
@cehongwang cehongwang force-pushed the flux-demo branch 6 times, most recently from 361fb76 to 0aeea36 Compare March 25, 2025 09:26
@cehongwang cehongwang marked this pull request as ready for review March 26, 2025 07:53
@cehongwang cehongwang force-pushed the flux-demo branch 4 times, most recently from 9964674 to cfbc9ea Compare March 26, 2025 07:59

import gradio as gr
import modelopt.torch.quantization as mtq
import register_sdpa
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can avoid copying the register_sdpa.py and sdpa_converter.py files by doing this

import sys
import os

# Register SDPA as a standalone operator. Converter and lowering pass are defined in register_sdpa.py
sys.path.append(os.path.join(os.path.dirname(__file__), '../dynamo'))
from register_sdpa import *

Copy link
Collaborator

Choose a reason for hiding this comment

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

what does this file do ?

@@ -112,6 +112,8 @@
min_block_size=1,
use_fp32_acc=True,
use_explicit_typing=True,
use_python_runtime=True,
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we default to using C++ runtime (use_python_runtime=False) ?

Comment on lines +126 to +131
backbone.to("cpu")
pipe.transformer = trt_gm
del ep
torch.cuda.empty_cache()
pipe.transformer.config = config

trt_gm.device = torch.device("cuda")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use the offload_module_to_cpu=True to handle this block of code ?

@@ -912,7 +913,7 @@ def contains_metadata(gm: torch.fx.GraphModule) -> bool:
parse_graph_io(submodule, subgraph_data)
dryrun_tracker.tensorrt_graph_count += 1
dryrun_tracker.per_subgraph_data.append(subgraph_data)

torch.cuda.empty_cache()
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this needed here ?

@@ -341,7 +370,7 @@ def refit_module_weights(

# Iterate over all components that can be accelerated
# Generate the corresponding TRT Module for those

new_weight_module.module().to(CPU_DEVICE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the new_weight_module the updated weights module that user provides ?

if verify_output and arg_inputs is not None:
new_gm.to(torch.cuda.current_device())
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should ensure we use the device that's passed in via args/Compilation settings or default device and not call rely on torch cuda calls unless it is needed.

Comment on lines +364 to 365
self.original_model.to("cpu")
torch.cuda.empty_cache()
Copy link
Collaborator

Choose a reason for hiding this comment

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

use deallocate module

from torch_tensorrt.dynamo.lowering.passes.pass_utils import (
clean_up_graph_after_modifications,
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

use them from examples

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should avoid copying the whole model scripts for measuring perf. Try using the sys.path approach and importing the model and just a perf loop. something like

import sys
import os
sys.path.append(torchtrt_root + "examples/dynamo/apps")
from flux_demo import *
model = <insert FLUX model (fp16 or fp8) > 
results = measure_flux_perf(.... )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: runtime component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants