pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
16.11k stars 6.94k forks source link

```GeneralizedRCNN``` on GPU always detects degenerate bounding boxes #8015

Open ehratjon opened 1 year ago

ehratjon commented 1 year ago

🐛 Describe the bug

Existing issues: There is no issue on this topic. Issue #6787 has a discussion on the assert statement on degenerate bboxes.

Problem description: When running a model that makes use of GeneralizedRCNN on GPU bounding boxes are always detected as degenerate. The model then throws the following error: ValueError: All bounding boxes should have positive height and width. Found invalid box [x1, y1, x2, y2] for target index 0.

Cause of the problem: The problem occurs because in generalized_rcnn.py on line 91. The problem is that '.any()' returns the correct values on CPU but not on GPU.

cpu_tensor = torch.tensor([[False, False], [False, False], [False, False]])
cpu_tensor.to('cpu')
gpu_tensor = cpu_tensor.to('cuda')

print(cpu_tensor)
# tensor([[False, False],
#         [False, False],
#         [False, False]])

print(gpu_tensor)
# tensor([[False, False],
#         [False, False],
#         [False, False]], device='cuda:0')

cpu_tensor.any()
# tensor(False)

gpu_tensor.any()
# tensor(True, device='cuda:0')

any(list(gpu_tensor.flatten()))
# False

Problem solution: I solved the issue by manually going into the side packages (venv/lib/python3.10/site-packages/torchvision/models/detection/generalized_rcnn.py) and changing line 91 to:

if any(list(degenerate_boxes.flatten())):

I hope this helps anyone running into the same problem.

Question: I am not sure if this is the most elegant solution and there is a TODO-comment wanting this part to be moved to a new function. Should I nevertheless open a PR to just change this line or is there already work done on this?

Versions

> python collect_env.py

Collecting environment information...

/venv_ml/lib/python3.10/site-packages/torch/cuda/__init__.py:546: UserWarning: Can't initialize NVML warnings.warn("Can't initialize NVML") PyTorch version: 2.0.1+rocm5.4.2 Is debug build: False CUDA used to build PyTorch: N/A ROCM used to build PyTorch: 5.4.22803-474e8620 OS: Ubuntu 22.04.3 LTS (x86_64) GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Clang version: Could not collect CMake version: version 3.27.4 Libc version: glibc-2.35 Python version: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (64-bit runtime) Python platform: Linux-5.19.0-45-generic-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: 11.5.119 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: AMD Radeon RX 6800 XT Nvidia driver version: Could not collect cuDNN version: Could not collect HIP runtime version: 5.4.22803 MIOpen runtime version: 2.19.0 Is XNNPACK available: True CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 16 On-line CPU(s) list: 0-15 Vendor ID: GenuineIntel Model name: 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz CPU family: 6 Model: 167 Thread(s) per core: 2 Core(s) per socket: 8 Socket(s): 1 Stepping: 1 CPU max MHz: 5300.0000 CPU min MHz: 800.0000 BogoMIPS: 7008.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap avx512ifma clflushopt intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid fsrm md_clear flush_l1d arch_capabilities L1d cache: 384 KiB (8 instances) L1i cache: 256 KiB (8 instances) L2 cache: 4 MiB (8 instances) L3 cache: 16 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-15 Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Retbleed: Mitigation; Enhanced IBRS Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Versions of relevant libraries: [pip3] numpy==1.25.2 [pip3] pytorch-lightning==1.9.5 [pip3] pytorch-triton-rocm==2.0.1 [pip3] torch==2.0.1+rocm5.4.2 [pip3] torchaudio==2.0.2+rocm5.4.2 [pip3] torchdata==0.6.1 [pip3] torchmetrics==1.1.2 [pip3] torchsummary==1.5.1 [pip3] torchtext==0.15.2 [pip3] torchvision==0.15.2+rocm5.4.2 [pip3] triton==2.0.0 [conda] Could not collect
abhi-glitchhg commented 1 year ago

gpu_tensor.any()
# tensor(True, device='cuda:0')

any(list(gpu_tensor.flatten()))
# False

I cant reproduce this. output is False both times for me.

ehratjon commented 1 year ago

Oh super wired! I don't know why this could happen on one system but not on another. As you can see, I am using torch version: '2.0.1+rocm5.4.2'. I had some trouble installing the GPU drivers, but I would assume this doesn't affect how pytorch behaves. After trying with a fresh install of torch (pip3 install torch --index-url https://download.pytorch.org/whl/rocm5.4.2) I still have the same output.

Do you think this is an issue with the rocm version of torch? Any suggestions on how to investigate this further and would the ROCm github be the right place to submit the issue?

abhi-glitchhg commented 1 year ago

I don't have any idea how this could happen..

this could be the pytorch + rocm issue; cause i tried it on nvidia gpus, and code is working perfectly as expected

I think the best way to confirm this behaviour is making a docker environment and reproduce it.

Then someone from pytorch can have a look at this.