tensorflow: tf.mul after tf.split + tf.sigmoid produces wrong numerical results with MKL enabled
Click to expand!
Issue Type
Bug
Have you reproduced the bug with TF nightly?
No
Source
binary
Tensorflow Version
intel-tensorflow 2.8 - 2.12
Custom Code
No
OS Platform and Distribution
Ubuntu 22.04
Mobile device
No response
Python version
3.10
Bazel version
No response
GCC/Compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current Behaviour?
When running with an MKL enabled tensorflow (e.g. intel-tensorflow from pypi) (or self-compiled with --config=mkl
). Starting with tensorflow 2.8.0 up until 2.12.0 The attached code produces the wrong numerical result. (1.7615 vs expected 2.6439).
If line 25 is changed to m = sig * (b + 0.0)
one can get the correct result.
This issue does not occur if installing “vanilla” tesorflow from pip with pip install tensorflow
.
This issue also does not occur if one uses tf.exp
or tf.log
instead of tf.sigmoid
.
Standalone code to reproduce the issue
#!/usr/bin/env python3
import math
import tensorflow as tf
import numpy as np
def sigmoid(x):
return 1 / (1 + math.exp(-x))
data = [[[2.0, 3.0]]]
tf.compat.v1.disable_eager_execution()
s = tf.compat.v1.Session()
p = tf.compat.v1.placeholder(dtype=tf.float32)
a, b = tf.split(p, 2, axis=2)
sig = tf.sigmoid(a)
m = sig * b
out = s.run([p, m], feed_dict={p: data})
print(out)
print('computed: ', out[-1][0,0,0])
print('expected: ', sigmoid(data[0][0][0]) * data[0][0][1])
Relevant log output
2023-06-21 18:37:35.713027: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-06-21 18:37:35.715264: I tensorflow/core/common_runtime/process_util.cc:146] Creating new thread pool with default inter op setting:
[array([[[2., 3.]]], dtype=float32), array([[[1.7615942]]], dtype=float32)]
computed: 1.7615942
expected: 2.642391233933647
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 22 (4 by maintainers)
Commits related to this issue
- ref https://github.com/tensorflow/tensorflow/issues/60941 — committed to albertz/playground by albertz a year ago
Hi @curufinwe ,
I am acknowledging that now the issue can be replicable from my side as per attached gist. The issue persists with
intel-tensorflow
package only but not with TF package itself which was tested in attached gist.Though the code involves V1 style session there is difference in outputs wr.t
intel-tensorflow
andtensorflow
. Hence assigning the issue to respective team for their comments.CC : @TensorFlow-MKL for commenting o this issue. CC: @learning-to-play