-
Notifications
You must be signed in to change notification settings - Fork 75.3k
tf.range have accumulate floating point error on CPU #58133
Copy link
Copy link
Closed
Labels
Description
Click to expand!
Issue Type
Bug
Source
binary
Tensorflow Version
tf 2.10.0
Custom Code
Yes
OS Platform and Distribution
Linux Ubuntu 20.04
Mobile device
No response
Python version
No response
Bazel version
No response
GCC/Compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current Behaviour?
tf.range have accumulate greater and greater floating point error on CPU. In the example below, range(- 10, 10, 0.01) gives [... 9.980267 9.990267] when the correct result should be [... 9.98 9.99], and this deviation is too much in my opinion.
Standalone code to reproduce the issue
import tensorflow as tf
with tf.device('cpu'):
tensor1 = tf.range(- 10, 10, 0.01) # [-10., -9.99 ... 9.980267 9.990267]
print(tensor1)
with tf.device('gpu'):
tensor2 = tf.range(- 10, 10, 0.01) # [-10., -9.99 ... 9.98 9.99]
print(tensor2)
assert np.allclose(tensor1, tensor2) # AssertionErrorRelevant log output
tf.Tensor([-10. -9.99 -9.98 ... 9.970266 9.980267 9.990267], shape=(2000,), dtype=float32)
tf.Tensor([-10. -9.99 -9.98 ... 9.969999 9.98 9.99 ], shape=(2000,), dtype=float32)
AssertionErrorReactions are currently unavailable