Skip to content
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

🐛 [Bug] The example of torch tensorrt cannot generate images correctly #3138

Open
pangyoki opened this issue Sep 2, 2024 · 4 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@pangyoki
Copy link

pangyoki commented Sep 2, 2024

Bug Description

The example of pytorch tensorrt cannot generate images correctly. There were no issues with version v2.3.0, but version v2.4.0 cannot generate images correctly.
https://github.com/pytorch/TensorRT/blob/main/examples/dynamo/torch_compile_stable_diffusion.py

To Reproduce

Steps to reproduce the behavior:

  1. python3 examples/dynamo/torch_compile_stable_diffusion.py

Expected behavior

the example can generate normal image.

Environment

Build information about Torch-TensorRT can be found by turning on debug messages

  • Torch-TensorRT Version (e.g. 1.0.0): 2.4.0
  • PyTorch Version (e.g. 1.0): 2.4.1
  • OS (e.g., Linux): linux
  • How you installed PyTorch (conda, pip, libtorch, source): pip
  • Python version: 3.9
  • CUDA version: 12.4

Additional context

@pangyoki pangyoki added the bug Something isn't working label Sep 2, 2024
@pangyoki pangyoki changed the title 🐛 [Bug] Encountered bug when using Torch-TensorRT 🐛 [Bug] The example of torch tensorrt cannot generate images correctly Sep 2, 2024
@lanluo-nvidia
Copy link
Collaborator

I have verified on my linux machine with the same torch/torch_tensorrt/cuda/python version,
it is not working, it first pop up the error:
Potential NSFW content was detected in one or more images. A black image will be returned instead. Try again with a different prompt and/or seed.
if I added the safety_checker = None, requires_safety_checker = False, flag then it will generate a nonsense image like this in the attachment.
majestic_castle_2 4_remove_safety_check

however I verified it does work on torch_tensorrt latest main branch. it can successfully generate the image attached here
majestic_castle_main

@pangyoki
Copy link
Author

pangyoki commented Sep 4, 2024

@lanluo-nvidia Thank you for your reply. I tried latest main branch, and "CompVis/stable-diffusion-v1-4" model in example works well. But both the "stabilityai/stable-diffusion-xl-base-1.0" and "stabilityai/stable-diffusion-3-medium" models are unable to generate normal images. Below is the test code.

import torch
import torch_tensorrt
from diffusers import StableDiffusion3Pipeline

model_id = "stabilityai/stable-diffusion-3-medium-diffusers"

pipe = StableDiffusion3Pipeline.from_pretrained(
    model_id, torch_dtype=torch.float16
)
pipe.to("cuda")

backend = "torch_tensorrt"
pipe.transformer = torch.compile(
    pipe.transformer,
    backend=backend,
    options={
        "truncate_long_and_double": True,
        "enabled_precisions": {torch.float32, torch.float16},
    },
    dynamic=False,
)

generator = torch.Generator(pipe.device).manual_seed(7)

image = pipe(prompt=["Dog."],
    height=1280,
    width=720,
    num_inference_steps=30,
    guidance_scale=7,
    num_images_per_prompt=1,
    generator=generator).images[0]

image.save("./dog.png")

@lanluo-nvidia
Copy link
Collaborator

@pangyoki
Currently I am facing a CUDA out of memory error when try to run this model in my RTX4080 which has 16G of GPU memory.
I will verify on another machine with more GPU memory later.

@lanluo-nvidia
Copy link
Collaborator

I have verified from the latest main branch that I am not able to generate correct image from "stabilityai/stable-diffusion-3-medium-diffusers" model, it gives me a nonsense image.
however I can successfully generate image from this model without torch_tensorrt compile.
@peri044 @narendasan how can I investigate further whether it is a torch_tensorrt issue or tensorrt issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants