Repository navigation
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
|
@Glencsa 后续该任务的PR模版都改成: |
好的好的 |
|
不好意思,上次通知错了,本任务的PR模版为 |
| HOSTDEVICE OutT operator()(InT in) const { | ||
| if constexpr (std::is_same<OutT, phi::dtype::float16>::value) { | ||
| float val = static_cast<float>(in); | ||
| if (val > 65504.0f && val <= 65519.0f) { |
There was a problem hiding this comment.
你说的16个数一起处理,和它的rounding行为有什么必然的联系吗?我看了 https://github.com/pytorch/FBGEMM/blob/3f2cd6e070b7266248ec17c77772068b90504f8f/src/FbgemmFloat16ConvertAvx512.cc#L20 代码,也没有哪里说65504-65519之间不用变成inf,我只看到它用了CPU的_mm512_cvtps_ph指令,而我们这里是GPU的,是不是设备不同行为也不同?
There was a problem hiding this comment.
astype, cast and Tensor.cast 这几个API也是CPU的,paddle中直接使用的static_cast,pytorch中用到了immintrin.h。这个结果的原因推测是pytorch中代码使用了immintrin.h的宏定义_MM_FROUND_TO_NEAREST_INT导致的rounding行为。函数原型:__m256i _mm512_cvtps_ph(__m512 src, const int rounding);//rounding传入的是_MM_FROUND_TO_NEAREST_INT,其他地方没找到rounding和clip相关的操作。
There was a problem hiding this comment.
改了你的PR简介,你看看有没有道理,以及测试一下修改是否影响性能
There was a problem hiding this comment.
PR简介没有问题,请问如何测试算子性能?
There was a problem hiding this comment.
我仔细想了一下,我认为这样改仍然是不对的,完整的测试应该是确保所有取值的 float32 -> float16 行为都和GPU一致,而不是只改接近INF的部分,这样改可能还有别的值有问题。
float32一共有2^32个取值,应该全部遍历一遍进行对比,如果问题根因在rounding模式上,我估计肯定还有别的值有问题,只是用整数的输入没测出来而已。
总之,这个PR还是没有说清楚本质的原因,缺乏全量的覆盖测试,我没法给通过。
There was a problem hiding this comment.
你说的有道理,我注意到了,我看看还有没有其他修改方法。
|
Sorry to inform you that b99309d's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
PR Category
Operator Mechanism
PR Types
Bug fixes
Description
Paddle CPU 相比 GPU 以及 Torch CPU/GPU 的 float32 -> float16 在接近inf时的行为不同,可通过以下代码进行测试:
输出:
Tensor(shape=[32], dtype=float16, place=Place(cpu), stop_gradient=True, [65472., 65472., 65472., 65472., 65504., inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. ]) Tensor(shape=[32], dtype=float16, place=Place(gpu:0), stop_gradient=True, [65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. , inf. ]) tensor([65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf], dtype=torch.float16) tensor([65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., 65504., inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf], device='cuda:0', dtype=torch.float16)分析:
因此,本PR修改代码将paddle和pytorch做对齐,增加测试数据,三个API测试结果均可通过:
