当前位置:网站首页>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时候这样做:
边栏推荐
- [basic knowledge of deep learning - 49] kmeans
- [daily accumulation - 07] CUDA multi version switching
- Release Samsung 3J1 sensor: the code implies that the safety of pixel 7 face recognition will be greatly increased
- [basic knowledge of deep learning - 39] comparison of BN, LN and WN
- S32k series chips -- Introduction
- Optimization of embedded C language for indefinite cycles
- 三星将推多款RISC-V架构芯片,5G毫米波射频芯片会率先采用
- 【深度学习基础知识 - 38】L1正则化和L2正则化的区别
- AutoCompleteTextView(输入框预匹配)
- Come to sword finger offer 03. Repeated numbers in the array
猜你喜欢
![[basic knowledge of deep learning - 43] concept of odds ratio](/img/74/d7d1562ada4671864961721b9a1baf.png)
[basic knowledge of deep learning - 43] concept of odds ratio

【深度学习基础知识 - 42】逻辑回归详解

ToggleButton(按钮开关)

FileOutputStream(文件储存)与FileInputStream(文件读取)
![[RCTF2015]EasySQL-1|SQL注入](/img/69/aa1fc60ecf9a0702d35d876e8c3dda.png)
[RCTF2015]EasySQL-1|SQL注入

SQlife(数据库)

【深度学习基础知识 - 43】优势比的概念

访问控制
![[basic knowledge of deep learning - 37] solve the imbalance between positive and negative samples](/img/71/4052607951eb52862a6fd36366f216.png)
[basic knowledge of deep learning - 37] solve the imbalance between positive and negative samples

【深度学习基础知识 - 45】机器学习中常用的距离计算方法
随机推荐
[basic knowledge of deep learning - 48] characteristics of Bayesian network
[deep learning target detection series - 01] what is target detection
Hdu1573 x problem [univariate linear congruence equations]
Chinese character search Pinyin wechat applet project source code
反超华为?爱立信已拿下超过75份5G商用合同
【深度学习基础知识 - 41】深度学习快速入门学习资料
Embedded C language structure
Matplotlib (basic usage)
mysql学习录(三)多表查询、子查询、分页查询、case语句、单行函数
[basic knowledge of deep learning - 38] the difference between L1 regularization and L2 regularization
SharePreference(存储)
[basic knowledge of deep learning - 37] solve the imbalance between positive and negative samples
DNSSEC verification with dig [verify DNSSEC with dig]
BroadcastReceiver(广播)
go-zero单体服务使用泛型简化注册Handler路由
英特尔发布Horse Ridge芯片:22nm工艺,能够控制多个量子位
RadioGroup(单选框)
What's new in helix QAC 2022.2, the ace code static testing tool (2)
[basic knowledge of deep learning - 39] comparison of BN, LN and WN
JS 寻找所有节点sibling childNodes children