Jittor / jittor

Jittor is a high-performance deep learning framework based on JIT compiling and meta-operators.
https://cg.cs.tsinghua.edu.cn/jittor/
Apache License 2.0
3.08k stars 311 forks source link

jt.mean produces computation results with insufficient floating point precision #342

Open Schizophreni opened 2 years ago

Schizophreni commented 2 years ago

A simple testing code example

import jittor as jt
# create a tensor 
arr = jt.ones((1, 3, 20, 20))
# 1st case
arr.mean()  # expect to get 1, but not in reality
# 2nd case
arr.mean(dims=[0, 1]).mean(dims=[0, 1]) # expect to get 1, but not in reality
# 3rd case
arr.data.mean() # expect to get 1, and get 1 in reality. However, grad information is removed

screenshot of the above example

1655649628(1)

This may be a bug in jittor, and it has brought inconsistent results with numpy or pytorch in terms of SSIM metrics.

Schizophreni commented 2 years ago

The above results may be due to the IEEE floating representation. However, when arr has shape [1, 3, 321, 481], jt.mean(arr) offers unexpected results with error ~4.3e-3 as shown below. image

Rlee719 commented 2 years ago

Same result in my case, which leads to imprecise SSIM.