cuda常见报错

[复制链接]
查看784 | 回复0 | 2023-8-23 11:57:44 | 显示全部楼层 |阅读模式
RuntimeError: CUDA error: device-side assert triggered

CUDA kernel errors might be asynchronously reported at some other API call,
so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
/pytorch/aten/src/ATen/native/cuda/IndexKernel.cu:93: 
operator(): block: [0,0,0], thread: [70,0,0] 
Assertion index >= -sizes && index < sizes && "index out of bounds" failed.
   Assertion `index >= -sizes && index < sizes && "index out of bounds"
  数据超出了边界。在给出label的时间,我的数据集在某个标签上会给进去一个小于零大概大于种别数的一个标签,大白话就是设定了模型分类数量为4,但是数据会合有大于4个种别则会报错,少于4个是不会报错。
  
  办理方法:修改预设的种别数量,class_map内里预先写好的种别个数和实际的数据集内里的标签种类和个数不同。可以要修改class_map大概修改数据集。
  
device-side assert triggered,CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.

/pytorch/aten/src/ATen/native/cuda/IndexKernel.cu:93: operator(): block: [0,0,0], thread: [28,0,0] Assertion index >= -sizes && index < sizes && "index out of bounds" failed.
   标签索引不正确,即标签编号大于界说标签,界说crf层的时间标签的种别数和yaml中的种别数不同,要么修改标签文件,要么修改层的种别数量界说
  

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

缘故原由:
  1. a = str(trues_cls.detach().numpy()[0]) #这样是错误的
复制代码


  • numpy不能读取CUDA tensor 须要将它转化为 CPU tensor。
办理方法:


  • CUDA tensor格式的数据改成numpy时,须要先将其转换成cpu float-tensor随后再转到numpy格式。
  1. a= str(trues_cls.detach().cpu().numpy()[0])  # 这样是正确的​​​​​​​
  2. # detach(): 返回一个新的Tensor,但返回的结果是没有梯度的。
  3. # cpu():把gpu上的数据转到cpu上。
  4. # numpy():将tensor格式转为numpy
复制代码
RuntimeError: CUDA error: invalid device ordinal

CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
   输入的显卡卡号错了,可以切换显卡号的数字实验
  
不同的设备同样参数的情况下练习效果不同等的标题

   缘故原由:dropout层的随机性,当输入dropout层的数据维度大于57346时,从第57347位开始不同显卡的效果会不一样,缘故原由是不同显卡的数据采样方法在第57346位后存在差别。
  
  办理方法:手动构造一个由randn实现的dropout层,可以实现跨机效果同等
  伯努利分布,使用torch.tensor,与cuda有关,randn和数字有关
  
服务器存在两个卡,但只能用其中一张卡跑程序

   缘故原由:情况使用了export,导致只有一个 GPU可见 (GPU:0),而程序中使用 GPUs:1。
  输入export CUDA_VISIBLE_DEVICES = '0,1',让设备变为两个,方便在情况中随意切换
  


来源:https://blog.csdn.net/qq_41900846/article/details/128536185
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则