TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

Diffusion demo generate nan value when using Dynamic shape option

Open yibolu96 opened this issue 3 years ago • 8 comments

Description

I tried to build engine with a sd1.4 model, with command python3 demo_txt2img.py "a mouse, baby pink" --version=1.4 --height 512 --width 512 --denoising-steps=20 --build-static-batch --scheduler="DPM" --seed 123 --build-dynamic-shape

It then generated the plan files out with min size: 256 * 256, opt size 512 * 512, and max size: 1024 * 1024.

I then tried to generate images with those three image sizes, which works great. However, when I tried to generate with other sizes like 640 * 384 or 1024 * 640, it will generate black images. I figured out that the results of unet model are NaN, and same thing happens to vae.

There are no ERROR messages when running the script.

Could you please help figure out why this might happen?

Environment

TensorRT Version:

NVIDIA GPU: A100 40G

NVIDIA Driver Version: 515.65.01

CUDA Version: 12.1

Docker Image: nvcr.io/nvidia/pytorch:23.02-py3

yibolu96 avatar May 08 '23 09:05 yibolu96

@rajeevsrao @nvpohanh ^ ^

zerollzeng avatar May 08 '23 15:05 zerollzeng

Description

I tried to build engine with a sd1.4 model, with command python3 demo_txt2img.py "a mouse, baby pink" --version=1.4 --height 512 --width 512 --denoising-steps=20 --build-static-batch --scheduler="DPM" --seed 123 --build-dynamic-shape

It then generated the plan files out with min size: 256 * 256, opt size 512 * 512, and max size: 1024 * 1024.

I then tried to generate images with those three image sizes, which works great. However, when I tried to generate with other sizes like 640 * 384 or 1024 * 640, it will generate black images. I figured out that the results of unet model are NaN, and same thing happens to vae.

There are no ERROR messages when running the script.

Could you please help figure out why this might happen?

Environment

TensorRT Version:

NVIDIA GPU: A100 40G

NVIDIA Driver Version: 515.65.01

CUDA Version: 12.1

Docker Image: nvcr.io/nvidia/pytorch:23.02-py3

Hello. Have you tried manually setting the width and height?

l-dawei avatar May 11 '23 08:05 l-dawei

Description

I tried to build engine with a sd1.4 model, with command python3 demo_txt2img.py "a mouse, baby pink" --version=1.4 --height 512 --width 512 --denoising-steps=20 --build-static-batch --scheduler="DPM" --seed 123 --build-dynamic-shape It then generated the plan files out with min size: 256 * 256, opt size 512 * 512, and max size: 1024 * 1024. I then tried to generate images with those three image sizes, which works great. However, when I tried to generate with other sizes like 640 * 384 or 1024 * 640, it will generate black images. I figured out that the results of unet model are NaN, and same thing happens to vae. There are no ERROR messages when running the script. Could you please help figure out why this might happen?

Environment

TensorRT Version: NVIDIA GPU: A100 40G NVIDIA Driver Version: 515.65.01 CUDA Version: 12.1 Docker Image: nvcr.io/nvidia/pytorch:23.02-py3

Hello. Have you tried manually setting the width and height?

How do I manually set the width and height? I tried many things that setting the height and width in model.py of UNET model, and I tried to set the input file parameter for the engine build function. However, nothing helps, the model only works when the input shape matches one of the min, opt, and max shape.

yibolu96 avatar May 12 '23 01:05 yibolu96

@zerollzeng Let's file an internal tracker to debug this.

nvpohanh avatar May 15 '23 05:05 nvpohanh

@yibolu96 Could you please try the latest 8.6 GA without plugin? if it still not work then could you please provide a detailed reproduce for this issue?

I then tried to generate images with those three image sizes, which works great. However, when I tried to generate with other sizes like 640 * 384 or 1024 * 640, it will generate black images. I figured out that the results of unet model are NaN, and same thing happens to vae.

Because I'm not very familiar with this sample so would be great if you can tell me how to reproduce, many thanks!

zerollzeng avatar May 16 '23 14:05 zerollzeng

@yibolu96 Could you please try the latest 8.6 GA without plugin? if it still not work then could you please provide a detailed reproduce for this issue?

I then tried to generate images with those three image sizes, which works great. However, when I tried to generate with other sizes like 640 * 384 or 1024 * 640, it will generate black images. I figured out that the results of unet model are NaN, and same thing happens to vae.

Because I'm not very familiar with this sample so would be great if you can tell me how to reproduce, many thanks!

Sure.

  1. docker run -it --rm --gpus all nvcr.io/nvidia/pytorch:23.02-py3
  2. install all diffusers dependency
  3. try python3 demo_txt2img.py "a mouse, baby pink" --version=1.4 --height 512 --width 512 --denoising-steps=20 --build-static-batch --scheduler="EulerA" --seed 123 --build-dynamic-shape to do model convert and generate a sample image
  4. add some print() of the noise_pred that generated by unet model
  5. try python3 demo_txt2img.py "a mouse, baby pink" --version=1.4 --height 640 --width 384 --denoising-steps=20 --build-static-batch --scheduler="EulerA" --seed 123 --build-dynamic-shape to try with different shape of image generation. see the nan value of unet model output

yibolu96 avatar May 22 '23 04:05 yibolu96

nvcr.io/nvidia/pytorch:23.02-py3 has TRT 8.5, could you please try nvcr.io/nvidia/pytorch:23.04-py3 first? it contains TRT 8.6 which has native fMHA support and we've fixed some bugs in this new version.

zerollzeng avatar May 23 '23 14:05 zerollzeng

closing since no activity for more than 3 weeks, thanks!

ttyio avatar Jun 13 '23 16:06 ttyio