Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tensorflow 1.x and 2.x produce different results during inferencing based on the same parameters #66212

Open
jamesYu365 opened this issue Apr 22, 2024 · 4 comments
Assignees
Labels
comp:apis Highlevel API related issues TF 1.15 for issues seen on TF 1.15 type:bug Bug

Comments

@jamesYu365
Copy link

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

tf 1.15 and tf 2.13

Custom code

Yes

OS platform and distribution

Windows

Mobile device

No response

Python version

3.8

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

None

GPU model and memory

None

Current behavior?

I trained a LSTM in Tensorflow1.15, then load the saved model parameters on Tensorflow2.13, the prediction is significantly different from Tensorflow1.15.

Standalone code to reproduce the issue

https://drive.google.com/file/d/1spHn4waDE3vNQzslA7AD06E0XQ1i-qL_/view?usp=sharing

Relevant log output

No response

@sushreebarsa
Copy link
Contributor

@jamesYu365 Could you have a look at the TensorFlow Compatibility Checker to identify deprecated or removed operations from your TensorFlow 1.x model. The tool suggests alternative operations for migration. Thank you!

@sushreebarsa sushreebarsa added stat:awaiting response Status - Awaiting response from author comp:apis Highlevel API related issues TF 1.15 for issues seen on TF 1.15 labels Apr 23, 2024
@jamesYu365
Copy link
Author

Hello, thank you for your prompt response. Following your instructions, I added compat.v1 when importing the TensorFlow-related modules:

import tensorflow.compat.v1 as tf
from tensorflow.compat.v1.keras.models import Sequential
from tensorflow.compat.v1.keras.layers import LSTM, Dense

The result now is the same between two versions.
However, I'm still curious why this happened. Since the LSTM model involves only basic arithmetic operations, I wonder why TensorFlow 1 and TensorFlow 2 give different results.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Apr 23, 2024
@sushreebarsa
Copy link
Contributor

@jamesYu365 Using compat.v1 likely mitigated the issue by forcing TF2 to use a more TF1-like behavior, potentially including non-deterministic behavior. This might have made the results from both versions more comparable.
Thank you!

@sushreebarsa sushreebarsa added the stat:awaiting response Status - Awaiting response from author label Apr 23, 2024
@jamesYu365
Copy link
Author

Thank you for your prompt response again. I'm still puzzled by the non-deterministic behavior you mentioned, considering that all the parameters and inputs are fixed. Where did this non-deterministic behavior come from? Could you please elaborate more on it? Perhaps you could provide some links related to this question, as I'm new to using TensorFlow. Thanks.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:apis Highlevel API related issues TF 1.15 for issues seen on TF 1.15 type:bug Bug
Projects
None yet
Development

No branches or pull requests

4 participants