Cuda error, happens in the 9th iteration

Abdelrahman_Akram: <p>This error pops up after the 9th iteration of training</p>
<pre><code class="lang-auto">
Traceback (most recent call last):
  File "train.py", line 75, in &lt;module&gt;
    train(args)
  File "train.py", line 64, in train
    output =  CIA_interface.cia_forward(batch ,epoch ,i)
  File "/notebooks/E2E/cia_interface.py", line 90, in cia_forward
    losses =  self.model(example, return_loss = True)
  File "/opt/conda/envs/btngan1/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/notebooks/cia/det3d/models/detectors/voxelnet.py", line 38, in forward
    return self.bbox_head.loss(example, preds)
  File "/notebooks/cia/det3d/models/bbox_heads/mg_head_v4_release.py", line 612, in loss
    iou_pred_loss = iou_pred_loss.sum() / batch_size
RuntimeError: CUDA error: invalid configuration argument
</code></pre>

ptrblck: <p>Could you post the output of <code>python -m torch.utils.collect_env</code> as well as an executable code snippet to reproduce this issue?</p>

Abdelrahman_Akram: <pre><code class="lang-auto">(btngan1) root@n1byw4j8oz:/notebooks# python -m torch.utils.collect_env
Collecting environment information...
PyTorch version: 1.6.0
Is debug build: No
CUDA used to build PyTorch: 10.2

OS: Ubuntu 20.04.1 LTS
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
CMake version: version 3.19.4

Python version: 3.8
Is CUDA available: Yes
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: Quadro P5000
Nvidia driver version: 450.36.06
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.1.0

Versions of relevant libraries:
[pip3] numpy==1.19.2
[pip3] torch==1.6.0
[pip3] torch-scatter==2.0.6
[pip3] torchsummary==1.5.1
[pip3] torchvision==0.7.0
[pip3] vit-pytorch==0.15.2
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               10.2.89              hfd86e86_1  
[conda] mkl                       2020.2                      256  
[conda] mkl-service               2.3.0            py38he904b0f_0  
[conda] mkl_fft                   1.3.0            py38h54f3939_0  
[conda] mkl_random                1.1.1            py38h0573a6f_0  
[conda] numpy                     1.19.2           py38h54aff64_0  
[conda] numpy-base                1.19.2           py38hfa32c7d_0  
[conda] pytorch                   1.6.0           py3.8_cuda10.2.89_cudnn7.6.5_0    pytorch
[conda] torch-scatter             2.0.6                    pypi_0    pypi
[conda] torchsummary              1.5.1                    pypi_0    pypi
[conda] torchvision               0.7.0                py38_cu102    pytorch
[conda] vit-pytorch               0.15.2                   pypi_0    pypi
</code></pre>

Abdelrahman_Akram: <p>The code is very big I will try to but it on a github repo and send it</p>

ptrblck: <p>Thanks! Could you update PyTorch in the meantime to the latest nightly release (in a new virtual env, in necessary) and rerun your code?</p>

Abdelrahman_Akram: <p>I will try, the thing is that there is to much dependencies on the pytorch and cuda version due to there is a lot of libraries to setup like the IOU3D_Cuda inhereted from the PointRCNN model and some other things. Can you tell me what is this error for or what is meant by it, it is non intuitive error, and the thing is that the line that produces the error executed normally 8 times before.</p>

ptrblck: <p>The error is raised by an invalid kernel launch config.<br>
In case you are using a custom CUDA extension, you could try to rerun the code via <code>CUDA_LAUNCH_BLOCKING=1 python script.py args</code> and check the kernel launch configs in the failing operation given by the stack trace.</p>

Abdelrahman_Akram: <pre><code class="lang-auto">Traceback (most recent call last):
  File "train.py", line 75, in &lt;module&gt;
    train(args)
  File "train.py", line 64, in train
    output =  CIA_interface.cia_forward(batch ,epoch ,i)
  File "/notebooks/E2E/cia_interface.py", line 90, in cia_forward
    losses =  self.model(example, return_loss = True)
  File "/opt/conda/envs/btngan1/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/notebooks/cia/det3d/models/detectors/voxelnet.py", line 38, in forward
    return self.bbox_head.loss(example, preds)
  File "/notebooks/cia/det3d/models/bbox_heads/mg_head_v4_release.py", line 612, in loss
    iou_pred_loss = iou_pred_loss.sum() / batch_size
RuntimeError: CUDA error: invalid configuration argument
</code></pre>
<p>it gives me the same error<br>
The error is in the sum() function and yes I uses IOU3D_CUDA  from this repo: <a href="https://github.com/sshaoshuai/PointRCNN" class="inline-onebox" rel="noopener nofollow ugc">GitHub - sshaoshuai/PointRCNN: PointRCNN: 3D Object Proposal Generation and Detection from Point Cloud, CVPR 2019.</a></p>

ptrblck: <p>In that case you could e.g. add debug prints to the CUDA code and check the launch configs, as apparently one kernel call (in the 9th iteration) is using invalid values (I guess the grid or block dimension might be too large).</p>

Abdelrahman_Akram: <p>Well, I’m new using CUDA extensions, could you illustrate to me where to put it as the file extension or something like this.</p>

Abdelrahman_Akram: <p>Okay now I changed the random seed, and the error became in the 11th iteration<br>
<a class="mention" href="/u/ptrblck">@ptrblck</a></p>

ptrblck: <p>You could check the launch config e.g. <a href="https://github.com/sshaoshuai/PointRCNN/blob/1d0dee91262b970f460135252049112d80259ca0/lib/utils/iou3d/src/iou3d_kernel.cu#L359">here</a> and make sure the values are valid.<br>
I’m not familiar with the code base and this was the first <code>.cu</code> file I’ve found, so the error could of course be raised by another kernel.</p>