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] Get an Input not on GPU warning when doing the inference #2235

Open
binliunls opened this issue Aug 16, 2023 · 3 comments
Open

🐛 [Bug] Get an Input not on GPU warning when doing the inference #2235

binliunls opened this issue Aug 16, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@binliunls
Copy link

Bug Description

When run the inference with a converted TensorRT torchscript of MONAI generative model, it reports the warning shown below.
trt_device_error

To Reproduce

Steps to reproduce the behavior:

The way to reproduce the error:

  1. Build the torch_tensorrt docker from main branch with TENSORRT_VERSION=8.6
  2. Start a container with the torch_tensorrt image
  3. Clone this branch of MONAI https://github.com/binliunls/MONAI/tree/6838-support-generative-and-hovernet-with-TensorRT
  4. Go into the cloned MONAI folder and run `python setup.py develop; pip install -r requirements-dev.txt'
  5. Run the python -m monai.bundle download brats_mri_axial_slices_generative_diffusion --bundle_dir ./ to download the model to a local path.
  6. Go into the brats_mri_axial_slices_generative_diffusion folder
  7. Run the command python -m monai.bundle trt_export --net_id network_def --filepath models/model_trt.ts --ckpt_file models/model.pt --meta_file configs/metadata.json --config_file configs/inference.json --precision fp32 --use_trace "True" --input_shape "[[1, 1, 64, 64], [1,]]" --converter_kwargs "{'truncate_long_and_double': True}" to convert the model

Run the inference with code like:

import torch

...
input_shapes = ([1, 1, 64, 64], [1,])
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = torch.jit.load("/path/to/exported/model_trt.ts")
inputs = [torch.rand(shape, dtype=torch.float32, device=device) for shape in input_shapes]
pred = model(*inputs)
...

Expected behavior

No need to move tensors from CPU to GPU.

Environment

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

  • TensorRT: 8.6.1+cuda12.0
  • Torch-TensorRT Version: 1.4.0
  • CPU Architecture: x86-64
  • OS: ubuntu 20.04
  • Python version:3.8.10
  • CUDA version: 12.1
  • GPU models and configuration: A100 80G

Additional context

@binliunls binliunls added the bug Something isn't working label Aug 16, 2023
@apbose apbose self-assigned this Aug 16, 2023
@apbose
Copy link
Collaborator

apbose commented Oct 23, 2023

Hi in this case I see that the inputs are getting moved to "cuda" device if it finds the target cuda device. Did you try explicitly placing the tensor to ".cuda()"?

@apbose
Copy link
Collaborator

apbose commented Nov 6, 2023

Hi @binliunls , I tried running the above steps to test the Runtime warning with dynamo path, but I run into ModuleNotFoundError: Cannot locate class or function path: 'generative.networks.nets.DiffusionModelUNet'. Is there something missing from requirements.txt?

@binliunls
Copy link
Author

Hi @apbose, very appreciate for your response. I think you the libraries shown below should be installed as shown in the metadata.json file.

"monai-generative": "0.2.2"

Thanks, Bin

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

2 participants