【笔记】【Pytorch】关于torch.matmul和torch.bmm的输出tensor数值不一致问题
2018-01-25 11:07
2211 查看
发现
对于torch.matmul和torch.bmm,都能实现对于batch的矩阵乘法:a = torch.rand((2,3,10)) b = torch.rand((2,2,10)) ### matmal() res1 = torch.matmul(a,b.transpose(1,2)) print res1 """ ... [torch.FloatTensor of size 2x3x2] """ ### bmm() res2 = torch.bmm(a,b.transpose(1,2)) print res2 """ ... [torch.FloatTensor of size 2x3x2] """
从打印出来的几位数字来看,嗯,是一样的,但是在用等式(或者torch.eq())检查是却发现了问题,竟然有很多不一样的元素
print torch.eq(res1,res2) """ (0 ,.,.) = 1 0 1 1 1 1 (1 ,.,.) = 0 1 1 1 1 1 [torch.ByteTensor of size 2x3x2] """
将一样的数值在ipython直接输出(print会截断位数)
>>>res1[0,0,0] 2.229752540588379 >>>res2[0,0,0] 2.229752540588379
再来看看不一样的
>>>res1[0,0,1] 3.035151720046997 >>>res2[0,0,1] 3.035151481628418
可以看到从小数点后位7位开始两个输出值出现了差异!
结论
所以说在tensor的同样操作下,出现不一致结果(精度上)的可能性很大,在做相等条件判断时需要注意,即使同样的输入同样的操作可能出现不一样的结果。之后又尝试对于a,b的位置进行交换,竟然发现即使是同一个函数操作,如matmal(),matmul(a,b.transpose(1,2))和matmul(b,a.transpose(1,2)).transpose(1,2)结果也存在不一样的元素。
相关文章推荐
- 关于textarea标签输出数据库数据时出现大量空格导致格式不一致的问题
- 关于空格和回车带来的输入输出不一致问题,使用了一个奇怪的replace
- 关于指针所指数值输出的问题
- 关于python 2.7要求输出汉字问题
- 嵌入式学习笔记--关于ARM中SWP指令的执行顺序问题【待验证】
- 关于从对话框获取数值的问题,谢谢
- 关于SQLServer2005的学习笔记——统计学自动分组问题
- 关于数据输入之先输入int数值在输入string的一些小问题
- 一次关于loback日志无法输出到文件的问题解决
- [C++基础]cout与wcout,printf与wprintf,ofstream与wofstream关于输出中文的问题解决
- 关于vmstat,top,ps aux查看的cpu占用率不一致的问题
- 关于Android SQLite3多线程并发问题,学习笔记。
- 关于输出较长 行数较多的结果不能全部显示 屏幕缓存区问题
- 关于SQLServer2005的学习笔记——多触发器执行问题
- vc6.0运用mysql数据库中的编码所导致的乱码问题(接收和输出的编码必须要一致)
- 关于SQL Server中将数值类型转换为字符串的问题
- Python学习笔记--关于split的分割问题
- 关于linux系统和tomcat时间不一致的问题
- 关于vs2010 中c++输出字符串到txt文件中的格式问题
- 【随笔】关于算法竞赛中使用文件输入输出和文件名的规定等问题