open-mmlab / mmdetection3d

OpenMMLab's next-generation platform for general 3D object detection.
https://mmdetection3d.readthedocs.io/en/latest/
Apache License 2.0
5.2k stars 1.53k forks source link

CUDA out of memeory while training Point R-CNN[Bug] #2917

Open WYYAHYT opened 7 months ago

WYYAHYT commented 7 months ago

Prerequisite

Task

I'm using the official example scripts/configs for the officially supported tasks/models/datasets.

Branch

main branch https://github.com/open-mmlab/mmdetection3d

Environment

sys.platform: linux
Python: 3.8.17 (default, Jul  5 2023, 21:04:15) [GCC 11.2.0]
CUDA available: True
numpy_random_seed: 2147483648
GPU 0,1,2,3,4: NVIDIA A100 80GB PCIe
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 11.3, V11.3.109
GCC: gcc (GCC) 10.1.0
PyTorch: 2.0.1+cu117
PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201703
  - Intel(R) oneAPI Math Kernel Library Version 2022.2-Product Build 20220804 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.7.3 (Git Hash 6dbeffbae1f23cbbeae17adb7b5b13f1f37c080e)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 11.7
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86
  - CuDNN 8.5
  - Magma 2.6.1
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.7, CUDNN_VERSION=8.5.0, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=0 -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wunused-local-typedefs -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_DISABLE_GPU_ASSERTS=ON, TORCH_VERSION=2.0.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=1, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, 

TorchVision: 0.15.2+cu117
OpenCV: 4.8.0
MMEngine: 0.8.2
MMDetection: 3.0.0
MMDetection3D: 1.1.1+f5c558b
spconv2.0: True

Reproduces the problem - code sample

see command

Reproduces the problem - command or script

 python tools/train.py configs/point-rcnn/point-rcnn_8xb2_kitti-3d-3class.py

Reproduces the problem - error message

03/03 23:39:52 - mmengine - INFO - Epoch(train)  [6][1800/3712]  base_lr: 1.5344e-03 lr: 1.5344e-03  eta: 18:28:07  time: 0.2351  data_time: 0.0058  memory: 78717  grad_norm: 1.6346  loss: 1.3600  rpn_bbox_loss: 0.5540  rpn_semantic_loss: 0.0455  loss_cls: 0.5406  loss_bbox: 0.1908  loss_corner: 0.0291
03/03 23:40:04 - mmengine - INFO - Epoch(train)  [6][1850/3712]  base_lr: 1.5370e-03 lr: 1.5370e-03  eta: 18:27:57  time: 0.2433  data_time: 0.0061  memory: 78899  grad_norm: 1.4929  loss: 1.3052  rpn_bbox_loss: 0.5103  rpn_semantic_loss: 0.0461  loss_cls: 0.5384  loss_bbox: 0.1827  loss_corner: 0.0277
03/03 23:40:15 - mmengine - INFO - Epoch(train)  [6][1900/3712]  base_lr: 1.5395e-03 lr: 1.5395e-03  eta: 18:27:39  time: 0.2316  data_time: 0.0057  memory: 79081  grad_norm: 1.5117  loss: 1.3186  rpn_bbox_loss: 0.5158  rpn_semantic_loss: 0.0426  loss_cls: 0.5414  loss_bbox: 0.1894  loss_corner: 0.0294
/home/xxx/mmdetection3d/mmdet3d/structures/bbox_3d/base_box3d.py:686: UserWarning: DeprecationWarning: points_in_boxes is a deprecated method, please consider using points_in_boxes_part.
  warnings.warn('DeprecationWarning: points_in_boxes is a deprecated '
/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmdet/models/task_modules/samplers/sampling_result.py:126: UserWarning: DeprecationWarning: bboxes is deprecated, please use "priors" instead
  warnings.warn('DeprecationWarning: bboxes is deprecated, '
/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmdet/models/task_modules/samplers/sampling_result.py:132: UserWarning: DeprecationWarning: pos_bboxes is deprecated, please use "pos_priors" instead
  warnings.warn('DeprecationWarning: pos_bboxes is deprecated, '
/home/xxx/mmdetection3d/mmdet3d/structures/bbox_3d/base_box3d.py:686: UserWarning: DeprecationWarning: points_in_boxes is a deprecated method, please consider using points_in_boxes_part.
  warnings.warn('DeprecationWarning: points_in_boxes is a deprecated '
/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmdet/models/task_modules/samplers/sampling_result.py:126: UserWarning: DeprecationWarning: bboxes is deprecated, please use "priors" instead
  warnings.warn('DeprecationWarning: bboxes is deprecated, '
/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmdet/models/task_modules/samplers/sampling_result.py:132: UserWarning: DeprecationWarning: pos_bboxes is deprecated, please use "pos_priors" instead
  warnings.warn('DeprecationWarning: pos_bboxes is deprecated, '
Traceback (most recent call last):
  File "tools/train.py", line 178, in <module>
    main()
  File "tools/train.py", line 142, in main
    runner.train()
  File "/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1735, in train
    model = self.train_loop.run()  # type: ignore
  File "/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/loops.py", line 96, in run
    self.run_epoch()
  File "/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/loops.py", line 112, in run_epoch
    self.run_iter(idx, data_batch)
  File "/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/loops.py", line 128, in run_iter
    outputs = self.runner.model.train_step(
  File "/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/model/base_model/base_model.py", line 116, in train_step
    optim_wrapper.update_params(parsed_losses)
  File "/home/xxx/mmdetection3d/mmdet3d/engine/optim_wrapper/isfp_optimizer_wrapper.py", line 46, in update_params
    self.backward(loss)
  File "/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/optim/optimizer/optimizer_wrapper.py", line 224, in backward
    loss.backward(**kwargs)
  File "/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/torch/_tensor.py", line 487, in backward
    torch.autograd.backward(
  File "/home/xxx/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/torch/autograd/__init__.py", line 200, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 128.00 MiB (GPU 0; 79.21 GiB total capacity; 77.00 GiB already allocated; 64.62 MiB free; 77.47 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

Additional information

Train Point R-CNN with KITTI dataset, it was a bug that had been fixed 2 years ago(refer #1907 and PR#1928), but it seemd that the major releases still have such bug.

WYYAHYT commented 7 months ago

refer to dev/1.0/mmdet3d/models/roi_heads/point_rcnn_roi_head/line213, I simply add decrator @torch.no_grad() for function _assign_and_sample(), and the GPU memory usage remains stable during training.

yuanze1024 commented 6 months ago

refer to dev/1.0/mmdet3d/models/roi_heads/point_rcnn_roi_head/line213, I simply add decrator @torch.no_grad() for function _assign_and_sample(), and the GPU memory usage remains stable during training.

Thank you very much. This solved my problem.

BTW, have you met a problem that the ETA increases instead of decreasing during the training?