基于Torch,测Qwen 3B训练的精度对比。
排查所有的torch.ops,具体会定位到tensor idx
使用工具:
前提 :bf16下,设置atol=0.001, rtol=0.001,单机8卡做Qwen 2.5训练。
1.现象:NPU vs CPU部分算子精度超过atol, rtol
2.排查工作:可以定位到出现误差layer的具体ops
3.堵点:客户测到的误差大约在0.03+,这个现象是否正常
比如Qwen2MLP:
...... input ........
0: Tensor ,
1: Tensor ,
...... output ........
Tensor
...... error idx ........
Element at index (0, 835, 4909) is not close:0.34765625(npu:5) vs 0.349609375(cpu)
Element at index (0, 841, 5094) is not close:0.33203125(npu:5) vs 0.330078125(cpu)
Element at index (0, 846, 5370) is not close:-0.421875(npu:5) vs -0.423828125(cpu)
Element at index (0, 858, 707) is not close:-0.328125(npu:5) vs -0.326171875(cpu)
Element at index (0, 869, 1463) is not close:-0.6171875(npu:5) vs -0.62109375(cpu)
Element at index (0, 875, 4798) is not close:-0.76953125(npu:5) vs -0.765625(cpu)
Element at index (0, 897, 4008) is not close:-0.392578125(npu:5) vs -0.390625(cpu)
问题答复:
正常现象,它把npu的输入直接转cpu然后计算。这个误差很有可能是转换的时候,内存排列contiguous产生的影响,所以会超过千分之一。