当前位置:网站首页>pytorch 常见报错
pytorch 常见报错
2022-07-27 17:10:00 【遨游的菜鸡】
文章目录
1.RuntimeError: cuda runtime error (59) : device-side assert triggered
分类时有数据的标签超出了分类数目的标签、或者小于0,就会报这个错。
比如数据的标签从0开始,最大标签值是118,那么self.fc=nn.Linear(hidden_size,118)就会报错,因为从0到118,共119个类别
改正:因此self.fc=nn.Linear(hidden_size,119)
https://www.cnblogs.com/henuliulei/p/13258297.html
https://blog.csdn.net/qq_31049727/article/details/90671689
2.CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling cublasCreate(handle)
当时报这个错的时候是因为发生了错误1当中的标签值和分类数目不匹配的结果,即标签值从0到118,但我给的分类数目是80,即self.fc=nn.Linear(hidden_size,80),这样就会报错。
改正:当时分类数目给定80是因为set(train_label)=80,即0-118并不是连续的,有些值没有用到,因此要对数据的标签值进行重新划分,既让数据得标签值变成连续的,范围为0-79或1-80
3.pytorch BrokenPipeError: [Errno 32] Broken pipe
该问题的产生是由于windows下多线程的问题,和DataLoader类有关,具体细节点这里Fix memory leak when using multiple workers on Windows。
解决方案:
修改调用torch.utils.data.DataLoader()函数时的 num_workers 参数。该参数官方API解释如下:
num_workers (int, optional) – how many subprocesses to use for data loading. 0 means that the data will be loaded in the main process. (default: 0)
该参数是指在进行数据集加载时,启用的线程数目。截止当前2018年5月9日11:15:52,如官方未解决该BUG,则可以通过修改num_works参数为 0 ,只启用一个主进程加载数据集,避免在windows使用多线程即可。
或者将电脑无用程序关闭:
https://blog.csdn.net/u014380165/article/details/79058479
4.AssertionError

这个错误发生在self.multihead_attention = nn.MultiheadAttention(embed_dim=num_hiddens * 2, num_heads=4) attn_output, attn_output_weights = self.multihead_attention(self.query,self.key,value)
造成错误的原因有两个:
1.nn.MultiheadAttention接受的query、key、value的形状是【seq_len,batch_size,embedding_dims】;
因此哪怕在init()中定义query=【batch_size,seq_len,embedding_dims】,然后在forward()中交换query维度变为【seq_len,batch_size,embedding_dims】也会出错
解决:直接在init()中定义query=【seq_len,batch_size,embedding_dims】,key同理;value在forward()中交换维度后输入self.multihead_attention即可(value在forward中交换并不会出错)
2.因为query和key在init中具体维度已经定了,因此在train时候,有的数据batch大小不等于batch_size就会报错,因此在具体train时候这样做:
边栏推荐
猜你喜欢

ArrayAdapter(数组适配器)与SimpleAdapter(简单适配器)

GestureOverlayView(手势识别2)

Intent(有无返回值得跳转)

Introduction to Flink operator

Detailed interpretation of IEC104 protocol (I) protocol structure
![[basic knowledge of deep learning - 46] Bayesian theorem and conditional probability formula](/img/9f/b9d7503404e068495fd8613df29366.png)
[basic knowledge of deep learning - 46] Bayesian theorem and conditional probability formula

BroadcastReceiver(广播)

Combinatorics -- permutation and combination

FileOutputStream(文件储存)与FileInputStream(文件读取)

【深度学习基础知识 - 46】贝叶斯定理与条件概率公式
随机推荐
【深度学习基础知识 - 39】BN、LN、WN的比较
Remember an unprepared internship interview
【深度学习基础知识 - 47】贝叶斯网络与朴素贝叶斯
Flink introduction and operation architecture
【深度学习基础知识 - 42】逻辑回归详解
Install Talib Library under Anaconda
【深度学习基础知识 - 49】Kmeans
嵌入式C语言对次数不定的循环的优化
A lock faster than read-write lock. Don't get to know it quickly
Unity-FairyGUI播放视频(Lua)
HDU1171_ Big event in HDU [01 backpack]
Adhering to the integration of software and hardware, one Hengke makes efforts to the intelligent educational robot market
File operation protection
5W bonus pool / for colleges and universities, 2022 legal science and technology innovation competition is in progress
Matplotlib (basic usage)
英特尔发布Horse Ridge芯片:22nm工艺,能够控制多个量子位
An unknown fastcgi error occurred in IIS: 0x80070005
爱立信承认在中国等五国行贿,向美支付10.6亿美元罚款
王牌代码静态测试工具Helix QAC 2022.2中的新增功能(2)
ReferenceError: __ dirname is not defined in ES module scope