微凉的衣柜 2021-06-03 00:16 采纳率: 64.7%
浏览 292
已采纳

(Libtorch) FP16 tensor 错误 C10error

I got c10 error when I define a FP16 tensor and use torch::max() and torch::sqrt(). The code are shown as follows:

当我定义一个FP16的tensor并使用torch::max() 和 torch::sqrt()函数时会出现C10 error错误,代码如下:

	float test_float[3][3] = { {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0 },{7.0, 8.0, 9.0} };
	torch::Tensor test_float_tensor = torch::from_blob(test_float, { 3, 3 }).to(at::kCPU).to(torch::kFloat16);
	torch::sqrt(test_float_tensor);
	torch::max(test_float_tensor, 1, true);

错误如下:

当把tensor改为FP32或FP64,错误就消失了,代码如下:

	float test_float[3][3] = { {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0 },{7.0, 8.0, 9.0} };
	torch::Tensor test_float_tensor = torch::from_blob(test_float, { 3, 3 }).to(at::kCPU).to(torch::kFloat32);
	torch::sqrt(test_float_tensor);
	torch::max(test_float_tensor, 1, true);

为什么会造成这种错误呢?采用FP16 tensor,执行torch::sum()函数时并不会出现这个错误。是FP16 tensor有什么不适用的地方吗?求解答,谢谢!

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法