tensorflow: Bug in tf.einsum - Returns different values from np.einsum for identical parameters
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- TensorFlow installed from (source or binary): Binary (Anaconda)
- TensorFlow version (use command below): 1.13.1
- Python version: 3.7.3
- CUDA/cuDNN version: 10.0/7.6.0
- GPU model and memory: NVIDIA Titan X (Pascal), 12 GB
Describe the current behavior
tf.einsum returns buggy values compared to np.einsum for identical parameters. Here is the current output (please find code below):
np: 8.610251426696777
tf: 0.0
Please also note that the same code works as expected when running on the CPU. It also works correctly on the GPU in TF 1.12.0, CUDA/cuDNN 9.0/7.3.1 and Python 3.6.8.
Describe the expected behavior
Here is the expected output:
np: 8.610251426696777
tf: 8.610251426696777
Code to reproduce the issue
from __future__ import (
absolute_import,
division,
print_function
)
import tensorflow as tf
import numpy as np
tf.enable_eager_execution()
einsum_string = "bijk,bijk->bij"
# load values
S_h_numpy = np.load("./S_h.npy")
S_h = tf.convert_to_tensor(S_h_numpy, dtype=tf.float32)
h_numpy = np.load("./h.npy")
h = tf.convert_to_tensor(
h_numpy,
dtype=tf.float32
)
# perform einsum
ht_S_h_numpy = np.einsum(einsum_string, h_numpy, S_h_numpy)
ht_S_h = tf.einsum(einsum_string, h, S_h)
print("np: {np_val}\ntf: {tf_val}".format(
np_val=ht_S_h_numpy[2, 191, 191],
tf_val=ht_S_h[2, 191, 191],
))
Other info / logs
Here are the input tensors used in the example: input_tensors.zip.
The tensors are of shape (4, 192, 192, 2). I could not choose a smaller example because the buggy values appear only in part of the second and all of the following batch items. The bug therefore seems to be connected to the size of the input.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (11 by maintainers)
I am able to reproduce the issue on colab with Tensorflow 1.13.1. Thanks!