open-mmlab / mmcv

OpenMMLab Computer Vision Foundation
https://mmcv.readthedocs.io/en/latest/
Apache License 2.0
5.89k stars 1.65k forks source link

Bug Point_sample.py RuntimeError: Expected condition, x and y to be on the same device, but condition is on cuda:0 and x and y are on cpu and cuda:0 respectively #2543

Open pedroHuang123 opened 1 year ago

pedroHuang123 commented 1 year ago

Describe the Issue I want to replace F.grid_sample with mmcv bilinear_grid_sample API, but failed. info: File "D:\software\miniconda3\envs\openmmlab\lib\site-packages\mmcv\ops\point_sample.py", line 64, in bilinear_grid_sample x0 = torch.where(x0 < 0, torch.tensor(0), x0) RuntimeError: Expected condition, x and y to be on the same device, but condition is on cuda:0 and x and y are on cpu and cuda:0 respectively image

Reproduction

  1. What command, code, or script did you run?
A placeholder for the command.
  1. Did you make any modifications on the code? Did you understand what you have modified?

Environment

  1. Please run python -c "from mmcv.utils import collect_env; print(collect_env())" to collect necessary environment information and paste it here.
  2. You may add addition that may be helpful for locating the problem, such as
    • How you installed PyTorch [e.g., pip, conda, source]
    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.)

Error traceback If applicable, paste the error traceback here.

A placeholder for traceback.

Bug fix If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!

pedroHuang123 commented 1 year ago

I try to upload the x to cuda,but the warning keep coming image image How can I avoid this warning?

grimoire commented 1 year ago

Please provide the script to reproduce the error and detail about your environment.

pedroHuang123 commented 1 year ago

val_mmcv_bilinear_grid_sample.zip 2023-01-17 18:28:26,542 - mmdeploy - INFO - **Environmental information** 2023-01-17 18:28:29,109 - mmdeploy - INFO - sys.platform: win32 2023-01-17 18:28:29,109 - mmdeploy - INFO - Python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:51:29) [MSC v.1929 64 bit (AMD64)] 2023-01-17 18:28:29,109 - mmdeploy - INFO - CUDA available: True 2023-01-17 18:28:29,109 - mmdeploy - INFO - GPU 0: NVIDIA GeForce RTX 3090 2023-01-17 18:28:29,109 - mmdeploy - INFO - CUDA_HOME: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1 2023-01-17 18:28:29,109 - mmdeploy - INFO - NVCC: Cuda compilation tools, release 11.1, V11.1.74 2023-01-17 18:28:29,109 - mmdeploy - INFO - MSVC: 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.33.31629 版 2023-01-17 18:28:29,109 - mmdeploy - INFO - GCC: n/a 2023-01-17 18:28:29,109 - mmdeploy - INFO - PyTorch: 1.9.0+cu111 2023-01-17 18:28:29,109 - mmdeploy - INFO - PyTorch compiling details: PyTorch built with:

2023-01-17 18:28:29,109 - mmdeploy - INFO - TorchVision: 0.10.0+cu111 2023-01-17 18:28:29,109 - mmdeploy - INFO - OpenCV: 4.6.0 2023-01-17 18:28:29,109 - mmdeploy - INFO - MMCV: 1.5.1 2023-01-17 18:28:29,109 - mmdeploy - INFO - MMCV Compiler: MSVC 192930137 2023-01-17 18:28:29,109 - mmdeploy - INFO - MMCV CUDA Compiler: 11.1 2023-01-17 18:28:29,109 - mmdeploy - INFO - MMDeploy: 0.12.0+c0e05b4 2023-01-17 18:28:29,109 - mmdeploy - INFO -

2023-01-17 18:28:29,109 - mmdeploy - INFO - **Backend information** 2023-01-17 18:28:29,233 - mmdeploy - INFO - tensorrt: 8.2.3.0 2023-01-17 18:28:29,234 - mmdeploy - INFO - tensorrt custom ops: Available 2023-01-17 18:28:29,320 - mmdeploy - INFO - ONNXRuntime: 1.8.1 2023-01-17 18:28:29,320 - mmdeploy - INFO - ONNXRuntime-gpu: None 2023-01-17 18:28:29,320 - mmdeploy - INFO - ONNXRuntime custom ops: Available 2023-01-17 18:28:29,324 - mmdeploy - INFO - pplnn: None 2023-01-17 18:28:29,351 - mmdeploy - INFO - ncnn: None 2023-01-17 18:28:29,397 - mmdeploy - INFO - snpe: None 2023-01-17 18:28:29,401 - mmdeploy - INFO - openvino: None 2023-01-17 18:28:29,406 - mmdeploy - INFO - torchscript: 1.9.0+cu111 2023-01-17 18:28:29,406 - mmdeploy - INFO - torchscript custom ops: NotAvailable 2023-01-17 18:28:29,473 - mmdeploy - INFO - rknn-toolkit: None 2023-01-17 18:28:29,473 - mmdeploy - INFO - rknn2-toolkit: None 2023-01-17 18:28:29,477 - mmdeploy - INFO - ascend: None 2023-01-17 18:28:29,480 - mmdeploy - INFO - coreml: None 2023-01-17 18:28:29,482 - mmdeploy - INFO - tvm: None 2023-01-17 18:28:29,483 - mmdeploy - INFO -

2023-01-17 18:28:29,483 - mmdeploy - INFO - **Codebase information** 2023-01-17 18:28:29,490 - mmdeploy - INFO - mmdet: None 2023-01-17 18:28:29,490 - mmdeploy - INFO - mmseg: None 2023-01-17 18:28:29,490 - mmdeploy - INFO - mmcls: 0.25.0 2023-01-17 18:28:29,490 - mmdeploy - INFO - mmocr: None 2023-01-17 18:28:29,490 - mmdeploy - INFO - mmedit: None 2023-01-17 18:28:29,490 - mmdeploy - INFO - mmdet3d: None 2023-01-17 18:28:29,490 - mmdeploy - INFO - mmpose: None 2023-01-17 18:28:29,490 - mmdeploy - INFO - mmrotate: None 2023-01-17 18:28:29,491 - mmdeploy - INFO - mmaction: None 2023-01-17 18:28:29,491 - mmdeploy - INFO - mmflow: 0.5.1 @grimoire

grimoire commented 1 year ago

torch.tensor(0) is a cpu tensor, which leads to operation between host and device. You can replace it with x0.new_tensor(0) or just use scalar 0. Do you want to create a PR to fix it?