🐛 [Bug] FLUX Accuracy Issue
Open
Nobody has claimed this yet.
bug
story: LLM & Generative AI
- Dominant language
- Python
- Stars
- 3k
- Forks
- 410
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 78
Description
Bug Description
FLUX fails to generate actual images. It has accuracy issue.
To Reproduce
import torch
import torch_tensorrt
from diffusers import FluxPipeline
from diffusers.models.transformers.transformer_flux import FluxTransformer2DModel
DEVICE = "cuda:0"
enabled_precisions = {torch.float16}
pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev",
torch_dtype=torch.float16,
).to(torch.float16)
from diffusers.models.transformers.transformer_flux import FluxTransformer2DModel
pipe.transformer = FluxTransformer2DModel(
num_layers=1, num_single_layers=1, guidance_embeds=True
).to(torch.float16)
backbone = pipe.transformer
pipe.to(DEVICE)
batch_size = 1
settings = {
"strict": False,
"allow_complex_guards_as_runtime_asserts": True,
"enabled_precisions": enabled_precisions,
"truncate_double": True,
"min_block_size": 1,
"use_python_runtime": True,
"immutable_weights": False,
"offload_module_to_cpu": True,
}
trt_gm = torch_tensorrt.MutableTorchTensorRTModule(backbone, **settings)
pipe.transformer = trt_gm
image = pipe(
"Test",
output_type="pil",
num_inference_steps=2,
num_images_per_prompt=batch_size,
).images
backbone.to(DEVICE)
inp, kwinp = trt_gm.arg_inputs, trt_gm.kwarg_inputs
trt_result = trt_gm(*inp, **kwinp)[0]
pytorch_result = backbone(*inp, **kwinp)[0]
assert torch.allclose(trt_result, pytorch_result)
Expected behavior
Environment
Build information about Torch-TensorRT can be found by turning on debug messages
- Torch-TensorRT Version (e.g. 1.0.0): main branch
- PyTorch Version (e.g. 1.0): nightly
- CPU Architecture:
- OS (e.g., Linux):
- How you installed PyTorch (
conda,pip,libtorch, source): - Build command you used (if compiling from source):
- Are you using local sources or building from archives:
- Python version:
- CUDA version:
- GPU models and configuration:
- Any other relevant information:
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided FLUX example using FluxPipeline, FluxTransformer2DModel, and MutableTorchTensorRTModule. Reproduce the two-step generation and compare trt_result with pytorch_result using the shown torch.allclose assertion, then inspect the relevant Torch-TensorRT handling for this transformer. Done means FLUX generates valid images and the TensorRT and PyTorch outputs agree for the reported setup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- devtools, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100