RuntimeError: CUDA error: device-side assert triggered Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions
时间: 2023-10-29 22:53:22 浏览: 87
在训练IDDPM时遇到了"RuntimeError: CUDA error: device-side assert triggered"的错误提示,这个错误表示在CUDA计算过程中触发了设备端断言。为了解决这个问题,可以尝试编译时加上`TORCH_USE_CUDA_DSA`选项来启用设备端断言。这个选项可以让CUDA在发生错误时阻塞并报告详细的错误信息,有助于更好地进行调试。你可以按照这个方法尝试解决这个问题。引用<span class="em">1</span><span class="em">2</span><span class="em">3</span>
相关问题
RuntimeError: CUDA error: device-side assert triggered Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
这个错误通常是由于CUDA设备端断言失败引起的。要解决此问题,可以按照以下步骤操作:
1. 确保你的PyTorch版本是1.7或更高版本,因为`TORCH_USE_CUDA_DSA`选项只在这些版本中可用。
2. 在你的代码中添加以下行,启用设备端断言:
```python
import os
os.environ['TORCH_USE_CUDA_DSA'] = '1'
```
或者,你也可以在终端中设置环境变量:
```shell
export TORCH_USE_CUDA_DSA=1
```
注意:启用设备端断言可能会影响性能,因此只在调试期间使用它。
3. 如果你仍然遇到问题,可以尝试使用CUDA-MEMCHECK工具来调试CUDA内存问题。你可以使用以下命令运行你的代码:
```shell
cuda-memcheck python your_script.py
```
这将会输出有关CUDA内存错误的详细信息。
torch.exp(-BCE_loss) RuntimeError: CUDA error: device-side assert triggered
根据提供的引用内容,出现这个错误的原因可能是GPU显存内存不够。解决方法如下:
1. 减小batch_size。
2. 确保传入传出的通道数和net最终全连接输出的class数目对得上labels。
3. 确保devices具体到某一个,而不是一个list。
4. 关闭程序重新连接。
另外,可以在测试阶段添加如下代码进行检验net的输入输出正确性:
```python
X = torch.rand(size=(32, 3, 224, 224)).to(devices[0])
for layer in net:
X = layer(X)
print(layer.__class__.__name__,'output shape:\t', X.shape)
```
如果以上方法都无法解决问题,可以尝试使用更高内存的GPU或者使用CPU运行程序。
关于`torch.exp(-BCE_loss)`出现`RuntimeError: CUDA error: device-side assert triggered`的问题,可能是因为BCE_loss的值过大,导致计算出的exp值超出了CUDA的范围。解决方法是将BCE_loss的值缩小,或者使用更高内存的GPU运行程序。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)