Diffusion demo generate nan value when using Dynamic shape option
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
@rajeevsrao @nvpohanh ^ ^
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-shapeIt 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?
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-shapeIt 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.
@zerollzeng Let's file an internal tracker to debug this.
@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!
@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.
- docker run -it --rm --gpus all nvcr.io/nvidia/pytorch:23.02-py3
- install all diffusers dependency
- 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-shapeto do model convert and generate a sample image - add some print() of the noise_pred that generated by unet model
- 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-shapeto try with different shape of image generation. see the nan value of unet model output
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.
closing since no activity for more than 3 weeks, thanks!