When using PyTorch or Python, you may come across a CUDA error. This can be caused by an error in the number of classes or labels in your output layer, or by an incorrect loss function input. To fix this error, use the CUDA_LAUNCH_BLOCKING=1 flag.
When attempting to use your GPU with this error, you should first try to restart the kernel session. In this way, you will be able to use the GPU again in the same kernel session. After restarting your kernel session, you should see a list of kernels. In the list, you will see an option to stop or edit each kernel.